Package org.scijava.parse
Class ExpressionParser
java.lang.Object
org.scijava.parse.ExpressionParser
A parser for mathematical expressions, using Dijkstra's famous shunting-yard
algorithm.
It is important to note that this parser does not attempt to evaluate the expression in any way; rather, it only provides the parsed tree according to the desired operators.
- Author:
- Curtis Rueden
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an expression parser with the default set of operators.ExpressionParser
(Collection<? extends Operator> operators) Creates an expression parser with the given set of operators. -
Method Summary
Modifier and TypeMethodDescriptionparsePostfix
(String expression) Parses the given mathematical expression into a queue in Reverse Polish notation (i.e., postfix notation).Parses the given mathematical expression into a syntax tree.
-
Constructor Details
-
ExpressionParser
public ExpressionParser()Creates an expression parser with the default set of operators. -
ExpressionParser
Creates an expression parser with the given set of operators.- Parameters:
operators
- The collection of operators available to expressions.
-
-
Method Details
-
parseTree
Parses the given mathematical expression into a syntax tree.- Parameters:
expression
- The mathematical expression to parse.- Returns:
- Parsed hierarchy of tokens.
- Throws:
IllegalArgumentException
- if the syntax of the expression is incorrect.
-
parsePostfix
Parses the given mathematical expression into a queue in Reverse Polish notation (i.e., postfix notation).- Parameters:
expression
- The mathematical expression to parse.- Returns:
- Parsed queue of tokens in postfix notation.
- Throws:
IllegalArgumentException
- if the syntax of the expression is incorrect.
-