Search in sources :

Example 6 with Operation

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

the class ClassAdParser method parseExpression.

private boolean parseExpression(ExprTreeHolder tree, boolean full) throws IOException {
    TokenType tt;
    if (!parseLogicalORExpression(tree)) {
        return false;
    }
    if ((tt = lexer.peekToken()) == TokenType.LEX_QMARK) {
        lexer.consumeToken();
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeM = objectPool.mutableExprPool.get();
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        parseExpression(treeM);
        if ((tt = lexer.consumeToken()) != TokenType.LEX_COLON) {
            throw new HyracksDataException("expected LEX_COLON, but got " + Lexer.strLexToken(tt));
        }
        parseExpression(treeR);
        if (treeL.getInnerTree() != null && treeM.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_TERNARY_OP, treeL, treeM, treeR, newTree);
            tree.setInnerTree(newTree);
            return (true);
        }
        tree.setInnerTree(null);
        return false;
    }
    // if a full parse was requested, ensure that input is exhausted
    if (full && (lexer.consumeToken() != TokenType.LEX_END_OF_INPUT)) {
        throw new HyracksDataException("expected LEX_END_OF_INPUT on full parse, but got " + String.valueOf(Lexer.strLexToken(tt)));
    }
    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 7 with Operation

use of org.apache.asterix.external.classad.Operation 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;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation)

Example 8 with Operation

use of org.apache.asterix.external.classad.Operation 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;
}
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 9 with Operation

use of org.apache.asterix.external.classad.Operation 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 10 with Operation

use of org.apache.asterix.external.classad.Operation 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)

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