Package cs2110

Class RpnParser

java.lang.Object
cs2110.RpnParser

public class RpnParser extends Object
Utilities for parsing RPN expressions.
  • Constructor Details Link icon

    • RpnParser Link icon

      public RpnParser()
  • Method Details Link icon

    • parse Link icon

      public static Expression parse(String exprString, Map<String,UnaryFunction> funcDefs) throws IncompleteRpnException, UndefinedFunctionException
      Parse 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`.