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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addFunction(String functionName)
Use this method to add any function identification to the grammar.String
getOppositeBracket(String bracket)
Returns the opposite bracket for the given bracket.int
getPrecedenceOrder(String operator, boolean isUnary)
Gets the precedence order of the given operatorint
getPrecedenceOrder(ExpressionToken operator, boolean isUnary)
Gets the precedence order of the given operatorboolean
isAllowed(String token)
Checks whether the token is allowed or not.boolean
isApproachable(String token)
Checks whether the given token is approachable using any of the pattern or not.boolean
isBinaryOperator(String token)
Checks whether the given token is a binary operator or not.boolean
isBinaryOperator(ExpressionToken token)
Checks whether the given token is a binary operator or not.boolean
isBracket(String token)
Check whether the given token is a bracket or not.boolean
isBracket(ExpressionToken token)
Check whether the given token is a bracket or not.boolean
isDelimiter(String token)
Checks whether the token is a delimiter or not.boolean
isDelimiter(ExpressionToken token)
Checks whether the token is a delimiter or not.boolean
isFunction(String token)
Checks whether the token is an function or not.boolean
isFunction(ExpressionToken token)
Checks whether the token is an function or not.boolean
isIgnoreBlank()
Checks whether to ignore the blanks in expression or not.boolean
isLeftBracket(String token)
Checks whether the token is a left bracket or not.boolean
isLeftBracket(ExpressionToken token)
Checks whether the token is a left bracket or not.boolean
isOperator(String token)
Checks whether the given token is an operator or not.boolean
isOperator(ExpressionToken token)
Checks whether the given token is an operator or not.boolean
isRightBracket(String token)
Checks whether the token is a right bracket or not.boolean
isRightBracket(ExpressionToken token)
Checks whether the token is a right bracket or not.boolean
isUnary(String operator)
Checks whether the given operator is a unary operator or not.boolean
isUnary(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:
true
if the token is delimiterfalse
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 delimiterfalse
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 approachablefalse
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 allowedfalse
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 operatorfalse
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 operatorfalse
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 functionfalse
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 functionfalse
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 operatorfalse
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 operatorfalse
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 operatorfalse
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 operatorfalse
otherwise.
-
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:
true
if the token can be used as left bracketfalse
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 bracketfalse
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 bracketfalse
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 bracketfalse
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 bracketfalse
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 bracketfalse
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 blanksfalse
otherwise.
-
-