jelan.elan.instruction
Class Repeat

java.lang.Object
  extended by jelan.elan.GrammarElement
      extended by jelan.elan.instruction.Instruction
          extended by jelan.elan.instruction.Repeat

public class Repeat
extends Instruction

An AST (abstract syntax tree) for a 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.

To 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

Constructor Summary
Repeat(Expression e, StrictInstructionList sil)
          Constructs a Repeat instruction that can be executed.
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Repeat

public Repeat(Expression e,
              StrictInstructionList sil)
Constructs a Repeat instruction that can be executed.

Parameters:
e - number of times to repeat the body
sil - strict instruction list that is the body
Method Detail

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