Professional Documents
Culture Documents
Esku Individual Aas Compiler
Esku Individual Aas Compiler
Esku Individual Aas Compiler
COUSE CODE:
ID NO 1100974
SECTION “A”
INDIVIDUAL ASSIGNMENT
General Form-
Three Address Statement Types, Assignment statement, Arithmetic operation, Logical
operation, Unary minus, Copy statement, Unconditional jump are basic concepts discussed of
course.Mar 11, 2012
What are the types of three address statements?
Common Three Address Instruction Forms-
a = b op c
Here,
Examples-
1. Assignment Statement-
x = y op z and x = op y
Here,
It assigns the result obtained after solving the right side expression of the assignment operator to
the left side operand.
2. Copy Statement-
x=y
Here,
3. Conditional Jump-
If x relop y goto X
Here,
4. Unconditional Jump-
goto X
5. Procedure Call-
E E E
E E E
E E
E E
E
E
E
Boolean expressions are used as conditions for statements changing the flow
of control.
Evaluation of boolean expressions can be optimized if it is sufficient to
evaluate a part of the expression that determines its value.
When translating Boolean expressions into three-address code, we can use
two different methods.
Numerical method.
Assign numerical values to true and false and evaluate the expression
analogously to an arithmetic expression. This is convenient for boolean
expressions which are not involved in flow of control constructs.
Jump method.
S E S1
S.after := newlabel
code1 := generate(S.begin ':') | | E.code | |
code2 := generate('if ' E.place '= 0 '
'goto' S.after) | | S1.code
code3 := generate('goto' S.begin) |
| generate(S.after)
FLOW OF CONTROL STATEMENTS WITH THE JUMP METHOD. We will consider here
the following rules.
S
E S1
S
E S1 S2
E S1
E.true := newlabel
S E S1
E.false := S.next
S1.next := S.next
S.code := E.code | | generate(E.true ':') |
| S1.code
E.true := newlabel
S E S1 S2
E.false := newlabel
S1.next := S.next
S2.next := S.next
code1 := E.code | | generate(E.true ':') |
| S1.code
code2 := generate('goto' S.next) | |
code3 := generate(E.false ':') | | S2.code
E.true := newlabel
E.false := S.next
S1.next := S.begin
code1 := generate(S.begin ':') | | E.code
code2 := generate(E.true ':') | | S1.code
code3 := generate('goto' S.begin)
Since several attributes are inherited and since each action above appears
after its associated production, this is not a translation scheme.
However it is an L-attributed definition.
Then its conversion into a translation scheme is obvious.
From now on, we may present a translation scheme as a syntax-directed
definition if the latter is an L-attributed definition.
The reason is to make large translation schemes easier to read.
There are two principal methods of representing the value of a boolean expression. They are :
* To encode true and false numerically and to evaluate a boolean expression analogously to an arithmetic
expression. Often, 1 is used to denote true and 0 to denote false.
* To implement boolean expressions by flow of control, that is, representing the value of a boolean expression by a
position reached in a program. This method is particularly convenient in implementing the boolean
expressions in flow-of-control statements, such as the if-then and while-do statements.
Numerical Representation
Here, 1 denotes true and 0 denotes false. Expressions will be evaluated completely from left to right, in a manner
similar to arithmetic expressions.
For example :
* The translation for a or b and not c is the three-address sequence
* t1 : = not c
t2 : = b and t1
t3 : = a or t2
* A relational expression such as a < b is equivalent to the conditional statement
* if a < b then 1 else 0
which can be translated into the three-address code sequence (aga statement numbers at 100) :
103 : t : = 1
104 :