public class SyntaxTree
extends java.lang.Object
Constructor and Description |
---|
SyntaxTree(java.lang.String exp)
Build up the syntax tree of the input arithmetic expression.
|
Modifier and Type | Method and Description |
---|---|
double |
evaluate() |
java.lang.String |
infix() |
java.lang.String |
postfix() |
java.lang.String |
prefix() |
public SyntaxTree(java.lang.String exp) throws java.lang.ArithmeticException
exp
- is a String of arithmetic expression in infix notation, e.g. "2+2+3".java.lang.ArithmeticException
- ("Illegal Expression") if the input string is not a valid arithmetic expression.public double evaluate() throws java.lang.ArithmeticException
java.lang.ArithmeticException
- ("Divided by zero") if divided by 0;public java.lang.String infix()
public java.lang.String prefix()
public java.lang.String postfix()