CD Question Bank
CD Question Bank
CD Question Bank
General
Question Bank
GMIT | KJS
Question Bank J
3. Explain the analysis and synthesis model of compilation. List the factors that affect the
design of compiler. Also list major functions done by compiler.(6)
7... Explain lexical analysis phase of a compiler and for a statement, write output of all
phases (except of an optimization phase) of a compiler. Assume a ,b and c are of float type
float a = a + b * c * 2; (7)
10... What is pass of a compiler? Explain how the single and multi pass compilers work. (7)
3... Convert the NFA-€ into NFA without € for following NFA.(7)
q1
€ €
q0 € a q3
€ q2 a
5. Draw Deterministic Finite Automata for the binary strings ending with 10. (4)
GMIT | KJS
Question Bank J
6. Construct DFA for the following regular expression. Use firstpos, lastpos and
followpos function to construct DFA. (7)
(a* | b*)*
(a + b) * abb (a + b)*
8... Find the regular expression corresponding to given statement, subset of {0,1}*(4)
1. The language of all strings containing at least one 0 and at least one 1.
2. The language of all strings containing 0's and 1's both are even.
3. The language of all strings containing at most one pair of consecutive 1's.
9. Draw syntax tree and DAG for the statement a= (a*b+c) ^ (b+c)*b+c. Write three address
for the same.(3)
11. Construct minimum state DFA's for following regular expression (a|b)*a(a|b)(a|b)
12... What are regular expressions? Find the regular expression described by
DFA {{A,B},{0,1},δ ,A, {B}}, where δ is detailed in following table.
0 1
A A B
B Φ A
13... Construct the NFA using thompson's notation for following regular expression and
then convert it to DFA. (7)
a+(c | d) b*f #
14. Draw the DFA for the regular expression (a|b)*abb using set construction method only.(7)
15. . Convert the (a|b|c)*d*(a*|b)ac*# regular expression to DFA directly and draw its DFA. (7)
GMIT | KJS
Question Bank J
Topic 3 : Parsing
1. Write a short note on context free grammar (CFG) explain it using suitable example. (7)
E -> E+T | T
T -> T*F | F
F -> (E) | id
4. S -> Aa | b
A -> Ac | Sd | €
5... Explain the left factoring and perform the left factoring of following grammar.
(7) D -> T L;
L -> L, id | id
2) Find first and follow for each non terminal for Resultant grammar
4) Parse the following string (show stack action 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 A ->
bA|d. Show all steps clearly.(7)
8.. Write down C program for recursive descend parser for: (7)
GMIT | KJS
Question Bank J
S -> ABC
B-> 1B | ^
A -> 0A1 | ^
C -> 1C0 | ^
A -> d
B -> d
10... Draw the transition diagram for the predictive parser for the following grammar. (7)
E -> TE'
T -> FT'
T -> *FT' | €
F -> (E) | id
11. Explain Non Recursive Predictive Parsers. Draw the block diagram of it. (4)
12. Consider following grammar for arithmetic expressions and construct parsing table. (7)
E -> E + T | T
T -> T * F | F
F -> (E) | id
13. Test whether grammar is LL(1) or not and construct parsing table. (7 + 7)
A -> €
B -> €
A ->1AC | 0C
GMIT | KJS
Question Bank J
B -> 0S
C -> 1
14. Find out FIRST and FOLLOW set for all the Nonterminals (7)
A -> da | BC
B -> g | €
C -> h | €
15... 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. (7)
S -> AB A
-> Ca | €
B -> BaAc |c
C -> b | €
16. Draw parsing table for Table Driven Parser for the given grammar. Is the grammar LL(1)?
(7)
A -> AaB | x
B -> BCb | Cy
C -> Cc | €
17... Implement the following grammar using Table Driven parser and check whether it is LL(1)
or not? (8)
S -> aBDh
B -> cC
C -> bC | €
D -> EF
E -> g | €
GMIT | KJS
Question Bank J
18.... What is bottom - up parsing? What is handle? And also differentiate top down and bottom
up parsing. (7)
20. Explain SLR parser in detail with the help of a suitable example. (7)
21... E -> E + T | T T
-> T * F | F F ->
(E)
F -> id
22. Construct SLR(1) parsing table for the following grammar. (7) S
23. Generate the SLR parsing table for the following grammar. (8) S
A -> d B
-> d
24. Construct the canonical parsing table for the following grammar. S'
-> S
S -> cC C ->
cC | d
25. Explain LALR parser in detail. Support your answer with example. (7)
26... Differentiate SLR, CLR, 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 grammar that can be parsed
with predictive parser" . (7)
27... Construct an LALR (1) parsing table for the following grammar: (7+7)
A -> d
A -> d
GMIT | KJS
Question Bank J
B -> d
E -> E + T | T
T -> TF | F
F -> F* | a | b
30... Define an operator precedence grammar. also write down the rules to find relations between
each pair of terminal symbols. (8)
31... Compute the operator precedence matrix and precedence function for the following
grammar if it exits. + ,* ,- , / , id , num , (and) are terminal symbols.(7)
G -> E
E -> E + T | E - T | T
T -> T * F | T/F/F F -
33... List the error generated by the syntax analysis phase. (3)
34. Discuss error handling methods in the syntax analysis phase. (4)
37... Show syntax directed definition for simple desk calculator. Also show annotated parse tree for
3*5+4n, where n indicates newline. (7)Discuss inherited attributes using a suitable grammar. (4)
40 What is the difference between parse tree and syntax tree? (2)
42... Give the translation scheme that converts infix to prefix expression for the following
grammar and also generate the annotated parse tree for input string 7+3+2 ; (7)
E -> E + T;
E -> T; T -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
GMIT | KJS
Question Bank J
3.. Explain quadruple, triple and indirect triple with suitable example. (6)
4... What is intermediate form of the code? what are the advantages of it? What are generally
used intermediate forms? Write N- Tuple notation for (a+b) * (c+d) - (a+b+c). (8)
5.. Translate the expression - (a+b) * (c+d) + (a+b+c) into 1) Quadruples 2) Triples 3) indirect
triples. (7)
1. syntax tree
2. Postfix notation
8. Convert the following statement into triple, indirect triple and quadruple forms. (7) A
= (B+C) $ E + (B+C) * F
3.... What is an activation record? Explain how they are used to access various local and global
variables. (7)
7... What is the use of a symbol table? How the identifiers are stored in the symbol table? (7)
2... Write an algorithm for global common sub expression elimination. (7)
2... Write down the algorithm for partitioning of basic blocks. (7)
GMIT | KJS
Question Bank J
IMP
Question Bank
GMIT | KJS
Question Bank J
q0 € a q3
€
A
q2
4 What are regular expressions? Find the regular expression described by DFA 7
{{A,B},{0,1}, δ ,A, {B}}, where δ is detailed in following table.
0 1
A A B
B Φ A
GMIT | KJS
Question Bank J
Topic 3 : Parsing
1 Consider following grammar for arithmetic expressions 5
E -> E+T | T
T -> T*F | F
F -> (E) | id
Eliminate left recursion from this grammar.
2 Explain the left factoring and perform the left factoring of following grammar. 5
A -> ad | a | ab | abc | b
3 How top down and bottom up parser will parse the string 'bbd' using grammar 7
A -> bA|d. Show all steps clearly.
4 Write down C program for recursive descend parser for: 7
S -> ABC
B-> 1B | ^
A -> 0A1 | ^
C -> 1C0 | ^
5 Draw the transition diagram for the predictive parser for the following 7
grammar. (7)
E -> TE'
E' -> +TE' | €
T -> FT'
T -> *FT' | €
F -> (E) | id
6 Is the following grammar suitable for LL(1) parsing? If not make it suitable 7
for LL(1) parsing compute FIRST and FOLLOW sets. Generate the parsing
table.
S -> AB
A -> Ca | €
B -> BaAc |c
C -> b | €
7 Implement the following grammar using Table Driven parser and check 8
whether it is LL(1) or not?
S -> aBDh
B -> cC
C -> bC | €
D -> EF
E -> g | €
F -> f | €
8 What is bottom - up parsing? What is handle? And also differentiate top down 7
and bottom up parsing.
9 Explain shift reduce parser with suitable example. 7
10 E -> E + T | T 7
T -> T * F | F
F -> (E)
F -> id
GMIT | KJS
Question Bank J
Construct SLR parsing table.
11 Differentiate SLR, CLR, and LALR . Also justify the statement "A class of 7
grammar that can be parsed using LR methods is a proper subset of the class
of grammar that can be parsed with predictive parser"
12 Construct an LALR (1) parsing table for the following grammar: 7+7
(1) S -> Aa | bAc | dc | bda
A -> d
(2) S -> Aa | aAc | Bc | bBa
A -> d
B -> d
13 Consider the following grammar 7
E -> E + T | T
T -> TF | F
F -> F* | a | b
(1) Construct the SLR parsing table.
(2) Construct LALR parsing table.
14 Define an operator precedence grammar. also write down the rules to find 8
relations between each pair of terminal symbols.
15 Compute the operator precedence matrix and precedence function for the 7
following grammar if it exits. + ,* ,- , / , id , num , (and) are terminal
symbols.
G -> E
E -> E + T | E - T | T
T -> T * F | T/F/F
F -> num | id | (E)
16 List the error generated by the syntax analysis phase. 3
17 Explain how panic mode recovery can be implemented. 7
18 How can phrase level recovery be implemented in LR parsers? 2-3
GMIT | KJS
Question Bank J
2. Postfix notation
GMIT | KJS
Question Bank J
Twisted
Question Bank
GMIT | KJS
Question Bank J
GMIT | KJS