Compiler Design QB

You might also like

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

REVA University

School of CSE
Compiler Design: B20EFS517 – Question Bank
Unit-1
1. Explain the various phases structure of compiler with a neat block diagram.
2. Explain input buffering strategy and its algorithms used in lexical analysis phase.
3. Classify the differences between Compiler & Interpreter.
4. Demonstrate the outputs at each phase with the expression given below. List out
the possible errors that could be encountered during the stages for the statement
identifier: = value + rate * 60;
5. Define Regular expression and Regular definition. Design the regular definition for
identifier and also draw the transition diagram for identifier.
6. List and explain the compiler construction tools.
7. Define regular expression and regular definition. Design the regular definition for
unsigned number and also draw the transition diagram for unsigned number.
8. Explain the various phases of a compiler & also illustrate using the string: sum =
initial + rate * 20
9. Explain the language processing system.
10. Demonstrate the outputs at each phase of a compiler with the expression given
below. Also list out the possible errors that could be encountered. (Assume A and
B to be integers) A=(B*3) +50
11. When lexical analyzer encounters relational operators (<,>,<=,>=,<>….),it has to
return a token. Show the same using a transition diagram and show the pseudo-
code.
12. Define lexeme, token and patterns with examples.

Unit-2
1. Given the grammar
S  aABb
Ac|ε
Bd|ε
i. Compute FIRST and FOLLOW sets.
ii. Construct the predictive parsing table.
iii. Show the sequence of moves made by predictive parser in the input
“acdb$”
iv. Is the given grammar LL (1). Justify your answer.
2. Define handle pruning? Show the bottom-up parser for the input: “aaa*a++” and
grammar: A  AA+ | AA* | a
3. What is derivation? Discuss the types of derivation with examples.
4. Discuss the key problems associated with the top-down parser. Explain recursive
descent parser having a string as “cad” for the grammar show below:
S  cAd
A  ab | a
5. Define Shift Reduce parser. Explain the four possible actions of shift reduce parser
and conflicts with an example.
6. Define left factoring Apply the left factoring for the following grammar.
S → bSSaaS / bSSaSb / bSb / a
7. Shifts reduce parsers generally not preferred bottom-up parser. Explain the
conflicts with suitable example.
8. Define CFG, LMD, RMD, parse tree & ambiguous grammar with examples.
9. Show the FIRST and FOLLOW sets and also construct the LL (1) predictive parser
and show the sequence of moves on string ‘a + a’.
SS+A|A
AA*B|B
Ba
10. Define Left recursion. Apply left recursion for the grammar.
A → ABd / Aa / a
B → Be / b
11. Evaluate left factoring the following grammar.
S → aAd / aB
A → a / ab
B → ccd / ddc
12. Explain bottom-up parser. Show the tree snapshots that are constructed for the
string id*id using bottom-up parser.
EE+T|T
TT*F|F
F  (E) | id
13. Calculate the FIRST and FOLLOW functions for the given grammar:
S→A
A → aB / Ad
B→b
C→g

