CD Question Bank
CD Question Bank
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?
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
12 What is DAG? What are its advantages in the context of optimization? How
does it help in eliminating common sub expression