Ground Expressions

All values processed by Refal Plus programs are so-called ground expressions.

Here are three examples of ground expressions:

    "John" "Smith" 33 "years"
    ("Dave" 17) ("Mary" 24) ("Elizabeth" 6)
    ("my" "house") "has" ("large" ("light" "windows"))

The salient feature of the above examples is the use of parentheses. If we modify the expressions by rearranging the parentheses, the structure of the expressions will be modified, changing the implied meaning of the expressions.

In addition to parentheses, the above expressions contain symbols. Here are a few examples of symbols:
    "John" "johN" "bye-bye" 1988 -99999999999999

In general, ground expressions consist of symbols and parentheses. A ground expression is a sequence of zero or more ground terms. A ground term is either a symbol or a ground expression enclosed in parentheses ( and ). Thus, a ground expression is a sequence of symbols and parentheses, in which the parentheses are "properly paired".

When in computer memory, ground expressions are usually stored as tree-structured objects. Nevertheless, in order to be input or output (printed, written to a file, read from a file, etc.), a ground expressions has to be represented as a linear sequence of characters.

Refal Plus implementations enable the ground expressions to be input or output, with all necessary conversions performed automatically.

A ground expression represented by a character stream is a sequence of tokens, each token representing either a parenthesis or a symbol. Tokens may be separated by spaces, which are ignored unless they are essential to separate two consecutive tokens. (New line characters are considered to be equivalent to spaces.)

The following symbols can appear in source Refal Plus programs as constants: character symbols, word symbols, and numeric symbols.

A character symbol corresponds to a printable character. A sequence of several character symbols is written as a single string consisting of the corresponding characters and enclosed in acute accents.

A word symbol corresponds to a character string and is written as the corresponding string enclosed in double quotes.

If a word symbol begins with either a capital letter, or an underscore _, and contains only letters, digits, and underscores _, the double quotes enclosing the symbol may be omitted.

Here are examples of words:
    "John"
    "A-Word"
    "a-very-very-long-Word"
    X_25m3s__
    "equal?"
    _x
A numeric symbol corresponds to a signed integer, and is written as a non-empty sequence of decimal digits, which may be preceded by one of the characters Add or Sub. For example:
    237
    -99999999999999999999999999999999999999999999999
    +13

Numeric symbols may be arbitrary large.