slogo.instruction.arithmetic
Class ArithmeticExpression

java.lang.Object
  extended by slogo.language.GrammarElement
      extended by slogo.instruction.Instruction
          extended by slogo.instruction.arithmetic.ArithmeticExpression
Direct Known Subclasses:
Addition, Division, Multiplication, Remainder, Subtraction

public abstract class ArithmeticExpression
extends Instruction

The base class of any binary expression, e.g., a + b, a - b, or, in future use, a < b and so on. A binary expression has two subexpressions that can be evaluated via the methods leftValue and rightValue which, presumably, subclasses will call.

The current version is tied to arithmetic expressions via the the return type of leftValue and rightValue.

Author:
Owen Astrachan, Sara Sprenkle

Field Summary
protected  GrammarElement myLeft
           
protected  GrammarElement myRight
           
protected  java.lang.String mySymbol
           
 
Fields inherited from class slogo.language.GrammarElement
gelementsToValue
 
Constructor Summary
ArithmeticExpression(GrammarElement lhs, GrammarElement rhs)
          construct a binary expression from two subexpressions
 
Method Summary
 double leftValue(Context c)
           
 double rightValue(Context c)
           
 java.lang.String toString()
          Combine left/right subexpressions, return result using symbol as the combiner/juxtaposer for the subexpressions.
 
Methods inherited from class slogo.instruction.Instruction
evaluate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mySymbol

protected java.lang.String mySymbol

myLeft

protected GrammarElement myLeft

myRight

protected GrammarElement myRight
Constructor Detail

ArithmeticExpression

public ArithmeticExpression(GrammarElement lhs,
                            GrammarElement rhs)
construct a binary expression from two subexpressions

Parameters:
lhs - is the left subexpression (left-hand side)
rhs - is the right subexpression (right-hand side)
Method Detail

leftValue

public double leftValue(Context c)
Returns:
the result of evaluating the left subexpression

rightValue

public double rightValue(Context c)
Returns:
the result of evaluating the right subexpression

toString

public java.lang.String toString()
Combine left/right subexpressions, return result using symbol as the combiner/juxtaposer for the subexpressions.

Overrides:
toString in class java.lang.Object
Returns:
a string representing this expression