jelan.elan.instruction
Class Assignment

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

Constructor Summary
Assignment(Variable v, Expression e)
          Construct an Assignment instruction from a variable and an expression, e.g., X = expression.
 
Method Summary
 java.lang.Double 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Assignment

public Assignment(Variable v,
                  Expression 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.Double 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