Question Bank
Question Bank
1. What do you mean by phase & pass of a complier? Explain lexical analysis phase of a compiler in
detail.
2. Discuss various phases of compiler in brief for the given expression, a= b * c + d / e
Give output of each phase of compiler including symbol table and memory representation.
3. Draw NFA for the regular expression
a*((aa/bb)*b
4. Define about phase and pass of a complier and discuss role of lexical analyzer in detail.
Discuss the use of Cross Compiler and explain the process of bootstrapping.
5. State names of Compiler Writing tools and state the use of each.
6. Write a LEX program that recognizes :-
i) Keyword if, while, for
ii) Identifier
iii) Operator + | - | * | /
Unit 2
1. Give short note on-Representation of the scope information in the symbol table.
2. What is an ambiguous and unambiguous grammar.
3. Construct an LL(1) parsing table for the following grammar-
𝑆 → 𝑎𝐵𝐷ℎ
𝐵 → 𝑐𝐶
𝐶 → 𝑏𝐶 | ∈
𝐷 → 𝐸𝐹
𝐸 →𝑔| ∈
𝐹 →𝑓| ∈
4. Discuss working of top down parser and justify the given statement- “The order in which
alternatives are tried affects the language accepted by the parser.”
7. State Handle. Show the handle of each sentential form for the string id + id * id
𝐸 → 𝐸 + 𝐸 | 𝐸 ∗ 𝐸 |𝑖𝑑
8. Check whether a given grammar is LL(1) or not.
𝑆 → 1𝐴𝐵 | ∈
𝐴 → 1𝐴𝐶 | 0𝐶
𝐵 → 0𝑆
𝐶 →1
9. State the contents of the symbol table for the given procedure-
i. Assuming that only one symbol table is maintained
ii. Assuming that new symbol table is built for each block on stack
Program main
Var x, y: integer
Procedure P:
Var x, a: Boolean
Procedure Q:
Var x, y,z: real
Begin
…..
End
Begin
……
End
Begin
…….
End
12. Is Left recursive grammar suitable for top down parsing? Eliminate left recursion from given
grammar.
𝑆 → 𝑎𝐵𝐷ℎ
𝐵 → 𝐵𝑏 | 𝑐
UNIT 3
4. Give SDTS for the following statement A[i,B[k]]=B[i+k]+ A[i,k].Assume array A is of size 20 x 30 and
B is of size 30, and bpw = 04
6. Generate SDTS for the arithmetic Expressions. Also draw annotated parse tree.
7. Generate SDTS for the following statement.
if(p>q and r<=s)
then
u=u*v;
else
u=u/v;
Draw annotated parse tree.
8. State concept of L-attributed definitions. & Write translation scheme for While loop.
9. Give role of semantic analyzer. Discuss translation of constructs using Syntax Directed
Translation.
10. Justify the purpose of syntax tree. Draw Syntax tree for the given grammar for the string
id + id * id
𝐸 →𝐸+𝐸
𝐸 →𝐸∗𝐸
𝐸 → 𝑖𝑑
UNIT-4
1. When error is detected in Top-Down parser? How LL(l) parser recovers from error.
2. Write short note on phrase level error recovery in LR parsing.
3. Consider the following lexically nested C code:
int a,b;
int foo() { int a,c;}
int bar() { int a,d; /* HERE*/}
4. How can symbol tables represent the state of each scope at the point marked HERE? Draw a
diagram.
5. Write short note on Run-Time support as provided by compiler.
6. Discuss different symbol table organization for block structured language.
7. Give error recovery in predictive parsing.
8. Give different types of intermediate codes? Comment following statement into all intermediate
code
a= SQRT(b* b- 4* a *c)/ 2* a
9. Differentiate syntactic & semantic errors ,suggest method to recover from these errors.
12. Give different types of intermediate codes? Explain using expression: a*(b+c)/d+e/f
13. Implement phrase Level error recovery routines For LR Parsing by considering given grammar.
E →E+E| EE|(E)| id
UNIT-5
1. Give Data Flow Equations? Compute IN and OUT equations for following graph
2. Give labeling algorithm and determine number of registers required to evaluate following
instructions set
T1= a + b
T2= c + d
T3= e + f
T4= T2 + T3
T5= T4 + T1
3. Compute IN and OUT equations for following graph.
4. How algebraic properties are used to reduce register requirement during code generation.
5. Consider some interlock code optimization without any data flow analysis by treating each
extended n if it is a basic block. Give algorithms to do the following Optimizations within as
extended basic block. In each case, indicate what effect on other extended basic blocks a change
within one extended basic block can have.
1) Common sub- expression elimination
2) Constant folding
3) Copy Propogation
7. Generate the code for following expression using simple code generation algorithm
x = (a + b) −((c+d) −e).