
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. You are advised
to make use of the predefined abstract syntax classes that come
with the MiniJava
project
(available here as a gzipped
tar-file).
- 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.
- 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. The
MiniJava project provides ready-
made classes using the visitor
pattern for this purpose, see this
link for a gzipped tar-file of the
visitor package.
- 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.
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!