Subject Name: Compiler Design Subject Code:2170701
Subject Name: Compiler Design Subject Code:2170701
Subject Name: Compiler Design Subject Code:2170701
11 For a statement given below, write output of all phases (except that of optimization phase) of a 07
complier.(Nov-2016) [LJIET]
a=a+b*c;
12 Explain Semantic analysis and Syntax analysis phases of compiler with suitable example. Also 07
explain the errors generated by these two phases.(April-2017_New) [LJIET]
13 What is the difference between compiler and interpreter? (Nov-2017_New)[LJIET] 03
14 Explain analysis phase of the source program with example. (Nov-2017_New)[LJIET] 04
15 Define cross compiler, token and handle. (April-2018_New)[LJIET] 03
16 Define following terms: (May-2018)[LJIET] 03
i. Compiler
ii. Interpreter
iii. Assembler
Sr. CHAPTER NO- 2 :Lexical Analyzer: Marks
No
Introduction to Lexical Analyzer, Input Buffering, Specification of Tokens,
Recognition of Tokens, A Language for Specifying Lexical Analyzers, Finite
Automata From a Regular Expression, Design of a Lexical Analyzer
Generator, Optimization of DFA
DESCRIPTIVE QUESTIONS
1 Write a regular definition for the language of all strings of 0’s and 1’s with an even number of 0’s 07
and odd number of 1’s. Write an algorithm for eliminating left recursion.(Nov-2011)[LJIET]
2 Write the two methods used in lexical analyzer for buffering the input. Which technique is used 07, 07,
for speeding up the lexical analyzer? (Nov-2011)[LJIET] 07, 07,
Write a brief note on input buffering techniques to Lexical Analyzer.(Nov-2013)[LJIET] 07, 07,
Write a brief note on input buffering techniques.(May-2014)[LJIET] 04, 04
Explain Buffer pairs and Sentinels. (Nov-2014)[LJIET]
Write a short note on input buffering methods.(Nov-2016_New)[LJIET]
Explain input buffering methods.(May-2017)[LJIET]
Explain buffer pairs and sentinels. (Nov-2017_New)[LJIET]
Write a short note on input buffering method. (April-2018_New)[LJIET]
3 Find the Regular Expression corresponding to given statement, subset of {0,1}* 07
i. The Language of all strings containing at least one 0 and at least one
ii. The Language of all strings containing 0’s and 1’s both are even.
iii. The Language of all strings containing at most one pair of consecutive 1’s.
iv. The Language of all strings that do not end with 01.(May-2012)
4 How do the parser and scanner communicate? Explain with the block diagram communication 07, 07
between them. Also explain: What is input buffering?(May-2012)(May-2018) [LJIET]
5 Convert the following NFA-ε into equivalent NFA. Here ε is a Λ-transition.(May- 07
2012)[LJIET]
Please note B is accepting state. Describe the language defined by the regular expression.
16 Construct the NFA using thompson’s notation for following regular expression and then convert 07
it to DFA. a+ (c |d) b*f # .(May-2015)[LJIET]
17 Construct DFA for following Regular expression. Use firstpos, lastpos and followpos functions to 07
construct DFA.(Dec-2015)[LJIET]
(a*|b*)*
18 Construct NFA for following Regular Expression using Thomson’s Construction. Apply subset 07
construction method to convert into DFA.(Dec-2015)[LJIET]
(a | b)*abb
Draw the DFA for the regular expression (a|b)*abb using set construction method
only.(May-2016)[LJIET]
Write an algorithm for Thompson’s construction method. Apply the algorithm to construct NFA
for following regular expression. (a | b)*abb. (Nov-2017_New)[LJIET]
19 What is regular expression, give all the algebraic properties of regular expression.(May- 07
2016)[LJIET]
21 Unsigned numbers are strings such as 5280, 39.37, 6.336E4 or 1.894E-4, give the regular 07
definitions for the above mentioned strings.(May-2016)[LJIET]
22 Convert the (a|b|c)*d*(a*|b)ac+# regular expression to DFA directly and draw its DFA.(May- 07
2016)[LJIET]
23 Convert the following regular expression into deterministic finite automata. (a+b)*abb(a+b)* 03
.(Nov-2011)[LJIET]
24 Construct DFA by syntax tree construction method .(May-2015)[LJIET] 07
a+ b* (c |d) f # Optimize the resultant DFA.
25 Construct DFA without constructing NFA for following regular expression: 07
a*b*a(a | b)b*a#
Minimize the same.(Nov-2016)[LJIET]
26 Construct NFA for following regular expression using Thompson’s notation and then convert it 07
into DFA.(Nov-2016)[LJIET]
a(b | c)*a*c#
27 Define the following terms: (Nov-2016_New)[LJIET] 07
1. Token
2. Pattern
3. Lexeme
4. Ambiguous grammar
5. Handle pruning
6. Compiler
7. DAG
28 Explain subset construction method for constructing DFA from an NFA with an example.(Nov- 07, 07
2016_New)[LJIET]
Explain subset construction method with an example. (May-2017)(April-2018_New) [LJIET]
29 Construct DFA for the following regular expression using syntax tree with firspos, laspos and 07, 07,
followpos function.(Nov-2016_New)[LJIET] 07
( a | b) *a
Draw DFA for the following regular expression using firstpos( ), lastpos ( ) and followpos ( )
functions. (April-2018_New)[LJIET]
( a | b) * a
Construct a DFA without constructing NFA for the following regular expression. (a | b) * a.
(May-2017)[LJIET]
30 Construct the NFA using thompson’s notation for following regular expression and then convert 07
it to DFA.(April-2017_New)[LJIET]
(a / b)* ab#
31 Explain role of lexical analyzer. (Nov-2017_New)[LJIET] 04
32 Draw transition diagram for relational operators. (April-2018_New)[LJIET] 04
33 Construct DFA for following regular expression without constructing NFA and optimize the 07
same. (May-2018)[LJIET]
( a | ε )* a b ( a | b )* #
34 Explain automatic generation of lexical analyzer and parser. (May-2018)[LJIET] 07
35 Define following terms: (May-2018)[LJIET] 04
i. Regular Expression
ii. Token
iii. Lexeme
iv. Pattern
13 What do you understand by a handle? Explain the stack implementation of shift reduce parser 07
with the help of example.(Nov-2014)[LJIET]
14 Explain recursive-descent and predictive parsing..(Nov-2014)[LJIET] 07
15 Implement the following grammar using Table Driven parser and check whether it is LL(1) 14or 07
not. S -> aBDh, B -> cC, C -> bC / ^, D -> EF, E -> g / ^, F-> f / ^ .(May-2014)[LJIET]
16 Implement the following grammar using Recursive Descent Parser.(May-2014)[LJIET] 08
S -> Aa | bAc | bBa, A -> d, B -> d
17 For the following grammar D T L ; L L , id | id T int | float (May-2015)[LJIET] 07
1)Remove left recursion (if required)
2)Find first and follow for each non terminal for Resultant grammar
3)Construct LL(1) parsing table
4)Parse the following string (show stack actions clearly) and draw parse tree for the input: int id,
id;
18 Develop a predictive parser for the following grammar.(May-2015)[LJIET] 07
S’->S S->aA|b|cB|d A->aA|b B->cB|d
19 How top down and bottom up parser will parse the string ‘bbd’ using grammar A bA | d. 07
Show all steps clearly.(May-2015)[LJIET]
20 Construct LL(1) parsing table for the following Grammar:(Dec-2015)[LJIET] 07
S(L)|a
LL,S|S
21 Define: Left Recursive. State the rule to remove left recursive from the grammar. Eliminate left 07
recursive from following grammar.(Dec-2015)[LJIET]
S Aa | b
A Ac | Sd | f
22 What is left recursion? Eliminate the left recursion from the following grammar.(May- 07
2016)[LJIET]
EE+T|T
TT*F|F
F ( E ) | id
23 Design the FIRST SET and FOLLOW SET for the following grammar.(May-2016)[LJIET] 07
EE+T|T
TT*F|F
F ( E ) | id
24 (i) Compare top-down and bottom-up parser. 07
(ii) Explain right-most-derivation-in-reverse with the help of an example.(Nov-2016)[LJIET]
25 Draw transition diagrams corresponding to production rules for arithmetic expressions consisting 07
of operators + and ^ for predictive parser. Explain how parsing takes place for the same using
transition diagrams.(Nov-2016)[LJIET]
26 Explain left factoring with the help of an example..(Nov-2016)[LJIET] 04, 03
Write a rule of Left factoring a grammar and give example. (Nov-2017_New)[LJIET]
27 Construct LL(1) Parsing table for the following grammar. Also show moves made by input string 07
: abba.(Nov-2016_New)[LJIET]
S aBa
B bB | ^
28 Check following grammar is LL (1) or not?(April-2017_New)[LJIET] 07
S -> aB | €
B -> bC | €
C -> cS | €
29 What is left factoring and left recursion? Explain it with suitable example.(April- 07
2017_New)[LJIET]
30 How do you check whether the grammar is LL (1) or not? Justify your answer with appropriate 07
Compiler Design (2170701) 2018 Page 6
L.J. Institute of Engineering & Technology Semester: VII (2018)
example. (May-2017)[LJIET]
31 Check the following grammar is left recursive or not. Justify your answer. If Left recursive then 04
make grammar as non-left recursive. (April-2018_New)[LJIET]
S(L)|a
LL,S|S
32 Consider the following grammar and construct the corresponding left most and right most 03
derivations for the sentence abab. (April-2018_New)[LJIET]
S -> aSbS | bSaS | €
33 Find out FIRST and FOLLOW for the following grammar. (April-2018_New)[LJIET] 04
S -> 1AB | €
A -> 1AC | 0C
B -> 0S
C -> 1
34 Check whether the given grammar is LL (1) or not? (May-2018)[LJIET] 07
S -> aAC | bB
B -> f | g
A -> Abc | Abd | e
C -> h |i
TOPIC:2 Bottom Up Parsing Algorithms
DESCRIPTIVE QUESTIONS
1 Compute the operator precedence matrix and precedence function for the following grammar if it 07
exists. +,*,-,/,id,num,( and ) are terminal symbols.(Nov-2011)[LJIET]
G→E
E→E+T|E-T|T
T→T*F|T/F/F
F→num|id|(E)
2 Consider the following grammar.(Nov-2011)[LJIET] 07
E → E+T | T
T → TF | F
F → F* |a |b
1) Construct the SLR parsing table for this grammar.
2) Construct the LALR parsing table.
3 Construct the canonical parsing table for the following Grammar.(May-2012)[LJIET] 07
S’S
SCC
CcC|d
4 Generate the SLR parsing table for the following Grammar.(May-2012)[LJIET] 07
SAa|bAc|bBa
Ad
Bd
5 Write unambiguous production rules for producing arithmetic expression consisting of symbols id, 07
*, -, ( ) and ^, where ^ represents exponent. Parse following string using shift – reduce parser:
id – id * id ^ id * (id ^ id ) ^ id. Explain various conflicts of a shift – reduce parser.(Dec-
2012)[LJIET]
6 Explain SLR parser in detail with the help of an example.(Dec-2012)(May-2016)[LJIET] 07, 07,
Explain SLR parser. How is its parse table constructed?(Nov-2016)[LJIET] 07, 07,
Explain SLR parsing method with example.(Nov-2016_New)(May-2017)(April-2018_New) 07, 07
[LJIET]
7 Explain Shift-Reduce parsing with suitable example.(Nov-2013)[LJIET] 07
Compiler Design (2170701) 2018 Page 7
L.J. Institute of Engineering & Technology Semester: VII (2018)
8 Write down steps to set precedence relationship for Operator Precedence Grammar. Design 07
precedence table for:(Nov-2013)[LJIET]
E E+ T | T T T * F | F F a
9 Write SLR parsing table for : S T T CC C cC C d .(Nov-2013)[LJIET] 08
10 What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is a handle? 08
.(May-2014)[LJIET]
11 Define an Operator Precedence Grammar. Also write down the rules to find relationship between 08
each pair of terminal symbols.(May-2014)[LJIET]
12 Construct SLR parsing table for the following grammar : (May-2014)[LJIET] 10
E->E+T E->T T->T*F T->F F->(E) F->a
13 Show that the following grammer S-> AaAb | BbBa A -> ϵ B -> ϵ is LL(1) but not SLR(1). (Nov- 07
2014)[LJIET]
14 Show that the following grammer S->Aa | bAc | dc | bda A->d is LALR(1) but not SLR(1). (Nov- 07
2014)[LJIET]
15 Show that the following grammer:(Nov-2014)[LJIET] 07
S->Aa | bAc | Bc | bBa A->d B->d is LR(1) but not LALR(1).
16 Construct the collection of sets of LR(0) items for the following grammar. S-> Aa | bAc | dc | bda 07
A->d .(May-2015)[LJIET]
17 Construct an SLR Parsing table for the following grammar.(May-2015)[LJIET] 07
E->E-T|T T->F↑T|F F->(E) | id
18 Check whether the following grammar is CLR or not.(Dec-2015)[LJIET] 07
S Aa | bAc | Bc | bBa
Ad
Bd
19 Construct SLR Parsing Table for the following grammar.(Dec-2015)[LJIET] 07
S 0S0 | 1S1 | 10
20 Explain Operator Precedence Parsing method with example.(Dec-2015)[LJIET] 07, 07,
Explain operator precedence parser by giving example for constructing a precedence graph and 07, 07,
table.(Dec-2012)[LJIET] 07
Write a short note on operator precedence parsing with an example.(Nov-2016_New)[LJIET]
Explain operator precedence parsing method.(May-2017)[LJIET]
Explain Operator precedence Parsing technique in detail. (May-2018)[LJIET]
21 Differentiate SLR, Canonical LR and LALR. Also justify the statement “A class of grammar 07
that can be parsed using LR methods is a proper subset of the class of grammars that can be
parsed with predictive parser”.(May-2016)[LJIET]
22 Explain LALR parser in detail. Support your answer with example.(Dec-2015)[LJIET] 07
23 Where do we use operator precedence parsing technique? Give the general precedence table for 07
operating precedence parsing, considering all the generalized rules.(May-2016)[LJIET]
24 Apply shift reduce parser for parsing following string using unambiguous grammar.(Nov- 07
2016)[LJIET]
id - id * id – id
25 Construct a precedence graph, precedence table for operator precedence parser to be used for 07
parsing a string consisting of id, - , * , $. Parse following string.(Nov-2016)[LJIET]
$ id - id * id * id $
26 Check that following grammar is LALR or not.(Nov-2016_New)[LJIET] 07
S L=R
S R
L*R
L id
RL
27 Construct CLR parsing table for following grammar.(April-2017_New)[LJIET] 07
Compiler Design (2170701) 2018 Page 8
L.J. Institute of Engineering & Technology Semester: VII (2018)
S -> aSA | €
A -> bS | c
28 Show that following grammar is not a SLR (1) grammar.(April-2017_New)[LJIET] 07, 07
S -> AaBa | BbBa
A -> €
B -> €
Check the following grammar is LR(1) or not.(May-2017)[LJIET]
S AaAb
S BbBa
A^
B ^
29 Define operator precedence grammar. Construct precedence matrix and precedence graph for 07
arithmetic grammar as shown below:(April-2017_New)[LJIET]
E -> E + T | T
T -> T * F | F
F -> (E) | id
30 Check given grammar is LL(1) but not SLR(1). (Nov-2017_New)[LJIET] 07
S -> AaAb | BbBa
A -> €
B -> €
31 What is operator grammar? Generate precedence function table for following grammar. (Nov- 07
2017_New)[LJIET]
E -> EAE | id
A -> + | *
32 Define handle and handle pruning. Explain the stack implementation of shift reduce parser with 07
the help of example. (Nov-2017_New)[LJIET]
33 What is operator grammar? Check the following grammar is operator or not. Justify your answer. 03
(April-2018_New)[LJIET]
E -> EOE
E -> id
O -> * | + | -
34 Construct CLR parsing table for the following grammar. (April-2018_New)[LJIET] 07
S -> CC
C -> cC | d
35 Construct a SLR parsing table for following grammar. (May-2018)[LJIET] 07
S -> aAb | bB
A -> Aa | ϵ
B -> Bb |ϵ
36 Construct the LALR parsing table for the following grammar. (May-2018)[LJIET] 07
S -> CC
C -> aC
C -> d
TOPIC:3 Syntax-Directed Definitions( Bottom-Up Evaluation of S-Attributed
Definitions, L-Attributed Definitions)
1 Write a syntax directed definition for desk calculator. Justify whether this is an S-attributed 07, 07
definition or L-attributed definition. Using this definition draw annotated parse tree for 3*5+4n.
(Nov-2011)(May-2018)[LJIET]
2 What is inherited attribute? Write syntax directed definition with inherited attributes for type 07, 07,
declaration for list of identifiers. Show annotated parse tree for the sentence real 07
id1,id2,id3.(Nov-2011)[LJIET]
What is inherited attribute? Write syntax directed definition with inherited attributes for type
20 Define syntax tree. What is s-attributed definition? Explain construction of syntax tree for the 07
expression a-4+c using SDD. (Nov-2017_New)[LJIET]
21 Write Syntax Directed Definition to produce three address code for the expression containing the 04
operators := , + , - (unary minus), ( ) and id. (Nov-2017_New)[LJIET]
TOPIC:4 Using Ambiguous Grammars , Parser Generators, Automatic
Generation of Parsers
DESCRIPTIVE QUESTIONS
1 Consider the grammar 04, 07
S -> SS+ | SS* | a
Show that the string aa+a* can be generated by the grammar.
Construct the parse tree for it. Is the grammar ambiguous? Justify.(Dec-2012)(Nov-2016)[LJIET]
2 Write production rules for producing following language. Strings of 0’s and 1’s with equal 03
numbers of 0’s and 1’s.(Dec-2012)[LJIET]
3 Draw transition diagrams corresponding to production rules for operators +, - , *, / and id for a 07
predictive parser. Explain how parsing takes place for it.(Dec-2012)[LJIET]
4 Write ambiguous and unambiguous production rules for if then else construct. Illustrate parsing 07
using both types of rules by giving an example. Also explain left factoring and its use.(Dec-
2012)[LJIET]
5 What is the difference between parse tree and syntax tree? Write appropriate grammar and draw 07
parse as well as syntax tree for a*(a-a^a).(Nov-2013)[LJIET]
6 Explain the following:(May-2015)[LJIET] 07
1) The Handle
2) Left Factoring
3) Directed Acyclic Graph
4) Conflicts in LR Parsing
5) Parser Generator
6) Dependency Graph
7) Locality of reference
7 Write a context free grammar for arithmetic expressions. Develop a syntax directed definition for 07
the grammar. Draw an annotated parse tree for the input expression: (3*2+2)*4 (May-
2015)[LJIET]
8 Write short note on context free grammar (CFG) explain it using suitable example.(May- 07
2016)[LJIET]
9 What is the difference between parse tree and syntax tree? Draw the parse tree for following 04
expression: a= a + a * b + a * b * c – a / b + a * b and write three address code for it.(May-
2012)[LJIET]
10 Write unambiguous production rules for if then else construct.(Nov-2016)[LJIET] 03
Sr. CHAPTER NO- 4 :Error Recovery: Marks
No
Error Detection & Recovery, Ad-Hoc and Systematic Methods
DESCRIPTIVE QUESTIONS
1 How can panic mode and phrase level recovery be implemented in LR parsers? Consider the 07
expression grammar :E → E + E | E * E | (E) | id
Prepare the SLR parsing table with error detection and recovery routines.(Nov-2011)[LJIET]
2 Explain: Error Recovery Strategies in Compiler in brief.(May-2012)(May-2014)(Nov- 07, 07,
2014)[LJIET] 07, 07,
Explain all error recovery strategies using suitable examples.(May-2016)[LJIET] 07, 04,
Discuss various error recovery strategies of compiler.(Nov-2016_New)[LJIET] 07
Explain error recovery strategies used by parser. (Nov-2017_New)[LJIET]
Compiler Design (2170701) 2018 Page 11
L.J. Institute of Engineering & Technology Semester: VII (2018)
21 Explain symbol table with two data structures suitable for it.(May-2017)[LJIET] 07
22 Explain static storage allocation technique.(May-2017)[LJIET] 07
23 Explain activation record organization in brief.(May-2017)[LJIET] 07
24 What is activation record? Explain stack allocation of activation records using example. (Nov- 07
2017_New)[LJIET]
25 What is activation tree? (Nov-2017_New)[LJIET] 03
26 What is symbol table? For what purpose , compiler uses symbol table? 03
(April-2018_New)[LJIET]
27 Write a short note on activation record. (April-2018_New)[LJIET] 04
28 Write difference(s) between stack and heap memory allocation. (April-2018_New)[LJIET] 03
29 Discuss various Storage allocation strategies in detail. (May-2018)[LJIET] 07
30 Explain various data structures used in symbol table management. (May-2018)[LJIET] 07
31 Explain activation tree, control stack, the Scope of Declaration and Bindings of Names. (May- 07
2018)[LJIET]
Sr. CHAPTER NO- 7:Code Optimization : Marks
No
Global Data Flow Analysis, A Few Selected Optimizations like Command Sub
Expression Removal, Loop Invariant Code Motion, Strength Reduction etc
DESCRIPTIVE QUESTIONS
1 Write an algorithm for global common subexpression elimination.(Nov-2011)(Nov- 07
2014)[LJIET]
2 Explain various code optimization techniques.(May-2012)(Nov-2014)(May-2015)(May- 04, 07,
2017)[LJIET] 07, 07
3 Explain any three types of optimization techniques.(Dec-2012)[LJIET] 04, 07,
Discuss any three methods for code optimization.(Nov-2016_New)[LJIET] 07, 07
Explain any three code optimization techniques with example.(Dec-2015)(April-
2018_New)[LJIET]
4 Write down the algorithm for partitioning of basic blocks.(Nov-2013)[LJIET] 07
5 Define a following: Basic block, Constant folding, Natural loop, Handle.(April- 07
2017_New)[LJIET]
6 Define dominators. Construct dominator tree for following graph.(April-2017_New)[LJIET] 07