M S RAMAIAH INSTITUTE OF TECHNOLOGY
(AUTONOMOUS INSTITUTE, AFFILIATED TO VTU)
BANGALORE - 560 054
SEMESTER END EXAMINATIONS - MAY / JUNE 2012
Course & Branch
B E - Com ut Science E
& n gineering
e rne s e r
Compiler Design Max. Marks : 100
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
B -^Bb ^Abd
UNIT - II
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
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)
Page 1 of 3
Define handle pruning. Consider the following grammar.
S ---> aABe
A -> Abe I b
Show the configurations of a shift reduce parser on input 'abbcde, b)
Show that the following grammar
S -> AaAb l BbBa
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
Find the LR(1) set of items. Also explain about the working of LR(1) parser. How it is advantageous compared to SLR parser?
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.
L ---> En
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.
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
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...
Please join StudyMode to read the full document