For problems A8P1 and A8P2 you are to construct reversed rightmost derivations for two problems from assignment 7. The format of your solution will be that of a CFG-R file which is identical to that of a CFG file except that derivations in CFG-R files are not indented, and represent reversed rightmost rather than forward leftmost derivations. We supply the source code for a tool (CFGrl.java or cfgrl.ss but unfortunately not yet in C++) that reads a CFG-R file containing a single derivation and outputs the equivalent CFG file. You may use this tool to verify your submissions to A8P1 and A8P2, and you may use this tool as a model for your implementations for A8P3 and A8P4.
For problem A8P3 you are to write an LR(1) parser which reads a representation of the DFA implementing the LR(1) oracle, along with an input sequence to be parsed. For problem A8P4 you are to embed an LR(1) parser for WLPP into a Java, Scheme or C++ program in much the same way that you embedded your scanner for assignment 6.
Due date: Tuesday, November 15, 2011 at 5:00 p.m.
For the sample lr1 file as input, the correct output is:
term id expr term term id expr term term ( expr ) expr expr - term term id expr expr - term S BOF expr EOFIf you replace the last line of this file by
BOF id - id ) - id EOFthe correct output (to standard error) is
ERROR at 5You may also test your program with the WLPP grammar and parse tables, in .lr1 format after adding a sequence to be recognized.
That is, each token is represented by a line containing the name of the token, followed by a space, followed by the string recognized as the token in the WLPP source program. Note: Unlike the input of A8P3, the input to your parser in this problem will not have lines containing BOF and EOF at the beginning and end.
If the input represents a syntactically valid WLPP program, the output from your program should be a .wlppi file. The format of a .wlppi represents the derivation and also the recognized token strings.
If the input does not represent a syntactically valid WLPP program, output "ERROR at k" to standard error where k is one greater the number of tokens in the longest correct prefix of the input (that is, not counting BOF).
The student.cs undergraduate enviroment includes two commands to help you test your parser:
Jslr -- a Simple LR(1) [SLR(1)] parser generator is a program that generates the LR(1) DFA for any SLR(1) grammar. You can use it to generate parsers for your own grammars, or to generate additional test inputs for A8P3. The input to Jslr.java is a .cfg file. If the .cfg file represents an SLR(1) grammar, the corresponding .lr1 file is output; otherwise an error message is produced.