Search in sources :

Example 16 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseRelationalExpression.

// RelationalExpression .= ShiftExpression
// | RelationalExpression '<' ShiftExpression
// | RelationalExpression '>' ShiftExpression
// | RelationalExpression '<=' ShiftExpression
// | RelationalExpression '>=' ShiftExpression
private boolean parseRelationalExpression(ExprTreeHolder tree) throws IOException {
    TokenType tt;
    if (!parseShiftExpression(tree)) {
        return false;
    }
    tt = lexer.peekToken();
    while (tt == TokenType.LEX_LESS_THAN || tt == TokenType.LEX_GREATER_THAN || tt == TokenType.LEX_LESS_OR_EQUAL || tt == TokenType.LEX_GREATER_OR_EQUAL) {
        int op = Operation.OpKind_NO_OP;
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseShiftExpression(treeR);
        switch(tt) {
            case LEX_LESS_THAN:
                op = Operation.OpKind_LESS_THAN_OP;
                break;
            case LEX_LESS_OR_EQUAL:
                op = Operation.OpKind_LESS_OR_EQUAL_OP;
                break;
            case LEX_GREATER_THAN:
                op = Operation.OpKind_GREATER_THAN_OP;
                break;
            case LEX_GREATER_OR_EQUAL:
                op = Operation.OpKind_GREATER_OR_EQUAL_OP;
                break;
            default:
                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;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 17 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseLogicalANDExpression.

// LogicalANDExpression .= InclusiveORExpression
// | LogicalANDExpression '&&' InclusiveORExpression
private boolean parseLogicalANDExpression(ExprTreeHolder tree) throws IOException {
    if (!parseInclusiveORExpression(tree)) {
        return false;
    }
    while ((lexer.peekToken()) == TokenType.LEX_LOGICAL_AND) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseInclusiveORExpression(treeR);
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_LOGICAL_AND_OP, treeL, treeR, null, newTree);
            tree.setInnerTree(newTree);
        } else {
            tree.setInnerTree(null);
            return false;
        }
    }
    return true;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation)

Example 18 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseExclusiveORExpression.

// ExclusiveORExpression .= ANDExpression
// | ExclusiveORExpression '^' ANDExpression
private boolean parseExclusiveORExpression(ExprTreeHolder tree) throws IOException {
    if (!parseANDExpression(tree)) {
        return false;
    }
    while ((lexer.peekToken()) == TokenType.LEX_BITWISE_XOR) {
        lexer.consumeToken();
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        parseANDExpression(treeR);
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_BITWISE_XOR_OP, treeL, treeR, null, newTree);
            tree.setInnerTree(newTree);
        } else {
            tree.setInnerTree(null);
            return false;
        }
    }
    return true;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation)

Example 19 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseExprList.

public boolean parseExprList(ExprList list, boolean full) throws IOException {
    TokenType tt;
    ExprTreeHolder tree = objectPool.mutableExprPool.get();
    ExprList loe = objectPool.exprListPool.get();
    if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_BRACE) {
        throw new HyracksDataException("while parsing expression list:  expected LEX_OPEN_BRACE" + " but got " + Lexer.strLexToken(tt));
    // return false;
    }
    tt = lexer.peekToken();
    while (tt != TokenType.LEX_CLOSE_BRACE) {
        // parse the expression
        parseExpression(tree);
        if (tree.getInnerTree() == null) {
            throw new HyracksDataException("while parsing expression list:  expected " + "LEX_CLOSE_BRACE or LEX_COMMA but got " + Lexer.strLexToken(tt));
        }
        // insert the expression into the list
        loe.add(tree);
        // the next token must be a ',' or a '}'
        tt = lexer.peekToken();
        if (tt == TokenType.LEX_COMMA) {
            lexer.consumeToken();
        } else if (tt != TokenType.LEX_CLOSE_BRACE) {
            throw new HyracksDataException("while parsing expression list:  expected " + "LEX_CLOSE_BRACE or LEX_COMMA but got " + Lexer.strLexToken(tt));
        }
    }
    lexer.consumeToken();
    list.setValue(ExprList.createExprList(loe, objectPool));
    // if a full parse was requested, ensure that input is exhausted
    if (full && (lexer.consumeToken() != TokenType.LEX_END_OF_INPUT)) {
        list.clear();
        throw new HyracksDataException("while parsing expression list:  expected " + "LEX_END_OF_INPUT for full parse but got " + Lexer.strLexToken(tt));
    }
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) ExprList(org.apache.asterix.external.classad.ExprList) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 20 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class FunctionalTester method handle_sameq.

/*********************************************************************
     * Function: handle_sameq
     * Purpose:
     * @param objectPool 
     *
     * @throws IOException
     *********************************************************************/
public static void handle_sameq(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) throws IOException {
    ExprTreeHolder tree = new ExprTreeHolder(objectPool);
    ExprTreeHolder tree2 = new ExprTreeHolder(objectPool);
    get_two_exprs(line, tree, tree2, state, parameters, objectPool);
    if (tree.getInnerTree() != null || tree2.getInnerTree() != null) {
        if (!tree.sameAs(tree2)) {
            print_error_message("the expressions are different.", state);
        }
    }
    return;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder)

Aggregations

ExprTreeHolder (org.apache.asterix.external.classad.ExprTreeHolder)25 TokenType (org.apache.asterix.external.classad.Lexer.TokenType)13 Operation (org.apache.asterix.external.classad.Operation)13 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)13 TokenValue (org.apache.asterix.external.classad.TokenValue)5 Value (org.apache.asterix.external.classad.Value)5 ExprList (org.apache.asterix.external.classad.ExprList)2 Literal (org.apache.asterix.external.classad.Literal)2 IOException (java.io.IOException)1 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)1 AMutableNumberFactor (org.apache.asterix.external.classad.AMutableNumberFactor)1 AttributeReference (org.apache.asterix.external.classad.AttributeReference)1 ClassAd (org.apache.asterix.external.classad.ClassAd)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1