Class ExpressionParser

java.lang.Object
org.scijava.parse.ExpressionParser

public class ExpressionParser extends Object
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 Details

    • ExpressionParser

      public ExpressionParser()
      Creates an expression parser with the default set of operators.
    • ExpressionParser

      public ExpressionParser(Collection<? extends Operator> operators)
      Creates an expression parser with the given set of operators.
      Parameters:
      operators - The collection of operators available to expressions.
  • Method Details

    • parseTree

      public SyntaxTree parseTree(String expression)
      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

      public LinkedList<Object> parsePostfix(String expression)
      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.