Sei sulla pagina 1di 7

DEPARTMENT OF INFORMATION TECHNOLOGY

III B.Tech II Semester


Subject : Compiler Design Assignment Test - II

1. What is a symbol table? What are the contents of a symbol table? Explain briefly
the data structures for symbol table.
2. Explain briefly the following code optimization techniques
(a) Folding
(b) Strength reduction.
3. Define code optimization. What are the principle sources of optimization? Explain
in detail
4. What is a three address code? What are its types? Generate three address code for
the executable statements of the following C program.
while (i<=m) {
a[i]=b+c;
i=i+1;
}
5. Write a syntax directed translation scheme for producing syntax tree for the
expressions generated by the following grammar and Draw the annotated parse tree for the
sting a+4-c using the SDD.
E→TR
R→+TR│-TR│ε
T→(E)│id│num

6. Construct CLR parsing method with the following grammar.

S→CC
C→aC / d
And parse the input string aadd
Notes on Syntax Directed Translation
CFG Translation rules
=== =================
exp -> exp + term exp1.trans = exp2.trans + term.trans
exp -> term exp.trans = term.trans
term -> term * factor term1.trans = term2.trans *
factor.trans
term -> factor term.trans = factor.trans
factor -> INTLITERAL factor.trans = INTLITERAL.value
factor -> ( exp ) factor.trans = exp.trans

Input
=====
2 * (4 + 5)

Annotated Parse Tree


====================

exp (18)
|
term (18)
/|\
/ | \
/ * \
/ factor (9)
/ /|\
(2) term ( | )
| |
(2) factor exp(9)
| /|\
2 / | \
/ | \
(4) exp + term (5)
| |
(4) factor factor (5)
| |
4 5

Potrebbero piacerti anche