4.CD Unit 4.3.pptx
4.CD Unit 4.3.pptx
In
Compiler design
Copyright ©
Prof. Vikas Chavan
Assistant Professor
CSE, JNEC.
● The p returns the entry for id.name in the symbol table.
● The Emit function is used for appending the three
address code to the output file. Otherwise it will report
an error.
● The newtemp() is a function used to generate new
temporary variables.
● E.place holds the value of E.
● 𝐄. 𝐏𝐋𝐀𝐂𝐄 − It tells about the name that will hold the
value of the expression.
E → E or E
E → E and E
E → not E
E → (E)
E → id relop id
E → id
E → TRUE
E → FALSE
Example 1:
A or B and C
Three address sequence:
T1 = B and C
T2 = A or T1
Example 2:
E → E1 OR E2 {E.place = newtemp();
nextstat + 3);
100: if p>q goto 103 Emit (E.place ':=' E1.place 'OR' E2.place)}
switch E
begin
case V1: S1
case V2: S2
.
.
.
case Vn-1: Sn-1
default: Sn
end
Code to evaluate E into T
goto TEST
L1: code for S1
goto NEXT
L2: code for S2
goto NEXT
.
.
Ln-1: code for Sn-1
goto NEXT
Ln: code for Sn
goto NEXT
TEST: if T = V1 goto L1
if T = V2 goto L2
.
.
if T = Vn-1 goto Ln-1
goto
NEXT:
● When switch keyword is seen then a new temporary T
a stack.
Procedures call
In
Compiler Design
Procedures call
Calling sequence:
The translation for a call includes a sequence of
actions taken on entry and exit from each
procedure. Following actions take place in a
calling sequence:
● When a procedure call occurs then space is
allocated for activation record.
● Evaluate the argument of the called procedure.
● Establish the environment pointers to enable
the called procedure to access data in
enclosing blocks.
● Save the state of the calling procedure so that it
can resume execution after the call.
● Also save the return address. It is the address
of the location to which the called routine must
transfer after it is finished.
● Finally generate a jump to the beginning of the
code for the called procedure.
Grammar for a simple procedure call statement
1. S → call id(Elist)
2. Elist → Elist, E
3. Elist → E
A suitable transition scheme for procedure call would be:
GEN (param p)
E.PLACE
Thank You
Copyright ©
Prof. Vikas Chavan
Assistant Professor
CSE, JNEC.