VELLORE INSTITUTE OF TECHNOLOGY
SCHOOL OF COMPUTER SCIENCE AND ENGINEERING
BCSE305L – COMPILER DESIGN
DIGITAL ASSIGNMENT
1. Below is a Context Free Grammar G= ({S}, {(,)}, P, S) for strings of balanced
parentheses where P is as follows
S →(S)S
S → ε
Construct the LR (0) configurating sets for this grammar. Note that when dealing with
the production S → ε, there is only one LR (0) item, which is S →·
2. Consider the below CFG
Stmts→Stmt
Stmts→Stmts; Stmt
Stmt →Var = E
Var →id [E]
Var→id
E →id
E → (E)
a) Construct the set of LR (0) items and SLR(1) parsing table
b) Construct the set of LR (1) items
c) Show that the grammar is both CLR(1) and LALR(1)
3. Consider the following grammar productions. Assume you have an attribute E.odd
which can be set to either true, false, or unknown, and an attribute CONST.val which is
the value of the constant.
E → CONST { E.odd = ?? }
| ID { E.odd = unknown }
| E1 + E2 { E.odd = ?? }
| E1 - E2 { E.odd = ?? }
| E1 * E2 { E.odd = ?? }
| ( E1 ) { E.odd = ?? }
| - E1 { E.odd = ?? }
Add rules to the attribute grammar to calculate E.odd for each grammar production.
4. Consider the following grammar, which generates expressions formed by applying
”+” to integer and floating point constants. When two integers are added, the result is
integer, otherwise, it is a float.