Java Reference
In-Depth Information
procedure
(Continuing cn )
currentList ← get
visit
L
abel
L
ist
()
if cn . stmtLabel =
null
then
while currentList
null do
currentLabel ← head
( currentList )
if currentLabel . kind = iterative
then return
currentList ← tail
( currentList )
call
error
(” Continue not inside iterative statement ”)
else
while currentList
null do
currentLabel ← head
( currentList )
if currentLabel . label = cn . stmtLabel and currentLabel . kind = iterative
then return
currentList ← tail
( currentList )
call
error
(” Continue label doesnot match an iterative statement ”)
end
Figure 9.12: Semantic Analysis for a Continue
the AST of the labeled statement). Looking at a label list, we can determine the
statements that enclose a break or continue, as well as all of the labels currently
visible to the break or continue.
The semantic analysis visitor for a LabeledStmt is shown in Figure 9.11.
The current label list is extendedby adding an entry for the current LabeledStmt
node using its label (which may be null), and its kind (determined by a call to
an auxiliary method,
). The subtree is analyzed using the extended
label list. After semantic analysis, the label list is returned to its original state
by removing its first element. Reachability and throws analyses are defined at
Figure 9.3, Marker 7 and Figure 9.4, Marker 14 .
A continue statement without a label references the innermost iterative
statement (while, do, or for) within which it is nested. This is easily checked
by looking for a node on the label list with kind = iterative (ignoring the value
of the label field).
Acontinue statement that references a label L (stored inASTfield stmtLabel )
must be enclosed by an iterative statement whose label is L . If more than one
containing statement is labeled with L , the nearest (innermost) is used. The
semantic analysis visitor for a continue statement is shown in Figure 9.12.
Reachability and throws analyses for a continue are defined at Figure 9.3,
Marker 8 and Figure 9.4, Marker 15 .
As an example, consider the following code fragment:
get
K
ind
 
Search WWH ::




Custom Search