CD QuestionBank
CD QuestionBank
CD QuestionBank
UNIT-1 INTRODUCTION
1. Define lexeme, token and pattern. Identify the lexemes that make up the tokens in
the following program segment. Indicate corresponding token and pattern. (WINTER-
2015 7 Marks)
void swap (int a, int b) { int k; k = a; a = b; b = k; }
2. Explain Semantic Analysis and Syntax Analysis phases of compiler with suitable
example. Also explain the reporting errors by these two phases. (WINTER-2015 7
Marks, SUMMER-2017 7 Marks)
3. Write a short note on Symbol Table Management. (WINTER-2015 7 Marks, SUMMER-
2017 7 Marks)
4. List the errors generated by the syntax analysis phase. Discuss error handling methods in
the syntax analysis phase. (SUMMER-2015 7 Marks)
5. Explain the phases of compiler with an example. (SUMMER-2016 7 Marks, SUMMER-
2015 7 Marks, SUMMER-2014 6 Marks, WINTER-2016 7 Marks)
6. What is the use of a symbol table? How identifiers are stored in the symbol table?
Explain: Symbol Table Management. How symbol table differs from other data
structures? For what purpose compiler uses symbol table? How characters of a name are
stored in symbol table? (WINTER-2014 7 Marks, SUMMER-2014 4 Marks, SUMMER-
2012 3 Marks, WINTER-2011 4 Marks)
7. What is the pass of a compiler? Explain how the single and multi-pass compilers work.
(SUMMER-2014 7 Marks)
8. Explain how type checking & error reporting is performed in compiler. (SUMMER-2016
7 Marks)
9. Draw structure of Compiler. Also explain Analysis Phase in brief. (WINTER-2013 7
Marks)
10. Explain the roles of linker, loader and preprocessor. (WINTER-2013 8 Marks)
11. Explain the analysis synthesis model of compilation. List the factors that affect the
design of compiler. Also List major functions done by compiler. (SUMMER-2012 6
Marks)
12. What does the linker do? What does the loader do? What does the preprocessor do?
Explain their role(s) in compilation process. (SUMMER-2012 4 Marks)
13. What is the difference between compiler and interpreter? (WINTER-2017 3 Marks)
14. What is a pass in a compiler? What is the effect of reducing the number of passes?
(WINTER-2011 4 Marks)
15. Explain analysis phase of the source program with example. (WINTER-2017 4 Marks)
16. What is a pass in a compiler? What is the effect of reducing the number of passes?
(WINTER-2017 3 Marks)
14. (i) What is a symbol table? Discuss the most suitable data structure for it by stating
merits / demerits.
(ii) Explain linker & loader. (WINTER-2016 7 Marks)
15. For a statement given below, write output of all phases (except that of optimization
phase) of a complier. (WINTER-2016 7 Marks)
a = a + b * c;
1. Construct DFA for following Regular expression. Use firstpos, lastpos and followpos
functions to construct DFA. (WINTER-2015 7 Marks)
(a*|b*)*
2. Construct NFA for following Regular Expression using Thomson’s Construction. Apply
subset construction method to convert into DFA. (WINTER-2015 7 Marks, WINTER-
2017 7 Marks)
(a | b)*abb
3. What are regular expressions? Find the regular expression described by DFA
{{A,B},{0,1},δ,A,{B}},where δ is detailed in following table. Please note B is accepting
state. Describe the language defined by the regular expression. (SUMMER-2015 7
Marks)
4. Construct the NFA using thompson’s notation for following regular expression and then
convert it to DFA. ( SUMMER-2015 7 Marks)
a+ (c |d) b*f #
5. Construct DFA by syntax tree construction method. a+ b* (c |d) f # Optimize the
resultant DFA.( SUMMER-2015 7 Marks)
6. Explain Buffer pairs and Sentinels. (WINTER-2014 7 Marks, WINTER-2017 4 Marks)
7. Explain role of lexical analyzer. (WINTER-2017 4 Marks)
8. Construct minimum state DFA’s for following regular expressions. (WINTER-2014 7
Marks)
i. (a|b)*a(a|b)
ii. (a|b)*a(a|b) (a|b)
9. Draw Deterministic Finite Automata. (SUMMER-2014 7 Marks)
i. (0+1)*101(0+1)*
ii. 10(0+1)*1
10. Write a brief note on input buffering techniques.
11. Write a brief note on input buffering techniques to Lexical Analyzer. Write the two
methods used in lexical analyzer for buffering the input. Which technique is used
for speeding up the lexical analyzer? (SUMMER-2014 7 Marks, WINTER-2013 7
Marks, WINTER-2011 7 Marks)
12. What is regular expression, give all the algebraic properties of regular expression.
(SUMMER-2016 7 Marks)
13. Draw the DFA for the regular expression (a|b)*abb using set construction method only.
(SUMMER-2016 7 Marks)
14. Unsigned numbers are strings such as 5280, 39.37, 6.336E4 or 1.894E-4, give the regular
definitions for the above mentioned strings. (SUMMER-2016 7 Marks)
15. Convert the (a|b|c)*d*(a*|b)ac+# regular expression to DFA directly and draw its DFA.
(SUMMER-2016 7 Marks)
16. Write short note on context free grammar (CFG) explain it using suitable example.
(SUMMER-2016 7 Marks)
17. Draw Deterministic Finite Automata for the binary strings ending with 10. (WINTER-
2013 4 Marks)
18. Write down the regular expression for the binary strings with even length. (WINTER-
2013 3 Marks)
19. Find the Regular Expression corresponding to given statement, subset of {0,1}*.
(SUMMER-2012 4 Marks)
i. The Language of all strings containing at least one 0 and at least one 1.
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.
20. Convert the following NFA-^ into equivalent NFA. Here ℇ is a ^-transition. (SUMMER-
2012 7 Marks)
1. Construct LL(1) parsing table for the following Grammar: (WINTER-2015 7 Marks)
S -> ( L ) | a
L -> L , S | S
2. Check whether the following grammar is CLR or not. (WINTER-2015 7 Marks)
S -> Aa | bAc | Bc | bBa
A -> d
B-> d
3. Construct SLR Parsing Table for the following grammar. (WINTER-2015 7 Marks)
S-> 0S0 | 1S1 | 10
4. Explain Operator Precedence Parsing method with example. Define an Operator
Precedence Grammar. Also write down the rules to find relationship between each pair
of terminal symbols. (WINTER-2015 7 Marks, SUMMER-2014 8 Marks, SUMMER-
2016 7 Marks)
5. Explain LALR parser in detail. Support your answer with example. (WINTER-2015 7
Marks)
6. For the following grammar (SUMMER-2015 7 Marks)
D -> T L ;
L -> L , id | id
T -> int | float
i. Remove left recursion (if required) S
ii. Find first and follow for each non terminal for Resultant grammar
iii. Construct LL(1) parsing table
iv. Parse the following string (show stack actions clearly) and draw parse tree for the
input: int id, id;
7. How top down and bottom up parser will parse the string ‘bbd’ using grammar.
(SUMMER-2015 7 Marks)
A -> bA | d.
Show all steps clearly.
8. Construct the collection of sets of LR(0) items for the following grammar. (SUMMER-
2015 7 Marks)
S-> Aa | bAc | dc | bda
A->d
9. Develop a predictive parser for the following grammar. (SUMMER-2015 7 Marks)
S’->S
S->aA|b|cB|d
A->aA|b
B->cB|d
10. Explain the following: (SUMMER-2015 7 Marks)
i. The Handle
ii. Left Factoring
iii. Directed Acyclic Graph
iv. Conflicts in LR Parsing
v. Parser Generator
vi. Dependency Graph
vii. Locality of reference
11. Construct an SLR Parsing table for the following grammar. (SUMMER-2015 7 Marks)
E->E-T|T
T->F↑T|F
F->(E) | id
12. Explain recursive-descent and predictive parsing. (WINTER-2014 7 Marks)
13. What do you understand by a handle? Explain the stack implementation of shift reduce
parser with the help of example. (WINTER-2014 7 Marks)
14. Write a rule of Left factoring a grammar and give example. (WINTER-2017 3 Marks)
15. Show that the following grammer: (WINTER-2014 7 Marks, WINTER-2017 7 Marks)
S-> AaAb | BbBa
A -> ϵ
B -> ϵ
is LL(1) but not SLR(1).
16. Show that the following grammer
S->Aa | bAc | dc | bda
A->d
is LALR(1) but not SLR(1). (WINTER-2014 7 Marks)
17. Show that the following grammer
S->Aa | bAc | Bc | bBa
A->d
B->d is LR(1) but not LALR(1). (WINTER-2014 7 Marks)
18. Implement the following grammar using Table Driven parser and check whether it is
LL(1) or not. (SUMMER-2014 8 Marks)
S -> aBDh
B -> cC
C -> bC / ^
D -> EF
E -> g / ^
F-> f / ^
19. Implement the following grammar using Recursive Descent Parser. (SUMMER-2014 8
Marks)
S -> Aa | bAc | bBa
A -> d
B -> d
20. What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is a
handle? (SUMMER-2014 8 Marks)
21. Construct SLR parsing table for the following grammar: (SUMMER-2014 10 Marks)
E->E+T
E->T
T->T*F
T->F
F->(E)
F->a
22. What is left recursion? Eliminate the left recursion from the following grammar.
(SUMMER-2016 7 Marks)
E -> E + T | T
T -> T * F | F
F -> ( E ) | id
23. Explain SLR parser in detail with the help of a suitable example. (SUMMER-2016 7
Marks)
24. Design the FIRST SET and FOLLOW SET for the following grammar. (SUMMER-2016
7 Marks)
E -> E + T | T
T -> T * F | F
F -> ( E ) | id
25. Differentiate SLR, Canonical LR and LALR. Also justify the statement “A class of
grammar that can be parsed using LR methods is a proper subset of the class of
grammars that can be parsed with predictive parser”. (SUMMER-2016 7 Marks)
26. Write down the algorithm for left factoring. (WINTER-2013 3 Marks)
27. Write down C program for Recursive Descend Parser for : (WINTER-2013 7 Marks)
S -> ABC
B->1B | ˄
A-> 0A1 | ˄
C-> 1C0 | ˄
28. Explain Shift-Reduce parsing with suitable example. (WINTER-2013 7 Marks)
29. What is operator grammar? Generate precedence function table for following grammar.
(WINTER-2017 7 Marks)
E -> EAE | id
A -> + | *
30. Draw parsing table for Table Driven Parser for the given grammar. Is the grammar
LL(1)? (WINTER-2013 7 Marks)
A-> AaB | x
B-> BCb | Cy
C-> Cc | ˄
31. Write down steps to set precedence relationship for Operator Precedence Grammar.
Design precedence table for: (WINTER-2013 7 Marks)
E -> E+ T | T
T ->T * F | F
F -> a
32. What is the difference between parse tree and syntax tree? Write appropriate grammar
and draw parse as well as syntax tree for a*(a-a^a). (WINTER-2013 7 Marks)
33. Write SLR parsing table for : (WINTER-2013 8 Marks)
S -> T
T -> CC
C -> cC
C -> d
34. Explain non-recursive predictive parsers. Draw the block diagram of it. (SUMMER-2012
4 Marks)
35. Define handle and handle pruning. Explain the stack implementation of shift reduce
parser with the help of example. (WINTER-2017 7 Marks)
36. Test whether the following grammar is LL (1) or not. Construct predictive parsing table
for it. (SUMMER-2012 7 Marks)
S-> 1AB | ℇ
A-> 1AC | 0C
B-> 0S C- >1
37. Explain the structure of an activation record with all its components. Construct predictive
parsing table for following. (SUMMER-2012 7 Marks)
S -> A
A -> aB | Ad
B -> bBC | f
C -> g
38. Eliminate left recursion from the following grammar and rewrite the Grammar.
(SUMMER-2012 3 Marks)
S -> Aa | b
A -> Ac | Sd | ℇ
39. (a) Perform the Left factoring of following Grammar
A -> ad | a | ab | abc | b
(b) Find out FIRST & FOLLOW set for all the Nonterminals
S-> AcB | cbB | Ba
A-> da | BC
B-> g | ℇ
C -> h | ℇ
(SUMMER-2012 10 Marks)
40. Construct the canonical parsing table for the following Grammar: (SUMMER-2012 7
Marks)
S’-> S
S-> CC
C-> cC|d
41. Generate the SLR parsing table for the following Grammar: (SUMMER-2012 7 Marks)
S-> Aa|bAc|bBa
A -> d
B -> d
42. How can panic mode and phrase level recovery be implemented in LR parsers? Consider
the expression grammar
E → E + E | E * E | (E) | id
43. Prepare the SLR parsing table with error detection and recovery routines. (WINTER-
2011 7 Marks)
44. Write an algorithm for eliminating left recursion. (WINTER-2011 3 Marks)
45. Is the following grammar suitable for LL(1) parsing? If not make it suitable for LL(1)
parsing. Compute FIRST and FOLLOW sets. Generate the parsing table. (WINTER-
2011 7 Marks)
S→AB
A→Ca | ϵ
B→BaAC | c
C→b | ϵ
F→num|id|(E)
46. Consider the following grammar: (WINTER-2011 7 Marks)
E → E+T | T
T → TF | F
F → F* |a |b
Construct the SLR parsing table for this grammar.
47. Check following grammar is LL (1) or not? (SUMMER-2017 7 Marks)
S -> aB | €
B -> bC | €
C -> cS | €
48. Construct the LALR parsing table.
49. Draw the transition diagrams for predictive parsers for the following grammar.(
WINTER-2011 7 Marks)
E → TE’
E’→ +TE’ | ϵ
T → FT’
T’ → *FT’ | ϵ
F → (E) | id
50. (i)Consider the grammar
S -> SS+ | SS* | a
Show that the string aa+a* can be generated by the grammar. Construct the parse tree for
the grammar.
(ii)Is the grammar ambiguous?
51. Write unambiguous production rules for if then else construct. (WINTER-2016 7 Marks)
52. Apply shift reduce parser for parsing following string using unambiguous grammar.
(WINTER-2016 7 Marks)
id - id * id – id
53. Compare top-down and bottom-up parser.
54. Explain right-most-derivation-in-reverse with the help of an example. (WINTER-2016 7
Marks)
55. Explain SLR parser. How is its parse table constructed? (WINTER-2016 7 Marks)
56. Construct a precedence graph, precedence table for operator precedence parser to be used
for parsing a string consisting of id, - , *, $. Parse following string. (WINTER-2016 7
Marks)
$ id - id * id * id $
57. Draw transition diagrams corresponding to production rules for arithmetic expressions
consisting of operators + and ^ for predictive parser. Explain how parsing takes place for
the same using transition diagrams. (WINTER-2016 7 Marks)
58. (i) Explain various parameter passing methods. (WINTER-2016 7 Marks)
(ii) Explain left factoring with the help of an example.
59. Compute the operator precedence matrix and precedence function for the following
grammar if it exists. +,*,-,/,id,num,( and ) are terminal symbols. (WINTER-2011 7
Marks)
G→E
E→E+T|E-T|T
T→T*F|T/F/F
60. Draw Transition diagram of following: (WINTER-2014 7 Marks)
i. Relational operators.
ii. Unsigned operator.
61. Draw the state transition diagram for the unsigned numbers. (SUMMER-2016 7 Marks)
62. What is left factoring and left recursion? Explain it with suitable example. (SUMMER-
2017 7 Marks)
63. Define operator precedence grammar. Construct precedence matrix and precedence
graph for arithmetic grammar as shown below: (SUMMER-2017 7 Marks)
E -> E + T | T
T -> T * F | F
F -> (E) | id
64. Show that following grammar is not a SLR (1) grammar. (SUMMER-2017 7 Marks)
S -> AaBa | BbBa
A -> €
B -> €
65. Construct CLR parsing table for following grammar. (SUMMER-2017 7 Marks)
S -> aSA | €
A -> bS | c
1. Explain any three code optimization techniques with example. (WINTER-2015 7 Marks)
2. Discuss various code optimization techniques. (SUMMER-2015 7 Marks, WINTER-
2014 7 Marks, SUMMER-2012 7 Marks)
3. Describe algorithm for global common subexpression elimination.( WINTER-2014 7
Marks, WINTER-2011 7 Marks)
4. Write a note on peephole optimization. (SUMMER-2014 7 Marks, SUMMER-2016 7
Marks, WINTER-2013 8 Marks, WINTER-2011 7 Marks, WINTER-2016 7 Marks,
WINTER-2017 4 Marks, SUMMER-2017 7 Marks)
5. Explain three loop optimization techniques with example. (WINTER-2017 3 Marks)
6. What is code optimization? Explain data flow equation. (WINTER-2017 4 Marks)