0% found this document useful (0 votes)
76 views8 pages

Unit Iv - Syntax Directed Translation & Run Time Environment

The document discusses topics related to compiler design including storage allocation strategies, symbol tables, activation records, static and dynamic scoping, code generation, optimization, and intermediate representations. Key points covered include the different storage allocation approaches, contents of activation records, defining dynamic scoping, symbol tables storing name binding information, code motion optimization, and constructing syntax trees and DAG representations for code blocks.

Uploaded by

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

Unit Iv - Syntax Directed Translation & Run Time Environment

The document discusses topics related to compiler design including storage allocation strategies, symbol tables, activation records, static and dynamic scoping, code generation, optimization, and intermediate representations. Key points covered include the different storage allocation approaches, contents of activation records, defining dynamic scoping, symbol tables storing name binding information, code motion optimization, and constructing syntax trees and DAG representations for code blocks.

Uploaded by

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

CS6660-Compiler Design

QBANK-UNIT IV & V

1. List the different storage allocation strategies.


2. What is symbol table? Draw the structure of symbol table.
3. Define activation record and list out the fields in it.
4. What are the source language issues?
5. Define environment and state.
6. What are the applications of DAG?
7. What is dynamic scoping?
8. Define address descriptor and register descriptor.
9. What is data flow and control flow analysis?
10. Compare static and dynamic storage allocation.
11. What are the techniques for optimizing basic blocks?
12. Define points and path

1. Explain storage organization and various storage allocation strategies.


2. i. Explain in detail about specification of simple type checker
ii. Explain parameter passing in detail
3. i. Explain the principle sources of code optimization in detail
ii. What is DAG? Describe the DAG representation algorithm and its applications.
Construct the DAG for the following Basic Block
d:=b*c
e:=a+b
b:=b*c
a:=e-d
4. i. Design the simple code Generator Algorithm with an example.
ii. Explain in detail about various issues in design of code generator.

UNIT IV - SYNTAX DIRECTED TRANSLATION & RUN TIME


ENVIRONMENT
1. List the different storage allocation strategies.
The strategies are:
Static allocation
Stack allocation
Heap allocation

• What are the contents of activation record?


The activation record is a block of memory used for managing the information needed by a
single execution of a procedure. Various fields f activation record are:
Temporary variables
Local variables
Saved machine registers
Control link
Access link
Actual parameters
Return values

3. What is dynamic scoping?


In dynamic scoping a use of non-local variable refers to the non-local data declared in most
recently called and still active procedure. Therefore each time new findings are set up for
local names called procedure. In dynamic scoping symbol tables can be required at run
time.

4. Define symbol table.


Symbol table is a data structure used by the compiler to keep track of semantics of the
variables. It stores information about scope and binding information about names.

5. What is code motion?


Code motion is an optimization technique in which amount of code in a loop is
decreased. This transformation is applicable to the expression that yields the same
result independent of the number of times the loop is executed. Such an expression is
placed before the loop.

6. What are the properties of optimizing compiler?


The source code should be such that it should produce minimum amount of target
code.
There should not be any unreachable code.
Dead code should be completely removed from source language.
The optimizing compilers should apply following code improving transformations on
source language.
• common subexpression elimination
• dead code elimination
• code movement
• strength reduction

7. What are the various ways to pass a parameter in a function?


Call by value
Call by reference
Copy-restore
Call by name

8. Suggest a suitable approach for computing hash function.


Using hash function we should obtain exact locations of name in symbol table. The hash function
should result in uniform distribution of names in symbol table.
The hash function should be such that there will be minimum number of collisions. Collision
is such a situation where hash function results in same location for storing the names.

• What are the functions used to create the nodes of syntax trees?
• Mknode (op, left, right)
• Mkleaf (id,entry)
• Mkleaf (num, val)
• What are the functions for constructing syntax trees for expressions?
• The construction of a syntax tree for an expression is similar to the translation of
the expression into postfix form.
• Each node in a syntax tree can be implemented as a record with several fields.

• Give short note about call-by-name?


Call by name, at every reference to a formal parameter in a procedure body the
name of the corresponding actual parameter is evaluated. Access is then made to the
effective parameter.

• How parameters are passed to procedures in call-by-value method?


This mechanism transmits values of the parameters of call to the called program. The
transfer is one way only and therefore the only way to returned can be the value of a
function.

Main ( )
{ print (5); }
Int
Void print (int n)
{ printf (“%d”, n); }

14. Define static allocations and stack allocations


Static allocation is defined as lays out for all data objects at compile time.
Names are bound to storage as a program is compiled, so there is no need for a run time support
package.
Stack allocation is defined as process in which manages the run time as a Stack. It is based on
the idea of a control stack; storage is organized as a stack, and activation records are pushed
and popped as activations begin and end.
17. Define a syntax-directed translation?
Syntax-directed translation specifies the translation of a construct in terms of Attributes
associated with its syntactic components. Syntax-directed translation uses a context free
grammar to specify the syntactic structure of the input. It is an input- output mapping.

18. Define an attribute. Give the types of an attribute?


An attribute may represent any quantity, with each grammar symbol, it associates a set of
attributes and with each production, a set of semantic rules for computing values of the
attributes associated with the symbols appearing in that production.
Example: a type, a value, a memory location etc.,
• Synthesized attributes.
• Inherited attributes.

19. Give the 2 attributes of syntax directed translation into 3-addr code?
i) E.place, the name that will hold the value of E and
• E.code , the sequence of 3-addr statements evaluating E.

• Write the grammar for flow-of-control statements?


The following grammar generates the flow-of-control statements, if-then, if- then-else,
and while-do statements.
S -> if E then S1| If E then S1 else S2| While E do S1.

