slogo.instruction
Class Assignment

java.lang.Object
  extended by slogo.language.GrammarElement
      extended by slogo.instruction.Instruction
          extended by slogo.instruction.Assignment

public class Assignment
extends Instruction

An assignment instruction assigns an expression to a variable, updating the global state to reflect the assignment.

Executing the assignment instruction causes the expression to be evaluated and assigned to the variable, until the assignment instruction executes, the expression isn't evaluated.

Author:
Owen Astrachan

Field Summary
protected  GrammarElement myExpression
           
protected  Variable myVariable
           
 
Fields inherited from class slogo.language.GrammarElement
gelementsToValue
 
Constructor Summary
Assignment(Variable v, GrammarElement e)
          Construct an Assignment instruction from a variable and an expression, e.g., X = expression.
 
Method Summary
 java.lang.Object evaluate(Context c)
          Evaluate the expression that's part of this instruction and update a global map/store to record the assignment of the expression to the variable.
 java.lang.String toString()
          Returns a String for this instruction.
 
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

myVariable

protected Variable myVariable

myExpression

protected GrammarElement myExpression
Constructor Detail

Assignment

public Assignment(Variable v,
                  GrammarElement e)
Construct an Assignment instruction from a variable and an expression, e.g., X = expression.

Parameters:
e - expression being assigned
v - variable to which the expression is assigned
Method Detail

evaluate

public java.lang.Object evaluate(Context c)
Evaluate the expression that's part of this instruction and update a global map/store to record the assignment of the expression to the variable.

Overrides:
evaluate in class Instruction
Parameters:
c - is the Context in which the evaluation takes place
Returns:
the result of evaluation (which is the expression assigned)

toString

public java.lang.String toString()
Returns a String for this instruction.

Overrides:
toString in class java.lang.Object
Returns:
VAR = EXPRESSION