org.scijava.sjep
Class ExpressionParser

java.lang.Object
  extended by org.scijava.sjep.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 Summary
ExpressionParser()
          Creates 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
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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.


Copyright © 2015 SciJava. All rights reserved.