CSE - III Year - I SEM - R19 - Compiler Design
CSE - III Year - I SEM - R19 - Compiler Design
Reg. No:
SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY:: PUTTUR
(AUTONOMOUS)
BTECH III Year I Semester Regular Examinations December 2021
COMPILER DESIGN
(COMMON TO CSE & CSIT)
OR
Page 1 of 13
Q.P. Code: 19CS0515 R19
2. a) Explain Bootstrapping. L2 6M
BOOTSTRAPPING:
1. Source Language
2. Target Language
3. Implementation Language
Page 2 of 13
Q.P. Code: 19CS0515 R19
The above grammar does not contain left recursion, so directly we can find the first and follow
of the given grammar.
First():-
First(S) = First(A) ={ d }
First(A)={d}
First (B) = {c }
First(D) = {b,Ɛ}
First (E) = {b}
Follow():
Follow(S) = { $}
Follow(A) = First(B) = { c}
Follow(B) = First (a) ={a} Ʋ Follow(S) = { $} = {a, $ }
Follow(D) = {Ǿ}
Follow(E) = {Ǿ}
Non Terminals
Terminals a b c d $
S->AB
S SABad
A Ad
B Bc
D Db
E E b
Here S->AB ,SAbad two productions occupies the same field . We can declared that the given
production is not LL(1).
OR
Page 3 of 13
Q.P. Code: 19CS0515 R19
4. a) Describe the procedure of eliminating Left recursion. L1 6M
A grammar is left recursive if it has a non-terminal A such that there is a derivation A=> Aα
A -> A α|β
A ->β A’
A’ ->α A’| ɛ
The given Grammar is having the form of Left Recursion i.eAAα. So eliminate the left
recursion from the grammar by replacing the production with,
AβA1
A1 α A1 /Ɛ
EE+T/T
TT*F/F
F(E)/id
A Handle is a substring that matches the body of a production. Handle reduction is a step in the
pruning.
Handle Pruning is the general approach used in shift-and-reduce parsing. A Handle is a substring
that matches the body of a production. Handle reduction is a step in the reverse of rightmost
Page 4 of 13
Q.P. Code: 19CS0515 R19
• Left to right bottom- up parsing constructs a rightmost derivation in reverse
E->T , T is not a handle in T*id2. If we replace T by E ◦ we get E*id2 which cannot be derived
from E leftmost substring that matches production body need not to be a handle
5. b) Summarize about SLR parsing? L3 8M
SLR (1) refers to simple LR Parsing. It is same as LR(0) parsing. The only difference is
in the parsing table. To construct SLR (1) parsing table, we use canonical collection of LR (0)
item.
In the SLR (1) parsing, we place the reduce move only in the follow of left hand side.
Page 5 of 13
Q.P. Code: 19CS0515 R19
UNIT-III
Types of Attributes:
1. Synthesised attributes
2. Inherited attributes
Page 6 of 13
Q.P. Code: 19CS0515 R19
Page 7 of 13
Q.P. Code: 19CS0515 R19
Example
S→E$ { printE.VAL }
Page 8 of 13
Q.P. Code: 19CS0515 R19
UNIT-IV
7. Explain Representation of Three Address Codes with suitable Examples L2 12M
Page 9 of 13
Q.P. Code: 19CS0515 R19
Page 10 of 13
Q.P. Code: 19CS0515 R19
8. Produce quadruple, triples and indirect triples for:(x + y) * (y+z)+(x+y+z) L6 12M
t1 = x + y
t2 = y + z
t3 = t1 * t2
t4= t1 + z
t5 = t3 + t4
Quadruples
1.(1)
2.(2)
3.(3)
4.(4)
5.(5)
Page 11 of 13
Q.P. Code: 19CS0515 R19
UNIT-V
9. Write about all issues in code gene ration. Describe it. L3 12M
Code generator converts the intermediate representation of source code into a form that
can be readily executed by the machine. A code generator is expected to generate the correct code.
Designing of code generator should be done in such a way so that it can be easily implemented,
tested and maintained.
The following issue arises during the code generation phase:
Input to code generator
Target program
Mem ory Management
Instruction selection
Register allocation issues
Evaluation order
Approaches to code generation issues
10. a) Write short notes on Simple code generator. L3 6M
Page 12 of 13
Q.P. Code: 19CS0515 R19
1.Register allocation, during which we select the set of variable that will reside in register at
each point in the program.
2.Register Assignment, during which we pick the specific register that a variable will reside in.
Various strategies used in register allocation and segment and those are
Page 13 of 13