CS451/651 Project 3 (Parsing) Swami Iyer
Objectives.
1. Support long and double basic types.
2. Support operators.
3. Support conditional expression and switch statement.
4. Support do-while and for statements.
5. Support exception handlers.
6. Support interface type declaration.
In this project, you will only be supporting the parsing of the above programming constructs and their representations in the
abstract syntax tree (AST). To compile (just parse for now) your j– programs, you need to run the j– command as follows:
$ $j/j–/bin/j– -p P.java
which will only parse P.java and print the AST for the program in XML format.
Note.
1. Consult Appendix C of our text for the grammar (ie, formal specification) for each new construct you will be supporting
in j–.
2. The AST shown (as XML) for each problem is only a suggestion as to what the AST ought to look like once the
syntactic constructs for that problem are implemented in j–. You are not expected to produce exactly the same AST,
but just something similar. The autograder will not match your AST against ours for correctness, but instead will test
if your parser parses our pass tests without errors and our fail tests with suitable error messages.
Problem 1. (Long and Double Basic Types) Add support for the long and double basic types.
$ $j/j–/bin/j– -p tests/BasicTypes.java
1 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
2 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 2. (Operators) Add support for the following operators, obeying precedence rules (see Appendix C).
~ != / /= -=
++ — *= % %=
>> >>= >>> >>>= >=
<< <<= < ^ ^= | |= || & &= $ $j/j--/bin/j-- -p tests/Operators.java
3 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
4 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
5 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
6 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 3. (Conditional Expression) Add support for conditional expression (e1 ? e2 : e3).
$ $j/j–bin/j– -p tests/ConditionalExpression.java
7 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 4. (Switch Statement) Add support for a switch statement.
$ $j/j–/bin/j– -p tests/SwitchStatement.java
8 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
9 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 5. (Do-while Statement) Add support for a do-while statement.
$ $j/j–/bin/j– -p tests/DoWhileStatement.java
10 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
11 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 6. (For Statement) Add support for a for statement.
$ $j/j–/bin/j– -p tests/ForStatement.java
12 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 7. (Exception Handlers) Add support for exception handling, which involves supporting the try, catch, finally,
throw, and throws clauses.
$ $j/j–/bin/j– -p tests/ExceptionHandlers.java
13 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Problem 8. (Interface Type Declaration) Implement support for interface declaration.
$ $j/j–/bin/j– -p tests/Interface.java
14 of 15
CS451/651 Project 3 (Parsing) Swami Iyer
Files to Submit
1. j–.tar.gz (j– source tree as a single gzip file)
2. report.txt (project report)
Before you submit:
• Make sure you create the gzip file j–.tar.gz such that it only includes the source files and not the binaries, which
can be done on the terminal as follows:
$ cd $j/j–
$ ant clean
$ cd ..
$ tar -cvf j–.tar j–/*
$ gzip j–.tar
• Make sure your report isn’t too verbose, doesn’t contain lines that exceed 80 characters, and doesn’t contain
spelling/grammatical mistakes
15 of 15