use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseExpression.
/**
* Parse an expression
*
* @param buffer
* Buffer containing the string representation of the expression.
* @param full
* If this parameter is true, the parse is considered to succeed
* only if the expression was parsed successfully and no other
* tokens are left.
* @return pointer to the expression object if successful, or null otherwise
*/
public ExprTree parseExpression(String buffer, boolean full) throws IOException {
stringLexerSource.setNewSource(buffer);
ExprTreeHolder mutableExpr = objectPool.mutableExprPool.get();
if (lexer.initialize(stringLexerSource)) {
parseExpression(mutableExpr, full);
}
return mutableExpr.getInnerTree();
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseInclusiveORExpression.
// InclusiveORExpression .= ExclusiveORExpression
// | InclusiveORExpression '|' ExclusiveORExpression
public boolean parseInclusiveORExpression(ExprTreeHolder tree) throws IOException {
if (!parseExclusiveORExpression(tree)) {
return false;
}
while ((lexer.peekToken()) == TokenType.LEX_BITWISE_OR) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
lexer.consumeToken();
parseExclusiveORExpression(treeR);
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(Operation.OpKind_BITWISE_OR_OP, treeL, treeR, null, newTree);
tree.setInnerTree(newTree);
} else {
tree.setInnerTree(null);
return false;
}
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseArgumentList.
// ArgumentList .= '(' ListOfArguments ')'
// ListOfArguments .= (epsilon)
// | ListOfArguments ',' Expression
public boolean parseArgumentList(ExprList argList) throws IOException {
TokenType tt;
argList.clear();
if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_PAREN) {
throw new HyracksDataException("expected LEX_OPEN_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
// return false;
}
tt = lexer.peekToken();
ExprTreeHolder tree = objectPool.mutableExprPool.get();
while (tt != TokenType.LEX_CLOSE_PAREN) {
// parse the expression
tree.reset();
parseExpression(tree);
if (tree.getInnerTree() == null) {
argList.clear();
return false;
}
// insert the expression into the argument list
argList.add(tree.getInnerTree());
// the next token must be a ',' or a ')'
// or it can be a ';' if using old ClassAd semantics
tt = lexer.peekToken();
if (tt == TokenType.LEX_COMMA || (tt == TokenType.LEX_SEMICOLON && false)) {
lexer.consumeToken();
} else if (tt != TokenType.LEX_CLOSE_PAREN) {
argList.clear();
throw new HyracksDataException("expected LEX_COMMA or LEX_CLOSE_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
// return false;
}
}
lexer.consumeToken();
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method evaluateFunction.
public ExprTree evaluateFunction(String functionName, ExprList argList) throws HyracksDataException {
Value val = objectPool.valuePool.get();
AMutableNumberFactor factor = objectPool.numFactorPool.get();
ExprTreeHolder tree = objectPool.mutableExprPool.get();
((Literal) argList.get(0)).getComponents(val, factor);
AMutableCharArrayString string_value = objectPool.strPool.get();
if (val.isStringValue(string_value)) {
if (functionName.equalsIgnoreCase("absTime")) {
tree.setInnerTree(Literal.createAbsTime(string_value, objectPool));
} else if (functionName.equalsIgnoreCase("relTime")) {
tree.setInnerTree(Literal.createRelTime(string_value, objectPool));
} else {
tree.setInnerTree(FunctionCall.createFunctionCall(functionName, argList, objectPool));
}
} else {
tree.setInnerTree(FunctionCall.createFunctionCall(functionName, argList, objectPool));
}
return tree;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseMultiplicativeExpression.
// MultiplicativeExpression .= UnaryExpression
// | MultiplicativeExpression '*' UnaryExpression
// | MultiplicativeExpression '/' UnaryExpression
// | MultiplicativeExpression '%' UnaryExpression
private boolean parseMultiplicativeExpression(ExprTreeHolder tree) throws IOException {
if (!parseUnaryExpression(tree)) {
return false;
}
TokenType tt = lexer.peekToken();
while (tt == TokenType.LEX_MULTIPLY || tt == TokenType.LEX_DIVIDE || tt == TokenType.LEX_MODULUS) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
int op;
lexer.consumeToken();
parseUnaryExpression(treeR);
switch(tt) {
case LEX_MULTIPLY:
op = Operation.OpKind_MULTIPLICATION_OP;
break;
case LEX_DIVIDE:
op = Operation.OpKind_DIVISION_OP;
break;
case LEX_MODULUS:
op = Operation.OpKind_MODULUS_OP;
break;
default:
// Make gcc's -wuninitalized happy
op = Operation.OpKind_NO_OP;
throw new HyracksDataException("ClassAd: Should not reach here");
}
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(op, treeL, treeR, null, newTree);
tree.setInnerTree(newTree);
} else {
tree.setInnerTree(null);
return false;
}
tt = lexer.peekToken();
}
return true;
}
Aggregations