CD250 Questions
CD250 Questions
UNIT-I:
1. Explain the input buffer scheme for scanning the source program. How the use of
sentinels can improve its performance? Describe in detail. (Apr 14)
3. a) Describe the steps involved for creating a lexical analyzer with Lex. (Apr 12)
b) Explain the boot strapping process. What is the advantage of using this process?
5. Explain with one example how LEX program perform lexical analysis for the
following patterns in `C': identifier, comments, numerical constants, arithmetic
operators. (May 10)
6. a) Construct an NFA for regular expression R= (aa |b)*ab convert it into an equivalent
DFA(May 10)
b) Write a LEX program for identifying the keywords and identifiers from the file?
7. a) Explain the different phases of a compiler, showing the output of each phase, using
the example of the following statement: position : = initial + rate * 60.
(May 09)
b) Compare compiler and interpreter with suitable diagrams.
10.a) What is LEX? Explain, in detail, different sections of LEX program. (May 09)
b) Write regular expressions for the following patterns. Use auxiliary definitions
wherever
convenient.
i.The set of words having a,e,i,o,u appearing in that order, although not
necessarily consecutively.
ii. Comments in C.
11. Compare compiler and interpreter with suitable diagrams. . (Apr 08)
12. Explain the different phases of a compiler, showing the output of each phase, using the
example of the following statement: (Apr 08)
position : = initial + rate * 60 .
16. Explain the input buffer scheme for scanning the source program. How the use of
sentinels can improve its performance? Describe in detail. (Apr 2008)
17. Construct minimum state DFA s for the following regular expressions (Feb
07)
i. (a+b)*a(a+b) ii. (a+b)*a(a+b)(a+b) iii. (a/b)*a(a/b)(a/b)(a/b) .
18. Write a procedure for constructing a deterministic finite automata from a non-
deterministic Automata, explain with one example . (Feb 07)
19. a) Write a procedure that combines two NFAs into a single NFA. The operations to be
performed are those of concatetion, union and closure. (Feb 07)
b) Write a procedure that detects all extraneous states in a DFA. .
20. Write regular expressions and NFA for the following patterns. Use auxiliary
definitions where convenient. (Mar 06)
i. The set of words having a,e,i,o,u appearing in that order , although not necessarily
consecutively.
ii. Comments as in C. .
21. Construct minimum state DFAs for the following regular expressions (Apr 05)
i. (a/b)* a (a/b) ii. (a/b)* a (a/b) (a/b) iii. (a/b)* a (a/b)(a/b)(a/b). .
22. Describe the languages denoted by the following regular expressions .(Apr 05)
i. (0/1) * 0(0/1) (0/1) ii. 0*10*10*10* iii. (00/11)_ ((01/10)(00/11)_ (01/10)
(00/11)_ )_
23. a)What is the string generated by the grammar A → (A)A (Apr 11)
b) Explain the basic method of LL(1) parsing and hence explain how very simple
grammar generates strings of balanced parentheses.
24. a) Explain the reasons for separating lexical analysis phase from syntax analysis.
(Apr 11)
b) Eliminate ambiguities from the following grammar.
S--> iEtSeS|iEtS|a
E--> b|c|d:
26 Explain with one example how LEX program perform lexical analysis for the
following patterns in `C': identifier, comments, numerical constants, arithmetic
operators. (Apr 11)
27 a) Construct predictive parse table for the following grammar. (Apr 11)
E → E + T|T
T → T F|F
F → F|a|b
b) What are the limitations of recursive descent parser?
28 a) Construct predictive parse table for the following grammar. (May 10)
E → E + T|T
T → T F|F
F → F |a|b
b) What are the limitations of recursive descent parser?
29 What do you mean by left most derivation? Explain with an example. (May 10)
32. a) What are the difficulties in top down parsing? Explain in detail. (May 09)
b) Consider the following grammar
S ! (L) |a
L ! L, S |S
33. Construct leftmost derivations and parse trees for the following sentences: (May
09)
i. (a,(a,a))
ii. (a,((a,a),(a,a)))
34. a) Construct predictive parse table for the following grammar. (May 09)
E ! E + T| T
T ! T _ F| F
F ! F _ |a |b
b) What are the limitations of recursive descent parser?
35. a) What is recursive descent parser? Construct recursive descent parser for the
following grammar.
E ! E + T|T (May 09)
T ! TF|F
F ! F_|a|b
b) What is ambiguous grammar? Eliminate ambiguities for the grammar:
E ! E + E|E_E|(E)|id. [8+8]
37. What is ambiguous grammar? Eliminate ambiguities for the grammar: (Apr 08)
E ! E+E|E* E|(E)|id.
38. a) What is recursive descent parser? Construct recursive descent parser for the
Following grammar.
E ! E+T|T . (Apr 08)
T ! TF|F
F ! F* |a|b
b) Consider the following grammar .
E ! T+E|T
T ! V*T|V
V ! id
Write down the procedures for the nontermils of the grammar to make a recursive
descent parser.
39. Construct predictive parsing table for the following grammar. . (Apr 08)
E ! TE'
E' ! +TE'|e
T ! FT' [16]
T' ! *FT' |e
F ! (E)|id
41. Convert the following grammar into LL(1) grammar (Mar 06)
R ! R“|'R|RR|R _ |(R)|a|b
43. What are the limitations of recursion descent parser? (Apr 05)
44. Construct predictive parse table for the following grammar. (Apr 05)
E ! E + T|T
T ! TF|F
F ! F _ |A|B
45. What is an LL(1) grammar. Can you convert every context free grammar into LL(1).
46. The grammar S ! aSa|aa generates all even length strings of a’s except for the empty
string-show that the prete free method of top down parsing succeeds of 2,4 and 8a’s
but fails on 6a’s. Also find out what are the even strings that are passed by the
technique.
. (Apr 05)
47 . Write a Lex program that copies a file, replacing each nonnull sequence of white
space by a single blank.
48. Write a Lex specification for the tokens of Pascal and use the Lex compiler jto
construct a lexical analyzer for Pascal
49. Construct a tool that produces a lexical analyzer from a regular expression
description of a set of tokens
50. What is a problem with 1-pass compiler. Explain its advantages and
disadvantages.
UNIT-II :
1. a) Explain LALR parsing, justify how it is efficient over SLR parsing. (Apr 14)
b) What is phrase level error recovery?
2. a) Construct SLR parsing table for the following grammar. (Apr 13)
S --> AS|b
A --> SA|a
b) What are the actions of shift reduce parse.
6. a) Construct LALR parsing table for the following grammar (May 10)
S - > CC
C - > cC|d
7. Give the algorithm to generate the canonical collection of LR(0) items. (May 10)
10. Construct LALR parsing table for the following grammar (Apr 09)
S ! CC
C ! cC|d
11. a) What are the common conflicts that can be encountered in shift – reduce parser.
(Apr 09)
(b) Construct SLR parsing table for the following grammar.
R ! R ′|′ R |RR |R∗ |(R) |a |b
14. a) Define LR(k) parser. Draw and explain model of LR parser. (Apr 08)
b) Write LR parsing algorithm.
15. Construct SLR parsing table for the following grammar. (Apr 08)
A ! SA|a
18. Construct SLR parse table for the following grammar. (Mar 06)
S ! Aa|bAc|dc|bda
A!d
20. Construct LALR parse table for the following grammar. (Apr 05)
S ! Aa|bAc|Bc|bBa
A!d
B ! d.
21. Construct SLR passing table for the following grammar. (Apr 05)
E ! E + T/T
T ! TF/F
F ! F_|a|b.
25. LL(1) language is defined as the language for which there exist some LL(1) grammar
generating the language. Consider the following statement:
“There exist an algorithm to determine whether the given grammar is LL(1), but
there exist no algorithm to determine whether a given language is LL(1)”.
Comment on the truth/falsehood of the above statement.
26. Is the following language LL(1)?
{ancbn | n1}
27. Show that a grammar with no production in which each alternative begins with
a distinct terminal is always LL(1).
28. Show that no left recursive grammar is LL(1)
32 The grammar S ! aSa|aa generates all even length strings of a’s except for the
empty string-show that the prete free method of top down parsing succeeds of 2,4
and 8a’s but fails on 6a’s. Also find out what are the even strings that are passed
by the technique.
33 What is ambiguous grammar? Explain the process of elimiting ambiguities from
a grammar with a suitable example.
34 What is recursive descent parser. Write recursive descent Parser for the following
grammar?
E →TE' .
E' → TE' /t
T → FT '
T '→ *FT ' /t
F → (E)/id
35 (a) Define LL(1) grammar.
(b) Construct LL(1) parse table for the following grammar
. bexpr ! bexpr or bterm/bterm
bterm ! bterm and bfactor|bfactor
bfactor ! notfactor|(blxpr)|true|false
Whereor,and,not,(,),true,falsearetermilsinthegrammar.
36. Show that no LR(1) grammar can be ambiguous
37. Show that SAa | bAc | Bc | bBa,
Ad, Bd is LR(1) but not LALR(1).
38. Write a YACC desk calculator program that will evaluate Boolean expressions.
39. Show that every LL(1) grammar is LR(1) grammar.
44 Construct operator precedence parser for the following grammar for reference
expressions.
R ! R‘10R|RR|R_|(R)|a|b. .
45 What is LR(1) parsing.
46 Distinguish top down and bottom up parsing.
47 Construct SLR passing table for the following grammar. . .
E E + T/T
T T*F/F
F F_|a|b.
50. Write the Differences Between top down and bottom up parsing.
UNIT-III :
2. a) Give a, c are 2 dimensional real arrays and b is a 2 dimensional integer array and i,
j are integer variables, write the 3-address code for the following program fragment
(Apr 13)
for (i = 0; j = 0; i < 10ANDj < 10; i + +; j + +)
f
C[i][j]=a[i][j]+b[i][j];
}
3. a) Explain SDD for Boolean expressions with and without back patching. (Apr 12)
b) Write the SDD for “Do - While" statement and explain?
5. a) Write a regular expressions and NFA for the following patterns. Use auxiliary
definitions where convenient? (May 10)
i. The set of words having a, e, i, o, u appearing in that order, although not having
necessarily consecutively.
ii.Comments in C.
b) Differentiate Interpreter and Compiler?
6. a) Write the quadruples, triples and indirect triples for the expression (May 10)
i. (a + b) * (c + d) *(a + b + c)
ii. a * (b + c)
b) Write a top-down translation scheme to produce quadruples for Boolean
Expression.
7. a) Why are quadruples preferred over triples in an optimizing compiler. Explain. (May
10)
b) Give the triple representation of an array operation x : = y [ i ]
c) Give the syntax directed definition of if else statement.
9. a) Write the three-address code for the following code. (May 10)
fact(x)
{ int f=1;
for (i=2, i >=x, i++)
{
f=f*i;
return f;
}
b) Write an algorithm for identifying leaders and partition the code into basic blocks
and apply it on the above derived three-address code.
12. a) What is a syntax tree? Write syntax directed definition for constructing a syntax
tree for an
expression. The grammar for an expression is given below. (Apr 09)
E ! E + T |E − T |T
T ! (E) |id |num
b) Write a detail notes on type conversion.
13. a) Write a S - attributed grammar to connect the following grammar with prefix
rotator (Apr 09)
L!E
E ! E+T | E-T | T
T ! T*F | T/F | F
F!P"F|P
P ! (E)
P ! id.
b) Construct triples of an expression: a _−(b + c).
14. a) Which of the following recursive type expressions are equivalent? Justify your
answer?
(Apr 09)
e1=integer ! e1; e2=integer ! ( integer ! e2 ); e3=integer ! ( integer !e1).
b) Suppose that the type of each identifier is a sub range of integers for expressions
with the operators +,-,*,div and mod as in pascal. Write type-checking rules that
assign to each sub expression, the subrange its value must lie in.
15. Write type expressions for the following types. (Apr 09)
a) An array of pointers to reals, where array index ranges from 1 to 100.
b) A two dimensional array of integers (i.e. an array of array) whose rows are indexed
from 0 to 9 and whose columns are indexed from -10 to 10.
c) Functions whose domains are functions from integers to pointers to integers and
whose ranges are records consisting of an integer and a character. (April/May 2009)
18 Write the quadruple , triple, indirect triple for the statement a:=b*-c+b*-c.
(Apr 08)
19. Write type expression for the following types. (Feb 07)
a) An array of pointers to real, where the array index ranges from 1 to 100.
b) A two dimensional array of integers (i.e an array of arrays) whose rows are indexed
from 0 to 9 and whose columns are indexed from 10 to 10.
20. Apply the translation scheme on the following expression a< b or c< d and e< f.
(Mar 06)
21. Give a syntax-directed translator scheme for converts the statements of the
following grammar into three address code: . (Mar 06)
S!while expr do begin S and
|S; S
|break
22. a) Discuss about the overloading of functions and operators with an examples.
(Mar 06)
b) Write a notes on polymorphic functions.
23. Give a syntax-directed translator scheme for converts the statements of the
following grammar into three address code (Apr 05)
while expr do begin S and
;S
break
|other`
L!id
25. Write a S-attributed grammar to connect the following grammar with prefix rotator
(Apr 05)
L!E .
E!E+T
E!E-T
E!T
T!T*F
T!T/F
T!F
F!P" F
F!P
P!(E)
P!id.
26. Which of the following recursive type expressions are equivalent ? Justify your
answer? (Apr 05)
e1 = integer ! e1 e2 = integer !(integer ! e2) e3 = integer !(integer ! e1)
27. Suppose that the type of each identifier is a sub range of integers for expressions
with the operators +, -,*, div and mod as in pascal. Write type checking rules that
assign to each sub expression, the sub range its value must lie in.
(Apr 05)
28. What are the advantages and disadvantages of Structural equivalence? Explain
through example.
(Apr 05)
29. What are the advantages and disadvantages of me equivalence. Explain through
examples. (Apr 05)
30. Which among the following expressions are Structurally equivalent? Which are me
equivalent? Justify your
answer. (Apr 05)
i. link ii. pointer(cell) iii. pointer(link)
32. How do you check the expressions in polymorphic functions? Explain through an
example. (Apr 05)
33. a)What is dangling reference in storage allocation? Explain with an example. (Apr
05/08)
b)Consider the following array declaration in ‘c’;
float a[100][100];
Assume that the main memory in byte addressable and that the array is stored starting
from the memory address 100. What is the address of a[40][50]?
34 a) What is the use of Symbol table in compilation process? List out various attributes
stored in the symbol table. (Apr 11)
b) Explain different schemes of storing name attribute in symbol table.
35. Explain how storage allocation is done for arrays, strings and records? (Apr 11)
36. What is a symbol table? Describe any two methods of implementing a symbol
table. (Apr 11)
37. List the various data structures that can be used to organize a symbol table?
Compare the performance.
(Apr 11)
38 a) Explain the importance of each attribute stored in symbol table? (Apr 11)
b) Compare the performance of different symbol table organization.
39 Explain activation tree and draw activation tree for any sorting method. (May 10)
41. Explain symbol table organization using hash tables? Construct hash based
structure for symbol table for the variable in the following program. (May 10)
int main()
{
int a1, a2, c1, c2;
char b1;
float d1, d2;
____
____
}
43. Explain activation trees and draw activation tree for quick sort program. (May 10)
45. Draw and explain the symbol table organization for C language with a program
block. (May 09)
46. Explain the importance of the following attributes of a symbol table. (May 09)
a) Variable name
b) Object time address
c) Type of a symbol table
d) Link field.
48. a) What is an ordered and unordered symbol table? What is the function of symbol
table in the compilation process? Explain. (Apr 08)
b) What are the various attributes of a Symbol Table?
49. Compare three different storage allocation strategies. (Apr 08)
50. Write an algorithm to perform the table lookup and insertion operation for hashed
symbol table.
(Apr 08)
UNIT-IV :
2. What is a DAG? Explain role of DAG in optimization with example. (Apr 13)
3. What is local and global optimization? Explain with example any three local
optimization techniques. (Apr 12)
5. Explain with example the various techniques in loop optimization. (Apr 11)
6. Write the iterative algorithm for reaching definition. Compute in and out for the
following figure 1.(Apr 11)
7. Write the procedure for identifying the basic blocks with example. For the same
example draw domination tree. (May 10)
8. What is a basic block? With an example explain the procedure to identifying basic
blocks in a given program. (May 10)
10. Explain with example the various techniques in loop optimization. (May 10)
11.a) Explain in detail the Optimization technique “strength reduction”. (Apr 09)
b)What is a DAG. Explain its applications.
12. a) Write the three-address code for the following code. (Apr 09)
begin
PROD: = 0;
I: =1;
do
begin
PROD:=PROD + A[I]∗B[I];
I:=I+1;
End
while I<=20
end
b) Write an algorithm for partition of basic blocks and apply it on the above derived
three-address
code.
14. Explain different principal sources of optimization technique with suitable examples.
(Apr 09)
15. a) What is DAG? Construct the DAG for the following basic block (Apr 09)
D := B_C
E :=A+B
B := B+C
A := E-D
b) What are the legal evaluation orders and names for the values at the nodes for the
DAG of problem (a).
i. Assuming A, B and C are alive at the end of the basic block?
ii. Assuming only A is live at the end?
17. a) What is code optimization? What are its advantages? (Apr 08)
b) What are the problems in optimizing compiler design?
18. Explain in detail the optimization technique “Strength Reduction”. (Feb 07)
19. Explain any two machine dependent code optimization techniques. (Mar 06)
23. Explain in detail the optimization technique “Strength Reduction”. (Apr 05)
24. Explain how redundant sub expression elimination and dead code elimination
techniques are applied across different blocks with examples. (Apr 11)
25. Explain about global data flow analysis? List the data flow equations for reaching
definitions for structured programs (Apr 11)
29 Describe the procedure to compute in and out values using data flow equations for
reaching definition in structured programs. (May 10)
30 a) Explain in detail the procedure that eliminate global common sub - expression.
(Apr 09)
b) What are the applications of du and ud chains?
31. Consider the following program which counts the primes form 2 to n using the sieve
method on a suitably large array (Apr 09)
begin
read n
for i : = 2 to n do
a[i] : = true / * initialize */
count: = 0;
for i : 2 to n ** .5 do
if a [i] then /* i is a prime */
begin
count := count +1
for j : = 2 * i to n by i do
a[j] : =false
/ * j is divisible by i */
end ;
print count
end
a) Propagate out copy statements wherever possible.
b) Is loop jumping possible? If so, do it.
c) Eliminate the induction variables wherever possible.
34. Explain about data flow analysis of structured programs (Apr 08)
36. a) Explain reducible and non-reducible flow graphs with an example. (Apr 08)
b) Explain structural loops and inner loops of a flow graph with an example.
38. A flow graph is useful for understanding code generation algorithm? (Apr 08)
Justify your answer with an example.
39. a) Write and explain live variable analysis algorithm. (Apr 2008)
b) Explain the use of algebraic transformations with an example
40. a) What are loop invariant components? Explain how they effect the efficiency of a
program. (Mar 06)
b) Explain how Redundant sub expression elimination can be done at global level in a
given program.
UNIT-V :
Data Flow Analysis: Flow graph, data flow equation, global optimization,
redundant sub expression elimination, Induction variable elements, Live
variable analysis, Copy propagation. Object Code Generation: Object code
forms, machine dependent code optimization, register allocation and
assignment, generic code generation algorithms, DAG for register allocation
2. a) Write about the issues in the design of code generator. (Apr 13)
b) Write about target code forms. Explain how the instruction forms effect the
computation time.
3. Generate the code for the following C statements using its equivalent three
address code. (Apr 12)
a) a = b + c
b) x = a/(b+c) d*(e+f)
c) *A=p
d) A=B+C
5. a) Write about global register allocation strategy for loops. (May 10)
b) Explain code generation from DAG. For the following instructions construct DAG.
t1:=a / b
t2:=a/b
t3:=e - t2
t4:=t1 -t3
t5:=e+t2
t6:=t4 * t5
6. Explain DAG and its use. Write the procedure to construct the DAG for a statement.
(May 10)
10. State and explain different machine dependent code optimization techniques.
(Apr 09)
11. a) What are the various addressing modes available? Give some example machine
instructions which reduces memory access time. (Apr 09)
b) Explain the concept of label tree of code generation.
12. a) Explain with an example the abstract machine code form of Intermediate code.
(Apr 08)
b) Explain the role of intermediate code generator in compilation process.
14. Generate code for the following statements for the target machine (Target Machine
is a byte addressable machine with four bytes to a word and N general purpose
registers.) Assuming all variables are static. Assume 3 registers are available.
(Mar 06)
a) x = a [I ] +1 [4] b) a[ I] = b [c[I ]] [4]
c) a[I] [J] = b[I] [k] * c[k] [J] d) a[I] = a[I] + b[J] [4]
15. a) Augment the code generation algorithm to incorporate the following features.
(Mar 06)
i. The parenthesis in an expression
ii. Non commutative
operators like ‘-‘ and ‘/’ etc
b) Show various steps in the code generation algorithm of the expression (a + b) / (c +
d). Assuming two machine registers to be available.
16. Write about the various object code forms. (Apr 05)
17. Explain with an example the abstract machine code form of Intermediate code.
(Apr 05)
18. Explain with an example how abstract machine code can be generated for a given
if-then-else statement. (Apr 05)
20. Augment the code generation algorithm to incorporate the following features.
(Apr 05)
i. The parenthesis in an expression
ii. Non commutative operators like ‘-‘ and ‘/’ etc
21. Show various steps in the code generation algorithm of the expression.
(Apr 05)
(a + b) / (c + d)
Assuming two machine registers to be available.
35.What are the properties of code generation phase? Also explain the Design Issues of this
phase.
36. What are basic blocks? Write the algorithm for partitioning into Blocks.
37. Write a short note on:
a. Flow graph (with example)
b. Dominators
c. Natural loops
d. Inner loops
e. Reducible flow graphs
38.Consider the following program code:
Prod=0;
I=1;
Do{
Prod=prod+a[i]*b[i];
I=i+1;
}while (i<=10);
a. Partition in into blocks
b. Construct the flow graph
39. What is code optimization? Explain machine dependent and independent code
optimization.
40. What is common sub-expression and how to eliminate it? Explain with example.
41. Write a short note with example to optimize the code:
a. Dead code elimination
b. Variable elimination
c. Code motion
d. Reduction in strength
42. What is control and data flow analysis? Explain with example.
1. t1:=4*i
2. t2:=a[t1]
3. t3:=4*i
4. t4:=b[t3]
5. t5:=t2*t4
6. t6:=prod+t5
7. prod:=t6
8. t7:=i+1
9. i:=t7
10. if i<=20 goto 1
50. Explain the simple code generator and generate target code sequence for the following
statement d:=(a-b)+(a-c)+(a-c)