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:
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:
1.2.1
Characters are put in single quotes.
A string of characters is enclosed in quotes as a whole;
thus 'ab c' is a sequence of four character-symbols (the third symbol is a blank). A string of characters cannot be broken by line transfers. A string of characters enclosed in double quotes is a compound symbols (see below).
There are three special characters which are referred to as escape characters: single quote ' , double quote " , backslash \ . They are used in lexical analysis, therefore we need a special representation for them in the cases where they just stand for themselves, not as the means of lexical analysis. We also need a representation of unprintable characters. Both goal are achieved by using escape sequences, which are sequences of characters starting with the backslash \ .
sequence stands for ------------ ------------ \' single quote ' \" double quote " \\ backslash \ \n new line \r carriage return \t horizontal tab \xHH character-byte whose code is HH, where each H is an arbitrary hexadecimal digit.
An escape sequence enter a quoted string. Escape characters (and, of course, unprintable characters) cannot be used otherwise.
1.2.2 A compound symbol is a sequence of arbitrary characters enclosed in double quotes, e.g. "a+B-c". As with strings, an escape character may enter a compound symbol only as its escape sequence. Unlike a single-quoted string, a compound symbol is handled as a whole: exactly one symbol.
1.2.3 An identifier is a sequence of characters which begins with a letter and may include letters, digits, and characters dash - , and underscore _ . An identifier may be enclosed in double quotes, then it can be seen as a special case of a compound symbol. This operation does not alter it: "abc" is the same as abc. As in a compound symbol, the case of the letters in an identifier is significant: abc is not the same as Abc.
1.2.4 Macrodigits are whole non-negative numbers. They are represented by strings of decimal digits. The value of the largest macrodigit is 232 - 1.
1.3 A variable is a type indicator followed by a dot, followed by an index. Type indicators are:
1.4 Blanks, tabs and new-lines (known collectively as white space) are ignored by the Refal compiler when they appear between lexical elements. They often serve as separators -- preventing lexical units from merging into something else, as in the case of a sequence of identifiers or numbers. At the same time, lexical elements can follow each other without intervening white space as long as this does not interfere with lexical analysis.
The syntax of Refal expressions in the BNF form is:
expression ::= empty term expression term ::= symbol variable (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 f-name ::= identifier 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 }
In line comments we usually refer to the following sentence(s); slashed comments