CD Assignement 24 25
CD Assignement 24 25
Text Book :
Compilers: Principles, Techniques and Tools by Aho, Lam, Sethi,
and Ullman, Second Edition, Pearson, 2014
Shri S’ad Vidya Mandal Institute of Technology
Department of Computer Science and Engineering
SUB: COMPILER DESIGN SUB CODE: 3170701
Assignment-II (chapter 3)
1] Write the two methods used in lexical analyzer for buffering the input. Which
technique is used for speeding up the lexical analyzer?
2] Describe language denoted by the following regular expression :(3.6)
A] 0 (0|1)*0
B] ((ε|0)1*)*
C] (0|1)*0(0|1)(0|1)
D] 0*|0*|0*|0*
E] (00|11)*((01|10)(00|11)* (01|10) (00|11)*)*
3] Construct nondeterministic finite automata for following regular expression
Using Thomson‟s Construction. Show the sequence of moves made by each in
Processing the input string ababbab (3.16)
a] (a|b)*
b] (a*|b*)*
c] ((ε|a)b*)*
d] (a|b)*abb(a|b)*
4] Construct DFA for (a|b)*abb(a|b)*.
5] Convert exercise 3 – c into DFA using subset construction method.
6] Construct DFA for (a|b)*abb(a|b)* using firstpos() and followpos().
7] Construct DFA and minimum state DFA for the following regular expression.(3.23)
A] (a|b)*a(a|b)
B] (a|b)*a(a|b)(a|b)
C] (a|b)*a(a|b)(a|b)(a|b)
8] Explain Lexical error found in Lexical analysis phase.
9] Define terms: pattern, lexeme, token
10] Draw transition diagram for following tokens.
1] relop
2] Identifier
3] Unsigned number
4] Whitespace
11] Explain LEx specification.
Shri S’ad Vidya Mandal Institute of Technology
Department of Computer Science and Engineering
SUB: COMPILER DESIGN SUB CODE: 3170701
SaSbS|bSaS|ε
9] Generate the SLR parsing table for the following Grammar(may-12 paper)
S->Aa|bAc|bBa
A->d
B->d
10] Compute the operator precedence matrix and precedence function for the
following grammar if it exists. +,*,-,/,id,num,( and ) are terminal symbols.
G→E
E→E+T|E-T|T
T→T*F|T/F/F
F→num|id|(E)
Shri S’ad Vidya Mandal Institute of Technology
Department of Computer Science and Engineering
SUB: COMPILER DESIGN SUB CODE: 3170701
1] Construct the parse tree and syntax tree for the expression ((a)+(b)) according to
2] For the input expression (4*7+1)*2 , construct on annotated Parse tree according to the
syntax directed definition of figure given below.
Production Semantic Rules
LEn Print(E.val)
E E1+T E.val:=E.val+T.val
ET E.val:=T.val
TT1 *F T.val:= T1.val * F.val
T(E) T.val:=E.val
Fdigit F.val:=digit.lexval
TF T.val:=F.val
3] Construct the dag and identify the value numbers for the subexpression of the following
expression assuming from the left.
a+a+(a+a+a+(a+a+a+a))
4] Construct syntax directed translation scheme and definition that translate arithmetic
operation from infix to postfix in which an operator appears before its operand as for
figure xy- is a positive notaion for x-y . Give annonated parse tree for the input 9-5+2 and
9-5*2(“11” for string concatenation)
5] Construct Syntax directed translation scheme and definition that translate postfix notaion into
infix notation 95-2+ and 95-2*.
6] A robot is to be moved to a unit step in a direction specified as a command given to it. The
robot moves in the direction North, South, East, West on receiving N, S, E, W command
respectively & in the direction North-East , North-West, South-East, South-West on receiving A,
B, C, D commands respectively. The current position of the robot is initialized to (0,0) Cartesian
coordinates on receiving command Start. Write production rules for producing sequence of
commands and semantic rules for knowing position of a robot after receiving a sequence of
commands. Draw annotated parse tree for following sequence:
Start N N A A C C N (dec-12 paper)
8] Explain with an appropriate example that how to perform bottom up evaluation of an inherited
attributes.
Shri S’ad Vidya Mandal Institute of Technology
Department of Computer Science and Engineering
SUB: COMPILER DESIGN SUB CODE: 3170701
Assignment-V(Chapter 7,8,9,10)
2. Explain activation record. How is task divided between calling & called program for stack
Updating?
3. Explain heap, dynamic storage allocation techniques and synthesized attributes.
4. Draw syntax tree and DAG for following statement. Write three address codes from
both.
a = (a + b * c) ^ (b * c) + b * c
5. What is Intermediate form of the code? What are the advantages of it? What are
generally used intermediate forms? Write three address code for following expression.
(a+b)*(c+d)-(a+b+c)
6. Explain: Symbol Table Management. How symbol table differs from other data structures?
7. Compare: Static v/s Dynamic Memory Allocation
8. What are the limitations of static storage allocation? Explain the problem of dangling
references.
9. Translate the arithmetic expression a*-(b+c) into
1. Syntax tree
2. Postfix notation
3. Three address code
10. Translate the expression –(a+b)*(c+d)+(a+b+c) into
1. Quadruples Note : All three are type of n-tuple notation.
2. Triples
3. Indirect triples.
11. Explain any three code optimization methods with examples.
12. Explain Peephole optimization in detail.
13. Explain various issues in design of code generator.