slogo.expression
Class BinaryExpression
java.lang.Object
slogo.language.GrammarElement
slogo.expression.Expression
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
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
mySymbol
protected java.lang.String mySymbol
myLeft
protected Expression myLeft
myRight
protected Expression myRight
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)
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