CD Assignment 1,2,3,4,5
CD Assignment 1,2,3,4,5
Shahina Anjum
Unit - I
1. Define Language Translator. Differentiate between: (i) compiler and assembler.
(ii) compiler and interpreter.
2. What is the pass of a compiler ? Explain how single pass and multi pass compiler work.
3. What are the Phases and Passes of compiler? Explain in detail the process of compilation for the
statement a = b + c * 70.
4. What is cross-compiler? How is boot-strapping of a compiler is done to a second machine.
5. (i) How do you specify the tokens? Differentiate Token, Lexeme and Pattern with an suitable
examples. And draw transition diagram also.
(ii) Write the Regular Expressions for specifying Identifiers and Constants of C. Draw the
transition diagram for an identifier.
6. How does finite automata useful for lexical analysis? Write the algorithm for moving forward
pointer in "input buffering" scheme.
7. Write regular expression to describe a language consist of strings made up of
(i) even number of a & b.
(ii) odd number of a & b.
8. Draw NFA for the regular expression ab*/ab using Thompson rule.
9. Construct the NFA and DFA for the following regular expression. (0+1)* (00+11) (0+1)* .
1
Compiler Design by Ms. Shahina Anjum
10. Discuss the subset construction algorithm for NFA to DFA conversion.
Convert following NFA to equivalent DFA and hence minimize the number of states in the DFA.
11. Construct a DFA that accepts a language L over input alphabets ∑ = {a, b} such that L is the set of all
strings starting with ‘aa’ or ‘bb’.
12. (i) What is an ambiguous grammar? Is the E+E |E*E| id grammar ambiguous? If yes convert it
into unambiguous.
(ii) Show that the following grammar is ambiguous.
13. Write short note on: (i) Context free grammar (ii) YACC and LEX tool
14. Write a CFG to represent: (i) the language L={an+m bn | m,n>=1} (ii) the palindrome .
15. Differentiate Parse tree , Syntax tree and Abstract Syntax Tree with an example.
Unit - II
1. Explain the difference between Top down Parsing & Bottom up Parsing.
2. Write the algorithm for FIRST and FOLLOW.
i. Find out the FIRST ( ) & FOLLOW ( ) of the following grammar:
S → aBDh
B → cC
C → bC | ε
D → EF
E→g|ε
F→f|ε
ii. A (A) A ϵ
iii. S → B | SabS
B → bB | ε
iv. S → XS | DS | ε
X → Y | Zb | aY
Y→ cZ
Z→e
2
Compiler Design by Ms. Shahina Anjum
3. What is Left Recursion? What is the role of Left Recursion? Write the rules to eliminate left
recursion.
i. Eliminate left recursion from the following grammar:
S AB
A BS | b
B SA | a
ii. Remove left recursion from the grammar
iii. Check whether left recursion exists for the following grammar:
4. What do you mean by left factoring? Explain with the help of example how left factoring can be
avoided. Remove left factoring of the following grammar: S→ aAB | aA | aAC
5. Consider the following grammar:
Write down the procedures for the non terminals of the grammar to make a recursive descent
parser.
6. Give algorithm for constructing of predictive parsing table.
i. Consider the following grammar and construct predictive parsing table.
ii. Consider the following left recursive grammar and eliminate the left recursion. Also
construct the predictive parsing table:
3
Compiler Design by Ms. Shahina Anjum
7. Explain Shift – Reduce conflict and Reduce-Reduce conflict in the parsing table.
Perform Shift Reduce Parsing for the given input strings using the grammar.
S -> (L) | a
L -> L, S | S
(i) (a, (a, a)) (ii) (a, a)
8. Construct the SLR parsing table for the following Grammar.
i.
S→ 0S0
S→ 1S1
S→ 10
ii.
S→ AaAb
S→ BbBa
A→ ε
B→ ε
9. Define the following terms and give suitable example for it.
i. Handle
ii. Handle pruning
10. What do you mean by operator precedence grammar? Explain the working of operator
precedence parsing technique with the help of example.
i. Compute the operator precedence and function table of the following grammar by using
operator precedence technique.
P SR|S , R bSR|bS , S WbS|W , W L*W|L , L id
ii. Compute the operator precedence table for the given grammar.
4
Compiler Design by Ms. Shahina Anjum
5
Compiler Design by Ms. Shahina Anjum
Unit - III
1. What is syntax directed translation? What are Synthesized and Inherited Attributes?
Differentiate S- Attributed and L- Attributed SDT.
2. Consider the following grammar and give the syntax directed definitions to construct parse tree.
For the input expression 4*7+3*9. Also Construct an annotated parse tree according to your
syntax - directed definition :
3. What is postfix notations? Explain it with suitable example. Translate (A+B+C) * (C+Q) into
postfix notation using syntax-directed translation schemes (SDTS).
4. Discuss the translation scheme for converting an infix expression to its equivalent postfix form.
5. Explain role of Array-references in the arithmetic expressions in syntax-directed translation.
6. Discuss about non-linear type of intermediate code. What are the various types of intermediate
code representation? [Hint: Postfix notation, three-address code, syntax tree and DAG]
i. Define backpatching and semantic rules for Boolean expression. Write SDD to produce
three-address code for Boolean expressions. Derive the three address code for the following
expression: A < B or C < D and E < F
ii. Generate three address code for the following code:
iii. Write the three address code for the following code segment:
iv. Consider the following code fragment, Generate three address code for it.
6
Compiler Design by Ms. Shahina Anjum
v. Give three address code for the following:
vi. Generate three address code for the following code segment. There are four bytes per word.
7. Write the quadruples, triple and indirect triple for the following expression:
(x+y)*(y+z)+(x+y+z)
8. Define a directed acyclic graph (DAG) and syntax tree. Draw both for p+p*(q-r)+(q-r)*s
Unit - IV
1. (i) Describe symbol table and its entries. Also discuss various data structures used for symbol
table with suitable example.
How names can be looked up in the symbol table? Discuss.
(ii) What is hashing? Explain. Discuss about hash table.
2. Explain the implementation of simple stack allocation scheme while Run - Time
Administration.
3. What are the three storage allocation strategies? What are their importance in compiler design?
[Static Allocation , Stack Allocation and Heap Allocation Strategies.]
4. What is meant by an activation record? Draw the format of Activation Record in stack
allocation and explain each field in it.
5. Distinguish between static scope and dynamic scope.
6. What are lexical phase errors, syntactic phase errors & semantic phase errors? Explain with
suitable example. Also suggest methods for recovery of errors.
7. Write down techniques to recover error from LR parser. Explain with an example.
8. Discuss the various parameter passing techniques with suitable examples. [also called as
procedure activation techniques.]
7
Compiler Design by Ms. Shahina Anjum
Unit - V
1. What is Code Generator? What are the various issues in design of code generator and code loop
optimization?
2. What are the code optimization techniques? Explain Machine-Independent Optimization.
3. What is machine dependent optimization? Explain how Peephole Optimization techniques
functions in this.
4. Construct the flow graph for the following code segment:
5. What is basic block? How can a sequence of three-address statements be transformed into a
list of basic blocks? Show it with examples.
6. Explain following code improving transformations with examples:
i. Local and global elimination of common sub-expressions.
ii. Copy propagation and dead code elimination.
7. Differentiate constant propagation and variable propagation.
8. Explain the need of code optimization. Explain different type of Loop Optimization
Technique with suitable examples.
OR
Write short notes on the following with the help of example:
i. Constant folding
ii. Code Motion (or Frequency Reduction) (or Invariant Variable Motion)
iii. Reduction in Strength.
iv. Loop unrolling
v. Loop Jamming
vi. Local and loop optimization
vii. Induction variable elimination
9. Explain Control flow analysis and Data flow analysis in the organization of the code
optimizer.
10. What is global data flow analysis? How does it use in code optimization?
11. Consider the following three-address code segment :-
8
Compiler Design by Ms. Shahina Anjum