|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.expr.ExpressionParser<T>
public class ExpressionParser<T>
Parses simple expressions using an implementation of the shunting-yard algorithm.
| Nested Class Summary | |
|---|---|
protected static class |
ExpressionParser.ArrayIndex
An array index identifier. |
protected static class |
ExpressionParser.FunctionCall
An function call identifier. |
protected static class |
ExpressionParser.Identifier
Wraps a string to identify it as an identifier. |
protected static class |
ExpressionParser.Operator
An operator identifier. |
protected static class |
ExpressionParser.OperatorStreamTokenizer
Extends StreamTokenizer slightly to handle multi-character operators. |
| Field Summary | |
|---|---|
protected Stack<Object> |
_operation
The operation stack. |
protected Stack<T> |
_output
The output stack. |
protected ExpressionParser.OperatorStreamTokenizer |
_strtok
The tokenizer from which we acquire tokens. |
protected static Map<String,ExpressionParser.Operator> |
OPERATORS
The operator map. |
protected static Map<String,ExpressionParser.Operator> |
UNARY_ALTERNATES
|
| Constructor Summary | |
|---|---|
ExpressionParser(Reader reader)
Creates a new parser to read from the specified reader. |
|
| Method Summary | |
|---|---|
protected static void |
addOperator(String name,
boolean rightAssociative,
int precedence,
int arity)
Adds an operator to the map. |
protected static void |
addUnaryAlternate(String name,
boolean rightAssociative,
int precedence,
int arity)
Adds an unary alternate for operators that can be both unary and binary. |
protected void |
handle(Object value)
Handles the supplied output value. |
protected T |
handleArrayIndex(String array)
Handles an array index. |
protected T |
handleFunctionCall(String function,
int arity)
Handles a function call. |
protected T |
handleIdentifier(String name)
Handles an identifier. |
protected T |
handleNumber(double value)
Handles a number. |
protected T |
handleOperator(String operator,
int arity)
Handles an operator. |
protected T |
handleString(String value)
Handles a string. |
static void |
main(String... args)
Main method for testing. |
T |
parse()
Parses the expression and returns the object at the top of the stack (or null
if the stack is empty). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ExpressionParser.OperatorStreamTokenizer _strtok
protected Stack<T> _output
protected Stack<Object> _operation
protected static final Map<String,ExpressionParser.Operator> OPERATORS
protected static final Map<String,ExpressionParser.Operator> UNARY_ALTERNATES
| Constructor Detail |
|---|
public ExpressionParser(Reader reader)
| Method Detail |
|---|
public static void main(String... args)
throws Exception
Exception
public T parse()
throws Exception
null
if the stack is empty).
Exception
protected void handle(Object value)
throws Exception
Exception
protected T handleNumber(double value)
throws Exception
Exception
protected T handleString(String value)
throws Exception
Exception
protected T handleOperator(String operator,
int arity)
throws Exception
Exception
protected T handleFunctionCall(String function,
int arity)
throws Exception
Exception
protected T handleArrayIndex(String array)
throws Exception
Exception
protected T handleIdentifier(String name)
throws Exception
Exception
protected static void addOperator(String name,
boolean rightAssociative,
int precedence,
int arity)
protected static void addUnaryAlternate(String name,
boolean rightAssociative,
int precedence,
int arity)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||