Search in sources :

Example 1 with Operation

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

the class ClassAdParser method parseUnaryExpression.

// UnaryExpression .= PostfixExpression
// | UnaryOperator UnaryExpression
// ( where UnaryOperator is one of { -, +, ~, ! } )
private boolean parseUnaryExpression(ExprTreeHolder tree) throws IOException {
    TokenType tt = lexer.peekToken();
    if (tt == TokenType.LEX_MINUS || tt == TokenType.LEX_PLUS || tt == TokenType.LEX_BITWISE_NOT || tt == TokenType.LEX_LOGICAL_NOT) {
        lexer.consumeToken();
        ExprTreeHolder treeM = objectPool.mutableExprPool.get();
        int op = Operation.OpKind_NO_OP;
        parseUnaryExpression(treeM);
        switch(tt) {
            case LEX_MINUS:
                op = Operation.OpKind_UNARY_MINUS_OP;
                break;
            case LEX_PLUS:
                op = Operation.OpKind_UNARY_PLUS_OP;
                break;
            case LEX_BITWISE_NOT:
                op = Operation.OpKind_BITWISE_NOT_OP;
                break;
            case LEX_LOGICAL_NOT:
                op = Operation.OpKind_LOGICAL_NOT_OP;
                break;
            default:
                throw new HyracksDataException("ClassAd: Shouldn't Get here");
        }
        if (treeM.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(op, treeM, null, null, newTree);
            tree.setInnerTree(newTree);
        } else {
            tree.setInnerTree(null);
            return (false);
        }
        return true;
    } else {
        return parsePostfixExpression(tree);
    }
}
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 2 with Operation

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

the class ClassAdParser method parseShiftExpression.

// ShiftExpression .= AdditiveExpression
// | ShiftExpression '<<' AdditiveExpression
// | ShiftExpression '>>' AdditiveExpression
// | ShiftExpression '>>>' AditiveExpression
private boolean parseShiftExpression(ExprTreeHolder tree) throws IOException {
    if (!parseAdditiveExpression(tree)) {
        return false;
    }
    TokenType tt = lexer.peekToken();
    while (tt == TokenType.LEX_LEFT_SHIFT || tt == TokenType.LEX_RIGHT_SHIFT || tt == TokenType.LEX_URIGHT_SHIFT) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        int op;
        lexer.consumeToken();
        parseAdditiveExpression(treeR);
        switch(tt) {
            case LEX_LEFT_SHIFT:
                op = Operation.OpKind_LEFT_SHIFT_OP;
                break;
            case LEX_RIGHT_SHIFT:
                op = Operation.OpKind_RIGHT_SHIFT_OP;
                break;
            case LEX_URIGHT_SHIFT:
                op = Operation.OpKind_URIGHT_SHIFT_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;
}
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 3 with Operation

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

the class ClassAdParser method parseANDExpression.

// ANDExpression .= EqualityExpression
// | ANDExpression '&' EqualityExpression
private boolean parseANDExpression(ExprTreeHolder tree) throws IOException {
    if (!parseEqualityExpression(tree)) {
        return false;
    }
    while ((lexer.peekToken()) == TokenType.LEX_BITWISE_AND) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseEqualityExpression(treeR);
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_BITWISE_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 4 with Operation

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

the class ClassAdParser method parseLogicalORExpression.

// LogicalORExpression .= LogicalANDExpression
// | LogicalORExpression '||' LogicalANDExpression
private boolean parseLogicalORExpression(ExprTreeHolder tree) throws IOException {
    if (!parseLogicalANDExpression(tree)) {
        return false;
    }
    while ((lexer.peekToken()) == TokenType.LEX_LOGICAL_OR) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseLogicalANDExpression(treeR);
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_LOGICAL_OR_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 5 with Operation

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

the class ClassAdParser method parseEqualityExpression.

// EqualityExpression .= RelationalExpression
// | EqualityExpression '==' RelationalExpression
// | EqualityExpression '!=' RelationalExpression
// | EqualityExpression '=?=' RelationalExpression
// | EqualityExpression '=!=' RelationalExpression
private boolean parseEqualityExpression(ExprTreeHolder tree) throws IOException {
    TokenType tt;
    int op = Operation.OpKind_NO_OP;
    if (!parseRelationalExpression(tree)) {
        return false;
    }
    tt = lexer.peekToken();
    while (tt == TokenType.LEX_EQUAL || tt == TokenType.LEX_NOT_EQUAL || tt == TokenType.LEX_META_EQUAL || tt == TokenType.LEX_META_NOT_EQUAL) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseRelationalExpression(treeR);
        switch(tt) {
            case LEX_EQUAL:
                op = Operation.OpKind_EQUAL_OP;
                break;
            case LEX_NOT_EQUAL:
                op = Operation.OpKind_NOT_EQUAL_OP;
                break;
            case LEX_META_EQUAL:
                op = Operation.OpKind_META_EQUAL_OP;
                break;
            case LEX_META_NOT_EQUAL:
                op = Operation.OpKind_META_NOT_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)

Aggregations

ExprTreeHolder (org.apache.asterix.external.classad.ExprTreeHolder)13 Operation (org.apache.asterix.external.classad.Operation)13 TokenType (org.apache.asterix.external.classad.Lexer.TokenType)8 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 AttributeReference (org.apache.asterix.external.classad.AttributeReference)1 TokenValue (org.apache.asterix.external.classad.TokenValue)1