Compiler-5
Compiler-5
SECTION – I
Q-1 Answer the question below. [07]
a. Which data structure in a compiler is used for managing information about variables
and their attributes?
(a)Abstract syntax tree (b) Symbol table
(c)Semantic check (d)Parse table
b. Which languages necessarily need heap allocation in the runtime environment?
(a)Those that support recursion (b)Those that use dynamic scoping
(c)Those that allow dynamic data structure (d)Those that use global variables
c. Object code is
(a) ready to execute (b)output of compiler but not assembler
(c) Must be loaded before execution (d) Must be rewritten before execution
d. A compiler for a high level language that runs on one machine and produces code for a
different machine is called
(a)Optimizing compiler (b)One pass compiler
(c)Cross compiler (d)Multi pass compiler
e. Consider line number 3 of the following C program.
int main(){ /*line 1 */
int i,n; /*line 2 */
fro(i=0;i<n;i++) /*line 3 */
}
Identify the compiler’s response about this line while creating the object-module
(a)No compilation error (b)Only a lexical error
(c)Only syntactic error (d)Both lexical and syntactic error
f. What are the conditions for any grammar to be operator grammar? [02]
Q – 2.a Construct Non Deterministic Finite Automaton (NFA) from following regular [04]
expression (RE) using firstpos(), followpos() and lastpos().
(a|b)∗ c (d|e)∗ #
Q – 2.b Answer any two questions. [10]
(i) Identify which phase of the compiler generates an error?
(a) Undeclared variable: semantic
Page 1 of 4
Candidate Seat no………….
Page 2 of 4
Candidate Seat no………….
Q – 5.a A major consideration in designing a symbol table is that insertion and retrieval should [07]
be as fast as possible. What are the possible data structures through which symbol table
is implemented? Which data structure is the most suitable to implement symbol table?
Justify your answer.
OR
Q – 5.a What is run time environment? Give brief idea of memory allocation done during [07]
compilation with block structured language. What are the limitations of stack based
memory allocation?
Q – 5.b What is activation record? Explain the structure of an activation record with all its [04]
components.
Q – 5.c Compute the operator precedence matrix and precedence function for the following [05]
grammar. +,id,( and ) are terminal symbols.
𝐺→𝐸
𝐸 → 𝐸 + 𝐸 | 𝑖𝑑 |(𝐸)
OR
Q – 6.a Generate SLR parsing table for following grammar and check whether grammar is SLR [07]
or not.
𝑆→𝐿=𝑅
𝑆→𝑅
𝐿 →∗𝑅
𝐿 → 𝑖𝑑
𝑅→𝐿
Q – 6.b Write an algorithm to manage forward pointer using sentinel while buffering the input [04]
Q – 6.c What is the use of deterministic finite automata in lexical analysis? [02]
OR
Page 3 of 4
Candidate Seat no………….
Q – 6.a Construct the LALR parsing table for following grammar: [07]
𝑆 → 𝐶𝐶
𝑆 → 𝑐𝐶
𝐶→𝑑
Q – 6.b Code generation phase of the compiler takes an intermediate code as an input and [05]
generates target machine code as an output. Discuss some common issues in design of
the code generator phase.
Q – 6.c Eliminate the left recursion from the following grammar: [02]
𝑆 → 𝐴𝑎 | 𝑏
𝑆 → 𝐴𝑐 | 𝑆𝑑| ∊
***
Page 4 of 4