Cs606 Compiler Construction Assignment No 4 Idea Solution Fall 2012 Due date 05 February 2013
Assignment No. 04
Semester Fall 2012
Compiler Construction CS606
Total Marks: 20
Due Date: 05-02-2013
Objective:
To learn and understand basic concepts of Context-sensitive grammars and attribute grammars.
Instructions:
It should be clear that your assignment will not get any credit (zero marks will be awarded) if:
o The assignment is submitted after due date.
o The submitted assignment does not open or file corrupt.
o The assignment is copied (from other student or copy from handouts or internet).
o It is in some format other than MS Word Document.
For any query about the assignment, contact at cs606@vu.edu.pk
BEST OF LUCK
Question No 1: Marks 20
Consider the following grammar productions. Suppose you have an attribute E.type which can
be set to either INT, BOOL. Assume that the type of an expression is set to INT if an error is
detected and you have a routine msg() similar to printf() that can be used to print error
message.
E → CONST {E.type=??}
| ID {E.type =getType(ID.name);}
| E1 +E2 {E.type=??}
| E1< E2 {E.type=??}
| E1= =E2 {E.type=??}
| (E1) {E.type=??}
You are required to add rules to the attribute grammar to calculate E.type for each grammar
production.
Assignment No. 04
Semester Fall 2012
Compiler Construction CS606
Total Marks: 20
Due Date: 05-02-2013
Objective:
To learn and understand basic concepts of Context-sensitive grammars and attribute grammars.
Instructions:
It should be clear that your assignment will not get any credit (zero marks will be awarded) if:
o The assignment is submitted after due date.
o The submitted assignment does not open or file corrupt.
o The assignment is copied (from other student or copy from handouts or internet).
o It is in some format other than MS Word Document.
For any query about the assignment, contact at cs606@vu.edu.pk
BEST OF LUCK
Question No 1: Marks 20
Consider the following grammar productions. Suppose you have an attribute E.type which can
be set to either INT, BOOL. Assume that the type of an expression is set to INT if an error is
detected and you have a routine msg() similar to printf() that can be used to print error
message.
E → CONST {E.type=??}
| ID {E.type =getType(ID.name);}
| E1 +E2 {E.type=??}
| E1< E2 {E.type=??}
| E1= =E2 {E.type=??}
| (E1) {E.type=??}
You are required to add rules to the attribute grammar to calculate E.type for each grammar
production.