Search in sources :

Example 1 with ExprTreeHolder

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

the class FunctionalTester method handle_diffq.

/*********************************************************************
     * Function: handle_diffq
     * Purpose:
     * @param objectPool 
     *
     * @throws IOException
     *********************************************************************/
public static void handle_diffq(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 the same.", state);
        }
    }
    return;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder)

Example 2 with ExprTreeHolder

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

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

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

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

the class ClassAdParser method asterixParseClassAd.

private boolean asterixParseClassAd(ClassAd ad) throws IOException {
    TokenType tt;
    ad.clear();
    lexer.initialize(currentSource);
    if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_BOX) {
        handleErrorParsing();
        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));
        }
        int positionBefore = lexer.getLexSource().getPosition();
        isExpr = false;
        // parse the expression
        parseExpression(tree);
        if (tree.getInnerTree() == null) {
            handleErrorParsing();
            throw new HyracksDataException("parse expression returned empty tree");
        }
        if ((!evaluateExpr || keepBoth) && isExpr && positionBefore >= 0) {
            // we will store a string representation of the expression
            int len = lexer.getLexSource().getPosition() - positionBefore - 2;
            // add it as it is to the classAd
            Literal lit = objectPool.literalPool.get();
            Value exprVal = objectPool.valuePool.get();
            exprVal.setStringValue((exprPrefix == null ? "" : exprPrefix) + String.valueOf(lexer.getLexSource().getBuffer(), positionBefore, len) + (exprSuffix == null ? "" : exprSuffix));
            Literal.createLiteral(lit, exprVal, NumberFactor.NO_FACTOR);
            if (!evaluateExpr) {
                ad.insert(tv.getStrValue().toString(), lit);
            } else {
                ad.insert(tv.getStrValue().toString() + exprFieldNameSuffix, lit);
            }
        }
        if (!isExpr || (evaluateExpr)) {
            // insert the attribute into the classad
            if (!ad.insert(tv.getStrValue().toString(), tree)) {
                handleErrorParsing();
                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) {
            handleErrorParsing();
            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();
        }
    }
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Literal(org.apache.asterix.external.classad.Literal) TokenValue(org.apache.asterix.external.classad.TokenValue) Value(org.apache.asterix.external.classad.Value) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) TokenValue(org.apache.asterix.external.classad.TokenValue)

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