Theory of Computation and Compilers 20CIC07
Theory of Computation and Compilers 20CIC07
: 20CIC07
CHAITANYA BHARATHI INSTITUTE OF TECHNOLOGY (Autonomous)
B.E. (CSM, CET) VI Sem (Main & Backlog) Examination May – June 2024
Theory of Computation and Compilers
Time: 3 Hours Max Marks: 60
Note: Answer ALL questions from Part-A & Part –B (Internal Choice) at one place in the
same order
Part - A
(5Q X 3M = 15 Marks)
M CO BT
1 Write all the lexemes that make up tokens in the C language function (3) 1 3
int MAX(int i, int j){
if( i>j)
return i;
else
return j;
}
2 Define CFG. Identify the language generated by the CFG (3) 3 1
S→aSb
S→ab
3 Differentiate Synthesized and Inherited Attributes. (3) 4 4
4 Discuss briefly about code motion technique of loop optimization. (3) 5 1
5 How to identify leaders in a program? (3) 5 2
Part – B
(5Q X 9M = 45 Marks)
M CO BT
6 (a) Give NFA with four states equivalent to the regular expression (5) 1 3
(01 +011 + 0111)*. Convert this automaton to an equivalent DFA.
(b) Discuss how Finite Automata is used to recognize tokens and perform (4) 1 2
lexical analysis with an example.
(OR)
7 (a) Explain the different phases of a compiler, showing the output of each (5) 2 3
phase using the example for the statement:
x=(a+b) * (c+d)
(b) Explain how regular expressions are used in lexical analysis phase with (4) 2 2
examples.
8 (a) Construct sets of LR(0) items for the following ambiguous grammar (5) 3 3
E→ E+E | E*E | (E) | id. Construct the SLR table for the given grammar.
(b) Is the following grammar ambiguous? Justify your answer with (4) 3 4
examples of different parse trees for the same string.
S → aSb | SS | ε
(OR)
Page 1 of 2
Code No.: 20CIC07
9 (a) Remove the left recursion for the following grammar and also find (5) 3 3
FIRST’s and FOLLOW’s.
E→E + T | T
T→T * F | F
F → (E)/id
(b) Write the steps/algorithm to construct the predictive parser table and (4) 3 2
explain with an example.
12 (a) Given the following code, construct the control flow graph and perform (5) 5 3
live variable analysis:
a = 3;
b = a + 2;
if (b > 4) { c = b; }
else { c = a; }
d = c + 1;
(b) What is Flow-Graph? Explain how a given program can be converted (4) 5 2
into Flow Graph?
(OR)
13 (a) Construct a DAG for the following program code: (5) 5 3
x=y*z
w=p+y
y=y*z
p=w-x
(b) Explain the following with an example (4) 5 2
i) Constant Propagation
ii) Strength Reduction
Page 2 of 2