The first phase of the compiler is the parser, which transforms an input program in text form into an abstract syntax tree. The parser is followed by the weeder, which performs some simple syntactical checks and transformations on the AST that are not (easily) expressible in the parser itself.

You must hand in two files parser.mly and weeding.ml (and optionally ast.ml if you extend some of the datatypes) that extend the skeleton so that it parses the input syntax and constructs the correct ASTs. You must also post an entry in your group blog that explains how your code works and which problems you have encountered and solved in the process.

The AST specified in ast.ml defines the interface between the parser and the weeder. You may add additional nodes to this AST, but after the weeding phase, the AST must contain only nodes specified in weedingast.ml. Other nodes may be added temporarily by the parser, but these must be rewritten or rejected by the weeder.

For any node with a Lexing.position field, the position field may be changed temporarily to use Lexing.dummy_pos, such that the node can be created without having a proper position available. However, in all such cases, the position must be filled out appropriately by the weeder.

Missing syntactical constructs

The parser.mly file in the skeleton covers most of the Joos 1 language, but a few, essential language constructs are missing. It is your job to fill in these missing parts of the grammar. In particular, the grammar is missing For a Joos 2 compiler, the grammar must furthermore be extended with

Syntactical checks and transformations

The AST delivered by the weeding phase must adhere to a number of additional requirements that are not expressed in the AST definition. Each of these requirements can be enforced syntactically in the grammar or checked explicitly in the weeder, or some combination (note that some of these are already enforced by the given grammar). When handling checks in the weeder, use the methods mentioned in parentheses to report the corresponding errors: Use error_syntax_error for reporting syntactical errors handled in the weeder.

Values of literals

The weeder is responsible for calculating the values of all literals. In particular:

Things to be done later

After the weeding phase, the AST nodes must correspond to the actual language constructs, except for a number of cases which cannot be resolved at this time.

The nodes that might be represented temporarily by different nodes are StaticInvoke, NonstaticInvoke, and NonstaticField. In particular,