Unit-3
1. Define Ambiguous grammar. Consider the production given below: S àCC | CSC
Prof. James wanted to parse input string CCCCCC, show that the given grammar is
ambiguous? Justify your answer.
2. John E Hopcroft and Jeffrey D Ullman want to design a bottom-up parser to parse
the string “aabb” for the given grammar
S AA
A  aA | b
i. Obtain the sets of canonical collection of sets of valid LR (0) items.
ii. Design the SLR parsing table.
iii. Show the sequence of moves for the above string.
iv. Identify whether the given grammar is SLR (1) or not. State the reasons.
3. What are LR Parsers? Explain the working principle of LR Parser with block
diagram.
4. Consider the following grammar:
SL=R|R
L  * R | id
RL
i. Obtain LR (0) items.
ii. Computer FIRST and FOLLOW symbols.
iii. Obtain CLR Parsing table.
iv. Check whether given grammar is CLR or not.
5. Consider the context free grammar given below:
S  En
E  E+T | E-T | T
T  T*F | T/F | F
F  (E) | digit
i. Show Syntax Directed Definition for the above grammar.
ii. Write Annotated parse tree for the input string 5*6+7.
6. Explain the parser stack implementation of postfix SDT, with an example.
7. Construct canonical parsing table and LALR for grammar
S  BB
B  bB
Bd
8. Define syntax directed definition and write the SDD for
E  E+T/T
T  T*F
F  (E)/digit
i. Construct annotated parse tree for the string “5+4” using the above
grammar.
9. List out the applications of Syntax directed translation.
10. Define Syntax directed Translation. Consider the LL grammar write the SDD and
also draw the annotated parse tree for the expression “6*4”.
T  FT’
T’ *FT’
F  digit
11. Write the SDD for simple type declaration
D TL
T  int /float
L L, id /id
i. Construct the dependency graph for the declaration int id1, id2.
12. Consider the following grammar:
S AA
A Aa| b
i) Construct sets of LR(1) items
ii) Construct canonical LR(1) parsing table
iii) Show the parsing steps for the string baaba
13. Consider the following grammar. A  a | (A)
i) Find LR(0) items
ii) Construct SLR(1) parsing table
iii) Show the parsing steps for the string “((a))”

14. Consider the following grammar:


EE+T|T
TT*F|F
F  (E) | id
i) Compute canonical sets of LR(0) items
ii) Construct SLR(1) parsing table
iii) Show the sequence of moves for the string id + id * id
iv) Is the grammar SLR (1). Justify your answer.
15. Define the following: LR(0) item , Augmented grammar , Closure , Goto
16. Define semantic analysis. Classify the two attributes of SDD and explain with
examples.
17. Define Annotated parse tree. Write the grammar and SDD for simple desk
calculator & show the annotated parse tree for the expression (3 + 4) * (5 + 6).
18. Obtain LALR parsing table for the grammar given below.
S  CC
C  cC
Cd
Also show the derivation tree for the string ccdd$.
19. Explain the working principle of SLR, CLR and LALR parsing with a neat diagram.

Unit - 4
1. Construct directed acyclic graph (DAG) for the input string:
a+(a*(b-c))+((b-c)*d). Using the input string, write the three-address code for
Quadruples, Indirect triples and Triples and also draw the syntax tree.
2. Explain the various issues in code generation phase with examples.
3. Construct intermediate code and basic blocks for the C-code.
for i=1….10 do
for j=1….10 do
a[i,j]=0.0
for i=1….10 do
a[i,i]=1.0
4. List out the optimization techniques of basic blocks of code generation. Discuss all
techniques with examples.
5. Define basic block. Construct the basic block for the given intermediate code
given below.
i=1
sum = sum + a[i]*b[i]
i = i+1
while(i<=20)
6. Construct the DAG representation for the following basic block.
x=x+3
y=y+x
x=y–z
y=x
7. Construct directed acyclic graph (DAG) for the input string ((a*b)*(a-b))/d. Write
the 3-address code for quadruples, triples and indirect triples.
8. Construct directed acyclic graph (DAG) for the input string d + (b-(a/c)) * (a-(a/c))
and also write the 3-address code for quadruples, triples and indirect triples.
9. Consider the following code-
prod = 0 ;
i=1;
do {
prod = prod + a[ i ] x b[ i ] ;
i=i+1;
} while (i <= 10) ;
i. Compute the three address code.
ii. Compute the basic blocks and draw the flow graph.
10. Construct directed acyclic graph (DAG) for the input string a + a * (b-c) + (b-c) * d
and also write the 3-address code, indirect triples, triples and quadruples also
draw the syntax tree.
11. Construct the intermediate code and basic blocks for the given code
X := 20;
WHILE X < 10
DO
X := X-1;
A[X] := 10;
IF X = 4 THEN X := X - 2; ENDIF;
ENDDO;
Y := X + 5;
12. Define Quadruples, Triples, and indirect triples for the following expression.
a=b*–c+b*–c
13. Construct a DAG for the expression: a+a*(b-c)+(b-c)*d

You might also like