slogo.instruction
Class Repeat

java.lang.Object
  extended by slogo.language.GrammarElement
      extended by slogo.instruction.Instruction
          extended by 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

Field Summary
protected  StrictInstructionList myList
           
protected  GrammarElement repeatExp
           
 
Fields inherited from class slogo.language.GrammarElement
gelementsToValue
 
Constructor Summary
Repeat(GrammarElement 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 slogo.instruction.Instruction
evaluateNumericExpression
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

repeatExp

protected GrammarElement repeatExp

myList

protected StrictInstructionList myList
Constructor Detail

Repeat

public Repeat(GrammarElement 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