Cclec01 PDF
Cclec01 PDF
Compilers: Principles, Techniques, and Tools,
Publisher: Addison-Wesley
:
http://Khademzadeh.mshdiau.ac.ir
(token)
(lexeme)
int a;
a = a + 2;
int
T_INT
a
T_IDENTIFIER
;
T_SPECIAL
";")
a
T_IDENTIFIER
=
T_OP
a
T_IDENTIFIER
+
T_OP
2
T_INTCONSTANT
;
T_SPECIAL
";")
[email protected]
(reserved word)
(variable name)
(special symbol with value of
(variable name)
(operator with value of "=")
(variable name)
(operator with value of "+")
(integer constant with value of 2)
(special symbol with value of
CFG
LHS RHS
)(derivation
Expression Expression + Expression |
Expression Expression |
...
Variable |
Constant |
...
Variable
T_IDENTIFIER
Constant
T_INTCONSTANT |
T_DOUBLECONSTANT
( )
X + 19
Expression Expression + Expression
Variable + Expression
T_IDENTIFIER + Expression
T_IDENTIFIER + Constant
T_IDENTIFIER + T_INTCONSTANT
) (
;int arr[2], c
;c = arr * 10
: )(TAC
:
a=b*c+b*d
_t1 = b * c
_t2 = b * d
_t3 = _t1 + _t2
a = _t3
-
if (a <= b)
a = a - c;
c = b * c;
_t1 = a > b
if _t1 goto L0
_t2 = a c
a = _t2
L0: _t3 = b * c
c = _t3
[email protected]
) - (
_t1 = b * c
_t2 = _t1 + 0
_t3 = b * c
_t4 = _t2 + _t3
a = _t4
_t1 = b * c
_t2 = _t1 + _t1
a = _t2
_t1 = b * c
_t2 = _t1 + _t1
a = _t2
ld [%fp-16], %l1
ld [%fp-20], %l2
smul %l1, %l2, %l3
add %l3, %l3, %l0
st %l0, [%fp-24]
# load
# load
# mult
# add
# store
)(symbol table
Multi-pass
One-pass