Java Reference
In-Depth Information
VariableListDeclaring
modifiers : a modifierSet
itemIdList
itemType
initialization
IdentifierList
Type
. . .
Expression
ids
Subtree
Subtree
Figure 8.17: AST for Generalized Variable Declarations
includes a reference to a type subtree similar to the one used in Figure 8.15 of
Section 8.6.3. The
method for these generalized variable declarations in
Figure 8.18 begins at Marker 33 just like the one Section 8.6.1, since it does
not matter whether the type of the variables being declared is specified by a
name or a type definition. An optional initialization subtree is also shown as
part of the VariableListDeclaring AST node in Figure 8.17. If initialization is
present (Marker 34 ), it is analyzed and checked for assignment compatibility
with the declared type (Marker 35 ). Initialization is required if a constant
is being declared, and appropriate checking is included in the visitor actions
(Marker 36 ).
visit
Depending on the language being compiled, the declaration syntax may
include one or more modifiers, such as const , static , public ,etc.Becausemany
combinations of such modifiers may be possible, we have designed our AST to
simply represent all of the modifiers present as a set rather than have di
erent
AST nodes representing each of the modifier keywords. Corresponding nodes
would be present in the parse tree, but they are eliminated and instead are
represented by themodifier set duringAST creation. AtMarker 37 , we assume
an extension to the Attributesdescriptor for variables defined in Figure 8.9 to
store this modifier set. Any
ff
method that needs information about the
attributes of a variable can check this set. The body of the declaration loop
ends after id . name is entered into the symbol table and the type and attributeRe f
fields in its AST node are set. The method ends once the entire list of variable
names has been processed.
visit
 
Search WWH ::




Custom Search