Next: Switch Statement Symbols, Previous: Class related Symbols, Up: Syntactic Symbols [Contents][Index]
Here is a (totally contrived) example which illustrates how syntax is assigned to various conditional constructs:
1: void spam( int index ) 2: { 3: for( int i=0; i<index; i++ ) 4: { 5: if( i == 10 ) 6: do_something_special(); 7: else 8: silly_label: 9: do_something( i ); 10: } 11: do { 12: another_thing( i-- ); 13: } 14: while( i > 0 ); 15: }
Only the lines that illustrate new syntactic symbols will be discussed.
Line 4 has a brace which opens a conditional’s substatement block. It
is thus assigned substatement-open
syntax, and since line 5 is
the first line in the substatement block, it is assigned
statement-block-intro
syntax. Line 10 contains the brace
that closes the inner substatement block, and is therefore given the
syntax block-close
38. Line 13 is treated the same way.
Lines 6 and 9 are also substatements of conditionals, but since they
don’t start blocks they are given substatement
syntax
instead of substatement-open
.
Line 8 contains a label, which is normally given label
syntax.
This one is however a bit special since it’s between a conditional and
its substatement. It’s analyzed as substatement-label
to let you
handle this rather odd case differently from normal labels.
Line 7 start with an else
that matches the if
statement on
line 5. It is therefore given the else-clause
syntax and is
anchored on the matching if
. The try
-catch
constructs in C++ and Java are treated this way too, except that
catch
and (in Java) finally
, are marked with
catch-clause
.
The while
construct on line 14 that closes a do
conditional is given the special syntax do-while-closure
if it
appears on a line by itself. Note that if the while
appeared on
the same line as the preceding close brace, that line would still have
block-close
syntax.
block-open
is used only for
“free-standing” blocks, and is somewhat rare (see Comment String Label and Macro Symbols for an example.)
Next: Switch Statement Symbols, Previous: Class related Symbols, Up: Syntactic Symbols [Contents][Index]