Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Compiler Design

RCS502/KIT052
Question Bank: Unit 1
Short answer type questions
1 Differentiate between compiler and assembler.
2 Write down short note on symbol table.
3 Define Lexeme, tokens and pattern with example.
4 Discuss different phases of compiler with an example.
5 Discuss analysis-synthesis model in detail.
6 Differentiate between Left most derivation and Right most derivation with the help of grammar.
7 Discuss the concept of Ambiguity with the help of a grammar and also discuss its removal.
8 Draw the minimized DFA for the regular expression a(a+b)*
9 Discuss the working of lexical analyzer and how input buffering is used for recognition of token.
10 Discuss the concept of bootstrapping with an example.
11 Discuss the concept of Left factoring with the help of an example.
12 Discuss the algorithm for conversion of NFA to DFA with an example.
13 Discuss the algorithm of minimization of DFA with an example.
14 Define Parse tree.
15 Discuss the concept of LEX.

Unit 2
Short answer type questions
1 Explain difference between Top down parsing and bottom up parsing.
2 Construct predictive parsing table for the grammar
E➔TE’
E’➔TE’ | є
T➔FT’
T’➔*FT’ | є
F➔€ | id

3 Check grammar is LL(1) or not


S➔iEtSS’ | a
S’➔eS | є
E➔b

4 Show that the following production is LL(1) or not


S➔AaAb | BbBa
A➔ є
B➔є

5 Explain Shift reduce parser with example


6 Explain the term handle pruning
7 Find LR(0) collection of items

S➔AaAb | BbBa
A➔a
B➔b
8 Construct SLR(1) parsing table of a given grammar and parse the input string “ aabb ” :
S➔AA
A➔aA | b
9 Construct CLR(1) parser of a given grammar:
S➔AA
A➔aA | b
10 Construct LALR(1) parsing table with the help of CLR(1) parsing table in question9

11 Construct SLR(1) parser of a given grammar:


S➔AA
A➔aA | b
12 Find CLR(1) collection of items

S➔AaAb | BbBa
A➔a
B➔b

13. Compute FIRST()&FOLLOW() for given grammar


S➔iEtSS’ | a
S’➔eS | є
E➔b
14 Construct LALR(1) parsing table for given grammar

S➔AaAb | BbBa
A➔a
B➔b

15 Discuss Handle pruning with an example.

Unit 3
Short answer type questions
1 Generate three address code for the following:
c = 0;
do{
if ( a<b ) then
x++;
else
x--;
c++;
}while(c<5)

2 Generate three address code for the following:


while (a<c and b>d) do
if (a=1) then
c=c+1
else
while (a<=d) do
a=a+b
3 Construct DAG for the following Three-address code:
a=b+c
t1 = a * a
b = t1 + a
c = t1 * b
t2 = c + b
a = t2 + t2
4 Represent the following expression into DAG:
a := b * -c + b* -c
5 Write down the translation procedure for control statement and switch statement.
6 Define Syntax Directed Translation. Construct an annotated parse tree for the expression (4 * 7 + 1)
* 2, using simple desk calculator grammar.
7 Translate the following expression to quadruple, triple and indirect triple-
a+b*c/e^f+b*a
8 What is postfix notation? Translate (C+D)*(E+Y) into postfix notation using syntax directed
translation scheme.
9 Generate three address code for the following:
add(int a, int b)
{
int c;
c=a+b;
return c;
}
main()
{
int v1,v2,v3,v4;
v1=10;
v2=20;
v3=add(v1,v2)
v4=v3+5
}
10 Construct the DAG for the expression: ((x + y) - ((x + y) * (x - y))) + ((x + y)*(x - y))
11 Define Annotated Parse tree.
12 Discuss 3 address code of looping statement with an example.
13 Define quadruple, triple, indirect triple used in three address code.
14 Give the 3 address code for assignment statements with an example.
15 Generate 3 address code for
If[(a<b)and((c>d) or(a>d))] then
z=x+y*z
Else
z=z+1

Unit 4
Short answer type questions
1 What is Symbol Table?
2 What is the use of symbol table?
3 What are the data structure used in symbol table?
4 What are the functions used in symbol table?
5 How the description of scope of a variable is represented in Symbol Table?
6 Explain activation tree with example.
7 What do you mean by error detection and error recovery in compiler?
8 Classify the types of ERROR.
9 Explain the four strategies of Error Recovery.
10 Explain Lexical phase and Syntactic phase error detection.
11 What is Symbol table with entries? Also, explain the data structures used for symbol table
12 Discuss the following storage allocation strategies with example:
a) Static Allocation
b) Stack Allocation
c) Heap Allocation

13 What do you mean by run time storage management? Explain Activation record and display
structures.

14 What are various types of errors that may appear in compilation process? Explain the functions
of error handling phase of Compiler.
15 Explain storage allocation for block structure languages.

Unit 5
Short answer type questions
1 What are the tasks of code generator?
2 What are the issues in the design of a code generator?
3 What are the modes of addressing in the target code?
4 Explain static allocation in the target code with example.
5 Explain stack allocation in the target code with example.
6 Explain procedure call in target code.
7 How basic blocks can be created? Explain with example.
8 Explain a flow graph with example.
9 What are the advantages of creating DAG of basic blocks?
10 How DAG can be represented of an Array reference?
11 Write short notes on Peephole optimization.
12 Explain the algorithm for following with example-
a) Global and local common sub expression elimination
b) Induction variable detection and elimination
13 Discuss Loop Optimization techniques with example.
14 Define basic block. Explain the algorithm for partitioning a sequence of three address code into
basic blocks. Illustrate with example.
15 Write short notes on:
a) Induction variable elimination
b) Common sub expression elimination
c) DAG representation of basic blocks and application of DAG
d) Control flow analysis
e) Data flow analysis
f) Loop unrolling and loop jamming

Multiple Choice Questions

16. A optimizing compiler


a) Is optimized to take less time for execution
b) Optimized the code
c) Is optimized to occupy less space
d) None of the mentioned
Answer - b

17. The graph that shows basic blocks and their successor relationship is called
a) Flow graph
b) Control graph
c) Hamiltonian graph
d) DAG
Answer - a

18. The optimization technique which is typically applied on loops is


a) Removal of invariant computation
b) Peephole optimization
c) Constant folding
d) All of these
Answer - d

19. DAG representation of a basic block allows


a) Automatic detection of local common sub expressions
b) Automatic detection of induction variables
c) Automatic detection of loop variant
d) None of the above
Answer - a

20. Code can be optimized at


a) Source from user
b) Target code
c) Intermediate code
d) All of the above
Answer – a

You might also like