Docsity

Lecture Notes on PL/0 Code Generation for Virtual Machine PM/0 | COP 3402, Assignments of Computer Science

Toggle sidebar
bg1
University of Central Florida
School of Electrical Engineering & Computer Science
COP 3402: System Software
Fall 2008
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:
pf3
pf4

Partial preview of the text

Download Lecture Notes on PL/0 Code Generation for Virtual Machine PM/0 | COP 3402 and more Assignments Computer Science in PDF only on Docsity!

University of Central Florida

School of Electrical Engineering & Computer Science

COP 3402: System Software

Fall 2008

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: ::= block ".". ::= <const-declaration> <var-declaration> <procedure-declaration> ::= [ “const” "=" {"," "=" } ";"] <var-declaration> ::= [ "var" ident {"," ident} ";"] <procedure-declaration> ::= { "procedure" ";" ";" } ::= [ ":=" | "call" | "begin" {";" } "end" | "if" "then" | "while" "do" | “write” | “read” | e ] ::= "odd" | <rel-op> <rel-op> ::= "="|“<>"|"<"|"<="|">"|">=“ ::= [ " + "|" - "] { (" + "|" - ") } ::= {(" ***** "|" / ") } ::= | | " ( " " ) “ ::= {} ::= { | } ::= " 0 " | " 1 " | " 2 " | " 3 " | " 4 " | " 5 " | " 6 " | " 7 " | " 8 " | " 9 “ ::= " a " | " b " | … | " y " | " z " | " A " | " B " | ... | " Y " | " Z " The read statement reads in a value from the console and put it on top of the stack. The write statement prints out the content of the top of the stack and decrement the stack pointer by one.

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.