Java Reference
In-Depth Information
procedure
visit
(Assigning n )
call C
ode
G
en
( n . child 2)
call E
mit
( "s" )
call E
mit
( n . child 1
. id )
call E
mit
( "0 k" )
14
end
procedure
visit
(Computing n )
call C
ode
G
en
( n . child 1)
call C
ode
G
en
( n . child 2)
call E
mit
( n . operation )
15
end
procedure
visit
(SymReferencing n )
call E
mit
( "l" )
call E
mit
( n . id )
end
procedure
visit
( Printing n )
call E
mit
( "l" )
call E
mit
( n . id )
call E
mit
( "p" )
call E
mit
( "si" )
16
end
procedure
visit
(Converting n )
call C
ode
G
en
( n . child )
call E
mit
( "5 k" )
17
end
procedure
visit
(Consting n )
call E
mit
( n . val )
end
Figure 2.14: Code generation for ac
• visit
(Printing n )istrickybecausedc does not discard the value on top-
of-stack after it is printed. The instruction sequence si is generated at
Marker 16 , thereby popping the stack and storing the value in dc's i
register. Conveniently, the ac language precludes a program from using
this register because the i token is reserved for spelling the terminal
symbol integer.
• visit
(Converting n ) causes a change of type from integer to float at
Marker 17 . This is accomplished by setting dc's precision to five frac-
tional decimal digits.
Figure 2.15 shows how code is generated for the AST shown in Figure 2.9.
Each section shows the code generated for a particular subtree of Figure 2.9.
 
Search WWH ::




Custom Search