Nothing Special   »   [go: up one dir, main page]

Question Bank CD - Final 2022-23

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

Department of Information Technology

Subject : Compiler Design


Question bank of all 6 units
Unit-I
1. What do you mean by compiler? With the help of neat diagram describe the various
phases of a compiler and show the interface between them.
2. What are Sentinels? explain the concept of input Buffering.
3. What is the role of Lexical Analyzer (Scanner)? Why it is implemented as a separate
phase? Explain.
4. Define Compiler. Explain how the Following statement would be translated? write the
output of each phase. if(x= =y) then x=x+y; else x=y
5. Minimize the Following DFA

6. Explain with example what are Tokens, Patterns & Lexemes. Elaborate in detail the
specification of tokens.
7. Give the output generated by Lexical Analyzer for each of the following. Identify
Tokens and Lexemes. Also give reasonable attributes value for token:

If (i<j)
max=i;
else
max=j;

8. consider the following statement


position=initial+rate*60 Show that representation of this statement after each phase of
complier
Unit-II

1. Construct the Predictive Parsing table for the given grammar.


S→aABb
A→c|€
B→d|€
2. Explain the FIRST and FOLLOW algorithm and calculate the same for the given
grammar.
E→E+T|T
T→T*F | F
F→(E)|id

3. Test Whether the Following Grammar is LL(1) or not?


E→10*T|5+T
T→PS
S→QP|ε
Q→+|*
P→a|b|c

4. What do you mean by ambiguity? Whether it is necessary to eliminate the


ambiguity? If yes, explain why Eliminate the ambiguity from the following
“dangling-else” grammar.
Stmt→if expr then stmt | if expr then stmt else stmt | other

5. Explain Error Recovery in predictive parsing.


6. Calculate the FIRST and FOLLOW for the given grammar.
S A
A aB|Ad
B bBC | f
C g
7. What is the role of Syntax Analyzer (Parser)? Show the position of Parser in the
compiler model list and explain all the errors at different levels?
8. Consider the following grammar.
S→ aABb , A→c/є , B→d/є
1) Obtain Predictive parsing table 2) Show that given grammar is LL (1) or not
9. Consider the following grammar
S→(L)/a
L→L,S/S
i)Eliminate the left recursion from the grammar ii) Construct PPT
iii)Show the behavior of the parser on string (a,a)
10. Explain Left-recursion and left factoring with example.
11. Consider the following grammar
E→ E+T/T
T→T*F/F
F→(E)/id
i)Eliminate left recursion from the grammar
ii)construct predictive parsing table for this grammar
iii)shows moves made by parser on string id+id*id

Unit-III

1. What is Shift-Reduce Parsing with example.


2. What is Parser? Explain Top Down and Bottom up Parser giving advantages and
disadvantages of each.

3. Consider the following grmmar


S →aSbS│bSaS│є
i) Obtained the A.G.
ii) Obtained the canonical collection of sets of LR(1) items
iii) Construct LR(1) parsing table
4. Consider the following grammar:
E→E+T | T
T→T*F | F
F→(E) | id
a) Write Augmented Grammar
b) Obtain canonical sets of LR(0) items
c) Construct SLR Parsing Table

5. Consider the following grammar


S→AA, A→aA, A→b
i) Construct the SLR parsing table
ii) Draw Transition Diagram for the grammar
iii) Show moves made by parser for input “abb”
6. Consider the following grammar.
E→ E+T|T
T→ T*F|F
F→ id
a) Obtain the augmented grammar
b) Obtain the canonical collection of sets of LR (1) items.
c) Construct LR (1) parsing table.
7. Construct an LALR (1) parsing table for the following grammar.
S→ A | aAc | Bc | bBa
A→ d
B→ d
8. What is Handle? What is Handle Pruning with an example of Shift Reduce Parser
9. Consider the following grammar. Construct CLR Parsing table for the following
grammar.
S‟→S
S→V=E
S→E
E→V
V→x
V→*E
Construct the LR(1) states for the grammar
Obtain LR (1) and LALR (1) parsing tables for this grammar

10. Explain following terms


i. Handles
ii. Handle pruning

Unit-IV

1) Show the DAG representation for expression a+a*(b-c)+(b-c)*d. List and explain the
instruction constructing for the above DAG.
2) Consider the following grammar
D→TL, T→ int/real, L→L1, id/id
i)Give the Syntax-directed definition with inherited attributes
ii)The parse tree for the real id1,id2,id3 and explain with inherited attributes at each
node
iii)Explain what is dependency graph is and construct D.G. for above parse tree.
3) Consider the following grammar for a desk calculator
L→En
E→ E1+T /T ,T→ T1*F/F, F→(E)/digit
i) Give a syntax-directed definition for this grammar to evaluate the given string and
and print the value „n‟ which indicates new line character
ii) Draw the annotated parse tree for 3*5+4n
iii) Give the implementation of this desk calculator with an LR parser
iv) Shows the moves of parser for parsing the string 3*5+4n
4. Consider the following grammar.
L→E
E→E1+T
E→T
T→T1*F
T→F
F (E)
F→digit
Where digit is terminal symbol
a) Obtain the syntax directed definition for the above grammar.
b) Give the implementation of above grammar using an LR Parser.
c) Show the moves made by the translator of part (b) on input 5+3*4.
5.What are syntax directed Translations? What are its types? Explain with suitable example.
6.Construct the DAG for:a+a+(a+a+a+(a+a+a+a))
What is the syntax directed definition for the simple desk calculator, write and explain. What
would be the parse tree for 1*2+3n?
7. Consider the following grammar.
E→E1+T|E1-T|T
T→ (E) |id | num
Where id and num are terminal symbols.
a) Obtain syntax directed definition for constructing syntax tree for the above
grammar.
b) Obtain suitable translation scheme for the definition in (a) above.
c) Show the steps for construction of syntax tree for expression „x-5+y‟

Unit-V
1. What do you mean by activation record? Explain general activation record structure
2. Describe each of the following-
i) Activation Record
ii) Activation Tree
3. Explain Storage allocation strategies and explain Stack allocation in detail.
4. Explain the subdivision of Run time memory.
5. Explain pass by value and pass by reference in detail.
6. What do you mean by Symbol table and symbol table entries? Explain how scope of
information is represented in symbol table.
7. Explain the following
i. control stack ii. Scope of declaration
8. Explain static and stack allocation strategies in detail.

Unit VI
1. Explain Basic Block and Flow Graph in detail?
2. Explain the run time storage management.
3. Consider the assignment statement.
a:=b*-c+b*-c
Construct the intermediate representation
i) Syntax Tree
ii) Directed Acyclic Graph
iii) 3 Address code corresponding to the syntax tree and DAG
4. Write the three address code for the following code fragment.
For(j=1;j<=10;j++)
Sum=sum+a[j]+b[j];
5. Explain generic issues of code generator.
6. Explain translation scheme for addressing array elements
7. write a three address code for the following code fragment
main()
prod=0;
i=1;
do begin
prod:=prod+a[i]*b[i];
i=i+1;
end
while i<=20
end
8. Explain Basic Block and Flow Graph in detail?
9. Explain Implementation of three address statements with the help of suitable
example

You might also like