Java Reference
In-Depth Information
/
Generalized visitor code for Marker 12
/
procedure
visit
(VariableListDeclaring vld )
typeVisitor
new TypeVisitor()
call vld . itemType . accept( typeVisitor )
declType vld . itemType . type
33
if vld . initialization null
then
checkingVisitor
34
new SemanticsVisitor()
call vld . initialization . accept( checkingVisitor )
if not
assignable
( vld . initialization . type , declType )
35
then
call
error
(” Initialization expression not assignable to variable type at
, vld )
else
if const vld . modi f iers
then
call error
36
(” Initialization expression missing in constant declaration at
, vld )
foreach id vld . itemIdList do
if currentSymbolTable . declaredLocally( id . name )
then
call
error
(” Variable name cannot be redeclared :”
, id . name )
id . type errorType
id . attributesRe f
null
else
attr . kind variableAttributes
attr . variableType declType
attr . modi f iers declType
call currentSymbolTable . enterSymbol( id . name , attr )
id . type declType
id . attributesRe f attr
37
end
Figure 8.18: Code for TopDeclVisitor's VariableListDeclaring
ArrayDefining
ArrayDefining
size
elementType
lower
upper
elementType
Type
IntegerLiteral
Constant
Subtree
Constant
Type
Subtree
Expression
Expression
Subtree
value
Subtree
Size of array specified
Upper and lower bounds included
(a)
(b)
Figure 8.19: Abstract Syntax Trees for Array Definitions
 
Search WWH ::




Custom Search