use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parsePostfixExpression.
// PostfixExpression .= PrimaryExpression
// | PostfixExpression '.' Identifier
// | PostfixExpression '[' Expression ']'
private boolean parsePostfixExpression(ExprTreeHolder tree) throws IOException {
TokenType tt;
if (!parsePrimaryExpression(tree)) {
return false;
}
while ((tt = lexer.peekToken()) == TokenType.LEX_OPEN_BOX || tt == TokenType.LEX_SELECTION) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
TokenValue tv = objectPool.tokenValuePool.get();
lexer.consumeToken();
if (tt == TokenType.LEX_OPEN_BOX) {
// subscript operation
parseExpression(treeR);
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(Operation.OpKind_SUBSCRIPT_OP, treeL, treeR, null, newTree);
if (lexer.consumeToken() == TokenType.LEX_CLOSE_BOX) {
tree.setInnerTree(newTree);
continue;
}
}
tree.setInnerTree(null);
return false;
} else if (tt == TokenType.LEX_SELECTION) {
// field selection operation
if ((tt = lexer.consumeToken(tv)) != TokenType.LEX_IDENTIFIER) {
throw new HyracksDataException("second argument of selector must be an " + "identifier (got" + String.valueOf(Lexer.strLexToken(tt)) + ")");
}
AttributeReference newTree = objectPool.attrRefPool.get();
AttributeReference.createAttributeReference(treeL, tv.getStrValue(), false, newTree);
tree.setInnerTree(newTree);
}
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class FunctionalTester method handle_diff.
/*********************************************************************
* Function: handle_diff
* Purpose:
*
* @throws IOException
*********************************************************************/
public static void handle_diff(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) throws IOException {
ExprTreeHolder tree = new ExprTreeHolder(objectPool);
ExprTreeHolder tree2 = new ExprTreeHolder(objectPool);
Value value1 = new Value(objectPool);
Value value2 = new Value(objectPool);
get_two_exprs(line, tree, tree2, state, parameters, objectPool);
if (tree.getInnerTree() != null || tree2.getInnerTree() != null) {
if (!evaluate_expr(tree, value1, parameters, objectPool)) {
print_error_message("Couldn't evaluate first expression.\n", state);
} else if (!evaluate_expr(tree2, value2, parameters, objectPool)) {
print_error_message("Couldn't evaluate second expressions.\n", state);
} else if (value1.sameAs(value2)) {
print_error_message("the expressions are the same.", state);
assert (false);
}
}
return;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class FunctionalTester method handle_same.
/*********************************************************************
* Function: handle_same
* Purpose:
*
* @throws IOException
*********************************************************************/
public static void handle_same(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) throws IOException {
ExprTreeHolder tree = new ExprTreeHolder(objectPool);
ExprTreeHolder tree2 = new ExprTreeHolder(objectPool);
Value value1 = new Value(objectPool);
Value value2 = new Value(objectPool);
try {
get_two_exprs(line, tree, tree2, state, parameters, objectPool);
if (tree.getInnerTree() != null || tree2.getInnerTree() != null) {
if (parameters.debug) {
System.out.println("Sameeval has two trees:");
System.out.print(" ");
print_expr(tree, state, parameters, objectPool);
System.out.print(" ");
print_expr(tree2, state, parameters, objectPool);
}
if (!evaluate_expr(tree, value1, parameters, objectPool)) {
print_error_message("Couldn't evaluate first expression.\n", state);
} else if (!evaluate_expr(tree2, value2, parameters, objectPool)) {
print_error_message("Couldn't evaluate second expressions.\n", state);
} else if (!value1.sameAs(value2)) {
print_error_message("the expressions are different.", state);
assert (false);
}
if (parameters.debug) {
System.out.println("They evaluated to: ");
System.out.println(" " + value1);
System.out.println(" " + value2);
}
}
} catch (Exception e) {
e.printStackTrace();
assert (false);
}
return;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseClassAd.
public boolean parseClassAd(ClassAd ad, boolean full) throws IOException {
TokenType tt;
ad.clear();
if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_BOX) {
return false;
}
tt = lexer.peekToken();
TokenValue tv = objectPool.tokenValuePool.get();
ExprTreeHolder tree = objectPool.mutableExprPool.get();
while (tt != TokenType.LEX_CLOSE_BOX) {
// Get the name of the expression
tv.reset();
tree.reset();
tt = lexer.consumeToken(tv);
if (tt == TokenType.LEX_SEMICOLON) {
// that was bitten by this.
continue;
}
if (tt != TokenType.LEX_IDENTIFIER) {
throw new HyracksDataException("while parsing classad: expected LEX_IDENTIFIER " + " but got " + Lexer.strLexToken(tt));
}
// consume the intermediate '='
if ((tt = lexer.consumeToken()) != TokenType.LEX_BOUND_TO) {
throw new HyracksDataException("while parsing classad: expected LEX_BOUND_TO " + " but got " + Lexer.strLexToken(tt));
}
isExpr = false;
parseExpression(tree);
if (tree.getInnerTree() == null) {
throw new HyracksDataException("parse expression returned empty tree");
}
// insert the attribute into the classad
if (!ad.insert(tv.getStrValue().toString(), tree)) {
throw new HyracksDataException("Couldn't insert value to classad");
}
// the next token must be a ';' or a ']'
tt = lexer.peekToken();
if (tt != TokenType.LEX_SEMICOLON && tt != TokenType.LEX_CLOSE_BOX) {
throw new HyracksDataException("while parsing classad: expected LEX_SEMICOLON or " + "LEX_CLOSE_BOX but got " + Lexer.strLexToken(tt));
}
// while the first case accounts for optional beginning semicolons.
while (tt == TokenType.LEX_SEMICOLON) {
lexer.consumeToken();
tt = lexer.peekToken();
}
}
lexer.consumeToken();
// if a full parse was requested, ensure that input is exhausted
if (full && (lexer.consumeToken() != TokenType.LEX_END_OF_INPUT)) {
throw new HyracksDataException("while parsing classad: expected LEX_END_OF_INPUT for " + "full parse but got " + Lexer.strLexToken(tt));
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseAdditiveExpression.
// AdditiveExpression .= MultiplicativeExpression
// | AdditiveExpression '+' MultiplicativeExpression
// | AdditiveExpression '-' MultiplicativeExpression
private boolean parseAdditiveExpression(ExprTreeHolder tree) throws IOException {
if (!parseMultiplicativeExpression(tree)) {
return false;
}
TokenType tt = lexer.peekToken();
while (tt == TokenType.LEX_PLUS || tt == TokenType.LEX_MINUS) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
lexer.consumeToken();
parseMultiplicativeExpression(treeR);
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation((tt == TokenType.LEX_PLUS) ? Operation.OpKind_ADDITION_OP : Operation.OpKind_SUBTRACTION_OP, treeL, treeR, null, newTree);
tree.setInnerTree(newTree);
} else {
tree.setInnerTree(null);
return false;
}
tt = lexer.peekToken();
}
return true;
}
Aggregations