The lexical units of Refal are divided into special signs,
symbols, and variables. Blanks in any number, as well as line
transfers, may
appear between lexical units. A blank
becomes a lexical unit when it appears inside a quoted string.
1.1
Special signs are:
equal sign = ``replace by'' semicolon ; ``otherwise'' colon : ``is'' comma , ``where'' dot . ``index follows'' braces { } ``begin'' and ``end''
There are also special system keywords: $ENTRY
and
$EXTERNAL
(the latter can also be spelled $EXTERN
or $EXTRN
).
System keywords must be in capital letters.
1.2 Symbols are:
real-number ::= unsigned-real - unsigned-real + unsigned-real
unsigned-real ::= digits . digits digits . digits E digits digits E digits
digits ::= decimal-digit decimal-digit digits
"Jimmy's Pizza" 'Jimmy''s Pizza'represent the same Refal object. To avoid spurious quotes, separate quoted strings by blanks when one follows immediately after another. The size of a string is limited to 255 characters, so break up long strings.
The syntax of Refal expressions in the BNF form is:
expression ::= empty term expression term ::= symbol variable (expression) <f-name expression> f-name ::= identifier empty ::=
A pattern expression, or pattern, is an expression which includes no activation brackets. A ground expression is an expression which includes no variables.
A Refal program is a list of function definitions (f-definition's -- see below) and external function declarations (external-decl). Semicolons must be used to separate an external declaration from the following function definition; they may also separate function definitions.
program ::= f-definition f-definition program f-definition ; program external-decl ; program program external-decl ; f-definition ::= f-name { block } $ENTRY f-name { block } external-decl ::= $EXTERNAL f-name-list $EXTERN f-name-list $EXTRN f-name-list f-name-list ::= f-name f-name , f-name-list block ::= sentence sentence ; sentence ; block sentence ::= left-side conditions = right-side left-side conditions , block-ending left-side ::= pattern conditions ::= empty , arg : pattern conditions arg ::= expression right-side ::= expression block-ending ::= arg : { block }
Comments can be inserted into a program as defined above. They are ignored by the Refal compiler. There are two kinds of comments:
In line comments we usually refer to the following sentence(s); slashed comments refer to the preceding text.