Notation

## A.2 Notation

- Character Classes
- Groups of characters
- Valid Tokens
- Escape Sequences within Strings and Atoms

The following notation is used in the syntax specification in this chapter:

- a term_h is a term which is the head of the clause.
- a term_h(N) is a term_h of maximum precedence N.
- a term_g is a term which is a goal (body) of the clause.
- a term_g(N) is a term_g of maximum precedence N.
- a term_a is a term which is an argument of a compound term or a list.
- a term(N) can be any term (term_h, term_a or term_h) of maximum precedence N.
- fx(N) is a prefix operator of precedence N which is not right associative.
- fy(N) is a prefix operator of precedence N which is right associative.
- similar definitions apply for infix (xfx, xfy, yfx) and postfix (xf, yf) operators.

### A.2.1 Character Classes

The following character classes exist:

Character Class | Notation Used | Default Members
upper_case | UC | all upper case letters
underline | UL | `_`
lower_case | LC | all lower case letters
digit | N | digits
blank_space | BS | space, tab and nonprintable ASCII characters
end_of_line | NL | line feed
atom_quote | AQ | `'`
string_quote | SQ | `"`
list_quote | LQ |
radix | RA |
ascii | AS |
solo | SL | `! ;`
special | DS | `( [ { ) ] } , |`
line_comment | CM | `%`
escape | ES | `\`
first_comment | CM1 | `/`
second_comment | CM2 | `*`
symbol | SY | `# + - . : < = > ? @ ^ ` ~ $ &`
terminator | TS |

The character class of any character can be modified by a chtab-declaration.

### A.2.2 Groups of characters

Group Type | Notation | Valid Characters
alphanumerical | ALP | UC UL LC N
any character | ANY |
non escape | NES | any character except escape
sign | SGN | `+ -`

### A.2.3 Valid Tokens

Terms are defined in terms of tokens, and tokens are defined in terms of characters and character classes. Individual tokens can be read with the predicates read_token/2 and read_token/3. The description of the valid tokens follows.

#### Constants

1. atoms

       ATOM    = (LC ALP*)
               | (SY | CM1 | CM2 | ES)+
               | (AQ (NES | ES ANY+)* AQ)
               | SL
               | []
               | {}
               | |

2. numbers
   1. integers

          INT = [SGN] N+

   2. based integers

          INTBAS = [SGN] N+ (AQ | RA) (N | LC | UC)+

      The base must be an integer between 1 and 36 included, the value being valid for this base.
      If the syntax option iso_base_prefix is active, the syntax for based integers is instead

          INTBAS = [SGN] 0 (b | o | x) (N | LC | UC)+

      which allows binary, octal and hexadecimal numbers respectively.
   3. character codes

          INTCHAR = [SGN] 0 (AQ | RA) ANY | AS ANY

      The value of the integer is the character code of the last character.
   4. rationals

          RAT = [SGN] N+ UL N+

   5. floats

          FLOAT = [SGN] N+ . N+ [ (e | E) [SGN] N+ | Inf ]
                | [SGN] N+        (e | E) [SGN] N+

      checks are performed that the numbers are in a valid range.
   6. bounded reals

          BREAL = FLOAT UL UL FLOAT

      where the first float must be less or equal to the second.
   If the syntax option blanks_after_sign is active, then blank space (`BS*`) is allowed between the sign and the following digits.
3. strings

       STRING = SQ (NES | ES ANY+ | SQ BS* SQ)* SQ

   By default, consecutive strings are concatenated into a single string. This behaviour can be disabled by the syntax option doubled_quote_is_quote, which causes doubled quotes to be interpreted as a single occurrence of the quote within the string.
4. lists of character codes

       LIST = LQ (NES | ES ANY+ | LQ BS* LQ)* LQ

   By default, consecutive character lists are concatenated into a single character list. This behaviour can be disabled by the syntax option doubled_quote_is_quote, which causes doubled quotes to be interpreted as a single occurrence of the quote within the string.

#### Variables

    VAR = (UC | UL) ALP*

#### End of clause

    EOCL = . (BS | NL | <end of file>) | TS | <end of file>

### A.2.4 Escape Sequences within Strings and Atoms

Within atoms and strings, the escape sequences (ES ANY+) are interpreted: if the sequence matches one of the following valid escape sequences, the corresponding special character is inserted into the quoted item.

Escape Sequence | Result
ES `a` | ASCII alert (7)
ES `b` | ASCII backspace (8)
ES `f` | ASCII form feed (12)
ES `n` | ASCII newline (10)
ES `r` | ASCII carriage return (13)
ES `t` | ASCII tabulation (9)
ES `v` | ASCII vertical tab (11)
ES `e` | ASCII escape (27)
ES `d` | ASCII delete (127)
ES ES | the ES character itself
ES AQ | the AQ character itself
ES SQ | the SQ character itself
ES LQ | the LQ character itself
ES NL | ignored
ES `c` (BS`|`NL)* | ignored
ES three octal digits | character whose character code is the given octal value
ES `x` hex digits ES | character whose character code is the given hexadecimal value

Any other character following the ES constitutes a syntax error. If the syntax option iso_escapes is active, the octal escape sequence can be of any length and must be terminated with an ES character.