Interface Grammar

  • All Known Implementing Classes:
    DefaultXMLGrammar

    public interface Grammar
    Object of this class provides the grammar rules for parsing the expression. Parser uses this class to parse the string expression in list of Expression Tokens, and Compiler uses it to build the expression tree.
    • Method Detail

      • isDelimiter

        boolean isDelimiter​(ExpressionToken token)
        Checks whether the token is a delimiter or not.
        Parameters:
        token - the token
        Returns:
        true if the token is delimiter false otherwise.
      • isDelimiter

        boolean isDelimiter​(String token)
        Checks whether the token is a delimiter or not.
        Parameters:
        token - the token
        Returns:
        true if the token is delimiter false otherwise.
      • isApproachable

        boolean isApproachable​(String token)
        Checks whether the given token is approachable using any of the pattern or not. Given token can be partially or fully constructed token during parsing process. Parser generally calls this method to check whether the current token can be combined with next character of expression to form some meaningful token or not. If not, then it utilize the existing collected characters as one token, otherwise it keep collecting characters.
        Parameters:
        token - the token, partially or full constructed, to check whether it can approach to any expression token pattern or not.
        Returns:
        true if the token pattern is approachable false otherwise.
      • isAllowed

        boolean isAllowed​(String token)
        Checks whether the token is allowed or not. A token is fully constructed token. Parser generally calls this method to check whether the current token is a valid token as per the production rules or not.
        Parameters:
        token - the token which is to be checked for its validity
        Returns:
        true if the token is allowed false otherwise.
      • isOperator

        boolean isOperator​(ExpressionToken token)
        Checks whether the given token is an operator or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is an operator false otherwise
      • isOperator

        boolean isOperator​(String token)
        Checks whether the given token is an operator or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is an operator false otherwise
      • isFunction

        boolean isFunction​(ExpressionToken token)
        Checks whether the token is an function or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is an function false otherwise
      • isFunction

        boolean isFunction​(String token)
        Checks whether the token is an function or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is an function false otherwise
      • addFunction

        void addFunction​(String functionName)
        Use this method to add any function identification to the grammar. Grammar implementation will generally load the function identification itself from some configuration file. Like, in case of DefaultXMLGrammar implementation, it is loaded from grammar.xml. However, developer may opt to add functions using API also.
        Parameters:
        functionName - name of the function to add
      • isBinaryOperator

        boolean isBinaryOperator​(ExpressionToken token)
        Checks whether the given token is a binary operator or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is a binary operator false otherwise
      • isBinaryOperator

        boolean isBinaryOperator​(String token)
        Checks whether the given token is a binary operator or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is a binary operator false otherwise
      • isUnary

        boolean isUnary​(ExpressionToken operator)
        Checks whether the given operator is a unary operator or not.
        Parameters:
        operator - the operator to check
        Returns:
        true if the operator is used as unary operator false otherwise.
      • isUnary

        boolean isUnary​(String operator)
        Checks whether the given operator is a unary operator or not.
        Parameters:
        operator - the operator to check
        Returns:
        true if the operator is used as unary operator false otherwise.
      • getPrecedenceOrder

        int getPrecedenceOrder​(ExpressionToken operator,
                               boolean isUnary)
        Gets the precedence order of the given operator
        Parameters:
        operator - the operator to check for precedence
        isUnary - true if the operator is unary, as an operator can behave either as unary or as binary
        Returns:
        the precedence order of the operator
      • getPrecedenceOrder

        int getPrecedenceOrder​(String operator,
                               boolean isUnary)
        Gets the precedence order of the given operator
        Parameters:
        operator - the operator to check for precedence
        isUnary - true if the operator is unary, as an operator can behave either as unary or as binary
        Returns:
        the precedence order of the operator
      • isLeftBracket

        boolean isLeftBracket​(ExpressionToken token)
        Checks whether the token is a left bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token can be used as left bracket false otherwise.
      • isLeftBracket

        boolean isLeftBracket​(String token)
        Checks whether the token is a left bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token can be used as left bracket false otherwise.
      • isRightBracket

        boolean isRightBracket​(ExpressionToken token)
        Checks whether the token is a right bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token can be used as right bracket false otherwise.
      • isRightBracket

        boolean isRightBracket​(String token)
        Checks whether the token is a right bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token can be used as right bracket false otherwise.
      • isBracket

        boolean isBracket​(ExpressionToken token)
        Check whether the given token is a bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is a bracket false otherwise
      • isBracket

        boolean isBracket​(String token)
        Check whether the given token is a bracket or not.
        Parameters:
        token - the token to check
        Returns:
        true if the token is a bracket false otherwise
      • getOppositeBracket

        String getOppositeBracket​(String bracket)
        Returns the opposite bracket for the given bracket.
        Parameters:
        bracket - the bracket for which we need to find the opposite bracket
        Returns:
        the opposite part of bracket w.r.t given bracket
      • isIgnoreBlank

        boolean isIgnoreBlank()
        Checks whether to ignore the blanks in expression or not. It tells the parser whether to exclude the extra blanks while parsing or not.
        Returns:
        true if parser wants to exclude the blanks false otherwise.