You are on page 1of 11

CSEITQUESTIONS.BLOGSPOT.

IN
[Year]

K.L.N. COLLEGE OF ENGINEERING


DEPARTMENT OF INFORMATION TECHNOLOGY

UNIT IV
SYNTAX DIRECTED DEFINTION & RUN TIME MEMORY
TWO MARK WITH ANSWERS

1. Define a syntax-directed translation?


A Syntax-directed definition is a generalization of a contextfree grammar in which each grammar symbol has an
associated set of attributes, partitioned into two subsets
called the synthesized and inherited attributes of that
grammar symbol.

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.

2.Define dependency graph?


A dependency graph can be constructed by drawing edges
connect dependent operations.
Edges in the dependency graph determine the evaluation
order for attribute values
Dependency graphs cannot be cyclic.
The interdependencies among the inherited and synthesized
attributes at the nodes in a parse tree can be depicted by a
directed graph is called a dependency graph. Example:
Production E E1 + E2 Semantic Rule E.val:= E1.va; + E2.val

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

3. Discuss about parameter transmission mechanisms?


call-by-value: In pass by value mechanism, the calling
procedure passes the r-value of
actual parameters and the
compiler puts that into the called procedures activation record.
call-by-reference: In pass by reference mechanism, the l-value
of the actual parameter is copied to the activation record of the
called procedure.
call-by-value-result(copy-restore): This parameter passing
mechanism works similar to pass-by-reference except that the
changes to actual parameters are made when the called procedure
ends.
call-by-name: In pass by name mechanism, the name of the
procedure being called is replaced by its actual body

4. Define symbol table.


Symbol table is an important data structure created and
maintained by compilers in order to store information about
the occurrence of various entities such as variable names,
function names, objects, classes, interfaces, etc. Symbol table
is used by both the analysis and the synthesis parts of a
compiler.
A symbol table is simply a table which can be either
linear or a hash table. It maintains an entry for each
name in the following format:
<symbol name, type, attribute>

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

5.Define back patching.


When generating the three address code for Boolean
expression and flow of control statements, we may not know
the lables that control must go to.
We can get around this by generating a series of branching
statement with the targets of the jumps temporarily left
unspecified.
Each statement will be put on a list of goto statements whose
labels will be filled in when the proper label can be
determined.
This subsequent filling in of labels is called backpatching.
6. Define Annotated parse tree?
A parse tree showing the values of attributes at each node is
called an annotated parse tree.
The process of computing the attribute values at the nodes
is called annotating of the parse tree.
Of course the order of these computations depends on the
dependency graph induced by the semantic rule.

7.Rules for Type checking?

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

Type checking can take on two forms:


Synthesis
Inference
Type synthesis:
Build up the type of an expression from the types of its
expression.
It requires names to be declared before they are used E1+E2
defined intrms of the types of E1 & E2.
Type Inference:
It determines the type of language construct from the way it
is used.
Appropriate formalism for type checking is logical rules of
inference.

8.Role of Type checker.


A type checker verifies that type of a construct matches that
expected by its context.
Type information gathered by a type checker may be needed
when code is generated.
Type checking:
It is the activity of ensuring that the operands of an
operator are of compatible types.
9.Define Type Expression.
A Type Expression denotes the type of a language construct.
A type expression is either a Basic Type or is built applying
Type Constructors to other types.
1. A Basic Type is a type expression (int, real, boolean, char).
The basic type void represents the empty set and allows
statements to be checked;
2. Type expressions can be associated with a name: Type
Names are type expressions;
3. A Type Constructor applied to type expressions is a type
expression.
Type constructors inlude:
(a) Array.

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

If T is a type expression, then array(I, T ) is a type


expression
denoting an array with elements of type T and index range in
Ie.g.,
array[1..10] of int == array(1..10,int);
(b)

Product.
If T1 e T2 are type expressions, then their Cartesian
Product
T1 T2 is a type expression;
(c) Record.
Similar to Product but with names for different fields
(used toaccess the components of a record). Example
of a C record type:
struct
{ double r;
int i;
}
(d) Pointer.
If T is a type expression, then pointer(T) is the type
expression pointer to an object of type T ;
(e)

Function.
If D is the domain and R the range of the function then
we
denote its type by the type expression: D : R.
The mod operator has type, int int : int. The Pascal
function:
function f(a, b: char): int
has type:
char char : int
10.Define Type System.
Type System: Collection of rules for assigning type
expressions to the
various part of a program.

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

Type Systems are specified using syntax directed definitions.


A type checker implements a type system.
Definition:
A language is strongly typed if its compiler can guarantee that
the program it accepts will execute without type errors.
11.Synthesized and Inherited attributes
Synthesized attributes
A Synthesized attributes for a
non terminal A at parse tree N
is defined.
A semantic rule associated with
the production N. Note that the
production must have A as its
head
A synthesized attribute at a
node N is defined only interms
of attribute values at the
children of N and at N itself.

Inherited attributes
An inherited attribute for
nonterminal B at a parse tree node
N is defined
A semantic rule associated with
the production at the parent of N.
Note that the production must
have B as symbol in its body.
An Inherited attribute at node N is
defined only interms of attribute
values at
N parent,
Nitself,
N siblings

12. S attribute definition.


If an SDT uses only synthesized attributes, it is called Sattribute SDT.
Thes attributes are evaluated using S-attributed SDTs that
have their semantic actions written after the production (right
hand side)
As depicted above, attributes in S-attributed SDTs are
evaluated in bottom up parsing, as the values of the parent
nodes depend upon the values of the child nodes.

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

13.L-attributed SDT.
This form od SDT uses both synthesized and inherited
attributes with restriction of not taking values from right
siblings.
In L-attributed SDTs a non terminal can get values from its
parent,child, and siblings.
EX:S ABC
S can take values from A,B,C
A can take values from S only
B can take values from S & A
C can take values from S,A,B
No non terminal can get values rom siblings to its right.
Attributes in L attributed SDTs are evaluated by depth first
and left to right parsing manner.

14.Syntax Directed Defintion and Translation Scheme


When we associate semantic rules with productions, we use
two notations
Syntax Directed Definition

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

Translation Scheme
Syntax Directed Definition:
Give high level specification for translation.
Hide many implementation details such as order of
evalution of semantic actions.
We associates a production rules with a set of semantic
actions and we do not say when they will be evaluated.
Translation scheme:
Indicate the order of evalution of semantic actions
associated with a production rule.
In other words, translation schemes give a little bit
information about implementation details.
15.Generalize the limitations of the static memory allocation?
size of data objects,as well as any constraints on their
positions in memory, must be available at compile time.
No recursion because all activations of a given procedure use
the same bindings for local names.
No dynamic data structures since no mechanism is provided
for runtime storage allocation.
If we declare more static data space than we need waste
space.
16.The Strategies of storage allocation.
The various storage allocation strategies to allocate storage in
different data areas of memorys are:
Static allocation:
Storage is allocated for all data objects it compile time.
Stack allocation:
The storage is managed as a stack
Heap allocation:(It is one of Dynamic storage allocation)

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

The storage is allocated and deallocated at runtime from a


data area know as heap.

17.Difference between stack and heap.

18.Static vs Dynamic memory allocation.

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

20.Activation tree.
The activation tree depends on runtime behaviour.
The activation tree may be different for every program
output.
Since activation tree probably nested a stack can track
currently activate procedures.
We can use a tree to show way control enters and leave
activations.
Each node represents an activation of a procedure.
The root represents the activations of the main program.
The node is a parent of the node b if the control flow a to b.

21.Activation record.
Whenever a procedure is executed, its activation record is
stored on the stack, also known as control stack.
When a procedure calls another procedure, the execution
of the caller is suspended until the called procedure
finishes execution.

At this time, the activation record of the called procedure


is stored on the stack.

CSEITQUESTIONS.BLOGSPOT.IN
[Year]

22.Static allocation in fortran 77.

You might also like