|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.parser.Operation
Class Operation encapsulates an operation
and its corresponding String symbol
for use with a parser.
This class is abstract since the method
performOperation must be defined.
As of 2.5.0, this class was extracted from the class
AbstractParser and made standalone.
| Field Summary | |
static Operation |
IDENTITY
The IDENTITY operation, equivalent to the function f(x,y)=y. |
private boolean |
isBinary
Whether or not the operation can act as a binary operation. |
private boolean |
isUnary
Whether or not the operation can act as a unary operation. |
static Operation |
OPERATION_PREFIX
The singleton operation object which designates that a symbol is a prefix for a known operation. |
private String |
symbol
The symbol representing this operation. |
| Constructor Summary | |
Operation(String id)
Constructs an operation with the given symbol. |
|
Operation(String id,
boolean unary,
boolean binary)
Constructs an operation with the given symbol and settings for unary and binary usage. |
|
| Method Summary | |
void |
checkBinary()
Throws parseException if operation cannot act as binary. |
void |
checkUnary()
Throws parseException if operation cannot act as unary. |
boolean |
isBinary()
Returns true if the operation may act as a binary operation. |
boolean |
isUnary()
Returns true if the operation may act as a unary operation. |
abstract Object |
performOperation(Object left,
Object right)
Performs the operation on the given values and returns the result. |
String |
symbol()
Returns the symbol for this operation. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final Operation IDENTITY
The IDENTITY operation, equivalent to the function f(x,y)=y.
In the class AbstractParser, this operation
is inserted with the lowest level of precedence and is used
as the base for evaluation of an expression.
public static final Operation OPERATION_PREFIX
The singleton operation object which designates that a symbol is a prefix for a known operation.
This operation operates as a return flag and may not
be inserted into the precedence structure of the class
AbstractParser.
private String symbol
private boolean isUnary
private boolean isBinary
| Constructor Detail |
public Operation(String id)
Constructs an operation with the given symbol.
The symbol "" is reserved for IDENTITY.
The symbol "\0" is reserved for OPERATION_PREFIX.
Throws IllegalArgumentException
if the operation id is not valid when tested by
AbstractParser.isPossibleOperation.
id - the symbol for the operation
IllegalArgumentException
public Operation(String id,
boolean unary,
boolean binary)
The symbol "" is reserved for IDENTITY.
The symbol "\0" is reserved for OPERATION_PREFIX.
Throws IllegalArgumentException
if the operation id is not valid when tested by
AbstractParser.isPossibleOperation.
id - the symbol for the operationunary - whether the operation may be unarybinary - whether the operation may be binary
IllegalArgumentException| Method Detail |
public abstract Object performOperation(Object left,
Object right)
throws ParseException
Performs the operation on the given values and returns the result.
left - the left side operand for a binary operation
or null for a unary operationright - the right side operand for a unary or binary
operation
ParseExceptionpublic final String symbol()
public final boolean isUnary()
public final boolean isBinary()
public final void checkUnary()
throws ParseException
ParseException
public final void checkBinary()
throws ParseException
ParseException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||