Java Reference
In-Depth Information
super(surrounding,surrounding.classContext(),
surrounding.compilationUnitContext());
offset=(surroundinginstanceofLocalContext)
?((LocalContext)surrounding).offset()
:0;
}
(e) A JVariableDeclaration declares the variable v in the LocalContext , allocating it
the oset 3.
(f) analyze() creates a new LocalContext for the nested JBlock , copying the nextOffset
4 from the context for the surrounding block.
(g) A JVariableDeclaration declares the variable w in the new LocalContext , for the
nested block, allocating it the offset 4.
(h) A second JVariableDeclaration declares the variable x in the same LocalContext ,
allocating it the offset 5. The subsequent assignment statement will be analyzed in this
context.
(i) When this first nested JBlock has been analyzed, analyze() returns control to the
analyze() for the containing JBlock , leaving the symbol table in exactly the state
that it was in step (e).
(j) Analyze() creates a new LocalContext for the second nested JBlock , copying the
nextOffset 4 from the context for the surrounding block. Notice the similarity to the
state in step (f). In this way, variables y and z will be allocated the same offsets in steps
(k) and (l) as w and x were in steps (g) and (h).
(k) A JVariableDeclaration declares the variable y in the new LocalContext , for the
nested block, allocating it the offset 4.
(l) A second JVariableDeclaration declares the variable z in the same LocalContext ,
allocating it the offset 5. The subsequent assignment statement will be analyzed in this
context.
(m) When this second nested JBlock has been analyzed, analyze() returns control to the
analyze() for the containing JBlock , leaving the symbol table in exactly the state that
it was in steps (e) and (i).
(n) When the method body's JBlock has been analyzed, analyze() returns control to the
analyze() for the containing JMethodDeclaration , leaving the symbol table in exactly
the state that it was in step (c).
(o) When the JMethodDeclaration has been analyzed, analyze() returns control to the
analyze() for the containing JClassDeclaration , leaving the symbol table in exactly
the state that it was before step (a).
We address the details of analyzing local variable declarations in the next section.
Analyzing Local Variable Declarations and Their Initializations
A local variable declaration is represented in the AST with a JVariableDeclaration . For
example, consider the local variable declaration from Locals :
intw=v+5,x=w+7;
 
Search WWH ::




Custom Search