0% found this document useful (0 votes)
3 views

Compiler-5

This document is an examination paper for the CE401 Compiler Construction course at Charotar University of Science & Technology, dated November 2014. It consists of two sections with various questions related to compiler design, including topics such as data structures, error types, grammar conditions, and parsing techniques. The exam allows the use of scientific calculators and requires candidates to attempt questions on separate answer sheets.

Uploaded by

jaymehta11th
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Compiler-5

This document is an examination paper for the CE401 Compiler Construction course at Charotar University of Science & Technology, dated November 2014. It consists of two sections with various questions related to compiler design, including topics such as data structures, error types, grammar conditions, and parsing techniques. The exam allows the use of scientific calculators and requires candidates to attempt questions on separate answer sheets.

Uploaded by

jaymehta11th
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Candidate Seat no………….

CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY


Seventh Semester of B. Tech (CE) Examination
November 2014
CE401 Compiler Construction
Date: 27.11.2014, Thursday Time: 10.00 a.m. To 01.00 p.m. Maximum Marks: 70
Instructions:
1. The question paper comprises two sections.
2. Section I and II must be attempted in separate answer sheets.
3. Make suitable assumptions and draw neat figures wherever required.
4. Use of scientific calculator is allowed.

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………….

(b) Not matching actual parameters with formal parameters: semantic


(c) Unbalanced parenthesis: syntax
(d) Spelling error: lexical
(e) Exceeding length of identifier : lexical
(ii) Why there is a need to have intermediate code generation phase? Explain any two
techniques to implement three address code.
(iii) Code optimization
Q-3 Answer any one. [14]
a. Consider the following CFG,
E → TR
R → + TR
R → − TR
R→ϵ
T → 0 | 1 | … … |9
With translation scheme to generate postfix expression equivalent to given infix
expression which is recognized by above grammar. All actions in the translation should
be at the end of each production.
b. What are the conditions for any grammar to be LL(1)? Check whether following
grammar is LL(1) or not.
S → iEtSS ′ | a
S′ → eS | ∊
E→b
SECTION – II
Q-4 Answer the question below. [07]

a. The errors that can be pointed out by the compiler are


(a) Syntax errors (b)Semantic errors (c)Logical errors (d)Internal errors
b. In a compiler, keywords of a language are recognized during
(a) Parsing of the program (b) The code generation
(b) (c)The lexical analysis of the program (d)Dataflow analysis
c. Which of the following derivations does a top down parser use while parsing as input
string? The input is assumed to be scanned in left to right order
(a) Left most derivation in reverse (b) Left most derivation
(b) Right most derivation (d)Right most derivation in reverse
d. A language L allows declaration of arrays whose sizes are not known during
compilation. It is required to make efficient use of memory. Which one of the
following is true?
(a) A compiler using static memory allocation can be written for L
(b) A compiler cannot be written for L; an interpreter must be used
(c) A compiler using dynamic memory allocation can be written for L
(d) None of these

Page 2 of 4
Candidate Seat no………….

e. Which of the following grammar rules violate the requirements of an operator


grammar? P,Q,R non terminals and r,s,t are terminals
(i) 𝑃 → 𝑄𝑅
(ii) 𝑃 → 𝑄𝑠𝑅
(iii) 𝑃 → 𝜀
(iv) 𝑃 → 𝑄𝑡𝑅𝑟
(a) (i) 0nly
(b) (i) and (iii) only
(c) (ii) and (iii) only
(d) (iii) and (iv) only
f. Explain, why it is better to have two passes in compiler than having one pass? [02]

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 – 5.c Code optimization example [05]

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]
𝑆 → 𝐴𝑎 | 𝑏
𝑆 → 𝐴𝑐 | 𝑆𝑑| ∊
***

Hide the table on completion of paper

Page 4 of 4

You might also like