Unit Iv - Syntax Directed Translation & Run Time Environment
Unit Iv - Syntax Directed Translation & Run Time Environment
QBANK-UNIT IV & V
• 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.
Main ( )
{ print (5); }
Int
Void print (int n)
{ printf (“%d”, n); }
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.
8. Write the addressing mode and associated costs in the target machine.
Absolute M M 1
Register R R 0
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.
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.
descriptor
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.