Questions Set Compiler
Questions Set Compiler
S->( L )|a
L->L ,S|S
14) For the following grammars find FIRST(X),Follow(X) for each variable in the grammar
G:{ E->E+T|T, T->TF|F, F->F* |a | b}
15) What do you understand by left factoring? Perform left factoring to dangling-else grammar S-
>iCtS | iCtSe|a , C->b
16) Describe input buffering in lexical analyser
17) Describe the language processing system with a diagram
18) what is DAG? Construct a DAG for the following code:
a=a+b,
e= a+d + e
19) What is code optimization? Optimize the following C-code:
count=0;
result= 0;
while(count++ < 20)
{
increment= 2*count;
result +=increment;
}
20) Construct the transition system equivalent to the given regular expression: a* +(ab + a)* using
Thompsons construction
15 MARKS QUESTIONS
E-> E or T|T
T->T and F|F
F-> not F|(E)| 0|1
a) Eliminate left recursion from the above grammar [3 marks]
b) Find FIRST(X),Follow(X) for each variable in the grammar [5 marks]
c) Construct a predictive parser table for the grammar[5 marks]
d) Is the above grammar LL(1). Justify your answer[2 marks]
2) Consider the regular expression (a+b)*a(a+b)(a+b)
I. Augment the expression and construct the syntax tree for the above regular expression
[3 marks]
II. Find Firstpos() and Lastpos() for every internal node in the syntax tree[6 marks]
III. Find Followpos() for every position in the syntax tree [3 marks]
IV. Construct the corresponding DFA for the given RE using Followpos()[3 marks]
S->L=R | R
L->*R |id
R-> L
a) Augment the grammar[1 mark]
b) What is the initial item? [1 mark]
c) Find FIRST(X),Follow(X) for each variable in the grammar [3 marks]
d) Construct the Set of SLR Items for the above grammar [5 marks ]
e) Construct a SLR parser table for the grammar[3 marks]
f) Can an SLR parser be generated for the grammar? Justify your answer[2 marks]
4) Consider the following augmented grammar
S’->S
S->CC
C->c C
C->d
a) Construct the Set of LR(1) Items for the above grammar [5 mark]
b) Construct an LALR parsing table for the same [3 marks]
c) Show which states LA LR parser could be combined and why [4 marks ]
d) Construct the corresponding CLR parsing table [3 marks]
5) Consider the following augmented grammar
E’->E
E->E+T|T
T->T*F|F
F->id
a) Construct the Set of SLR Items for the above grammar [6 mark]
b) Construct the goto graph [2 marks]
c) Construct an SLR parsing table for the same [3 marks]
d) Use the above table to demonstrate the parsing of the string id * id + id [4 marks ]
6) i) Express the expression y=(a+b)*c in [9+6]marks
I. postfix notation
II. Abstract syntax tree
III. Three address code
ii) Implement the TAC using
a. quadruples
b. triples
c. indirect triples
7) a) What is LEX?
b) Explain the working of LEX
c) Show the step by step construction of a lexical analyzer with the following three tokens
• a {}
• abb{}
• a*b+
8) a) What is a compiler?
b) Explain the different phases of compiler with an example
c) Compare and contrast between a compiler and an interpreter
9) What are basic blocks? How are leaders in basic blocks determined? What are equivalent basic
blocks? Explain the different kinds of local transformations that can be applied to a basic block
for optimization. What is a flow graph? How a flow graph is constructed? [2+3+1+4+1+4]marks
10) Define syntax directed translation. Construct an annoted parse tree for the expression
(4*7+1)*2. Define back patching and semantic rule for Boolean expression (2+8+5)
11) Write short notes on (3 × 5=15)
I. Lexical Error And Syntax Error
II. Activation Record
III. yacc parser generator
12) Consider the following three address code segment: (6+9)marks
I. prod:=0
II. i=1
III. t1=4*i
IV. t2=addr(A)-4
V. t3=t2[t1]
VI. t4= addr(B)-4
VII. t5:=t4[t1]
VIII. t6:=t3*t5
IX. prod:=prod + t6
X. i=i+1
XI. if i<=20 goto(3)
i. Find the basic blocks and flow graph of the above sequence
ii. Optimize the code sequence by applying function preserving transformation and
loop optimization techniques
b) Find the output, given grammar G1 and associated semantic rules and input: 00011 [5 marks]
• S->0X {print(1)}
• S->00Y{print(2)}
• A->1Y|1 {print(3)}
S’->S
S->c A|cc B
A->cA|a
B->ccB|b
a) Construct the Set of SLR Items for the above grammar [6 mark]
b) Construct the goto graph [3 marks]
c) Construct an SLR parsing table for the same [3 marks]
d) Is the above grammar SLR(0). Justify your answer [3 marks ]
18) a) What do you mean by peephole optimization?[2 marks]
b) Explain with example (i)constant folding (ii) common sub-expression elimination (iii)loop
unrolling (iv)loop jamming [3×4=12]
c) What do you mean by redundant load store statement? [1 mark]