CD Important Questions
CD Important Questions
1. List and draw the phases of compiler? Demonstrate the Analysis and
Synthesis Model of Compiler. Mention the input and output of each
phase.
2. Explain the concept of bootstrapping with an example.
3. Construct the transition diagram for relational operators and unsigned
numbers.
4. Show the structure of LEX program and demonstrate the usage of
LEX in Lexical Analyzer Generator.
5. How the lexical analyzer does identify the tokens? Explain with
example.
6. What is the need for separating lexical analysis and syntax analysis?
7. Find the minimized DFA for the following regular expression:
(0 + 1) * (0 + 1) 1 0.
(a|b) * a(a|b) (a|b) (a|b)
8. Explain an algorithm for LEX that recognizes the tokens. Describe in
detail the tool for generating lexical analyzer.
9. Distinguish lexical analysis and parsing.
10. Explain the concepts of specification and recognition of tokens.
Derive the regular expression for the tokens given below and also
draw the transition diagram to recognize the tokens:
i. Relational operators
ii. Integer constant
iii. Identifier
iv. White spaces
v. Exponent part of a number
11. Explain in detail about LEX tool.
12. Write the steps to convert Non-Deterministic Finite Automata
(NDFA) into Deterministic Finite Automata (DFA).
13. Define the terms tokens, patterns and lexeme.
14. Explain in detail the process of compilation. Illustrate the output
of each phase of compilation for the input:
a = (b + c) *(b + c) *2.
15. What is the role of transition diagrams in the construction of
lexical analyzer?
16. Write a pseudo code to recognize the identifiers and keywords.
17. Explain how input buffering helps to speed-up the reading of
source program.
18. Explain about Language Processors and its types.
19. Explain the role of Lexical Analyzer and its phases.
20. Discuss about Finite Automata(FA).
CD UNIT-2
1. Construct the predictive parser for the following grammar:
s (L) | a
LL, S | S.
2. State and explain the rules used to compute first and follow functions
with the help of E E+T |T
TT*F | F
F F* | a | b.
3. Construct LL (1) parsing table for the following grammar:
S L=R, S R, L *R, L id, RL.
4. Define Ambiguous grammar? Explain it with an example.
5. Check whether the grammar is LL (1) or not, and construct a
predictive parsing table for the following grammar:
S iEtSS1 / a, S1 eS/ €, E b.
6. Check whether the grammar SAab, AbC/cd, Ccd, Bc / d, is
Ambiguous or not.?
7. Parse the input string int id, id; using predictive parser for the
grammar:
STL;
Tint | float
LL,id | id
8. What is Dangling ELSE ambiguity? How it can be solved with LR
parsers? Explain with an example.
9. Verify whether the following grammar is LL (1) or not?
E E+T | T
T T*F /F
F (F) | a |b.
10. Construct recursive descent parser for the given grammar.
bexpr bexpr OR bterm | bterm
bterm bterm AND bfactor | bfactor
bfactor NOT bfactor | (bexpr) | TRUE | FALSE
11. Explain the rules to perform preprocessing steps of two down
parser. Explain with given grammar G. S Aa | bAc | Bc | bBa,
A d, B d.
12. Discuss about error recovery strategies in predictive parsing.
13. Construct the LL (1) parser for G: S (L) | a, L L,S | S and
check the acceptance of input string (a,(a,a)).
14. Compute FIRST and FOLLOW for the grammar: SS S + \
S S * \ a.
15. Eliminate left recursion in the following grammar: AAbd | Aa |
a, B Be | b.
16. Describe the structure of non recursive predictive parser and
error recovery strategies.
17. Justify the following grammar is ambiguous and Eliminate the
ambiguity.
SiCtS
SiCtSeS
Sa
Cb
18. Show that the following grammar is LL (1) or not.
SAaAb | BbBa
A€
B€
19. Identify the conflicts that may occur during shift reduce parsing
with an example.
20. Construct SLR parsing table for the following grammar:
EE + T / T
TT * F / F
F (E) / a
21. Perform shift reduce parsing for the following grammar:
S (L) | a
L L,S | S
i) (a,(a,a)) ii) (a,a)
22. List out different error recovery strategies and Explain them.
23. Show the following grammar:
S AaAb | BbBa
A€
B€
Is LL (1) and parse the input string “ba”.
24. Eliminate left recursion of the following grammar:
S Aa | b
AAc | Sd | €
25. List the features of LR parsers.
26. Find whether the following grammar is LL (1) or not.
SabSa | aaAb
AbaAb | b.
27. Construct LALR (1) parse table for the following grammar:
S Aa | bAc | Bc | bBa
Ad
Bd.
28. Write the properties of LR parser with its structure. Also explain
the techniques of LR parser.
29. What is Left Recursion? How to eliminate Left Recursion?
30. Explain the role of parser in compiler model.
31. Draw annotated parse tree for the expression:
3 * 5 + 4n.
32. Explain the parsing techniques with a hierarchial diagram.
33. Write Recursive Descent for the following grammar:
ScAd, Aab | a.
34. Differentiate Top down parsing and Bottom up parsing.
35. Consider the grammar:
E E + E
EE * E
Eid
Perform shift reduce parsing of the input string “id1 + id2 * id3”.
36. Define Context free grammar and derivations.
Explain about Backtracking
CD UNIT-3
1. What is an intermediate code? Explain different types of intermediate
code forms and represent the following statement in different forms:
W = (A+ B) – (C+ D) + (A+ B+ C).
2. Differentiate between Synthesized and Inherited attributes with
suitable examples.
3. Explain the structure of LR parsers and various functions of it.
4. S L = R | R, L R | id, RL.
For the given grammar construct SLR parse table. Explain the Rules.
5. Write the quadruple, triple, indirect triple for the expression
(a* b) + (c+ d) – (a+ b+ c+ d).
6. For the grammar given below: EE + T | T, Tnum. num | num
Give an SDD to determine the type of each term T and expression E.
7. Differentiate LR (0) and LR (1) items with examples.
8. S L= R | R, L *R | id, R L construct CLR (1) parser and explain
the procedure.
9. Write Syntax directed definition for constructing syntax tree of an
expression derived from the grammar E E + T | E – T | T, T (E) |
id | num.
10. S L= R | R, L *R | id, RL construct LALR (1) parser.
11. With LALR (1) parse table constructed above check the
acceptance of any input string.
12. Construct the collection of LR (0) item sets and draw the go to
graph for the grammar S S S | a | €. Indicate the conflicts (if any) in
the various states of the SLR parser.
13. Explain in detail how an L- attributed grammar can be
converted into a translation scheme.
14. Discuss the evolution order of SDTs. Also write its applications.
15. Write the SDD for a simple type declaration and draw the
annotated parse tree for the declaration float a, b, c.
16. Explain various data structures used for implementing symbol
tables.
17. Illustrate how the SDT scheme is used for assignment
statements to generate the intermediate code.
18. Write the short notes on:
i) Abstract Syntax Tree
ii) Polish Notation
iii) Three address code
iv) Back patching
19. Construct 3 address code for the following:
If [ (a<b) and ((c>b) or (a>b))] then
z = x+ y* z
else
z = z+ 1
20. Draw Directed Acyclic Graph for the expression:
a + a * (b – c) + (b – c) * d.
21. What is symbol table? Explain how hash table is used to
construct a symbol table.
22. What are the reasons to use intermediate code in a compiler?
Write the intermediate code for the expression:
a + a * (b + c) * d.
23. Write down the translation procedure for the control statement.
24. What are the contents of a symbol table? Explain in detail about
the symbol table organization for block structured languages.
25. Generate three address code for the grammar below: ( B is a
Boolean expression and S is a statement)
S if (B) S1
S if (B) S1 else S2
S while (S) S1
26. Explain with suitable example SDT scheme for synthesized
attributes and inherited attributes.
27. Explain the various operations provided by system table.
28. Give the SDD scheme for desk calculator. Draw the annotated
parse tree for the following expression: 6+ 8* 5/8.
29. Explain the method of generating syntax directed definition for
control statements.
30. Test whether the following semantic rules are L-attribute or not?
A.s = B.b;
B.i = f(C.c,A.s)
31. Elaborate the Back patching with an example.
32. Differentiate between LR and LL parsers and discuss about the
types of LR parsers.
33. Write about Shift Reduce Parsing.
34. Discuss about the construction of SLR parsing tables.
35. Write a short notes on Dangling Else Ambiguity.
36. Explain how Ambiguity Grammar is handled with LR parsers
and discuss about Error Recovery in LR parsing.
37. Discuss about the following concepts:
i) Type Checking
ii) Control Flow
iii) Intermediate code for procedures.
CD UNIT-4
1. What is code optimization? Explain about various levels and types of
optimizations.
2. What is meant by activation of procedure? How it can be represented
with activation tree and record? Explain with quick sort example.
3. What is a Flow Graph? Explain how a given program can be
converted into a Flow Graph?
4. With an example explain the following loop optimization techniques:
i. Code motion
ii. Induction variable elimination
iii. Strength reduction
5. What is a leader of basic block? Write and explain the algorithm used
to find leaders. Draw flow graph for matrix multiplication.
6. Explain in detail about global common sub expression elimination
technique.
7. Discuss in detail the role of dead code elimination and strength
reduction during code optimization of a compiler.
8. Draw and explain the Runtime memory organization static storage
allocation strategy with pros and cons.
9. Explain storage allocation strategies used for recursive procedure
calls.
10. Explain in brief about peephole optimization techniques.
11. What are the principle sources of optimization? Give the
classification of code optimization.
12. Describe the various fields in an activation record.
13. Explain in brief about Heap Storage allocation strategy.
14. Explain various sources of loop optimization with suitable
examples.
15. Generate basic blocks and flow graph for quick sort algorithm.
16. Discuss the role of structure preserving transformations in code
optimization.
17. How to design calling sequences and analyze the principles of
activation records?
18. Differentiate between stack and heap allocation.
19. Describe the main idea of activation tree.
20. Write about all issues in code generation and describe it.
21. Write a short notes with an example to optimize the code:
i. Dead code elimination
ii. Variable elimination
iii. Code motion
iv. Strength reduction
22. Consider the following program code:
prod=0;
i=1;
do{
prod=prod +a[I]*b[i];
i=i+1;
}while(i<=10):
i. Partition in into blocks
ii. Construct the flow graph.
23. Compare static versus dynamic memory allocation.
24. Describe in detail about stack allocation of space and heap
management.
25. Illustrate the mechanism of elimination of partial redundancy in
data flow analysis.
26. Write about storage organization.
27. Discuss about Run Time storage allocation.
CD UNIT-5
1. Write the algorithm for a simple code generator.
2. Discuss about register allocation and assignment in target code
generation.
3. Explain various issues that affect the efficiency of generated code.
4. What are the different object code forms in code generation and
explain.
5. Explain the simple code generator and generate target code
sequence for the following statement d=(a-b) +(a-c) +(a-c)
6. Give an example to show how DAG is used for register allocation.