Compiler-7
Compiler-7
SECTION – I
Q-1 Answer the question below.
a. Identify the phase of a compiler detecting following types of errors/warnings. Justify [03]
your answer.
a. Exceeding length of identifier
b. Unbalanced parenthesis
c. Not matching actual parameters with formal parameters
b. What is difference between parse tree and syntax tree? Draw the syntax tree for [04]
following expression:
𝐚 = 𝐚 + 𝐚 ∗ 𝐛 + 𝐚 ∗ 𝐛 ∗ 𝐜 − 𝐚/𝐛
Q – 2.a Construct NFA for (𝐚|𝐛)∗ 𝐜(𝐝|𝐞)∗ # using Thompson’s Construction. [04]
Q – 2.b Attempt any TWO questions. [10]
(i) Differentiate between s-attributed Syntax Directed Translation (S-SDT) and L-
attributed Syntax Directed Translation (L-SDT).
(ii) Find basic block and draw control graph for following code written in higher level
language.
fact(x)
{
int f = 1;
for (i = 2; i <= x; i++)
f = f * i;
return f;
}
(iii) Explain the technique that reduces the amount of overhead required to process an input
character during scanning process.
Q - 3 Attempt any TWO Questions. [14]
a. Symbol Table is an important data structure created and maintained by the compiler.
What information is stored in symbol table? Also explain which data structures are
used to implement symbol table with its pros and cons.
Page 1 of 3
Candidate Seat no………….
b. Justify that following grammar is not LL (1), not SLR (1) but it is CLR (1).
𝐒 → 𝐀𝐚 | 𝐛𝐀𝐜 |𝐁𝐜 | 𝐛𝐁𝐚
𝐀→𝐝
𝐁→𝐝
c. Check whether below grammar is LALR (1) or not.
𝐒 → 𝐂𝐂
𝐂 → 𝐜𝐂 | 𝐝
SECTION – II
Q-4 Answer the below questions.
a. Why there is a need to have intermediate code generation phase? Explain any two [03]
techniques to implement three address code.
b. Consider SLR (1) and LALR (1) table for a CFG, justify whether below statements are [04]
true or false.
1. Goto of both tables may be different.
2. Reduce entries in tables may be different.
3. Error entries in table may be different.
4. Shift entries in tables may be different.
a. Justify what is the maximum number of reduce moves that can be taken by a bottom-up
parser for a grammar with no epsilon- and unit-production (i.e., of type 𝐴 −> є
and 𝐴 −> 𝑎) to parse a string with n tokens.
b. Consider the grammar
S → (S) | a
Let the number of states in SLR (1), LR (1) and LALR (1) parsers for the grammar be
n1, n2 and n3 respectively. Specify the relation between n1, n2 and n3.
c. Compute the operator precedence relation graph and precedence relation table for given
grammar.
𝐆→ 𝐄
𝐄→ 𝐄+𝐓
𝐓→ 𝐓∗𝐅
𝐅 → 𝐢𝐝
d. Why there is a need to have code optimization phase? Classify optimization types with
an example.
Page 2 of 3
Candidate Seat no………….
a. What is run time environment? Give brief idea of memory allocation done during
compilation with block structured language. What are the limitations of stack based
memory allocation?
b. Deign Syntax Direction Translation (SDT) to count number of 0’s and 1’s in a string.
Also draw the parse tree for the string 11001.
c. Code generation phase of the compiler takes an intermediate code as an input and
generates target machine code as an output. Discuss some common issues in design of
the code generator phase.
d. Write down the goals of an error handler in a parser. What are the different error
strategies used by a parser to recover from a syntactic error?
***
Page 3 of 3