Submit your assignment at the web submission site. We will use your last submission for your final marks for this assignment. For each submission you will get your marks instantly by email. Note that this time the test casess are randomized, which means that it may indicate different error cases even when you submit the same program.
Please test your program on our sample inputs and other cases devised by you before submission. Passing the sample inputs will not guarantee a high mark. You need to fully understand the grammar and implement that grammar correctly so that your parser can cope with all situations.
Some example test cases can be obtained here. Test cases may be different from those example programs. They can be anything that can be generated by the grammar for legal cases. Note that you should break it up into individual tests. You can also the cases used before.The purpose of this assignment is to understand that topdown recursive parser is easy to construct manually, but it is inefficient when it runs.
You are required to write a Java program that parses programs written in our Tiny language, without the help of a parser generator. Please follow the recursive-decent parser example given in the lecture. You only need to judge whether a Tiny program is syntactically correct or not. You are not required to handle the ambiguity of the grammar.
You will write a Java class called A5.java, which is the parser for our Tiny language. The main method in A5.java should be:
public static void main(String[] args) throws Exception { //construct the token array BufferedWriter bw=new BufferedWriter(new FileWriter("a5.output")); A5Scanner scanner = new A5Scanner(new FileInputStream(new File("A5.tiny"))); // note that yylex() is the default method to get the next token in scanner that is generated by JLlex. Symbol token; while ((token=scanner.yylex()).sym!= A5Sym.EOF) { tokens.add(token); } tokens.add(token); // add EOF as the last token in the array boolean legal= program() && nextToken().sym==A5Sym.EOF; bw.write((legal)?"legal":"illegal"); bw.close(); }The commands to test your program are:
javac A5.java A5Scanner.java A5Sym.java Symbol.java java A5
Please make sure that those two commands can run without any other classes. That is, to test your program, you should create a clean directory with no other classes, no JLex, no java_cup. All you have in this directory are those 4 classes and the input file.
If a5.input is a correct Tiny program,the output file a5.output will contain a single word "legal"; otherwise a word "illegal". Please note that the program may run several minutes to process our sample Tiny program.
Notice how slow this program is and why it is better to use other parsing methods.
In addition to the parser class itself, you need to define the following auxiliary classes:
You need to submit the following java files:
yourMark=0; for (each of the 10 tests A5.tiny) { if (your program runs longer than 5 minutes) { break; } if (A5.tiny is legal program && a5.output says "legal") yourMark+=0.5; if (A5.tiny is not a correct Tiny program && a5.output says "illegal" ) yourMark+=0.5; }This time we do not have bonus mark for this assignment--one component of the project will be an extension of this assignment by making it faster.