The TL/1 language is extremely limited.
A TL/1 compilation unit is composed of a single main() procedure.
Available statements are if-then-else, while, and assignment.
Variables are not declared, they come into scope at their first assignment and stay in scope thereafter.
Arithmetic expressions, string concatenation, and comparison expressions are available.
To compile a TL/1 program, invoke jburg.test.tl1.TL1Compiler.main(), passing the name of your
TL/1 program as the only argument.
The TL/1 compiler is not good about removing path information, so it's best to execute the compiler
in the working directory that contains the file.
For example, to compile mytl1.tl1 and save mytl1.class on disk:
java jburg.test.tl1.TL1Compiler mytl1.tl1From the command line, invoke the TL/1 class as the main class, e.g.
java mytl1From a Java program, construct a new instance of your TL/1 class and invoke its TL1main() method, e.g.
new mytl1().TL1main()
TL1Compiler.main() gets its arguments from the command line. Only one argument is accepted: the name of the TL/1 program to compile. By convention, TL/1 programs use the extension ".tl1". main() passes the name of the TL/1 file to TL1Compiler.compile(inputFile).
TL1Compiler.compile() forms a class name by stripping the ".tl1" extension from the input name; the TL/1 compiler is not good about removing path information, so it's best to execute the compiler in the working directory that contains the file.
TL1Compiler.compile() creates a new BCEL ClassGen object and a new TL1Reducer, and sets the reducer's properties so it can reference the compiler's ClassGen, the class name, etc. TL1Compiler.compile() then invokes the BURM's burm() method, which labels and reduces the tree of TL1INode objects, generating BCEL InstructionList objects as it goes.
TL1Compiler.compile() then adds a simple main() and a no-args constructor to the generated code, and writes the .class file out on disk.
The parser recognizes TL/1 syntax and constructs TL1INode objects to represent the program's Abstract Syntax Tree.
When the parser recognizes a list of objects, such as a list of statements, it constructs
CONS_CELL TL1INodes to represent the list as a "tree."
The CONS_CELL list is "backwards" in that new elements are added to the head instead of the tail;
it makes the emitter slightly more readable. If having the CONS_CELL lists in the "correct" order
were important, the emitter code that processes CONS_CELL lists would need to be inverted.
TL1INode
The TL1INode class has four property access methods of interest.
The BURM uses the TL1Inode's operator to identify the type of INode it's labelling/reducing.
The left-most (or only) child of this node. May be null if there are no children.
The right-most child of this node. May be null if there are less than two children.
TL1INode objects that represent primitive elements of the TL/1 language, such as identifiers,
literals, and operators, have an associated syntax token.
This token's kind is also used as the TL1INode's operator, if no explicit operator is set.