


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Homework #4 (PL/0 Code generation for virtual machine PM/0) Due Tuesday December 2nd, 2008 by 11:59 p.m. (Projects submitted after the due date will not be accepted) Recursive descent parsing uses recursive procedures to model the parse tree to be constructed. The compiler for tiny-PL/0 implemented in HW3 was a recursive descent parser where error handling and intermediate code generation was included for a subset of PL/0. The next task of our PL/0 compiler project is to generate intermediate code for the PM/0 virtual machine developed in HW1 for PL/0. In this project the symbol table must be expanded to include attributes which allow the compiler to associate literal numbers and addresses with each identifier declared. For example: if the identifier denotes a constant, its attribute is the constant value; if the identifier denotes a variable, the attribute in its address, consisting of a level (L) and a displacement (M); and if the identifier denotes a procedure, then its attribute are the procedure’s entry address and its level. In this assignment you have to enhance the compiler you wrote in HW3. This time you have to implementing a recursive descent parser and intermediate code generation for PL/0. The compiler has to read in and print out a program written in PL/0, runs the scanner, and then the parser and generate intermediate code for the virtual machine PL/M0 (HW1). The parser must be capable to read in the tokens produce by your scanner(HW2) and produce, as output, a message that states that the program is well-formed (syntactically correct) otherwise, a message indicating the type of errors. If the program is syntactically correct, code must be generated, printed out and executed on the PL/M0 Machine (HW1). The grammar of the PL/0 language you have to implement is described as follows:
EBNF for PL/0 grammar:
Use this example (nested procedures program): var x,y,z,v,w; procedure a; var x,y,u,v; procedure b; var y,z,v; procedure c; var y,z; begin z:=1; x:=y+z+w end; begin y:=x+u+w; call c end; begin z:=2; u:=z+w; call b end; begin x:=1; y:=2; z:=3; v:=4; w:=5; x:=v+w; write z; call a; end.