Package picasso.parser
Class ExpressionTreeGenerator
java.lang.Object
picasso.parser.ExpressionTreeGenerator
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioninfixToPostfix(String infix) This method converts the String infix expression to a Stack of tokens, which are in postfix.infixToPostfix(List<Token> tokens) This method converts the List of tokens (in infix order) to a Stack of tokens, which are in postfix.makeExpression(String infix) Converts the given string into expression tree for easier manipulation.private intorderOfOperation(Token token)
-
Field Details
-
CONSTANT
private static final int CONSTANT- See Also:
-
GROUPING
private static final int GROUPING- See Also:
-
ADD_OR_SUBTRACT
private static final int ADD_OR_SUBTRACT- See Also:
-
MULTIPLY_OR_DIVIDE
private static final int MULTIPLY_OR_DIVIDE- See Also:
-
-
Constructor Details
-
ExpressionTreeGenerator
public ExpressionTreeGenerator()
-
-
Method Details
-
makeExpression
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
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
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
- Parameters:
token-- Returns:
-