Professional Documents
Culture Documents
CD Question Bank
CD Question Bank
2.) Construct minimum state DFA for regular expression (0 + 1)* 00 + 01.
main()
int x, y, z;
z = x + y;
List down the lexemes, tokens and the attributes of the tokens, at the end of
lexical analysis of the above program.
9.) Explain the various phases of compiler with the help of a diagram. Explain
the kind of transformation done on the source program by the individual
phases of the compiler on the statement position = initial + rate * 60.
12.) Explain the phases that constitute the front end of a compiler.
13.) What is LEX compiler? Write a LEX program to recognize tokens identifier,
number and relational operator.
14.) Construct a DFA over alphabet ∑ = {0,1}, which accepts the set of strings
either start with 01 or end with 01.
16.) Describe the different phases of a compiler for given input string
(b + c) * (b + c) * 2.
17.) Describe the various components of a compiler and also draw the block
diagram of a compiler.
18.)
19.)
20.) Given the language L = {ab, aa, baa}, derive L*. Explain each step in details.
UNIT-2
1.) Differentiate between top down and bottom up parser.
2.) Why there is a need to eliminate left recursion in top down parsing,
construct predictive parsing table for:
S → iEtSS1/a
S1 → eS/ε
E→b
S → AaAb/ BbBa
A→ε
B→ε
Test whether the grammar is LL(1) or not and construct a predictive
parsing table for it.
4.) ) Write an algorithm to obtain the First() and following table, left factoring
the given grammar:
E→E+T/T
T→ T* F / F
F→ (E) / id
5.) What do you mean by left recursion? Support your answer with example.
6.) Give the rules to find out FIRST and FOLLOW of Non terminals of grammar.
For the given grammar find out FIRST and follow:
E → TE1
E1 → + TE1/ ε
T → FT1
T1 → *FT1
F → (E)/ id
S → AA
S → aA
A→b
T → T * F/F
F → id
S→ CC
C → cC
C→d
S → 1 AB/ ε
A → 1 AC/OC
B → OS
C→1
S → AA
A → aA
A→b
16.) Test whether the grammar is LL.(1) or not and construct a predictive
parsing table for it.
S → AaAB/BbBa
A→ε
B→ε
grammar:
S → xAy/xBy/xAz
A → As/b
B→b
18.) Let a Context Free Grammar CFG {N, T, P, S} be N = {S), T= (a, b), Starting
symbol = S. P =S → SS | aSb | ε. One derivation from the above CFG is
"abaabb". Draw the tree representation.
S → ASA / aB
A → B/S
B → b/ε.
UNIT-3
1.) Describe Boolean expression and procedure calls.
2.) What is the role of semantic analyzer? Explain synthesized and inherited
attributes with example.
(i) Quadruples
(ii) Tripal
E → E1 + T
E → E1 - T
E→T
T → T1 * F
T →T1/F
T→F
F → (E)
F → num
Give the semantic rule to represent syntax directed definition for arithmatic
expression and draw annotated parse tree for 4-6/3+ 5.
Q : = - b * (c + d)
give the quadruple, triple and indirect triple representation with brief
explanation.
9.) What are quadruples, triples and indirect triples. Give their examples.
Give the quadruples, triple and indirect triple representation of the statement
X = (a + b)* + -c/d.
11.) Write the three address code for the following program fragment:
if P = 1 then q = q + 1
else
while (p < = s) do
P=P+3
A = - b * (c + d)
Into
(i) Quadruples
(ii) Triples
E → E1 - T
E→T
T → (E)
T → id
T → num
E→E+T
E→T
T→T*F
T→F
F → id
And write:
18.) Explain in details the construction of a syntax tree for a binary infix
arithmetic expression:
a + a * (b – c) + (b - c) * d
UNIT-4
1.) What is dynamic storage allocation? Explain allocation strategies.
3.) What is the use of symbol table. describe ways to implement symbol table
and write the various fields of symbol table
9.) Discuss the following parameter passing techniques with suitable example:
10.) Explain different data structures used for symbol table organization
...
scanf("%s", username);
show_data(username);
return 0;
16.) Explain the working of procedures and its activations and run-time. Write
with suitable example.
17.) Give a brief explanation on static allocation and dynamic allocation with
respective diagram.
18.) Discuss the role of symbol table in run- time environment with example.
UNIT-5
1.) Define the term loop optimization explain any two loop optimization
techniques.
1 PROD = 0
21=1
3 T2 = addr(A)-4
4 T4 = addr(B)-4
5 T1 = 4*i
6 13 = T2[T1]
7 T5 = T4[T1]
8 T6 = T3*T5
9 PROD = PROD + T6
10 i = i + 1
11 IF I < = 20 GOTO 5.
5.) Translate the following code to basic block and flow graph
Sum : = 0
U:=1
Sum : = sum + a [ 2 * I ]
I:=I+i
Avg = sum/ i
a: = x - y + x - z + x - z .
7.) What is basic block?
9.) Consider the following expression, apply the algorithm of code generation
on it.
a = (p + q) - ((r + s) - t)
address code:
a = (p + q) - ((r+ s) - t)
t1 = p+ q
t2 = r + s
t3 = t2 – t
a = t1 +t2
Exp(x)
int p = 1;
p=p*i
return(p);
15.) Create a Control Flow Graph for the following code and explain the steps
in details:
Int i, j, v, x; // temps
if (n <= m) return;
i=m-1
j=n
v = a[n];
while(1) {
do i =i + 1;
while( a[i]<v];
do j=j-1;
while(a[j]>v);
if(i>=j) break;
x = a[i];
a[j];
a[j] = x;
} //end while
X = a[i];
a[i] = a[n];
a[n] = x;
quicksort(m,j);
quicksort(i+1,n);
} //end quicksort
16.)