There are several XL compilers, but they all follow the same basic architecture:
- The scanner reads the input file and decomposes it into tokens.
- The parser takes the sequence of tokens and turns it into a a parse tree (or abstract syntax tree).
- Rewrite rules are applied on the parse tree, transforming it over time.
- The transformed parse tree is fed into the back-end
Design differences between XL2 and XLR
The primary difference between the XL2 and XLR implementations are the following:
- The rewrite rules in XL2 are slightly more sophisticated, whereas the XLR rules are designed to evaluate quickly.
- The back-end in XL2 is designed to generate text, to be fed for example to another compiler or to XLR, whereas XLR uses LLVM to dynamically generate machine code.
These differences result from the different usage models for the two languages.
- XL2 is designed as a statically-compiled language where it's acceptable to spend a little more time compiling ahead of time. Therefore, the rewrite rules can be more sophisticated, and it's acceptable to feed the result for example to an optimizing C or Java compiler.
- XLR is designed as a dynamically-compiled language, where the parse tree rewrites occur at run-time. Therefore, the time it takes to apply the rewrite rules matters. Also, the dynamic aspect of the language implies immediate execution.