slogo.expression
Class BinaryExpression

java.lang.Object
  extended by slogo.language.GrammarElement
      extended by slogo.expression.Expression
          extended by slogo.expression.BinaryExpression
Direct Known Subclasses:
Addition, Division, Multiplication, Subtraction

public abstract class BinaryExpression
extends Expression

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, subclases will call.

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

Author:
Owen Astrachan

Field Summary
protected  Expression myLeft
           
protected  Expression myRight
           
protected  java.lang.String mySymbol
           
 
Fields inherited from class slogo.language.GrammarElement
gelementsToValue
 
Constructor Summary
BinaryExpression(Expression lhs, Expression 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.expression.Expression
evaluate, value
 
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 Expression myLeft

myRight

protected Expression myRight
Constructor Detail

BinaryExpression

public BinaryExpression(Expression lhs,
                        Expression 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