slogo.instruction
Class Assignment
java.lang.Object
slogo.language.GrammarElement
slogo.instruction.Instruction
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
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
myVariable
protected Variable myVariable
myExpression
protected GrammarElement myExpression
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 assignedv
- variable to which the expression is assigned
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