Interface Grammar
-
- All Known Implementing Classes:
DefaultXMLGrammar
public interface GrammarObject 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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddFunction(String functionName)Use this method to add any function identification to the grammar.StringgetOppositeBracket(String bracket)Returns the opposite bracket for the given bracket.intgetPrecedenceOrder(String operator, boolean isUnary)Gets the precedence order of the given operatorintgetPrecedenceOrder(ExpressionToken operator, boolean isUnary)Gets the precedence order of the given operatorbooleanisAllowed(String token)Checks whether the token is allowed or not.booleanisApproachable(String token)Checks whether the given token is approachable using any of the pattern or not.booleanisBinaryOperator(String token)Checks whether the given token is a binary operator or not.booleanisBinaryOperator(ExpressionToken token)Checks whether the given token is a binary operator or not.booleanisBracket(String token)Check whether the given token is a bracket or not.booleanisBracket(ExpressionToken token)Check whether the given token is a bracket or not.booleanisDelimiter(String token)Checks whether the token is a delimiter or not.booleanisDelimiter(ExpressionToken token)Checks whether the token is a delimiter or not.booleanisFunction(String token)Checks whether the token is an function or not.booleanisFunction(ExpressionToken token)Checks whether the token is an function or not.booleanisIgnoreBlank()Checks whether to ignore the blanks in expression or not.booleanisLeftBracket(String token)Checks whether the token is a left bracket or not.booleanisLeftBracket(ExpressionToken token)Checks whether the token is a left bracket or not.booleanisOperator(String token)Checks whether the given token is an operator or not.booleanisOperator(ExpressionToken token)Checks whether the given token is an operator or not.booleanisRightBracket(String token)Checks whether the token is a right bracket or not.booleanisRightBracket(ExpressionToken token)Checks whether the token is a right bracket or not.booleanisUnary(String operator)Checks whether the given operator is a unary operator or not.booleanisUnary(ExpressionToken operator)Checks whether the given operator is a unary operator or not.
-
-
-
Method Detail
-
isDelimiter
boolean isDelimiter(ExpressionToken token)
Checks whether the token is a delimiter or not.- Parameters:
token- the token- Returns:
trueif the token is delimiterfalseotherwise.
-
isDelimiter
boolean isDelimiter(String token)
Checks whether the token is a delimiter or not.- Parameters:
token- the token- Returns:
trueif the token is delimiterfalseotherwise.
-
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:
trueif the token pattern is approachablefalseotherwise.
-
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:
trueif the token is allowedfalseotherwise.
-
isOperator
boolean isOperator(ExpressionToken token)
Checks whether the given token is an operator or not.- Parameters:
token- the token to check- Returns:
trueif the token is an operatorfalseotherwise
-
isOperator
boolean isOperator(String token)
Checks whether the given token is an operator or not.- Parameters:
token- the token to check- Returns:
trueif the token is an operatorfalseotherwise
-
isFunction
boolean isFunction(ExpressionToken token)
Checks whether the token is an function or not.- Parameters:
token- the token to check- Returns:
trueif the token is an functionfalseotherwise
-
isFunction
boolean isFunction(String token)
Checks whether the token is an function or not.- Parameters:
token- the token to check- Returns:
trueif the token is an functionfalseotherwise
-
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:
trueif the token is a binary operatorfalseotherwise
-
isBinaryOperator
boolean isBinaryOperator(String token)
Checks whether the given token is a binary operator or not.- Parameters:
token- the token to check- Returns:
trueif the token is a binary operatorfalseotherwise
-
isUnary
boolean isUnary(ExpressionToken operator)
Checks whether the given operator is a unary operator or not.- Parameters:
operator- the operator to check- Returns:
trueif the operator is used as unary operatorfalseotherwise.
-
isUnary
boolean isUnary(String operator)
Checks whether the given operator is a unary operator or not.- Parameters:
operator- the operator to check- Returns:
trueif the operator is used as unary operatorfalseotherwise.
-
getPrecedenceOrder
int getPrecedenceOrder(ExpressionToken operator, boolean isUnary)
Gets the precedence order of the given operator- Parameters:
operator- the operator to check for precedenceisUnary- 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 precedenceisUnary- 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:
trueif the token can be used as left bracketfalseotherwise.
-
isLeftBracket
boolean isLeftBracket(String token)
Checks whether the token is a left bracket or not.- Parameters:
token- the token to check- Returns:
trueif the token can be used as left bracketfalseotherwise.
-
isRightBracket
boolean isRightBracket(ExpressionToken token)
Checks whether the token is a right bracket or not.- Parameters:
token- the token to check- Returns:
trueif the token can be used as right bracketfalseotherwise.
-
isRightBracket
boolean isRightBracket(String token)
Checks whether the token is a right bracket or not.- Parameters:
token- the token to check- Returns:
trueif the token can be used as right bracketfalseotherwise.
-
isBracket
boolean isBracket(ExpressionToken token)
Check whether the given token is a bracket or not.- Parameters:
token- the token to check- Returns:
trueif the token is a bracketfalseotherwise
-
isBracket
boolean isBracket(String token)
Check whether the given token is a bracket or not.- Parameters:
token- the token to check- Returns:
trueif the token is a bracketfalseotherwise
-
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:
trueif parser wants to exclude the blanksfalseotherwise.
-
-