|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jparsec.OperatorTable<T>
public final class OperatorTable<T>
Builds Parser
to parse expressions with operator-precedence grammar. The operators
and precedences are declared in this table.
Operators have precedences. The higher the precedence number, the higher the precedence. For the same precedence, prefix > postfix > left-associative > non-associative > right-asscociative.
For example:
Unary<Integer> negate = new Unary<Integer>() {... return -n; }
; Binaryplus = new Binary () {... return a + b; }}; Binary minus = new Binary calculator = new OperatorTable() .prefix(terms.token("-").retn(negate), 100) .infixl(terms.token("+").retn(plus), 10) .infixl(terms.token("-").retn(minus), 10) .infixl(terms.token("*").retn(multiply), 20) .infixl(terms.token("/").retn(divide), 20) .build(Terminals.IntegerLiteral.PARSER.map(stringToInteger)); Parser parser = calculator.from( terms.tokenizer().or(Terminals.IntegerLiteral.TOKENIZER), Scanners.WHITESPACES.optional()); return parser.parse(text); }
Constructor Summary | |
---|---|
OperatorTable()
|
Method Summary | |
---|---|
Parser<T> |
build(Parser<? extends T> operand)
Builds a Parser based on information in this OperatorTable . |
OperatorTable<T> |
infixl(Parser<? extends Map2<? super T,? super T,? extends T>> parser,
int precedence)
Adds an infix left-associative binary operator. |
OperatorTable<T> |
infixn(Parser<? extends Map2<? super T,? super T,? extends T>> parser,
int precedence)
Adds an infix non-associative binary operator. |
OperatorTable<T> |
infixr(Parser<? extends Map2<? super T,? super T,? extends T>> parser,
int precedence)
Adds an infix right-associative binary operator. |
OperatorTable<T> |
postfix(Parser<? extends Map<? super T,? extends T>> parser,
int precedence)
Adds a postfix unary operator. |
OperatorTable<T> |
prefix(Parser<? extends Map<? super T,? extends T>> parser,
int precedence)
Adds a prefix unary operator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OperatorTable()
Method Detail |
---|
public OperatorTable<T> prefix(Parser<? extends Map<? super T,? extends T>> parser, int precedence)
parser
- the parser for the operator.precedence
- the precedence number.
public OperatorTable<T> postfix(Parser<? extends Map<? super T,? extends T>> parser, int precedence)
parser
- the parser for the operator.precedence
- the precedence number.
public OperatorTable<T> infixl(Parser<? extends Map2<? super T,? super T,? extends T>> parser, int precedence)
parser
- the parser for the operator.precedence
- the precedence number.
public OperatorTable<T> infixr(Parser<? extends Map2<? super T,? super T,? extends T>> parser, int precedence)
parser
- the parser for the operator.precedence
- the precedence number.
public OperatorTable<T> infixn(Parser<? extends Map2<? super T,? super T,? extends T>> parser, int precedence)
parser
- the parser for the operator.precedence
- the precedence number.
public Parser<T> build(Parser<? extends T> operand)
Parser
based on information in this OperatorTable
.
operand
- parser for the operands.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |