CS416 Compiler Design: Programming Assignment 2 Due Date: April 2, 2007
CS416 Compiler Design: Programming Assignment 2 Due Date: April 2, 2007
For example, the followings are some possible production rules for a CFG: S S S A A -> -> -> -> -> aS bA This means that the production rule is c bAb S
The non-terminals and the terminals of the given CFG are the non-terminals and the terminals appearing in the given production rules. The starting non-terminal is S. You may assume that the syntax of the production rules (as described above) is correct, and you do not have to handle the incorrect ones. If the given CFG is not a LL(1) grammar, your program should print a message indicating this fact together with the reason (which entries contain more than one production rule). If the given CFG is a LL(1) grammar, it should create its LL(1) parsing table, and store it internally. Your program should also print that LL(1) parsing table into a file. For example, your program should print the following LL(1) parsing table into a file for the CFG above. a S -> aS b S -> bA A -> bAb c A -> c $ S ->
S A
Parse A String If there is a LL(1) parsing table that is created, your program should read a string and should parse using that LL(1) parsing table. If the given string is in the language of the current grammar, your program should print its leftmost derivation. If it is not, your program should give error messages. Your program should give the positions of the errors together with error messages. Your program should use panic-mode error recovery to give error messages, and it should be able to handle multiple errors in the input (i.e. you program should be able to give multiple errors).
For example, if the current grammar is the CFG above and the given string is abc , your program should print the following leftmost derivation below: S => aS => abA => abc For example, if the given string is an erroneous string abbab, it should print the following error message Error: Unexpected a at the position 4. You should hand-in: Your source program (email to your assistant (Turhan Daybelge) ( [email protected] )) Some test runs of your program with correct and incorrect strings (email to the assistant) Executable of the your program by email and a message indicating how to run your executable on a PC or a Unix machine which is available at our department.