The Sather Lisp syntax is described using an Extended Backus_Naur Formalism (EBNF): brackets [ and ] denote optionality of the enclosed sentential form, braces and denote its repetition (possibly zero times). Alternative forms are separated by vertical bars |. Syntactic entities (non_terminal symbols) are denoted by English words starting with a capital letter (the only one is Expression). Tokens of the language vocabulary (terminal symbols) are either denoted by English words starting with a small letter (e.g., number), or are denoted by strings enclosed in double quotes (e.g., "."). No white space may appear within tokens. However, arbitrary white space and comments may appear between tokens. Comments are denoted by the curly braces and and may be nested.
Expression = "'" Expression |
"(" {Expression} ["." Expression] ")" |
symbol | number | string.
symbol = letter {letter | digit} |
special {special}.
number = ["-"] digit {digit} ["/" digit {digit}].
string = """ char """.
letter = "A" | "B" ... "Z" | "a" | "b" ... "z".
digit = "0" | "1" ... "9".
special = "!" | "#" | "$" | "%" | "&" | "*" | "+" | "-" | "/" | ":" |
"<" | "=" | ">" | "?" | "@" | "\\ " | "^" | "|" | "~".
char = any printable character except "
Examples:
-1234 (negative) integer
7/31 (positive) rational number
"This is a string" string
() empty list, nil
myFunc symbol
<= (special) symbol
'a quoted symbol
(a (b 3/4 c) d) list consisting of 3 elements
(a . b) dotted pair
(a b c (u v w) x . d) list terminated with dotted pair
(a . (b . (c . ()))) = (a b c) equivalence of dotted pair and list notation
Note: The negative sign of a number must be immediately before the first digit and must not be preceeded by another special character, otherwise it is interpreted as (special) symbol. 'x is a shortcut for (quote x) (unless quote has been redefined).