Syntax
Syntax is defined at the XL0 level. The XL0 phase of the compiler can be configured using a syntax description file, where properties like the text representation and precedence of operators are defined. A basic syntax file defines common mathematical notations, like + for addition, with the usually accepted order of operations.
The parse tree consists of 7 node types, 4 leaf node types (integer, real, text and symbol) and 3 internal node types (infix, prefix and block).
- integer nodes represent an integer literal, such as
2
. The#
sign can be used to specify a base other than 10, as in (2#1001
). A separating underscore can be used to improve readability, as in1_000_000
. - real nodes represent non-integral numbers, such as
2.5
. Based-notations and separators can be used, as for integer nodes, for example16#F.FFF#E-10
is a valid real literal. - text nodes represent textual contents. They are normally surrounded by simple or double quotes, like
"Hello"
or'a'
, but the syntax file can be used to add other separators, including for multi-line textual contents. - symbol nodes represent names or operators. Names are sequence of alphanumeric characters beginning with a letter, like
Hello
. XL0 preserves case, but XL1 ignores case and underscores, so thatJohnDoe
andjohn_doe
are the same name. Operators are sequences of non-alphanumeric characters, like*
or=/=
. - infix nodes represent two nodes related by an infix symbol, like
A+1
or2 and 3
. Infix nodes are in particular used to separate lines, with an infix "new-line" symbol. - prefix nodes represent two consecutive nodes, like
Write "Hello"
. It is also used for postfix notations, like3!
orOpen?
. - block nodes represent a node surrounded by grouping symbols, like
(A)
,. Indentation is internally represented by a block node.
With the default syntax file, the following is valid XL0, irrespective of any semantics.
A = B + "Hello"It parses as:
infix("=", symbol("A"), infix("+", symbol("B"), text("Hello")))Read more about this topic: XL (programming Language)