public class ExpressionParser extends Object
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.
| Constructor and Description |
|---|
ExpressionParser()
Creates an expression parser with the standard set of operators and default
separator symbols (
, for group elements, ; for statements). |
ExpressionParser(BiFunction<ExpressionParser,String,ParseOperation> parseOperationFactory)
Creates an expression parser with custom
ParseOperation behavior. |
ExpressionParser(Collection<? extends Operator> operators)
Creates an expression parser with custom operators and default separator
symbols (
, for group elements, ; for statements). |
ExpressionParser(Collection<? extends Operator> operators,
String elementSeparator,
String statementSeparator)
Creates an expression parser with custom operators and separator symbols.
|
ExpressionParser(Collection<? extends Operator> operators,
String elementSeparator,
String statementSeparator,
BiFunction<ExpressionParser,String,ParseOperation> parseOperationFactory)
Creates an expression parser maximally customized to your requirements!
|
ExpressionParser(String elementSeparator,
String statementSeparator)
Creates an expression parser with custom separator symbols.
|
| Modifier and Type | Method and Description |
|---|---|
String |
elementSeparator()
Separator symbol between group elements.
|
List<Operator> |
operators()
Gets the list of operators available to expressions.
|
LinkedList<Object> |
parsePostfix(String expression)
Parses the given mathematical expression into a queue in Reverse Polish
notation (i.e., postfix notation).
|
SyntaxTree |
parseTree(String expression)
Parses the given mathematical expression into a syntax tree.
|
String |
statementSeparator()
Separator symbol between statements.
|
public ExpressionParser()
, for group elements, ; for statements).Operators.standardList()public ExpressionParser(Collection<? extends Operator> operators)
, for group elements, ; for statements).operators - The collection of operators available to expressions.public ExpressionParser(String elementSeparator, String statementSeparator)
elementSeparator - The symbol to use for separating group elements.statementSeparator - The symbol to use for separating statements.public ExpressionParser(BiFunction<ExpressionParser,String,ParseOperation> parseOperationFactory)
ParseOperation behavior.
Customizing this behavior allows you to control lower level parsing
characteristics, including what character sequences constitute whitespace,
literals, variables, operators, group terminators, element separators, and
statement separators.parseOperationFactory - A function producing ParseOperation
objects with behavior customized to your requirements. The typical
use case is to subclass ParseOperation to override one or
more of its parseSomething methods, and then pass
MyCustomParseOperation::new for this argument.public ExpressionParser(Collection<? extends Operator> operators, String elementSeparator, String statementSeparator)
operators - The collection of operators available to expressions.elementSeparator - The symbol to use for separating group elements.statementSeparator - The symbol to use for separating statements.public ExpressionParser(Collection<? extends Operator> operators, String elementSeparator, String statementSeparator, BiFunction<ExpressionParser,String,ParseOperation> parseOperationFactory)
operators - The collection of operators available to expressions.elementSeparator - The symbol to use for separating group elements.statementSeparator - The symbol to use for separating statements.parseOperationFactory - A function producing ParseOperation
objects with behavior customized to your requirements. The typical
use case is to subclass ParseOperation to override one or
more of its parseSomething methods, and then pass
MyCustomParseOperation::new for this argument.public SyntaxTree parseTree(String expression)
expression - The mathematical expression to parse.IllegalArgumentException - if the syntax of the expression is
incorrect.public LinkedList<Object> parsePostfix(String expression)
expression - The mathematical expression to parse.IllegalArgumentException - if the syntax of the expression is
incorrect.public List<Operator> operators()
public String elementSeparator()
,). Example: f(1, 2)public String statementSeparator()
;). Example: x = 1; y = 2; z = x + yCopyright © 2015–2023 SciJava. All rights reserved.