slogo.instruction.arithmetic
Class ArithmeticExpression
java.lang.Object
slogo.language.GrammarElement
slogo.instruction.Instruction
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
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 GrammarElement myLeft
myRight
protected GrammarElement myRight
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)
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