The document is an examination paper for the CE-401 Compiler Construction course at Charotar University of Science & Technology, dated December 2012. It includes instructions for answering questions, two sections with various topics related to compiler design such as NFA, DFA, symbol tables, grammar analysis, and code optimization. Students are required to demonstrate their understanding of compiler construction concepts through algorithms, parsing techniques, and grammar manipulation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
14 views3 pages
Compiler 2
The document is an examination paper for the CE-401 Compiler Construction course at Charotar University of Science & Technology, dated December 2012. It includes instructions for answering questions, two sections with various topics related to compiler design such as NFA, DFA, symbol tables, grammar analysis, and code optimization. Students are required to demonstrate their understanding of compiler construction concepts through algorithms, parsing techniques, and grammar manipulation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY
Seventh Semester of B. Tech. Examination (CE)
December 2012
CE-401 Compiler Construction (CC)
Date: 04.12.2012, Tuesilay ‘Time: 10:00 a.m. To 01:00 p.m. Maximum Marks: 70
Tasiructions:
1. ‘The question paper comprises of two sections
2. Section and Il must be attempted in separate answer sheets.
3. Make suitable assumptions and draw neat figures wherever required.
4 Rough work is to be done in the last page of main supplementary, please don’t write anything
on the questi
n paper.
Indicate clearly, the option(s) you attempt atong with its respective question no.
6. Figures to the right indicate marks.
SECTION-I
Q-1 Answer the following questions.
1, Prepare NFA and DFA for: (0| 1)* 101 01)"
2. Explain the processing of various phases of “
statement.
answer data *(int)data2;
3. For the following C++ fragment, identify the lexemes that make up the 4
tokens and also show symbol table entries for this module.
void main(int argc, int argv{])
{char a,b,c;
int m=a++2; /* float b=5.6*/}
compiler on the following
Q2
[A] Weite an algorithm for scanner, which can identify following *C* language tokens. 4
(i) Keywords (if, else, while)
(i) String constants e.g. “this is constant”
(iii) single line comments-/* this is comment*/
(iy) punctuation symbols ~ 4", %,3 4}
B) 1 A= 6*(B+C), 4
347* (BHO);
E:=A*(B4C),
2. while (count < limit) do
INPUT SALES;
VALUE := SALES * (MARK_UP +TAX );
OUTPUT := VALUE;
COUNT := COUNT + 1;
end;
1. Which kinds of optimizations possible on the code.
2. Eliminate common sub expression from/for each basic block
3. Find the induction variables of each loop and eliminate them.
OR
{B] Explain the Linking Loader and its significance in the execution of the 4
program in a compiler. Explain the structure of Activation Record.
c) nd out the operator precedence parsing for the following Input string. 4
id * Gd Tid ) — id /id. Assume the Grammar, OR Explain the Operator
Precedence Parsing by giving your own example,
Q3
1A] Discuss the importance of symbol table in compiler design. How is symbol table 4
manipulated at various phases of the compilation? What should be the typical
Page 1 of 35
{B]
[B]
{c]
{c]
entries in the symbol table for the ‘C’ language? Explain how scope rules and
block structure of a programming language influence the organization strategies
for symbol table.
What is the difference between parse tree and syntax tree? Draw the parse tree for
following expression:
asata®b+a*b*e—a/b+a*b and write threo address code frit
OR
Write quadruples for the expression: (a+b) * (+d) — (atb+c)
What are the challenges in the design of the compiler? Which are the factors to be
considered in the task of code generation?
OR
Draw the block diagram of communication between Scanner(s) and Parser.
Explain the types of errors detected by lexical analysis phase.
SECTION-IE
1. Show that the following grammar is LR(1) but not LALR(1):
SAa|bAc | Be | bBa
Add
Bod
2. Test whether the following grammar is LL (1) or not. Construct predictive
parsing table forit.
SSH
S— aSA|C
A> bS|c
Parse the input string aabace#
3. Left factor the following Grammar:
‘SiELS [iEtScS | a
EDb
What language does following grammar generate? Justify your answer
S> aSbS | bSaS | €
Is the following grammar ambiguous? Give reason.
S? aS|aSbS|c
Ss? Mla
LSLS|s
What are the terminal and non terminal symbols? Contract the lefl-most and
right-most derivations and prepare the corresponding parse trees (derivations) for
the sentence: (a,(aa)).
OR
A RISC processor has smaller number of instructions and more number of
registers than a CISC machine, Describe the pros and cons of compiler
design targeted to a RISC machine as compared to a CISC machine.
Give the translation of three address code for the following stmt:
whilea if expr then stmt | stmt| if expr then stmt else stint
‘Show that the grammar is ambiguous. Write an equivalent unambiguous grammar
for the same,
OR
{B] Consider the grammar that has the produetions.
S> bA | aB
AD dAA|aS|a
BS aBB | bS|b.
Find the equivalent grammar in CNP.
{C] Write Syntax Directed Definition for translating following grammar for postfix
notation. Also draw annotated parse tree for 9-542,
expr expr + term
expr > expr —term
expr> term
term 90] |.....9
oR
[Cc] s>s#
SABC
Aa bbD
Bale
C>ble
D3cle
Construct the FIRST and FOLLOW sets for the given Grammar.
Design LL (1) Parsing table.
Page 3 of 3