Compiler Design Final Exam

Topics: Parsing, Compiler, Top-down parsing Pages: 6 (720 words) Published: December 5, 2013
FUSN

1

M

S

M S RAMAIAH INSTITUTE OF TECHNOLOGY
(AUTONOMOUS INSTITUTE, AFFILIATED TO VTU)
BANGALORE - 560 054

SEMESTER END EXAMINATIONS - MAY / JUNE 2012
Course & Branch

.

Subject

B E - Com ut Science E
S
F. er
& n gineering

t
VI
e rne s e r

Compiler Design Max. Marks : 100

Subject Code

: CS612

Duration : 3 Hrs

Instructions to the Candidates: '
. Answer one full question from each unit
UNIT - I
1. a) What is the front end and back end of a compiler? What are the (08) advantages of breaking up the compiler functionality into two distinct stages?
b) Show that translation made by each of the compiler phases for the (06) statement
a:=b+c*10 where a,b,c, are float
c) What are the common programming errors? How should the passer recover (06) once an error is detected?
2. a) Explain the role of lexical analyzer in a compiler. Why Lexical Analysis and (08) parsing are separated into two phases?
b) Write regular expression for the following character sets (04) i) All strings of lowercase letters that begin and end with a ii) All string of digits that does not contain he substring 110 iii) All strings of a's and b's such that the 3rd letter from right is 'a' and minimum length of string is three

iv) All strings of digits that contain no leading zeros
c) Explain left recursion and show how it is eliminated from the following (08) grammar. Also describe the algorithm for eliminating left recursion

A -^BalAaIc
B -^Bb ^Abd

3.

a)
b)

UNIT - II
(02)
Define an LL(1) grammar with example.
Write the rules to compute FIRST(X) and FOLLOW(A). Applying the rules (08) compute the FIRST and FOLLOW sets for the following grammar. S --^aSeIB

B-^bBeIC
C--^cCeId
c) Check whether the following grammar is suitable for predictive passing . If (10) not do necessary transformations to make it suitable for LL(1) parsing. Construct a predictive parsing table and show the moves made by the parser on input (() O)

G:-S-*S(S)AIs
A --^aIc

Page 1 of 3

No mobile
phones

a)

CS612

Define handle pruning. Consider the following grammar.
S ---> aABe

(05)

A -> Abe I b
B-^d.
Show the configurations of a shift reduce parser on input 'abbcde, b)

Show that the following grammar
S -> AaAb l BbBa

(10)

A -^s

c)

B-*e
is LL(1 ) but not SLR ( 1) by constructing parsing table for both . Indicate any action conflicts in the set of items.
For the grammar
S^Aa^bAc!Be!bBa

(05)

A d

B -*d
Find the LR(1) set of items. Also explain about the working of LR(1) parser. How it is advantageous compared to SLR parser?

a)

b)
c)

a)

UNIT - III
Define S-Attributed and L-Attributed definitions. Give an SDD based on a grammar suitable for top-down parsing. Identify whether it is L-attributed or S-attributed.
Define Dependency graph.
Define control stack and activation record. Explain about the downward growing stack of activation records.
Write the actions of desk-calculator SDT by manipulating the parser stack explicitly. Explain the implementation with respect to the following grammar.

(11)

(03)
(06)

(08)

L ---> En
E--*F+T1T
T-->T*FIF
F -* (E) ; digit
b) Give the SDD for simple type declarations for the SDD. Give annotated (07) parse trees for the following expressions.
i) int a,b,c
ii) float w,x,y,z
c) Show the SDT for infix to prefix translation during parsing. (05) UNIT - IV
a) Construct DAG for the following expressions.
i) a+b+(a+b)

(03)

ii) a+a*(b-c)+(b-c)*d
iii) a+b+a+b
b) Translate the following statements to three address code and quadruples (08) i)x=a*b+c*d-e*.f

ii)x = _/'(0,y+1)-1
c) Give the semantic rules for translating expressions . Show the translation of (09) assignment statement a=b+-c into three - address code sequence using the rules.
Page 2 of 3

CS612
8. a) Consider the following grammar (10)
T -> BC

B - int I float
C -+ [num]C I c
Associate semantic action for array reference with...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Compiler Design Essay
  • Compiler Essay
  • Basic Compiler Design Essay
  • Compiler Essay
  • HRM 595 Final Exam Essay
  • Accounting Final Exam Essay
  • MGT 330 Final EXAM Essay
  • ACC 544 Final Exam Essay

Become a StudyMode Member

Sign Up - It's Free