slogo.jelan.expressions
Class BinaryExpression

java.lang.Object
  extended by slogo.jelan.GrammarElement
      extended by slogo.jelan.expressions.Expression
          extended by slogo.jelan.expressions.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, subclasses will call.

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

Author:
Owen Astrachan

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.jelan.expressions.Expression
evaluate, value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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