Java Reference
In-Depth Information
/
Visitor methods
/
procedure
visit
(Computing
n
)
n
.
type
←
C
onsistent
(
n
.
child
1
,
n
.
child
2)
end
procedure
visit
(Assigning
n
)
n
.
type
←
C
onvert
(
n
.
child
2
,
n
.
child
1
.
type
)
end
procedure
visit
(SymReferencing
n
)
n
.
type
←
L
ookup
S
ymbol
(
n
.
id
)
end
procedure
visit
( IntConsting
n
)
n
.
type
←
integer
end
procedure
visit
(FloatConsting
n
)
n
.
type
←
float
end
/
Type-checking utilities
/
function
C
onsistent
(
c
1
,
c
2)
returns
type
m
←
G
eneralize
(
c
1
.
type
,
c
2
.
type
)
call
C
onvert
(
c
1
,
m
)
call
C
onvert
(
c
2
,
m
)
return
(
m
)
end
function
G
eneralize
(
t
1
,
t
2)
returns
type
if
t
1
=
float
or
t
2
=
float
then
ans
←
float
else
ans
←
integer
return
(
ans
)
end
procedure
C
onvert
(
n
,
t
)
if
n
.
type
=
float
and
t
=
integer
then call
error
( "Illegal type conversion" )
else
if
n
.
type
=
integer
and
t
=
float
then
/
replace node
n
by convert-to-float of node
n
/
13
else
/
nothing needed
/
end
Figure 2.12: Type analysis for ac.