Class LineNumberingShuntingYard
java.lang.Object
com.singularsys.jep.configurableparser.ShuntingYard
com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard
- All Implemented Interfaces:
GrammarParser
Version of the shunting yard algorithm which sets lines numbers in the parse tree.
By convention numbering starts from line 1 column 1.
Must be used with the ConfigurableParser and LineNumberingNodeFactory.
Jep jep = new Jep( new StandardConfigurableParser(), new LineNumberingNodeFactory(), new LineNumberingShuntingYard.LineNumberGrammarParserFactory());
- Since:
- 3.4.0
- Author:
- rich
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNested classes/interfaces inherited from class com.singularsys.jep.configurableparser.ShuntingYard
ShuntingYard.PrefixRes, ShuntingYard.ShuntingYardGrammarParserFactory -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stack<com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard.Position>Stack to track positions when pushing and popping operatorsFields inherited from class com.singularsys.jep.configurableparser.ShuntingYard
DUMP, implicitMul, it, jep, matchers, nf, nodes, ops, sentinel -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCallback function used by GrammarMatchersprotected voidpopOp()Pops an operator off the Operator stack, and creates a new node.protected voidprefix()Matches identifies, numbers, prefix operators and plugged in grammar matchers.protected voidThe pushOp function is worth some explanation Say 1+2*3 is parsed.Methods inherited from class com.singularsys.jep.configurableparser.ShuntingYard
compareOps, dumpState, expression, getIterator, parse, parsePrefixSuffix, prefixSuffix, prefixSuffixUnchecked, prefixUnchecked, setIterator
-
Field Details
-
posns
protected final Stack<com.singularsys.jep.misc.lineNumbering.LineNumberingShuntingYard.Position> posnsStack to track positions when pushing and popping operators
-
-
Constructor Details
-
LineNumberingShuntingYard
Constructor- Parameters:
jep-gm-
-
-
Method Details
-
parseSubExpression
Description copied from class:ShuntingYardCallback function used by GrammarMatchers- Specified by:
parseSubExpressionin interfaceGrammarParser- Overrides:
parseSubExpressionin classShuntingYard- Returns:
- node tree
- Throws:
ParseException- if the input cannot be parsed
-
popOp
Description copied from class:ShuntingYardPops an operator off the Operator stack, and creates a new node. The children of the node are popped off the node stack and the result is pushed onto the node stack.- Overrides:
popOpin classShuntingYard- Throws:
ParseException
-
prefix
Description copied from class:ShuntingYardMatches identifies, numbers, prefix operators and plugged in grammar matchers. Wrapper function around theShuntingYard.prefixUnchecked()- Overrides:
prefixin classShuntingYard- Throws:
ParseException- if input fails to match or error construction node tree
-
pushOp
Description copied from class:ShuntingYardThe pushOp function is worth some explanation Say 1+2*3 is parsed. First + is pushed onto the stack, then * is pushed. For 1*2+3. * is pushed, when + is encountered * has tighter precedence so it and the top two elements from the node stack are popped, the result computed and pushed on the node stack. Special cases -1+2 [uminus,+],[1] -> [+],[-1] -> [+],[-1,2] -> [],[(-1)+2] -1^2 [uminus,^],[1] -> [uminus,^],[1] -> [uminus,^],[1,2] -> [uminus],[1^2] -> [],[-(1^2)] 1^-2 [^],[1] -> [^,uminus],[1] ->[^,uminus],[1,2] -> [^],[1,(-2)] ->[],[1^(-2)]- Overrides:
pushOpin classShuntingYardtok- Token operator came from- Throws:
ParseException
-