0% found this document useful (0 votes)
28 views4 pages

Unit Iii Syntax Directed Translation &intermediate Code Generation

The document discusses Syntax Directed Translation (SDT) and Intermediate Code Generation, explaining concepts such as synthesized and inherited attributes, intermediate representations like syntax trees and three-address code, and various methods for implementing three-address statements. It also covers Boolean expressions, viable prefixes, and calling sequences, along with detailed explanations of specific topics in Part B, including type conversion and translation of array references. The content is aimed at students of engineering, particularly in the context of programming languages and compiler design.

Uploaded by

sample260405
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)
28 views4 pages

Unit Iii Syntax Directed Translation &intermediate Code Generation

The document discusses Syntax Directed Translation (SDT) and Intermediate Code Generation, explaining concepts such as synthesized and inherited attributes, intermediate representations like syntax trees and three-address code, and various methods for implementing three-address statements. It also covers Boolean expressions, viable prefixes, and calling sequences, along with detailed explanations of specific topics in Part B, including type conversion and translation of array references. The content is aimed at students of engineering, particularly in the context of programming languages and compiler design.

Uploaded by

sample260405
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

[Link].

in
4931_GRACE College of Engineering, Thoothukudi

UNIT III
SYNTAX DIRECTED TRANSLATION
&INTERMEDIATE CODE GENERATION
[Link] is syntax directed translation?
A syntax directed definition specifies the values of attributes by associating semantic rules with
the grammar productions
Production E->E1+T
Semantic Rule [Link]=[Link]||[Link]||’+’
2. What is synthesized attributes?
A synthesized attribute at node N is defined only in terms of attribute values of children
of N and at N
3. What is inherited attributes ?
An inherited attribute at node N is defined only in terms of attribute values at N’s parent, N itself
and N’s siblings
4. List the three kinds of intermediate representation.
The three kinds of intermediate representations are
i. Syntax trees
ii. Postfix notation
iii. Three address code
5. What is postfix notation?
A Postfix notation is a linearized representation of a syntax tree. It is a list
ofnodes of the tree in which a node appears immediately after its children.
6. What is the usage of syntax directed definition.
Syntax trees for assignment statement are produced by the syntax
directeddefinition.
7. Why “Three address code” is named so?
The reason for the term “Three address code” is that each usually
containsthree addresses, two for operands and one for the result.

8. Define three-address code.


Three-address code is a sequence of statements of the general
formx := y op z
where x, y and z are names, constants, or compiler-generated temporaries; op stands
for any operator, such as fixed or floating-point arithmetic operator, or a logical
operator on boolean-valued data.
Three-address code is a linearized representation of a syntax tree or a dag in which
explicit names correspond to the interior nodes of the graph.

9. State quadruple
A quadruple is a record structure with four fields, which we call op, arg1,
arg2and result.

CS3501_CD

[Link] 2
[Link]
4931_GRACE College of Engineering, Thoothukudi

10. What is called an abstract or syntax tree?


A tree in which each leaf represents an operand and each interior node an
operator is called as abstract or syntax tree.
11. What are the functions used to create the nodes of syntax trees?
Mknode (op, left, right) Mkleaf (id,entry)
Mkleaf (num, val)

12. What are the advantages of generating an intermediate representation?


Ease of conversion from the source program to the intermediate [Link] with which
subsequent processing can be performed from the intermediate code.
13. 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 an attribute values at the nodes is called annotating parse
tree.
14. What are triples?
The fields arg1,and arg2 for the arguments of op, are either pointers to
the symbol table or pointers into the triple structure then the three fields used
in the intermediate code format are called triples.
In other words the intermediate code format is known as triples.
15. Write a short note on declarations?
Declarations in a procedure, for each local name, we create a symbol table entry with
information like the type and the relative address of the storage for the name. The relative
address consists of an offset from the base of the static data area or the field for local data
in an activation record. The procedure enter (name, type, offset) create a symbol table
entry.
16. List the types of three address statements.
The types of three address statements are
a. Assignment statements
b. Assignment Instructions
c. Copy statements
d. Unconditional Jumps
e. Conditional jumps
f. Indexed assignments
g. Address and pointer assignments
h. Procedure calls and return

17. What are the various methods of implementing three-address statements?


a. Quadruples
b. Triples
c. Indirect triples

18. What is S-Attributed Syntax Directed Translation(SDT)?


If an SDT uses only synthesized attributes, it is called as S-attributed SDT. S-attributed
SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon
the values of the child nodes.
19. What is L-Attributed Syntax Directed Translation(SDT)?
If an SDT uses either synthesized attributes or inherited attributes with a restriction that it
can inherit values from left siblings only, it is called as L-attributed SDT. Attributes in L-
attributed SDTs are evaluated by depth- first and left-to-right parsing manner.

20. Define Boolean Expression.


CS3501_CD

[Link] 3
[Link]
4931_GRACE College of Engineering, Thoothukudi

Expressions which are composed of the Boolean operators (and, or, and not) applied to
elements that are Boolean variables or relational expressions are known as Boolean
expressions

21. What are the two methods to represent the value of a Boolean expression?
a. The first method is to encode true and false numerically and to evaluate
aBoolean expression analogously to an arithmetic expression.
b. The second principal method of implementing Boolean expression is by flow
of control that is representing the value of a Boolean expression by a position
reached in a program.

22. What do you mean by viable prefixes.


Viable prefixes are the set of prefixes of right sentinels forms that can appear on the stack
of shift/reduce parser are called viable prefixes. It is always possible to add terminal
symbols to the end of the viable prefix to obtain a right sentential form.

23. What is meant by Shot-Circuit or jumping code?


We can also translate a Boolean expression into three-address code without generating
code for any of the Boolean operators and without having the code necessarily evaluate the
entire expression. This style of evaluation is sometimes called “short-circuit” or “jumping”
code.

24. What is known as calling sequence?


A sequence of actions taken on entry to and exit from each procedure is known
ascalling sequence.
25. 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., i) Synthesized attributes.
ii) Inherited attributes.

CS3501_CD

[Link] 4
[Link]
4931_GRACE College of Engineering, Thoothukudi

PART B
1. Discuss the following in detail about the Syntax Directed Definitions.
(i)Inherited Atrributes and Synthesized attributes.
(ii) Evaluate SDD of a parse tree.
2. Explain the steps for constructing a DAG. Construct the DAG for the following expression
((x+y)-((x+y)*(x-y)))+((x+y)*(x-y))
3. What is Type conversion? What are the two types of type conversion? Evaluate the rules for
the type conversion.
4. Generate an intermediate code for the following code segment with the required syntax-
directed translation scheme.
if ( a > b)
x = a + b else
x=a-b
5. Create the following for the arithmetic expression a+- (b+c)* into
(i)Syntax tree (ii)Quadruples (iii)Triples (iv)Indirect Triples
6. Describe in detail about addressing array Elements.
7. Discuss in detail about Translation of array reference.
8. Describe in detail about types and declaration with suitable example
9. Discuss in detail about
(i)Dependency graph (ii)Ordering Evaluation of Attributes

CS3501_CD

[Link] 5

You might also like