Next: Attributes for unit
Up: Various attributes and functions
Previous: Attributes for conditional statements
The following attributes give a quick access to the most useful parts of DO
statements. They must be applied to a AST of variant "do".
-
stat.BOUND
-
The expression returns the whole control
structure of the DO statement stat. Its variant is "bounds" for an
indexed DO statement (i.e. something like 'DO I=1,n ...'), "while" for a DO
WHILE statement and "none" for an infinite DO.
Example 44:How to differentiate DO statements
IF (stat.VARIANT=="do") THEN
IF (stat.BOUND.VARIANT=="bounds") THEN
PRINT "I am an indexed DO loop"
ELSEIF (stat.BOUND.VARIANT=="while") THEN
PRINT "I am a DO WHILE loop"
ELSEIF (stat.BOUND.VARIANT=="none") THEN
PRINT "I am an infinite DO loop"
ELSE
PRINT "I don't know who I am."
ENDIF
ENDIF
Remark: stat.BOUND is equivalent to stat.CHILD(3)
-
stat.INDEX
-
The expression returns the variable index of
the indexed DO statement stat. This is a shortcut to stat.CHILD(3).CHILD(1)
-
stat.START
-
The expression returns the start value of
the indexed DO statement stat. This is a shortcut to stat.CHILD(3).CHILD(2)
-
stat.END
-
The expression returns the start value of
the indexed DO statement stat. This is a shortcut to stat.CHILD(3).CHILD(3)
-
stat.STEP
-
The expression returns the start value of the
indexed DO statement stat. The step variant is "none" when the step is implicit.
This is a shortcut to stat.CHILD(3).CHILD(4)
-
stat.BODY
-
The expression returns the body of
the DO statement stat. This is a shortcut to stat.CHILD(4)
-
stat.LABEL
-
The expression returns the label associated
to the DO statement stat (i.e. the label before the index variable).
If there is no label (the statement is ended by ENDDO) then the attribute
returns a node of variant "none".
Example 45:A simple inversion of the step sign
SCRIPT SignInvert ()
loop := $cstat
IF (loop.VARIANT == "do") THEN
IF (loop.BOUND.VARIANT == "bounds") THEN
// Exchange the start and the step
start := loop.START
loop.START <- loop.END
loop.END <- start
// Invert the condition
step := loop.STEP
IF (step.VARIANT=="none" )THEN
step := PARSEEXPR("-1")
ELSE
step := PARSEEXPR("-(%e)",step)
ENDIF
loop.STEP <- step
ENDIF
ENDIF
ENDSCRIPT
Next: Attributes for unit
Up: Various attributes and functions
Previous: Attributes for conditional statements
Yann Mevel
1999-04-30