Word Syntax

Words are tokens that are not enclosed by some characters. Character classes determine the border from one word to another. We have defined the classes of delimiters, alphabetical characters, decimal digits and graphic characters. Delimiters are characters that form a word by their own. Alphabetical characters and digits glue together to form words. Similarly graphic characters form a word when arranged in sequence:

word        --> delimiter 
| alpha { alpha | digit }
| graphic { graphic }
| number
| reference.
delimiter   --> "(" | "{" | "[" | "]" | "}"
| ")" | "," | ";" | "!" | "|".

alpha --> upperscore | lower.
upperscore --> "_" | "A" ... "Z".
lower --> "a" ... "z".
digit --> "0" ... "9".
graphic     --> "\\" | "=" | "<" | ">" | "."
| ":" | "?" | "-" | "+"
| "*" | "/" | "#" | "@"
| "&" | "^" | "~" | "$".

Numbers and references share in common that they start with a digit. Their syntax is documented in more detail in the next section. Words are further classified into names, variables and the rest. The rest cannot be used as a name or a variable in a Prolog text. The accepted word syntax depends on the character set extension. By default Jekejeke Prolog provides a Unicode character set extension which is documented in a later section.

name        --> delimiter except "(", "{", "[", 
"]", "}", ")", ",", "|"
| lower { alpha | digit }
| graphic { graphic } except "."
| str_single.

variable --> upperscore { alpha | digit }
| str_back.

Examples:

(                       % A word, but not a name and not a variable.
! % The name '!'.
:- % The name ':-'.
foobar % The name 'foobar'.
'arc sin' % The name 'arc sin'.
X12 % The variable 'X12'.
`col 7` % The variable 'col 7'.

Words that start with an upper case letter or with the underscore (“_”) are considered as variables. Back quoted strings also belong to the category of variables, they allow for arbitrary character sequences used as variables. Words that start with a lower case letter or a graphic character are considered as names. Finally single quoted strings also belong to the category of names, similarly they allow for arbitrary character sequences used as names.

Kommentare