CS451/651-Project 4 Scanning and Parsing with JavaCC Solved
In this project you will only modify the JavaCC specification file $j/j--/src/jminusminus/j--.jj for j-- to add more Java tokens and programming constructs to the j-- language. In the first part, you will modify the scanner section of the j--.jj file to support the Java tokens that you handled as part of Project 2 (Scanning). In the second part, you will modify the parser section of the file to support the Java programming constructs that you handled as part of Project 3 (Parsing). To compile the j-- compiler with the JavaCC front-end, ie, with the scanner and parser generated by JavaCC, run the following command:
$ ant clean javacc compileJavaCC jar
Part I: Additions to JavaCC Scanner To scan your j-- programs using the JavaCC scanner, you need to run the javaccj-- command as follows:
$ $j/j--/bin/javaccj-- -t P.java
which only scans P.java and prints the tokens in the program along with the line number where each token appears.
Problem 1. (Multiline Comment) Add support for multiline comment, where all the text from the ASCII characters /* to the ASCII characters */ is ignored.
Part II: Additions to JavaCC Parser To parse your j-- programs using the JavaCC parser, you need to run the javaccj-- command as follows:
$ $j/j--/bin/javaccj-- -p P.java
which will only parse P.java and print the AST for the program in XML format.
Note.
1. Consult the appendix at the end for the grammar (ie, formal specification) for each new construct you will be supporting in j--.
2. The AST output provided for each problem is meant to give you an idea as to what the AST ought to look like once the syntactic constructs for that problem are implemented in j--. You are expected to implement the writeToStdOut() method in the J* files for the constructs such that your AST output is 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.
Problem 6. (Long and Double Basic Types) Add support for the long and double basic types.
$ $j/j--/bin/javaccj-- -p tests/BasicTypes.java
See tests/BasicTypes.ast for output.
Problem 7. (Operators) Add support for the following operators, obeying precedence rules (see appendix at the end).