Class Parser.OperatorParser

  • Enclosing class:
    Parser

    private class Parser.OperatorParser
    extends java.lang.Object
    An operator-precedence parser for the binary operations we understand. It implements an algorithm from Wikipedia that uses recursion rather than having an explicit stack of operators and values.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Parser.Operator currentOperator
      The operator we have just scanned, in the same way that Parser.c is the character we have just read.
    • Constructor Summary

      Constructors 
      Constructor Description
      OperatorParser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void nextOperator()
      Updates currentOperator to be an operator read from the input, or Parser.Operator.STOP if there is none.
      (package private) ExpressionNode parse​(ExpressionNode lhs, int minPrecedence)
      Parse a subexpression whose left-hand side is lhs and where we only consider operators with precedence at least minPrecedence.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • currentOperator

        private Parser.Operator currentOperator
        The operator we have just scanned, in the same way that Parser.c is the character we have just read. If we were not able to scan an operator, this will be Parser.Operator.STOP.
    • Constructor Detail

      • OperatorParser

        OperatorParser()
                throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • parse

        ExpressionNode parse​(ExpressionNode lhs,
                             int minPrecedence)
                      throws java.io.IOException
        Parse a subexpression whose left-hand side is lhs and where we only consider operators with precedence at least minPrecedence.
        Returns:
        the parsed subexpression
        Throws:
        java.io.IOException
      • nextOperator

        private void nextOperator()
                           throws java.io.IOException
        Updates currentOperator to be an operator read from the input, or Parser.Operator.STOP if there is none.
        Throws:
        java.io.IOException