0% found this document useful (0 votes)
34 views7 pages

CD Question Bank

This document is a comprehensive question bank on Compiler Design, covering various topics such as compiler phases, parsing techniques, syntax trees, and optimization methods. It includes questions on both theoretical concepts and practical applications, such as constructing NFAs, DFAs, and parsing tables. The content is divided into units focusing on different aspects of compiler design, including lexical analysis, syntax analysis, semantic analysis, and code generation.

Uploaded by

formovies0312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

CD Question Bank

This document is a comprehensive question bank on Compiler Design, covering various topics such as compiler phases, parsing techniques, syntax trees, and optimization methods. It includes questions on both theoretical concepts and practical applications, such as constructing NFAs, DFAs, and parsing tables. The content is divided into units focusing on different aspects of compiler design, including lexical analysis, syntax analysis, semantic analysis, and code generation.

Uploaded by

formovies0312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Subject:Compiler Design

Question Bank

UNIT-1
What is a compiler?Explain the phases of a compiler with an example and for a
1 statement given below, write output of all phases of a compiler.
[a=a+b*c*2;a,b,c=float]
What is a pass in a compiler? Compare one pass and two pass compilers. What is the
2
effect of reducing the number of passes?

3 Explain the roles of linker, loader and preprocessor.

What is the difference between parse tree and syntax tree? Write appropriate
4
grammar and draw parse as well as syntax tree for a*(a-a^a)
Define lexeme, token and pattern. Identify the lexemes that make up the tokens in the
following program segment. Indicate corresponding token and pattern.
1)void swap (int a, int b)
{
5 int k;
k = a;
a = b;
b = k;
}
6 Write a brief note on input buffering techniques.
7 Differentiate between compiler and interpreter.
8 Write a note on cousins of compiler
9 Write a note on cross compiler and incremental compiler
Explain Semantic Analysis and Syntax Analysis phases of the compiler with A
10
suitable example. Also explain the reporting errors by these two phases.
11 Write a short note on Symbol Table Management.
Construction of a NFA from Regular expression (Thompson’s Construction). Apply
subset construction method to convert into DFA
12
1)a*b
2) (a | b)*abb or (a + b)*abb
13 Construct an NFA for following regular expression and then convert it to DFA.
a+ (c |d) b*f #
14 Convert the (a|b|c)*d*(a*|b)ac+# regular expression to DFA.
Draw Deterministic Finite Automata for :
1. (0+1)*101(0+1)*
15
2. 10(0+1)*1
3.(010+00)*(10)*
Construct DFA for following Regular expression. Use firstpos, lastpos and followpos
16
functions to construct DFA. ( a * | b * ) *
Construct DFA by syntax tree construction method.
17 a*b*a(a|b)*b*a#
Optimize the resultant DFA
Construct DFA by syntax tree construction method.
a+ b* (c |d) f #
18
Convert the (a|b|c)*d*(a*|b|ac+)#regular expression to DFA directly and draw its
DFA.
Construct minimum state DFA for following Regular Expression.
19 1)(a|b)*a(a|b)
2)(a|b)*a(a|b)(a|b)
UNIT-II
1 Explain role of parser in compiler design.
2 Differentiate between top down and bottom up parser.
How top down and bottom up parser will parse the string ‘bbd’ using grammar
3
A -> bA | d. Show all steps clearly.
For the following grammar
D -> T L ;
L -> L , id | id
T -> int | float
4 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;
5 Define: Left Recursion. State the rule to remove left recursive from the grammar.
Eliminate left recursive from following grammar.
1. S -> Aa | b
A -> Ac | Sd | f
2. A->ABd|Aa|a
B->Be|b
3. S -> Aa | b
A -> Ac | Sd | €

Define: Left Factoring. State the rule to remove left factoring from the grammar.
Eliminate left recursive from following grammar.
6 1. A->aAB|aA|a
b->bB|b
2. A->ad|a|ab|abc|b

Write unambiguous grammar for producing arithmetic expressions consisting of


