You are on page 1of 4

18CSC362J – Compiler Design

QUESTION BANK

UNIT 1

1. Describe the various phases of compiler and trace it with the program segment
(position := initial + rate * 60).
2. Explain in detail the process of compilation. Illustrate the output of each phase of the
compilation for the input “a = (b+c) * (b+c) *2”
3. Discuss input buffering techniques in detail.
4. Construct Regular expression to NFA for the sentence (alb)*a.
5. Construct NFA using the regular expression (a/b)*abb.
6. Construct the NFA from the (a|b)*a(a|b) using Thompson’s construction algorithm.
7. Construct the DFA for the augmented regular expression (a | b )* # directly using syntax
tree.
8. Write an algorithm for minimizing the number of states of a DFA.
9. Explain the structure of a LEX program with an example.
10. Illustrate how does LEX work?
11. Consider the regular expression below which can be used as part of a specification of the
definition of exponents in floating-point numbers. Assume that the alphabet consists of
numeric digits (‘0’ through ‘9’) and alphanumeric characters (‘a’ through ‘z’ and ‘A’
through ‘Z’) with the addition of a selected small set of punctuation and special
characters. (say in this example only the characters ‘+’ and ‘-‘ are relevant). Also, in this
representation of regular expressions the character ‘.’ Denotes concatenation.
Exponent = (+|-|€) . (E | e) . (digit)+
(i) Derive an NFA capable of recognizing its language using Thompsons’ construction.
(ii) Derive the DFA for the NFA found in i) above using subset construction.
(iii) Minimize the DFA found in (ii) above.
12. Write Lex program to identify the following tokens - relational operators , arithmetic
operators and keywords (if, while, do, switch, for ).
Unit II
PART-B QUESTIONS
1. Consider the following CFG grammar over the non-terminals {X, Y, Z} and terminals {a,
b, d} with the productions below and start symbol Z.
X -> a | Y
Z -> d | X Y Z
Y -> c | €
Compute the FIRST and FOLLOW sets of every non-terminal and the set of nonterminals that
are nullable.
2. Eliminate left recursion E->E+T | T, T->T*F | F, F->(E)|id
3. Write the LR parsing algorithm.
4. Construct predictive parsing table for the grammar
S->(L) | a, L->L,S | S
show whether the following string will be accepted or not. (a, (a, (a,a)))

Unit III
PART B QUESTIONS
1. Consider the CFG depicted below where “begin”, “end” and “x” are all terminal symbolsof
the grammar and stat is considered the starting symbol for this grammar. Productions are
numbered in parenthesis and you can abbreviate “begin” to “b” and “end” to “e”
respectively.
Stat -> Block
Block -> begin Block end
Block -> Body
Body -> x
a. Compute the set of LR (1) items for this grammar and draw the corresponding
DFA.
b. Construct the corresponding LR parsing table.

2. Show that the grammar is LR(1) but not LALR(1)


S-> Aa | bAc | Bc |bBa
A->d
B->d
And parse the statement “bdc” and “dd”.

3. Show that the following grammar:


S -> Aa | bAc | dc | bda
A -> a
Is LALR(1) but not SLR(1)
4. Check whether the grammar is SLR (1) or not. Justifythe answer with reasons.
S->L=R | R; L->*R | id; R->L
5. Construct the SLR parsing table for the following grammar. Show the actions for the
parser for the input string “abab” & “baab”
S->AS | b , A->SA|a
6. Construct Stack Implementation of shift reduce parsing for the grammar
E->E+E | E*E | (E) | id. And the input string id1 + id2 * id3
7. Construct Operator precedence matrix table for the operators +,-,*,/, ↑,id,(,),$

UNIT –IV
1. Evaluate the expressions for the SDD annotated parse tree for the follow expressions.
a) 3 * 5 + 4n
b) (3 + 4) * (5 + 6)
2. (i)Analyze the grammar and syntax-directed translation for desk calculator
(ii) Explain how the procedure of constructing syntax tree from SDD
3. What is three address codes. Mention the types. How would you implement the three
address statement with an example.
4. Write about Bottom-Up evaluation S-Attributed definitions.
5. What is L-attributed definition? Give some example.
6. Explain synthesized attribute and inherited attribute with suitable examples.
7. Generate an intermediate code for the following code segment with the required
syntax-directed translation scheme. if ( a > b) x = a + b else x = a – b
8. What is cross compiler, explain its issues and give T-diagram representation.
9. (i) What are the issues in the design of code generator?
(ii) Explain simple code generator with suitable example.
10. Write a code generation algorithm. Explain about the descriptor and function getreg().
Generate a code for x = (( a + b) / (b-c)) – ( a + b) * ( b-c) +f.

UNIT –V

1. Explain in detail about stack allocation space.


2. Draw the activation tree for the quick soft algorithm.
3. Let fib(n) be the function
int fib(n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fib(n-1) + fib(n-2)}
I. Show the activation tree for fib(3).
II. Show the activation records that are on the run-time stack when fib(1) is invoked for
the first time during the invocation of fib(3). Just show four fields in each activation
record: the returned value, the argument, the control link (which is a pointer the
caller's AR), and the return address.
III. As a function of n, what is the time complexity of this program?
4. Explain in detail about parameter passing methods
5. (i) Describe the source language issues in detail.
(ii) Describe in detail about storage organization.
(ii) Explain about activation records and its purpose.
6. Give the data flow equation and state the use of gen, kill, in an out function
7. Explain principal source of optimization methods
8. Define DAG, state its applications and construct DAG
S1:= 4 * i
S2:= a[S1]
S3:= 4 * i
S4:= b[S3]
S5:= s2 * S4
S6:= prod + S5
Prod:= s6
S7:= i+1
i := S7
if i<= 20 goto (1)

You might also like