CSE (2)
CSE (2)
- 1 0
Total Number of Pages : 04
0 2 5- BTech/IDD(B.Tech and M.Tech
RCS6C002
5/ 2
/ 0
6th Semester Back Examination: 2024-25
6
-0 COMPILER DESIGN
215
CSE, CSEAIML, CSEDS, CST
Time : 3 Hour
Max Marks : 100
- 1 0
Q.Code : S072
Answer Question No.1 (Part-1) which is compulsory, any eight from Part-II and any two
25 -
from Part-III.
2 0
The figures in the right hand margin indicate marks.
/
6 / 05 Part-I
Q1
- 0
Answer the following questions : (2 x 10)
a)
15 the role of a parser in syntax analysis phase.
Define
2Find - 1 0
the regular expression for the language L = {All strings-of 0’s and 1’s whose
b)
2 5 is at least 4}.
first symbol is 0 and last symbol is 1 and length of the0string
c) State the work of linker and loader in language 5 / 2
6 / 0 processing system.
d) Generate the string w = abaaba from-the
5 0 given grammar by applying leftmost
derivation. 21
A → aBA | ϵ
B → AbB | AA - -
| ba
10
2 5
0 used for parsing is left recursive.
/ 2
e) State the problems will arise if a grammar
5the grammar:
/ 0
Eliminate left recursion from
6S → S * S | T
5 - 0
1
2 0 T → ( S ) | id - 1 0
f) Justify why 1 2 5 -
5 - - the below grammar is not LL(1) grammar? /20
2 0 2 S → abSa | aaAb
/ 0 5
0 5/ A → baAb | bb
- 0 6
0 6 / g) Distinguish between SDD and SDT. 15
5- 2
21 h)
i)
List out possible lexical and syntax errors while compiling a program
Demonstrate the properties of code generation phase.
j) Suggest some examples of compiler.
Part-II
Q2
- 1 0
Only Focused-Short Answer Type Questions- (Answer Any Eight out of (6 × 8)
a)
Twelve)
2 5-
Give the LL(1) parsing table for the below mentioned grammar find the FIRST &
0
FOLLOW
5/ 2
E -> TE'
6 / 0
-0
E' -> +TE' | ε
215
T -> FT'
T' -> *FT' | ε
F -> id | (E)
b)
1 0
What is Peephole optimization? Explain with suitable example.
-
c)
25 -
Consider the following grammar and check if the grammar is suitable for SLR
S → AS | b
parser.
/ 2 0
A → SA | a
d)
/ 05
Consider the following grammar, Remove common prefix if any or do left factoring
6
5- 0
in the following grammars.
1.A → aAB | aBc | aAc
- 1 0
Draw the annotated parse tree of the following SDT for the input string : 4 * 6 + 3 *
f)
7 and evaluate it.
2 5-
What is Bottom up Parsing? Show the handle of each right sentential form. S → C
0
+ E + C C → d/ad/b C → id
5/ 2
g)
/ 0
Discuss the rules to create Directed Acyclic Graph (DAG). Consider the following
6
-0
block of TAC, construct a DAG for it and find out the common expressions
5
eliminated by DAG.
1 0
20 - 1
(1) a = b * c
2 5-
2 5 --1 (2) d = b
/ 20
0 (3) e = d * c
05
0 5/2 (4) b = e
- 0 6/
6 / 5
21
(5) f = b * c
5 -0 (6) g = f + d
21 h) Illustrate canonical collection of LR(1) items for the following grammar.
S→AA
A→aA | b
i) Discuss different loop optimization techniques with suitable examples of each type.
j) Construct the nondeterministic finite automata for the regular expression:
q ( p | q )* p. Convert this NFA to DFA.
- 1 0
k)
common expressions eliminated by DAG.
0 2 5-
Consider the following block of TAC, construct a DAG for it and find out the
2
(1) a = b5*/c
6 / 0
5 - 0(2) d = b
21 (3) e = d * c
(4) b = e
- 1 0
(5) f = b * c
25 -
2 0(6) g = f + d
/ of using intermediate code for the source code. For the
0 5
l) List out the benefits
/ * (c+d) –(a+b+c) find its representation in quadruple, triple form
expression6(a+b)
5 - 0
1
2Only Long Answer Type Questions Part-III - 1 0
(Answer Any Two 5
2 - of Four)
out
- 1
- S→(A)|a 20 2
5
A →2A , S | S
0 syntax directed translation (SDT). For the following /
5 SDT, what is the
Q5 a) /2 Discuss / 0
6input a + b * c. (8)
/ 0 5 output generated if SDT is carried out with the
5 - 0
given
0 6 2 1
5-
Rule Semantic Action
21 E → E + T { printf(“ + “); }
E→T { }
T→T*F { printf(“ * “); }
T→F { }
F→ id { printf( id.val); }.
b)
- 1 0
Write down the roles of a symbol table and error handler in compilation process. (8)
handler
0 2 5-
Briefly explain the lexical, syntactic and semantic errors that are handled by error
5 2
/ in compilation? Discuss the different code
optimization techniques 6/
0
Q6 a) What is the necessity of optimization (8)
5
b) Discuss the techniques- 0used for error handling in YAAC compiler. Or, Write a (8)
2 1 code to recognize identifier, number, relational operators and
sample lex pseudo
whitespaces.
- - 10
0 2 5
5 / 2
6 / 0
5 - 0
21 - 1 0
2 5-
/ 20
/ 05
- 0 6
2 1 5
- 1 0
2 5 -
/ 2 0
/ 0 5
- 0 6
20 1 5 1 0
5 - -
- - 1 2 0 2
0 2 5 5 /
/ 2 6/ 0
0 5 - 0
5 -06/ 2 1 5
21