slogo.instruction
Class Repeat
java.lang.Object
slogo.language.GrammarElement
slogo.instruction.Instruction
slogo.instruction.Repeat
public class Repeat
- extends Instruction
An AST (abstract syntax tree) for a MoboLogo/Slogo REPEAT instruction. A
REPEAT instruction has two components: (1) an expression representing the
number of times to repeat the instructions that follow and (2) a
strict instruction list that is the list of instructions that will
be (repeatedly) executed.
Subroutine evaluate a REPEAT instruction the expression is evaluated first, this
determines the number of times the instruction list is executed. This
instruction list is executed the appropriate number of times.
The value returned by evaluating a REPEAT instruction is the last value
returned by evaluating the instruction list.
- Author:
- Owen Astrachan
Method Summary |
java.lang.Object |
evaluate(Context c)
Evaluate this instruction in a Context. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
repeatExp
protected GrammarElement repeatExp
myList
protected StrictInstructionList myList
Repeat
public Repeat(GrammarElement e,
StrictInstructionList sil)
- Constructs a Repeat instruction that can be executed.
- Parameters:
e
- number of times to repeat the bodysil
- strict instruction list that is the body
evaluate
public java.lang.Object evaluate(Context c)
- Evaluate this instruction in a Context.
- Overrides:
evaluate
in class Instruction
- Parameters:
c
- the Context for the evaluation
- Returns:
- the result of evaluating the instruction list the last time
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
- Returns:
- a String representing this instruction