{"id":52,"date":"2021-01-16T20:32:43","date_gmt":"2021-01-16T20:32:43","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/?page_id=52"},"modified":"2021-01-16T21:04:07","modified_gmt":"2021-01-16T21:04:07","slug":"example-of-an-exception-hierarchy","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/","title":{"rendered":"Example of an Exception Hierarchy"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a6d4a891e5cb\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a6d4a891e5cb\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Token\" >Token<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parser\" >Parser<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Exceptions\" >Exceptions<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#ParserException\" >ParserException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#DivisionByZeroException\" >DivisionByZeroException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#ParserIOException\" >ParserIOException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#ParserNumberFormatException\" >ParserNumberFormatException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#UnbalancedParenthesesException\" >UnbalancedParenthesesException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#UnexpectedExtraTokenException\" >UnexpectedExtraTokenException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#UnexpectedTokenFoundException\" >UnexpectedTokenFoundException<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#UnsupportedFeatureException\" >UnsupportedFeatureException<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Results\" >Results<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_1234\" >Parsing [1+2*3\/4]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_1_2_3\" >Parsing [ 1 + 2 * 3]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_33\" >Parsing [3^3]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_1_2_3-2\" >Parsing [(1 + 2) * 3]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_535\" >Parsing [53%5]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_720\" >Parsing [72^0]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_5_-6_-3_4\" >Parsing [+5 + -6 * -(3 * 4)]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_X_1\" >Parsing [ X + 1]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_11_%E2%80%93_6_7\" >Parsing [11 &#8211; 6 7]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_3_%E2%80%93_2_4\" >Parsing [ 3 &#8211; +(2 + 4 ]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_4_50\" >Parsing [4 + 5\/0]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_10_8\" >Parsing [10 ** 8]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_10-59\" >Parsing [(10-5)*9)]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/exceptions\/example-of-an-exception-hierarchy\/#Parsing_8\" >Parsing [\/8]<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Here is an example of how to set up an exception hierarchy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application is a simple expression parser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Token\"><\/span>Token<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the <strong>Token<\/strong> class, which represents the known tokens for the parser to consume.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Class to represent a token for the parser\n * \n * @author Bryan\n *\/\npublic class Token\n{\n  \/**\n   * The allowed token types\n   *\/\n  public static enum TYPE\n  {\n    UNDEFINED,\n    NUMBER,                         \/\/ numeric literal\n    PLUS, MINUS, MULTIPLY, DIVIDE,  \/\/ arithmetic operators\n    REMAINDER, EXPONENTIATION,      \/\/ more arirthmetic operators\n    OPEN_PAREN, CLOSE_PAREN,        \/\/ open and close parentheses\n    END_OF_INPUT                    \/\/ Special token to flag end of input\n  };\n\n  \/**\n   * Returns the type of the token.\n   * \n   * @return token type\n   *\/\n  public TYPE getType()\n  {\n    return m_type;\n  }\n  \n  \/**\n   * Sets the type of the token\n   * \n   * @param type The type to set\n   *\/\n  void setType(TYPE type)\n  {\n    m_type = type;\n  }\n  \n  \/**\n   * Get the token string value\n   *\/\n  public String getValue()\n  {\n    return m_value;\n  }\n  \n  \/**\n   * Sets the token string value\n   * \n   * @param value\n   *\/\n  public void setValue(String value)\n  {\n    m_value = value;\n  }\n\n  \/**\n   * Gets the token offset within the line\n   *\/\n  public int getOffset()\n  {\n    return m_offset;\n  }\n  \n  \/**\n   * Sets the token offset within the line\n   * \n   * @param offset\n   *\/\n  public void setOffset(int offset)\n  {\n    m_offset = offset;\n  }\n\n  \/**\n   * Return a usable string\n   *\/\n  @Override\n  public String toString()\n  {\n    return &quot;Token &quot; + getType() + &quot; &#x5B;&quot; + getValue() + &quot;]&quot; +\n           &quot; Offset: &quot; + getOffset();\n  }\n  \n  \/\/\/\/ Private data \/\/\/\/\n  private TYPE m_type = TYPE.UNDEFINED; \/\/ The token type\n  private String m_value = &quot;&quot;;          \/\/ The token string value\n  private int m_offset = 0;             \/\/ The offset of the token in the line\n  \n  \/**\n   * Main entry point, for testing\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    Token token = new Token();\n    token.setType(Token.TYPE.EXPONENTIATION);\n    token.setValue(&quot;^&quot;);\n    System.out.println(token);\n  }\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parser\"><\/span>Parser<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the source code for the expression <strong>Parser<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\nimport java.io.IOException;\nimport java.io.StreamTokenizer;\nimport java.io.StringReader;\n\n\/**\n  This parser supports an expression represented by\n  the following grammar:\n\n   expression = term {(&quot;+&quot;|&quot;-&quot;) term}\n\n   term = factor {(&quot;*&quot;|&quot;\/&quot;|&quot;%&quot;) factor}\n\n   factor = subfactor &#x5B;&quot;^&quot; subfactor]\n\n   subfactor = &#x5B;&quot;+&quot;|&quot;-&quot;] subexpression\n \n   subexpression = &quot;(&quot; expression &quot;)&quot; | atom\n\n   atom = number\n\n*\/\n\n\/**\n * Class to implement a recursive-descent expression parser.\n * \n * @author Bryan J. Higgs\n *\/\npublic class Parser\n{\n  \/**\n   * Constructor\n   *\/\n  public Parser()\n  {}\n  \n  \/**\n   * Gets the expression string being parsed.\n   *\/\n  public String getExpression()\n  {\n    return m_expression;\n  }\n\n  \/**\n   * Gets the current token for the parse\n   * (changes as the parse state changes)\n   *\/\n  public Token getCurrentToken()\n  {\n    return m_currentToken;\n  }\n  \n  \/**\n   * Top-level parse entry point\n   *\/\n  public double parse(String expression) throws ParserException\n  {\n    System.err.println(&quot;\\nStarting parse on &#x5B;&quot; + expression + &quot;]...&quot;);\n\n    m_expression = expression;    \n    m_reader = new StringReader(expression);\n    try\n    {\n      m_tokenizer = new StreamTokenizer(m_reader);\n      m_tokenizer.ordinaryChar(&#039;\/&#039;); \n                   \/\/ Ensure that &#039;\/&#039; are not considered comment chars\n      \/\/m_tokenizer.slashSlashComments(true);\n      \/\/m_tokenizer.slashStarComments(true);\n      \/\/m_tokenizer.eolIsSignificant(false);\n\n      nextToken(); \/\/ Get the first token from the input.\n\n      double result = parseExpression(); \/\/ Parse the expression until the end.\n\n      if (m_currentToken.getType() != Token.TYPE.END_OF_INPUT)\n      {\n          throw new UnexpectedExtraTokenException(m_currentToken, \n                                                  m_expression);\n      }\n\n      System.err.println(&quot;Value of &#x5B;&quot; + expression + &quot;] : &quot; + result);\n      return result;\n    }\n    finally\n    {\n      \/\/ Close the reader, regardless\n      m_reader.close();\n    }\n  }\n\n  \/\/\/\/ Private methods \/\/\/\/\n  \n  \/**\n   * Returns the next token encountered in the expression\n   *\/\n  private void nextToken() throws ParserException\n  {\n    \/\/ Set token to unknown, in case something goes awry\n    m_currentToken.setType(Token.TYPE.UNDEFINED);\n    m_currentToken.setValue(&quot;&quot;);\n    \n    try\n    {\n      int token = m_tokenizer.nextToken();\n      switch (token)\n      {\n        case StreamTokenizer.TT_NUMBER:\n          System.err.println(&quot;Token: &#x5B;Number] &quot; + m_tokenizer.nval);\n          m_currentToken.setType(Token.TYPE.NUMBER);\n          m_currentToken.setValue(&quot;&quot; + m_tokenizer.nval);          \n          break;\n          \n        case StreamTokenizer.TT_EOF:\n          \/\/ We came to the end of the stream\n          System.err.println(&quot;Token: &#x5B;END_OF_INPUT]&quot;);\n          m_currentToken.setType(Token.TYPE.END_OF_INPUT);\n          m_currentToken.setValue(&quot;&quot;);\n          break;\n          \n        case &#039;+&#039;:\n          System.err.println(&quot;Token: &#x5B;PLUS]&quot;);\n          m_currentToken.setType(Token.TYPE.PLUS);\n          m_currentToken.setValue(&quot;+&quot;);\n          break;\n        case &#039;-&#039;:\n          System.err.println(&quot;Token: &#x5B;MINUS]&quot;);\n          m_currentToken.setType(Token.TYPE.MINUS);\n          m_currentToken.setValue(&quot;-&quot;);\n          break;\n        case &#039;*&#039;:\n          System.err.println(&quot;Token: &#x5B;MULTIPLY]&quot;);\n          m_currentToken.setType(Token.TYPE.MULTIPLY);\n          m_currentToken.setValue(&quot;*&quot;);\n          break;\n        case &#039;\/&#039;:\n          System.err.println(&quot;Token: &#x5B;DIVIDE]&quot;);\n          m_currentToken.setType(Token.TYPE.DIVIDE);\n          m_currentToken.setValue(&quot;\/&quot;);\n          break;\n        case &#039;%&#039;:\n          System.err.println(&quot;Token: &#x5B;REMAINDER]&quot;);\n          m_currentToken.setType(Token.TYPE.REMAINDER);\n          m_currentToken.setValue(&quot;%&quot;);\n          break;\n        case &#039;^&#039;:\n          System.err.println(&quot;Token: &#x5B;EXPONENTIATION]&quot;);\n          m_currentToken.setType(Token.TYPE.EXPONENTIATION);\n          m_currentToken.setValue(&quot;^&quot;);\n          break;\n        case &#039;(&#039;:\n          System.err.println(&quot;Token: &#x5B;OPEN_PAREN]&quot;);\n          m_currentToken.setType(Token.TYPE.OPEN_PAREN);\n          m_currentToken.setValue(&quot;(&quot;);\n          break;\n        case &#039;)&#039;:\n          System.err.println(&quot;Token: &#x5B;CLOSE_PAREN]&quot;);\n          m_currentToken.setType(Token.TYPE.CLOSE_PAREN);\n          m_currentToken.setValue(&quot;)&quot;);\n          break;\n          \n        case StreamTokenizer.TT_WORD:\n          m_currentToken.setValue(m_tokenizer.sval);\n          throw new UnsupportedFeatureException(m_currentToken, m_expression,\n                                                &quot;Variable name&quot;);\n          \/\/ break;\n          \n        default:\n          System.err.println(&quot;Stream Token: &quot; + token + \n                             &quot; &#039;&quot; + (char) (token) + &quot;&#039;&quot;);\n          break;\n      }\n    \n      \/\/ If we failed to get a valid token, report it...\n      if (m_currentToken.getType() == Token.TYPE.UNDEFINED)\n      {\n          throw new UnexpectedTokenFoundException(m_currentToken,\n                                                  m_expression);\n      }\n    }\n    catch (IOException ioe)\n    {\n      throw new ParserIOException(getExpression(), 0, ioe);\n    }\n  }\n\n  \/**\n   * Parse an expression\n   * expression = term { (&quot;+&quot;|&quot;-&quot;) term }\n   *\/\n  private double parseExpression() throws ParserException\n  {\n    System.err.println(&quot;In expression...&quot;);\n    double result = parseTerm();\n    System.err.println(&quot;Back in expression...&quot;);\n\n    for ( Token.TYPE type = m_currentToken.getType();\n          ( type == Token.TYPE.PLUS || type == Token.TYPE.MINUS );\n          type = m_currentToken.getType()\n        )\n    {\n        nextToken();\n\n        double temp = parseTerm();\n        System.err.println(&quot;Back in expression...&quot;);\n        \n        switch (type)\n        {\n        case PLUS:\n            result += temp;\n            break;\n        case MINUS:\n            result -= temp;\n            break;\n        }\n    }\n    return result;\n  }\n\n  \/**\n   * Parse a term\n   * term = factor { (&quot;*&quot;|&quot;\/&quot;|&quot;%&quot;) factor }\n   *\/\n  private double parseTerm() throws ParserException\n  {\n    System.err.println(&quot;In term...&quot;);\n    double result = parseFactor();\n    System.err.println(&quot;Back in term...&quot;);\n\n    for ( Token.TYPE type = m_currentToken.getType();\n          ( type == Token.TYPE.MULTIPLY ||\n            type == Token.TYPE.DIVIDE || type == Token.TYPE.REMAINDER );\n          type = m_currentToken.getType()\n        )\n    {\n        nextToken();\n\n        double temp = parseFactor();\n        System.err.println(&quot;Back in term...&quot;);\n        \n        switch (type)\n        {\n        case MULTIPLY:\n            result *= temp;\n            break;\n        case DIVIDE:\n            if (temp == 0.0)\n            {\n                throw new DivisionByZeroException( m_expression,\n                                                   0 \/\/ Offset\n                                                 );\n            }\n            result \/= temp;\n            break;\n        case REMAINDER:\n            if (temp == 0.0)\n            {\n                throw new DivisionByZeroException( m_expression,\n                                                   0 \/\/ Offset\n                                                 );\n            }\n            result = (long) result % (long) temp;\n            break;\n        }\n    }\n\n    return result;\n  }\n\n  \/**\n   * Parse a factor\n   * factor = subfactor &#x5B;&quot;^&quot; subfactor]\n   *\/\n  private double parseFactor() throws ParserException\n  {\n    System.err.println(&quot;In factor...&quot;);\n    double result = parseSubfactor();\n    System.err.println(&quot;Back in factor...&quot;);\n    \n    Token.TYPE type = m_currentToken.getType();\n    if ( type == Token.TYPE.EXPONENTIATION )\n    {\n        nextToken();\n\n        double temp = parseSubfactor();\n        System.err.println(&quot;Back in factor...&quot;);\n\n        result = Math.pow(result, temp);\n    }\n    return result;\n  }\n\n  \/**\n   * Parse a &#039;subfactor&#039;\n   * subfactor = &#x5B;&quot;+&quot;|&quot;-&quot;] subexpression\n   *\/\n  private double parseSubfactor() throws ParserException\n  {\n    System.err.println(&quot;In subfactor...&quot;);\n    \n    Token.TYPE type = m_currentToken.getType();\n    if ( type == Token.TYPE.PLUS || type == Token.TYPE.MINUS )\n    {\n        nextToken();\n    }\n\n    double result = parseSubexpression();\n    System.err.println(&quot;Back in subfactor...&quot;);\n    \n    switch (type)\n    {\n    case MINUS:\n        result = -result;\n        break;\n    case PLUS:\n        \/\/ Do nothing\n    }\n    return result;\n  }\n\n  \/**\n   * Parse precedence level 5\n   * subexpression = &quot;(&quot; expression &quot;)&quot; | atom\n   *\/\n  private double parseSubexpression() throws ParserException\n  {\n    System.err.println(&quot;In subexpression...&quot;);\n    \n    double result = 0.0;\n    \n    Token.TYPE type = m_currentToken.getType();\n    if ( type == Token.TYPE.OPEN_PAREN )\n    {\n        nextToken();\n\n        result = parseExpression();\n        System.err.println(&quot;Back in subexpression...&quot;);\n\n        type = m_currentToken.getType();\n        if (type != Token.TYPE.CLOSE_PAREN)\n        {\n            throw new UnbalancedParenthesesException( m_expression,\n                                                      0 \/\/ Offset\n                                                    );\n        }\n\n        nextToken();\n    }\n    else\n    {\n        result = parseAtom();\n        System.err.println(&quot;Back in subexpression...&quot;);\n    }\n    \n    return result;\n  }\n\n  \/**\n   * Parse atoms\n   * atom = number\n   *\/\n  private double parseAtom() throws ParserException\n  {\n    System.err.println(&quot;In atom...&quot;);\n    \n    double result = 0.0;\n    \n    Token.TYPE type = m_currentToken.getType();\n    switch (type)\n    {\n    case NUMBER:\n        try\n        {\n          result = Double.parseDouble( m_currentToken.getValue() );\n        }\n        catch (NumberFormatException nfe)\n        {\n          throw new ParserNumberFormatException(m_currentToken,\n                                                m_expression, nfe);\n        }\n        nextToken();\n        break;\n        \n    default:\n        throw new UnexpectedTokenFoundException( m_currentToken,\n                                                 m_expression);\n    }\n    return result;\n  }\n  \n  \/**\n   * Convenient output for Parser\n   * \n   * @return a string representation for the Parser object\n   *\/\n  @Override\n  public String toString()\n  {\n    return &quot;Parser: &quot; + getExpression() + &quot;\\n&quot; +\n                        getCurrentToken();\n  }\n  \n  \/**\n   * Test Expression method for testing\n   * \n   * @param expression\n   *\/\n  public static void testExpr(String expression)\n  {\n    try\n    {\n      double result = m_parser.parse(expression);\n      System.err.println(&quot;Result of &#039;&quot; + m_parser.getExpression() + \n                         &quot;&#039; = &quot; + result);\n    }\n    catch (ParserException pe)\n    {\n        System.err.println(&quot;&gt;&gt;&gt; &quot; + pe.getFormattedMessage());\n    }\n  }\n\n  \/**\n   * Main entry point for testing\n   * \n   * @param args the command line arguments\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    m_parser = new Parser();\n    testExpr(&quot;1+2*3\/4&quot;);\n    testExpr(&quot;  1 + 2 * 3&quot;);\n    testExpr(&quot;3^3&quot;);\n    testExpr(&quot;(1 + 2) * 3&quot;);\n    testExpr(&quot;53%5&quot;);\n    testExpr(&quot;72^0&quot;);\n    testExpr(&quot;+5 + -6 * -(3 * 4)&quot;);\n    testExpr(&quot; X + 1&quot;);\n    testExpr(&quot;11 - 6 7&quot;);\n    testExpr(&quot; 3 - +(2 + 4  &quot;);\n    testExpr(&quot;4 + 5\/0&quot;);\n    testExpr(&quot;10 ** 8&quot;);\n    testExpr(&quot;(10-5)*9)&quot;);\n    testExpr(&quot;\/8&quot;);\n  }\n  \n  \/\/\/\/ Private data \/\/\/\/\n  private String m_expression = &quot;&quot;;\n  private StringReader m_reader;\n  private StreamTokenizer m_tokenizer;\n  private Token m_currentToken = new Token(); \/\/ UNDEFINED token type\n  \n  private static Parser m_parser;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Exceptions\"><\/span>Exceptions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The exceptions that this parser uses form a hierarchy:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ParserException\n  DivisionByZeroException\n  ParserIOException\n  ParserNumberFormatException\n  UnbalancedParenthesesException\n  UnexpectedExtraTokenException\n  UnexpectedTokenFoundException\n  UnsupportedFeatureException<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By structuring these exceptions in this way, we can simplify the parser code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ParserException\"><\/span>ParserException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Class to act as the superclass of all Parser exceptions.\n *\n * @author Bryan J. Higgs\n *\/\npublic abstract class ParserException extends Exception\n{\n  \/**\n   * Gets the message associated with an exception.\n   * (Abstract method)\n   *\/\n  @Override\n  public abstract String getMessage();\n\n  \/**\n   * Gets the Line of source where the exception occurred\n   *\/\n  public String getLine()\n  {\n    return m_line;\n  }\n\n  \/**\n   * Gets the character offset within the line where the\n   * exception occurred.\n   *\/\n  public int getOffset()\n  {\n    return m_offset;\n  }\n\n  \/**\n   * Gets a formatted message of the form:\n   *\n   * &lt;message&gt;\n   * &lt;contents of line&gt;\n   *       ^\n   * (the above caret is aligned with the character\n   *  corresponding to the offset within the line).\n   *\/\n  public String getFormattedMessage()\n  {\n    String msg = getMessage() + &quot;\\n&quot;;\n    msg += getLine() + &quot;\\n&quot;;\n    for (int i = 0; i &lt; getOffset(); i++)\n    {\n      msg += &quot; &quot;;\n    }\n    msg += &quot;^\\n&quot;; \/\/ The caret (^) should point to the error location.\n\n    return msg;\n  }\n\n  \/**\n   * Constructor\n   * (protected because it&#039;s only used by derived classes)\n   *\/\n  protected ParserException(String line, int offset)\n  {\n    m_line = line;\n    m_offset = offset;\n  }\n\n  \/\/\/ Private data \/\/\/\n  private String  m_line;   \/\/ The line containing the expression\n  private int     m_offset; \/\/ The offset within the line\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"DivisionByZeroException\"><\/span>DivisionByZeroException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Exception thrown when a division by zero was detected by the parser.\n *\n * @author Bryan J. Higgs\n *\/\npublic class DivisionByZeroException extends ParserException\n{\n  \/**\n   * Constructor\n   *\/\n  public DivisionByZeroException(String line, int offset)\n  {\n    super(line, offset);\n  }\n\n  \/**\n   * Gets the message for the exception\n   * (implementation of abstract method)\n   *\/\n  public String getMessage()\n  {\n    return &quot;Division by zero attempted&quot;;\n  }\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ParserIOException\"><\/span>ParserIOException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\nimport java.io.IOException;\n\n\/**\n * Class to represent an IOException when encountered in the parser\n *\n * @author Bryan J. Higgs\n *\/\npublic class ParserIOException extends ParserException\n{\n  public ParserIOException(String line, int offset, IOException ioe)\n  {\n    super(line, offset);\n    m_ioe = ioe;\n  }\n\n  @Override\n  public String getMessage()\n  {\n    return &quot;An IOException occurred during parsing&quot;;\n  }\n\n  \/\/\/ Private data \/\/\/\n  private IOException m_ioe;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ParserNumberFormatException\"><\/span>ParserNumberFormatException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Class to represent a NumberFormatException that occurred\n * during parsing.\n *\n * @author Bryan J. Higgs\n *\/\npublic class ParserNumberFormatException extends ParserException\n{\n  public ParserNumberFormatException(Token token, String line, \n                                     NumberFormatException nfe)\n  {\n    super(line, token.getOffset());\n    m_token = token;\n    m_nfe = nfe;\n  }\n\n  @Override\n  public String getMessage()\n  {\n    return &quot;A NumberFormatException occurred during parsing&quot;;\n  }\n\n  \/\/\/ Private data \/\/\/\n  private Token m_token;\n  private NumberFormatException m_nfe;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"UnbalancedParenthesesException\"><\/span>UnbalancedParenthesesException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Exception thrown when unbalanced parentheses were detected by the parser.\n *\n * @author Bryan J. Higgs\n *\/\npublic class UnbalancedParenthesesException extends ParserException\n{\n  \/**\n   * Constructor\n   *\/\n  public UnbalancedParenthesesException(String line, int offset)\n  {\n    super(line, offset);\n  }\n\n  \/**\n   * Gets the message for the exception\n   * (implementation of abstract method)\n   *\/\n  public String getMessage()\n  {\n    return &quot;Unbalanced parentheses&quot;;\n  }\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"UnexpectedExtraTokenException\"><\/span>UnexpectedExtraTokenException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Exception thrown when an unexpected extra token was detected by the parser.\n *\n * @author Bryan J. Higgs\n *\/\npublic class UnexpectedExtraTokenException extends ParserException\n{\n  \/**\n   * Constructor\n   *\/\n  public UnexpectedExtraTokenException(Token token, String line)\n  {\n    super(line, token.getOffset());\n    m_token = token;\n  }\n\n  \/**\n   * Gets the message for the exception\n   * (implementation of abstract method)\n   *\/\n  public String getMessage()\n  {\n    return &quot;Unexpected token after end of expression: &quot; + m_token;\n  }\n\n  \/\/\/ Private data \/\/\/\n  private Token m_token;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"UnexpectedTokenFoundException\"><\/span>UnexpectedTokenFoundException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Exception thrown when no expression was found by the parser.\n *\n * @author Bryan J. Higgs\n *\/\npublic class UnexpectedTokenFoundException extends ParserException\n{\n  \/**\n   * Constructor\n   *\/\n  public UnexpectedTokenFoundException(Token token, String line)\n  {\n    super(line, token.getOffset());\n    m_token = token;\n  }\n\n  \/**\n   * Gets the message for the exception\n   * (implementation of abstract method)\n   *\/\n  public String getMessage()\n  {\n    return &quot;Unexpected token encountered &quot; + m_token;\n  }\n\n  \/\/\/\/ Private data \/\/\/\/\n  private Token m_token;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"UnsupportedFeatureException\"><\/span>UnsupportedFeatureException<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage parser;\n\n\/**\n * Class to represent an unsupported feature exception\n * found during parsing.\n *\n * @author Bryan J. Higgs\n *\/\npublic class UnsupportedFeatureException extends ParserException\n{\n  public UnsupportedFeatureException(Token token, String line, String msg)\n  {\n    super(line, token.getOffset());\n    m_token = token;\n    m_msg = msg;\n  }\n  \n  @Override\n  public String getMessage()\n  {\n    return &quot;Unsupported feature: &quot; + m_msg;\n  }\n\n  \/\/\/\/ Private data \/\/\/\/\n  private Token m_token;\n  private String m_msg;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Results\"><\/span>Results<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what the expression parser produces for output, from the test cases supplied from the <strong>Parser<\/strong>&#8216;s main method:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_1234\"><\/span>Parsing [1+2*3\/4]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [1+2*3\/4]...\nToken: [Number] 1.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 2.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MULTIPLY]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 3.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [DIVIDE]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 4.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [1+2*3\/4] : 2.5\nResult of '1+2*3\/4' = 2.5<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_1_2_3\"><\/span>Parsing [ 1 + 2 * 3]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [  1 + 2 * 3]...\nToken: [Number] 1.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 2.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MULTIPLY]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 3.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [  1 + 2 * 3] : 7.0\nResult of '  1 + 2 * 3' = 7.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_33\"><\/span>Parsing [3^3]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [3^3]...\nToken: [Number] 3.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [EXPONENTIATION]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nToken: [Number] 3.0\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [3^3] : 27.0\nResult of '3^3' = 27.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_1_2_3-2\"><\/span>Parsing [(1 + 2) * 3]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [(1 + 2) * 3]...\nToken: [OPEN_PAREN]\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nToken: [Number] 1.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 2.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [CLOSE_PAREN]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nBack in subexpression...\nToken: [MULTIPLY]\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 3.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [(1 + 2) * 3] : 9.0\nResult of '(1 + 2) * 3' = 9.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_535\"><\/span>Parsing [53%5]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [53%5]...\nToken: [Number] 53.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [REMAINDER]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 5.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [53%5] : 3.0\nResult of '53%5' = 3.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_720\"><\/span>Parsing [72^0]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [72^0]...\nToken: [Number] 72.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [EXPONENTIATION]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nToken: [Number] 0.0\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [72^0] : 1.0\nResult of '72^0' = 1.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_5_-6_-3_4\"><\/span>Parsing [+5 + -6 * -(3 * 4)]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [+5 + -6 * -(3 * 4)]...\nToken: [PLUS]\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nToken: [Number] 5.0\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] -6.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MULTIPLY]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [MINUS]\nIn factor...\nIn subfactor...\nToken: [OPEN_PAREN]\nIn subexpression...\nToken: [Number] 3.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MULTIPLY]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 4.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [CLOSE_PAREN]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nBack in subexpression...\nToken: [END_OF_INPUT]\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nValue of [+5 + -6 * -(3 * 4)] : 77.0\nResult of '+5 + -6 * -(3 * 4)' = 77.0<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_X_1\"><\/span>Parsing [ X + 1]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [ X + 1]...\n&gt;&gt;&gt; Unsupported feature: Variable name\n X + 1\n^<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_11_%E2%80%93_6_7\"><\/span>Parsing [11 &#8211; 6 7]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [11 - 6 7]...\nToken: [Number] 11.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MINUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 6.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [Number] 7.0\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\n>>> Unexpected token after end of expression: Token NUMBER [7.0] Offset: 0\n11 - 6 7\n^<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_3_%E2%80%93_2_4\"><\/span>Parsing [ 3 &#8211; +(2 + 4 ]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [ 3 - +(2 + 4  ]...\nToken: [Number] 3.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MINUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [PLUS]\nIn term...\nIn factor...\nIn subfactor...\nToken: [OPEN_PAREN]\nIn subexpression...\nToken: [Number] 2.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 4.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nBack in subexpression...\n&gt;&gt;&gt; Unbalanced parentheses\n 3 - +(2 + 4  \n^<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_4_50\"><\/span>Parsing [4 + 5\/0]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [4 + 5\/0]...\nToken: [Number] 4.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [PLUS]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nToken: [Number] 5.0\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [DIVIDE]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [Number] 0.0\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [END_OF_INPUT]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\n>>> Division by zero attempted\n4 + 5\/0\n^<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_10_8\"><\/span>Parsing [10 ** 8]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [10 ** 8]...\nToken: [Number] 10.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [MULTIPLY]\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nToken: [MULTIPLY]\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\n>>> Unexpected token encountered Token MULTIPLY [*] Offset: 0\n10 ** 8\n^<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_10-59\"><\/span>Parsing [(10-5)*9)]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [(10-5)*9)]...\nToken: [OPEN_PAREN]\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nToken: [Number] 10.0\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\nToken: [Number] -5.0\nBack in subexpression...\nBack in subfactor...\nBack in factor...\nBack in term...\nBack in expression...\nBack in subexpression...\n&gt;&gt;&gt; Unbalanced parentheses\n(10-5)*9)<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Parsing_8\"><\/span>Parsing [\/8]<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Starting parse on [\/8]...\nToken: [DIVIDE]\nIn expression...\nIn term...\nIn factor...\nIn subfactor...\nIn subexpression...\nIn atom...\n&gt;&gt;&gt; Unexpected token encountered Token DIVIDE [\/] Offset: 0\n\/8\n^<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is an example of how to set up an exception hierarchy. The application is a simple expression parser. Token Here&#8217;s the Token class, which represents the known tokens for the parser to consume. Parser Here&#8217;s the source code for the expression Parser: Exceptions The exceptions that this parser uses form a hierarchy: ParserException DivisionByZeroException [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":42,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","ocean_front_end_style_editor":"no","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-52","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":7,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/52\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/52\/revisions\/66"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/42"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/media?parent=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}