Class ExpressionTreeGenerator

java.lang.Object
picasso.parser.ExpressionTreeGenerator

public class ExpressionTreeGenerator extends Object
Parses a string into an expression tree based on rules for arithmetic.
Author:
former student solution, Robert C. Duvall (added comments, exceptions), Sara Sprenkle modified for Picasso
  • Field Details

  • Constructor Details

    • ExpressionTreeGenerator

      public ExpressionTreeGenerator()
  • Method Details

    • makeExpression

      public ExpressionTreeNode makeExpression(String infix)
      Converts the given string into expression tree for easier manipulation.
      Parameters:
      infix - - a non-empty expression to parse.
      Returns:
      ExpressionTreeNode representing the root node of the given infix formula
    • infixToPostfix

      public Stack<Token> infixToPostfix(String infix)
      This method converts the String infix expression to a Stack of tokens, which are in postfix.
      Parameters:
      infix - the String to parse, as we would typically write it
      Returns:
      a stack of tokens, in postfix order
    • infixToPostfix

      private Stack<Token> infixToPostfix(List<Token> tokens)
      This method converts the List of tokens (in infix order) to a Stack of tokens, which are in postfix.
      Parameters:
      tokens - the Tokens, in infix order
      Returns:
      a stack of tokens, in postfix order
    • orderOfOperation

      private int orderOfOperation(Token token)
      Parameters:
      token -
      Returns: