Package cs2110
Class RpnParser
java.lang.Object
cs2110.RpnParser
Utilities for parsing RPN expressions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Expression
parse
(String exprString, Map<String, UnaryFunction> funcDefs) Parse the RPN expression in `exprString` and return the corresponding expression tree.
-
Constructor Details
-
Method Details
-
parse
public static Expression parse(String exprString, Map<String, UnaryFunction> funcDefs) throws IncompleteRpnException, UndefinedFunctionExceptionParse the RPN expression in `exprString` and return the corresponding expression tree. Tokens must be separated by whitespace. Valid tokens include decimal numbers (scientific notation allowed), arithmetic operators (+, -, *, /, ^), function names (with the suffix "()"), and variable names (anything else). When a function name is encountered, the corresponding function will be retrieved from `funcDefs` using the name (without "()" suffix) as the key.- Throws:
IncompleteRpnException
- if the expression has too few or too many operands relative to operators and functions.UndefinedFunctionException
- if a function name applied in `exprString` is not present in `funcDefs`.
-