edu.neu.ccs.parser
Class AbstractParser.Operation

java.lang.Object
  |
  +--edu.neu.ccs.parser.AbstractParser.Operation
Direct Known Subclasses:
JPTParser.BooleanOperation, JPTParser.NumericOperation
Enclosing class:
AbstractParser

public static class AbstractParser.Operation
extends Object

Class encapsulating an operation and its corresponding String symbol for use with a parser.

Replaces the class named Operator.

Since:
2.2
See Also:
Parser

Field Summary
 boolean isBinary
          Whether or not the operation can act as a binary operation.
 boolean isUnary
          Whether or not the operation can act as a unary operation.
 String symbol
          The symbol representing this operation.
 
Constructor Summary
AbstractParser.Operation()
          Constructs an operation with the default initial settings.
AbstractParser.Operation(String s)
          Constructs an operation with the given symbol.
AbstractParser.Operation(String s, boolean unary, boolean binary)
          Constructs an operation with the given symbol and settings for unary and binary usage.
 
Method Summary
protected  void checkBinary()
          Throws parseException if operation cannot act as binary.
protected  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.
 Object performOperation(Object left, Object right)
          Performs the operation on the given values and returns the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbol

public String symbol
The symbol representing this operation.


isUnary

public boolean isUnary
Whether or not the operation can act as a unary operation.


isBinary

public boolean isBinary
Whether or not the operation can act as a binary operation.

Constructor Detail

AbstractParser.Operation

public AbstractParser.Operation()
Constructs an operation with the default initial settings.


AbstractParser.Operation

public AbstractParser.Operation(String s)
Constructs an operation with the given symbol.

Parameters:
s - the symbol for the operation

AbstractParser.Operation

public AbstractParser.Operation(String s,
                                boolean unary,
                                boolean binary)
Constructs an operation with the given symbol and settings for unary and binary usage.

Parameters:
s - the symbol for the operation
unary - whether the operation may be unary
binary - whether the operation may be binary
Method Detail

performOperation

public Object performOperation(Object left,
                               Object right)
                        throws ParseException
Performs the operation on the given values and returns the result. Replaces the method named operationPerformed.

Parameters:
left - the left side operand for a binary operation or null for a unary operation
right - the right side operand for a unary or binary operation
ParseException
Since:
2.2

isUnary

public boolean isUnary()
Returns true if the operation may act as a unary operation.

Since:
2.2

isBinary

public boolean isBinary()
Returns true if the operation may act as a binary operation.

Since:
2.2

checkUnary

protected void checkUnary()
                   throws ParseException
Throws parseException if operation cannot act as unary.

ParseException

checkBinary

protected void checkBinary()
                    throws ParseException
Throws parseException if operation cannot act as binary.

ParseException