UNIT V CODE OPTIMISATION AND CODE GENERATION

1. Define code generations with ex?


It is the final phase in compiler model and it takes as an input an
intermediate representation of the source program and output produces as equivalent
target
programs. Then intermediate instructions are each translated
into a sequence of machine instructions that perform the same task.

2. What are the issues in the design of code generator?


Input to the generator
Target programs
Memory management
Instruction selection
Register allocation
Choice of evaluation order
Approaches to code generation.

3. Give the variety of forms in target program.


Absolute machine language.
Relocatable machine language.
Assembly language.

4. Give the factors of instruction selections.


Uniformity and completeness of the instruction sets
Instruction speed and machine idioms
Size of the instruction sets.

5. What are the sub problems in register allocation strategies?


During register allocation, we select the set of variables that will reside in register at a
point in the program.
During a subsequent register assignment phase, we pick the specific register that a
variable reside in.

8. Write the addressing mode and associated costs in the target machine.

MODE FORM ADDRESS ADDED COST

Absolute M M 1

Register R R 0

Indexed c(R) c+contents(R) 1

Indirect register *R contents(R) 0

Indirect indexed *c(R) contents(c+contents(R)) 1

9. Define basic block and flow graph.

A basic block is a sequence of consecutive statements in which flow of Control enters at the
beginning and leaves at the end without halt or possibility Of branching except at the end.

A flow graph is defined as the adding of flow of control information to the Set of basic blocks
making up a program by constructing a directed graph.

10. Write the step to partition a sequence of 3 address statements into basic blocks.
1. First determine the set of leaders, the first statement of basic blocks.
The rules we can use are the following. The first statement is a leader.
Any statement that is the target of a conditional or unconditional goto is a leader. Any statement
that immediately follows a goto or conditional goto statement is a leader.
2. For each leader, its basic blocks consists of the leader and all statements
Up to but not including the next leader or the end of the program.

11. Give the important classes of local transformations on basic blocks


Structurepreservationtransformations
Algebraic transformations.

12. Describe algebraic transformations.


It can be used to change the set of expressions computed by a basic blocks into A
algebraically equivalent sets. The useful ones are those that simplify the
Expressions place expensive operations by cheaper
ones. X = X+ 0
X=X*1
13. What is meant by register descriptors and address descriptors?
A register descriptor keeps track of what is currently in each register. It is
Consulted whenever a new register is needed.An address descriptor keeps track of the
location where ever the current Value of the name can be found at run time. The location
might be a register, a Stack location, a memory address,

14. What are the actions to perform the code generation algorithms?
Invoke a function get reg to determine the location L. Consult the address descriptor for y to
determine y‟, the current location of y.If the current values of y and/or z have no next uses,
are not live on exit from the block, and are in register, alter the register descriptor.

15. Write the code sequence for the d:=(a-b)+(a-c)+(a-c).

Statement Code generation Register descriptor Address

descriptor

t:=a-b MOV a,R0 R0 contains t t in R0


SUB b,R0

u:=a-c MOV a,R1 R0 contains t t in R0


SUB c,R1 R1 contains u u in R1
v:=t+u ADD R1,R0 R0 contains v u in R1
R1 contains u v in R0

d:=v+u ADD R1,R0 R0 contains d d in R0


MOV R0,d d in R0 and
memory

16. Write the labels on nodes in DAG.

A DAG for a basic block is a directed acyclic graph with the following Labels on nodes:
Leaves are labeled by unique identifiers, either variable names or constants. Interior nodes
are labeled by an operator symbol.
Nodes are also optionally given a sequence of identifiers for labels.

17. Give the applications of DAG.

Automatically detect the common sub expressions


Determine which identifiers have their values used in the block.
Determine which statements compute values that could be used outside the blocks.

18. Define Peephole optimization.


A Statement by statement code generation strategy often produces target code that
contains redundant instructions and suboptimal constructs. “Optimizing” is misleading
because there is no guarantee that the resulting code is optimal. It is a method for trying to
improve the performance of the target program by examining the short sequence of target
instructions and replacing this instructions by shorter or faster sequence.

20. What are the structure preserving transformations on basic blocks?


Common sub-expression elimination
Dead-code elimination
Renaming of temporary variables
Interchange of two independent adjacent statement

21. Define Common sub-expression elimination with ex.


It is defined as the process in which eliminate the statements which has
the Same expressions. Hence this basic block may be transformed into the
equivalent Block.
Ex:
a : =b + c
b :=a - d
c :=b + c
After elimination:
a : =b + c
b :=a - d
c:=a

22. Define Dead-code elimination with ex.


It is defined as the process in which the statement x=y+z appear in a basic block, where x is
a dead that is never subsequently used. Then this statement maybe safely removed without
changing the value of basic blocks.

23. Define Renaming of temporary variables with ex.


We have the statement u:=b + c ,where u is a new temporary variable, and change all uses
of this instance of t to u, then the value of the basic block is not changed.

24. Define reduction in strength with ex.


Reduction in strength replaces expensive operations by equivalent cheaper ones on
the target machines. Certain machine instructions are cheaper than others and can often be
used as special cases of more expensive operators. Ex:
X^2 is invariably cheaper to implement as x*x than as a call to an exponentiation
routine.

25. Define use of machine idioms.


The target machine may have harder instructions to implement certain specific
operations efficiently. Detecting situations that permit the use of these instructions can
reduce execution time significantly.

26. Define code optimization and optimizing compiler


The term code-optimization refers to techniques a compiler can employ in an attempt to
produce a better object language program than the most obvious for a given source
program. Compilers that apply code-improving transformations are called Optimizing-
compilers.

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