0% found this document useful (0 votes)
46 views13 pages

CSE - III Year - I SEM - R19 - Compiler Design

The document contains questions and answers related to compiler design. 1) It explains the various phases of a compiler with a diagram showing lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, symbol table management, and error handling. 2) It discusses bootstrapping and how a self-hosting compiler can compile its own source code. It also explains input buffering and how the lexical analyzer uses pointers to scan input characters. 3) It constructs the predictive parsing table for a sample grammar and determines that it is not an LL(1) grammar because two productions occupy the same field.

Uploaded by

SIETK CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views13 pages

CSE - III Year - I SEM - R19 - Compiler Design

The document contains questions and answers related to compiler design. 1) It explains the various phases of a compiler with a diagram showing lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, symbol table management, and error handling. 2) It discusses bootstrapping and how a self-hosting compiler can compile its own source code. It also explains input buffering and how the lexical analyzer uses pointers to scan input characters. 3) It constructs the predictive parsing table for a sample grammar and determines that it is not an LL(1) grammar because two productions occupy the same field.

Uploaded by

SIETK CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Q.P.

Code: 19CS0515 R19

Reg. No:
SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY:: PUTTUR
(AUTONOMOUS)
BTECH III Year I Semester Regular Examinations December 2021
COMPILER DESIGN
(COMMON TO CSE & CSIT)

Time: 3 hours Max. Marks: 60


(Answer all Five Units 5 x 12 = 60 Marks)
UNIT-I
1. Explain the phases of a compiler with neat diagram? L2 12M
The various phases of a compile r are:
1. Lexical Analysis
2. Syntax Analysis
3. Semantic Analysis
4. Intermediate code generation
5. Code Optimization
6. Code Generation
7. Symbol table manager
8. Error handler

OR

Page 1 of 13
Q.P. Code: 19CS0515 R19
2. a) Explain Bootstrapping. L2 6M

BOOTSTRAPPING:

 Bootstrapping is widely used in the compilation development.


 Bootstrapping is used to produce a self- hosting compiler. Self-hosting compiler is a type
of compiler that can compile its own source code.
 Bootstrap compiler is used to compile the compiler and then you can use this compiled
compiler to compile everything else as well as future versions of itself.

A compiler can be characterized by three languages:

1. Source Language
2. Target Language
3. Implementation Language

The T- diagram shows a compiler SCIT for Source S, Target T, implemented in I.

2. b) Write about Input Buffering. L3 6M


Input Buffering
The process of storing inputs in a buffer. The data or program written is stored in input
buffer is called “Input Buffering”. The lexical analyzer scans the input from left to right one
character at a time. It uses two pointers begin ptr(bp) and forward to keep track of the pointer of the
input scanned.

Page 2 of 13
Q.P. Code: 19CS0515 R19

3. Consider the grammar L6 12M


SAB|Abad
Ad
E b
Db| ε
Bc
Construct the predictive parse table and check whether the given grammar is LL(1) or not.

The above grammar does not contain left recursion, so directly we can find the first and follow
of the given grammar.

Here Non Terminals: { S, A , B , D, E}


Terminals: { a, b, c, d}

Step 1: Now Calculate First() and Follow() for the 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) = {Ǿ}

Step2: Construct LL(1) Table:

Non Terminals
Terminals a b c d $
S->AB
S SABad

A Ad

B Bc

D Db

E E b

Here S->AB ,SAbad 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α

 Top down parsing methods cant handle left-recursive grammars

 A simple rule for direct left recursion elimination:

 For a rule like:

A -> A α|β

 We may replace it with

A ->β A’

A’ ->α A’| ɛ

 The given Grammar is having the form of Left Recursion i.eAAα. So eliminate the left
recursion from the grammar by replacing the production with,
AβA1
A1 α A1 /Ɛ

4. b) Eliminate left recursion for the following grammar. L3 6M

EE+T/T
TT*F/F
F(E)/id

After Eliminating the left recursion, grammar will be like,


ETE1
E1 +TE1 /Ɛ
TFT1
T1 *FT1 /Ɛ
F(E)/id
UNIT-III

5. a) Define Handle pruning? L3 4M

A Handle is a substring that matches the body of a production. Handle reduction is a step in the

reverse of rightmost derivation. A rightmost derivation in reverse can be obtained by handle

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

derivation. A rightmost derivation in reverse can be obtained by handle pruning.

Page 4 of 13
Q.P. Code: 19CS0515 R19
• Left to right bottom- up parsing constructs a rightmost derivation in reverse

• Handle = substring that matches the body of a production

• Handle reduction = a step in the reverse of rightmost derivation

Handles During a Parse id1 *id2

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.

Various steps involved in the SLR (1) Parsing:

 For the given input string write a context free grammar


 Check the ambiguity of the grammar
 Add Augment production in the given grammar
 Create Canonical collection of LR (0) items
 Draw a data flow diagram (DFA)
 Construct a SLR (1) parsing table

Page 5 of 13
Q.P. Code: 19CS0515 R19
UNIT-III

6. a) Explain syntax directed definition with simple examples? L2 6M

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

6. b) Describe in detail the Translation scheme of SDD. L2 6M

 The Syntax directed translation scheme is a context - free grammar.


 The syntax directed translation scheme is used to evaluate the order of semantic rules.
 In translation scheme, the semantic rules are embedded within the right side of the
productions.
 The position at which an action is to be executed is shown by enclosed between braces. It is
written within the right side of the production.

Example

Production Semantic Rules

S→E$ { printE.VAL }

E→E+E {E.VAL := E.VAL + E.VAL }

E→E*E {E.VAL := E.VAL * E.VAL }

E → (E) {E.VAL := E.VAL }

E→I {E.VAL := I.VAL }

I → I digit {I.VAL := 10 * I.VAL + LEXVAL }

I → digit { I.VAL:= LEXVAL}

Parse Tree for SDT

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

Operation op1 op2 Result


1 + x y t1
2 + y z t2
3 * t1 t2 t3
4 + t1 z t4
5 + t3 t4 t5
Triple

Operation op1 op2


1 + x y
2 + y z
3 * (1) (2)
4 + (1) z
5 + (3) (4)
Indirect Triple

Operation op1 op2


1 + x y
2 + y z
3 * (1) (2)
4 + (1) z
5 + (3) (4)

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

10. b) Classify Register allocation and register assignme nt. L3 6M

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

1. Global register allocation


2. Usage count
3. Register assignment for outer loop
4. Register allocation by graph coloring

Page 13 of 13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy