1. What are the benefits of using machine-independent intermediate form?
· Retargeting is facilitated; a compiler for a different machine can be created by attaching a back end for the new machine to an existing front end.
· A machine-independent code optimizer can be applied to the intermediate representation.
2. List the three kinds of intermediate representation.
The three kinds of intermediate representations are
i. Syntax trees
ii. Postfix notation
iii. Three address code
3. How can you generate three-address code?
The three-address code is generated using semantic rules that are similar to those for constructing syntax trees for generating postfix notation.
4. What is a syntax tree? Draw the syntax tree for the assignment statement a := b * -c + b * -c.
· A syntax tree depicts the natural hierarchical structure of a source program.
· Syntax tree:
5. What is postfix notation?
A Postfix notation is a linearized representation of a syntax tree. It is a list of nodes 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 directed definition.
7. Why “Three address code” is named so?
The reason for the term “Three address code” is that each usually contains three 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 form
x := 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, arg2 and result.
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. Construct Three address code for the following
position := initial + rate * 60
temp1 := inttoreal(60)
temp2 := id3 * temp1
temp3 := id2 + temp2
id1 := temp3
12. 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.
13. Draw the DAG for a := b * -c + b * -c assign
14. 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
15. What are the various methods of implementing three-address statements?
iii. Indirect triples
16. What is meant by declaration?
The process of declaring keywords, procedures, functions, variables, and statements with
proper syntax is called declaration.
17. How semantic rules are defined?
The semantic rules are defined by the following ways
18. What are the two primary purposes of Boolean Expressions?
· They are used to compute logical values
· They are used as conditional expressions in statements that alter the flow of control, such as if-then, if-then-else, or while-do statements.
19. Define Boolean Expression.
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
20. What are the two methods to represent the value of a Boolean expression?
i. The first method is to encode true and false numerically and to evaluate a Boolean expression analogously to an arithmetic expression.
ii. 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.
21. What do you mean by viable prefixes. Nov/Dec 2004
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.
22. 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.
23. What is known as calling sequence?
A sequence of actions taken on entry to and exit from each procedure is known as calling sequence.
What is the intermediate code representation for the expression a or b and not c? (Or) Translate a or b and not c into three address code.
Three-address sequence is
t1 := not c
t2 := b and t1
t3 := a or t2
25. Translate the conditional statement if a<b then 1 else 0 into three address code.
Three-address sequence is
100: if a < b goto 103
101: t := 0
102: goto 104
103: t := 1
26. Explain the following functions:
i) makelist(i) ii) merge(p1,p2) iii) backpatch(p,i)
i. makelist(i) creates a new list containing only I, an index into the array of quadruples; makelist returns a pointer to the list it has made.
ii. merge(p1,p2) concatenates the lists pointed to by p1 and p2 , and returns a pointer to the concatenated list.
iii. backpatch(p,i) inserts i as the target label for each of the statements on the list pointed to by p.
27. Define back patching. May/June 2007 & Nov/Dec 2007
Back patching is the activity of filling up unspecified information of labels using appropriate semantic actions in during the code generation process.
28. What are the methods of representing a syntax tree?
i. Each node is represented as a record with a field for its operator and additional fields for pointers to its children.
ii. Nodes are allocated from an array of records and the index or position of the node serves as the pointer to the node
29. Give the syntax directed definition for if-else statement.
Copyright © 2018-2021 BrainKart.com; All Rights Reserved. (BS) Developed by Therithal info, Chennai.