
Compiler Construction (D7011E) – Programming project
Step 2: Parsing MiniJava
Instructions
- Implement a parser for the MiniJava language according to the
grammar
in Appel, Appendix
A.1, using the ANTLR tool .
- Apart from simply checking whether the input conforms to the
MiniJava definition, the parser
should also construct an abstract syntax representation of the
parsed program.
- Input to the parser should be the token stream produced by the
lexer implemented in step 1.
- Check that your parser accepts all files in testsuite (same files as in step
1). Also check that it
is able to detect and report the errors embedded in the badsuite files.
- The main class of your program must be named Main.
- A short main method
shall call the parser when the program is executed with the "-p" flag,
- To make it possible to observe the result of parsing, your
program should print a textual
representation of the abstract syntax tree once it is built.
and then print ”Parsing succeeded/failed”
depending on whether parsing errors were found in the
input or not.
That is, you should be able to run the parser with
java Main -p BinarySearch.java
to test the
parser on BinarySearch.java.
- Note that you should retain the ability to run the lexer with -l, as in the previous lab!
- Note: the grammar specification in Appel, A.2 cannot be used as is in any
of the parser
implementations listed above. The challenge is thus to rewrite
the grammar so that it suits the
predictive parsing technique of ANTLR. This particularly
involves sorting out how nested
expressions like !a.b(c)+d[e]*f.length<g.h().i()
should be read, and how to
express that grammatically.
- Note: A good start is to respect the Java operator precedence as given in the JLS or for instance
in the following quick reference.
Report by sending your commented
ANTLR input file via email to your lecturer.
Subject line: D7011E - 2.
(See course homepage for mail address and deadline.)
The programming project should be carried out individually.
Oral discussion is good, copying files is not!