|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.singularsys.jep.configurableparser.ShuntingYard
public class ShuntingYard
An operator precedence parser based on the shunting yard algorithm.
Nested Class Summary | |
---|---|
static class |
ShuntingYard.ShuntingYardGrammarParserFactory
Factory creating new ShuntingYard instances. |
Field Summary | |
---|---|
protected static boolean |
DUMP
|
protected static Operator |
implicitMul
|
protected Lookahead2Iterator<Token> |
it
|
protected Jep |
jep
|
protected java.util.List<GrammarMatcher> |
matchers
|
protected NodeFactory |
nf
|
protected java.util.Stack<Node> |
nodes
|
protected java.util.Stack<Operator> |
ops
|
protected static Operator |
sentinel
|
Constructor Summary | |
---|---|
ShuntingYard(Jep jep,
java.util.List<GrammarMatcher> gm)
|
Method Summary | |
---|---|
protected boolean |
compareOps(Operator op1,
Operator op2)
Compare operators based on their precedence and associativity. |
protected void |
dumpState(java.lang.String msg)
|
protected void |
expression()
Match prefixSuffix() optionally followed by a binary or ternary operator or an implicit multiplication. |
Lookahead2Iterator<Token> |
getIterator()
|
Node |
parse(java.util.Iterator<Token> input)
Main entry point, construct tree from sequence of tokens. |
Node |
parseSubExpression()
Callback function used by GrammerMatchers |
protected void |
popOp()
Pops an operator off the Operator stack, and creates a new node. |
protected void |
prefix()
Matches identifies, numbers, prefix operators and plugged in grammar matchers. |
protected void |
prefixSuffix()
A prefix() optionally followed by suffix operators. |
protected void |
pushOp(Operator op,
Token tok)
The pushOp function is worth some explanation Say 1+2*3 is parsed. |
void |
setIterator(Lookahead2Iterator<Token> it)
Set the iterator used by the GrammarParser.parseSubExpression() |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final boolean DUMP
protected java.util.Stack<Operator> ops
protected java.util.Stack<Node> nodes
protected Lookahead2Iterator<Token> it
protected java.util.List<GrammarMatcher> matchers
protected Jep jep
protected static final Operator sentinel
protected static final Operator implicitMul
protected NodeFactory nf
Constructor Detail |
---|
public ShuntingYard(Jep jep, java.util.List<GrammarMatcher> gm)
Method Detail |
---|
public Node parse(java.util.Iterator<Token> input) throws ParseException
parse
in interface GrammarParser
input
- iterator with the list of tokens
ParseException
public Node parseSubExpression() throws ParseException
parseSubExpression
in interface GrammarParser
ParseException
protected void expression() throws ParseException
ParseException
protected void prefixSuffix() throws ParseException
ParseException
protected void prefix() throws ParseException
ParseException
protected void pushOp(Operator op, Token tok) throws ParseException
op
- tok
- Token operator came from
ParseException
protected boolean compareOps(Operator op1, Operator op2)
op1
- op2
-
protected void popOp() throws ParseException
ParseException
protected void dumpState(java.lang.String msg)
public Lookahead2Iterator<Token> getIterator()
public void setIterator(Lookahead2Iterator<Token> it)
GrammarParser
GrammarParser.parseSubExpression()
setIterator
in interface GrammarParser
it
- the iterator
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |