Class ExpressionParser


  • public class ExpressionParser
    extends Object
    A parser for mathematical expressions. The parser class defines a method parse() which takes a string and returns an ExpressionNode that holds a representation of the expression. Parsing is implemented in the form of a recursive descent parser.
    • Constructor Detail

      • ExpressionParser

        public ExpressionParser()
    • Method Detail

      • parse

        public ExpressionNode parse​(String expression)
        Parse a mathematical expression in a string and return an ExpressionNode. This is a convenience method that first converts the string into a linked list of tokens using the expression tokenizer provided by the Tokenizer class.
        Parameters:
        expression - the string holding the input
        Returns:
        the internal representation of the expression in form of an expression tree made out of ExpressionNode objects
      • parse

        public ExpressionNode parse​(LinkedList<Token> tokens)
        Parse a mathematical expression in contained in a list of tokens and return an ExpressionNode.
        Parameters:
        tokens - a list of tokens holding the tokenized input
        Returns:
        the internal representation of the expression in form of an expression tree made out of ExpressionNode objects