Search in sources :

Example 6 with TokenType

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

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

the class ClassAdParser method parseArgumentList.

// ArgumentList .= '(' ListOfArguments ')'
// ListOfArguments .= (epsilon)
// | ListOfArguments ',' Expression
public boolean parseArgumentList(ExprList argList) throws IOException {
    TokenType tt;
    argList.clear();
    if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_PAREN) {
        throw new HyracksDataException("expected LEX_OPEN_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
    // return false;
    }
    tt = lexer.peekToken();
    ExprTreeHolder tree = objectPool.mutableExprPool.get();
    while (tt != TokenType.LEX_CLOSE_PAREN) {
        // parse the expression
        tree.reset();
        parseExpression(tree);
        if (tree.getInnerTree() == null) {
            argList.clear();
            return false;
        }
        // insert the expression into the argument list
        argList.add(tree.getInnerTree());
        // the next token must be a ',' or a ')'
        // or it can be a ';' if using old ClassAd semantics
        tt = lexer.peekToken();
        if (tt == TokenType.LEX_COMMA || (tt == TokenType.LEX_SEMICOLON && false)) {
            lexer.consumeToken();
        } else if (tt != TokenType.LEX_CLOSE_PAREN) {
            argList.clear();
            throw new HyracksDataException("expected LEX_COMMA or LEX_CLOSE_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
        // return false;
        }
    }
    lexer.consumeToken();
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 8 with TokenType

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

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

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

Aggregations

ExprTreeHolder (org.apache.asterix.external.classad.ExprTreeHolder)13 TokenType (org.apache.asterix.external.classad.Lexer.TokenType)13 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)12 Operation (org.apache.asterix.external.classad.Operation)8 TokenValue (org.apache.asterix.external.classad.TokenValue)4 ExprList (org.apache.asterix.external.classad.ExprList)2 Value (org.apache.asterix.external.classad.Value)2 AttributeReference (org.apache.asterix.external.classad.AttributeReference)1 ClassAd (org.apache.asterix.external.classad.ClassAd)1 Literal (org.apache.asterix.external.classad.Literal)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1