symbols id, +, - , /, $. Find first & follow for non-terminal symbols of the grammar
7 for non recursive predictive parser. Construct the parse table and parse following
string.
id - id + id - id $
Write ambiguous and unambiguous production rules for if then else construct.
8 Illustrate parsing using both types of rules by giving an example. Also explain left
factoring and its use.
Implement the following grammar using Recursive Descent Parser.
9 1. S -> Aa | bAc | bBa, A -> d, B -> d
2. S ->ABC,B->1B | ^,A-> 0A1 | ^,C->1C0 | ^
Implement the following grammar using Table Driven parser and check whether it is
LL(1) or not.
S -> aBDh,
B -> cC,
10
C -> bC / ^,
D -> EF,
E -> g / ^,
F-> f / ^
Construct LL(1) parsing table for the following Grammar:
11 S -> ( L ) | a
L -> L , S | S
Construct predictive parsing table for following.
S -> A
12 A -> aB | Ad
B -> bBC | f
C -> g
13 Develop a predictive parser for the following grammar.
S’->S
S->aA|b|cB|d
A->aA|b
B->cB|d
What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is
14
a handle?
Write unambiguous production rules for producing arithmetic expression consisting
of symbols id, *, -, ( ) and ^, where ^ represents exponent. Parse following string
15 using shift – reduce parser:
id – id * id ^ id * (id ^ id ) ^ id
Explain various conflicts of a shift – reduce parser.
16 Explain Operator Precedence Parsing method with example.
Construct LL(1) parsing table for the following Grammar:
17 S -> ( L ) | a
L -> L , S | S
Check whether the following grammar is CLR or not.
S -> Aa | bAc | Bc | bBa
18
A -> d
B -> d
Construct an SLR Parsing Table for the following grammar.
19
S-> 0S0 | 1S1 | 10
Write SLR parsing table for :
S ->T
20 T ->CC
C ->cC
C-> d
21 Explain LALR parser in detail. Support your answer with an example.
Show that the following grammar S-> AaAb | BbBa A -> ϵ B -> ϵ
22
is LL(1) but not SLR(1).
Show that the following grammar S->Aa | bAc | dc | bda A->d
23
is LALR(1) but not SLR(1).
Construct the collection of sets of LR(0) items for the following grammar.
24 S-> Aa | bAc | dc | bda
A->d
Construct an SLR Parsing table for the following grammar.
E->E-T|T
25
T->F↑T|F
F->(E) | id
26 Generate the SLR parsing table for the following Grammar
S->Aa|bAc|bBa
A->d
B->d
Define operator precedence grammar. Construct precedence matrix and precedence
graph for arithmetic grammar as shown below:
27 E -> E + T | T
T -> T * F | F
F -> (E) | id
Construct the canonical parsing table for the following Grammar
S’->S
28
S->CC
C->cC|d
Differentiate SLR, Canonical LR and LALR. Also justify the statement “A class of
29 grammar that can be parsed using LR methods is a proper subset of the class of
grammars that can be parsed with predictive parser”
30 Explain syntax directed translation scheme with example.
Explain with an appropriate example how to perform bottom up evaluation of
31
inherited attributes.
Write syntax directed Definition for translating following grammar for
postfix notation. Also draw annotated parse tree for 9-5+2.
32 expr -> expr + term
expr -> expr – term
term -> 0 | 1 |…..|9
Show syntax directed definition for simple desk calculator. Also show annotated
33
parse tree for 3*5+4n, where n indicates newline.
Construct a Syntax-Directed Translation scheme that translates arithmetic expressions
34 from infix into postfix notation. Show the application of your scheme to the string
“3*4+5*2”.
35 Discuss synthesized and inherited attributes using a suitable grammar
Write a context free grammar for arithmetic expressions. Develop a syntax directed
36 definition for the grammar. Draw an annotated parse tree for the input expression:
(3*2+2)*4
37 Explain all error recovery strategies using suitable examples.
38 Explain how panic mode recovery can be implemented.
UNIT-III
1 What is intermediate code? write benefits of intermediate code generation.
Explain different forms of intermediate code generation.
1. Abstract syntax tree
2
2. Polish notation
3. Three address code
Explain Quadruple, triple, and indirect triple with a suitable example. OR writ about
3
implementation of 3 address code
4 Write a short note on symbol table management.
5 Explain how type checking & error reporting is performed in the compiler.
List out various syntax directed translation Mechanisms. Explain any two with an
6
example.
7 Explain Activation record and Activation tree in brief.
8 Explain Stack allocation and Activation record organization in brief.
9 List out and explain various storage allocation strategies.
10 Write in brief about storage organization in compiler
11 Compare and contrast between static , stack and heap allocation
12 What is the use of a symbol table? How are identifiers stored in the symbol table?
13 Write a note on symbol table management.
14 Explain dynamic storage allocation techniques.
UNIT-IV
1 Write a note on peephole optimization.or Explain Peephole Optimization.
Explain code generator design issues. or Explain various issues in design of code
2
generator
3 Give Data Flow Properties.
4 Explain role of code generator.
5 Explain various issues in design of code generator
Explain the following parameter passing methods.
1. Call-by-value
2. Call-by-reference
6 3. Copy-Restore
4. Call-by-Name
OR
Explain various parameter passing methods.
7 Draw a DAG for expression: a + a * (b – c) + (b – c) * d.
8 Explain following:
1. Basic block
2. Constant folding
3. Handle
4. constant propagation
5. Common subexpression elimination
6. variable propagation
7. Code Movement
8. Strength Reduction
9. Dead Code elimination
10. Busy Expression
11. Live Variables
9 Explain code-optimization technique in detail
10 Explain Basic Block and Flow Graph with examples.
11 Discuss the functions of error handler

12 What is DAG? What are its advantages in the context of optimization? How
does it help in eliminating common sub expression

13 Explain code scheduling constraints in brief.

14 Explain panic mode and phrase level error recovery techniques.

15 What is global optimization? Name the 2 types of analysis performed


for global optimization.
Explain the following with example
16 1) Lexical phase error
2) Syntactic phase error
17 Explain various techniques involved in loop optimization

18 What is code optimization?Why is it needed? Classify code optimization and write


benefits of it.
19 Write a note on Global data flow analysis
20 Write a short note on a simple Code Generator
21 Write applications of DAG.
Construct DAG for a + a * (b- c) + (b – c) * d. also generate three address code
22
for the same.
Draw syntax tree and DAG for the statement
23 a = (a * b + c) ^ (b + c) * b + c.
Write three address codes from both.

You might also like