|
|
|
|
Quick Links
Understanding XL
In depth
Other projects
|
XLR: Extensible Language and Runtime
|
XL doesn't really have a notion of "built-in operator" as most programming languages do. Instead, a precedence table drives the parsing of operators found in XL0 text into the appropriate parse tree structure. By default, this precedence table is specified by the xl.syntax input file. It is considered bad taste to change the priority of any of the operators defined in this table, as this would introduce significant syntactic noise. However, it is OK to add entries in this table, notably when extending the language. This can be done by compiler plug-ins. From a parsing point of view, XL only classifies operators along two dimensions: name vs. symbol, and prefix vs. infix vs. block.
XL (more precisely XL1) uses operators in roles which are typically played by keywords in older languages. In particular, the new-line and semi-colon ; are two operators, which are in general used to sequence instructions. Structures such as while loops, if-then-else, or indentation blocks, are also defined in terms of operators. For instance, consider the following text:
while X > 0 loop if not EOF then A := A+1 B *= (2.54 + MATH.sqrt(1-A)) Below is the C++ translation of the creation of the corresponding parse tree (this C++ code was generated by using quote and asking the XL compiler to emit C++ code). You can find the various operators from the source code replicated in that structure. Note the use of I+ and I- to denote indentation delimiters, and the use of a new-line operator (ascii::cr).
// C++ code generating the above parse tree newinfix(text("loop"), newprefix( newname(text("while")), newinfix(text(">"), newname(text("x")), newinteger(0))), newblock( newinfix(text("then"), newprefix( newname(text("if")), newprefix( newname(text("not")), newname(text("eof")))), newblock( newinfix(xl::textio::encoding::ascii::cr, newinfix(text(":="), newname(text("a")), newinfix(text("+"), newname(text("a")), newinteger(1))), newinfix(text("*="), newname(text("b")), newblock( newinfix(text("+"), newreal(2.54), newprefix( newinfix(text("."), newname(text("math")), newname(text("sqrt"))), newblock( newinfix(text("-"), newinteger(1), newname(text("a"))), "(", ")"))), "(", ")"))), "I+", "I-")), "I+", "I-")))
|
Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)