Search in sources :

Example 11 with StatementContext

use of org.apache.sysml.parser.pydml.PydmlParser.StatementContext in project incubator-systemml by apache.

the class PydmlSyntacticValidator method exitElifBranch.

@Override
public void exitElifBranch(ElifBranchContext ctx) {
    IfStatement elifStmt = new IfStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    elifStmt.setConditionalPredicate(predicate);
    elifStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.elifBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.elifBody) {
            elifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
        }
        elifStmt.mergeStatementBlocksIfBody();
    }
    ctx.info.stmt = elifStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : IfStatement(org.apache.sysml.parser.IfStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Example 12 with StatementContext

use of org.apache.sysml.parser.pydml.PydmlParser.StatementContext in project systemml by apache.

the class PydmlSyntacticValidator method exitIfStatement.

@Override
public void exitIfStatement(IfStatementContext ctx) {
    IfStatement ifStmt = new IfStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    ifStmt.setConditionalPredicate(predicate);
    ifStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.ifBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.ifBody) {
            ifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
        }
        ifStmt.mergeStatementBlocksIfBody();
    }
    IfStatement tailIfStmt = ifStmt;
    if (ctx.elifBranches.size() > 0) {
        for (ElifBranchContext elifCtx : ctx.elifBranches) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(elifCtx.info.stmt));
            tailIfStmt = (IfStatement) elifCtx.info.stmt;
        }
    }
    if (ctx.elseBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.elseBody) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(stmtCtx.info.stmt));
        }
        tailIfStmt.mergeStatementBlocksElseBody();
    }
    ctx.info.stmt = ifStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : ElifBranchContext(org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext) IfStatement(org.apache.sysml.parser.IfStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Example 13 with StatementContext

use of org.apache.sysml.parser.pydml.PydmlParser.StatementContext in project systemml by apache.

the class PydmlSyntacticValidator method exitInternalFunctionDefExpression.

@Override
public void exitInternalFunctionDefExpression(InternalFunctionDefExpressionContext ctx) {
    FunctionStatement functionStmt = new FunctionStatement();
    ArrayList<DataIdentifier> functionInputs = getFunctionParameters(ctx.inputParams);
    functionStmt.setInputParams(functionInputs);
    // set function outputs
    ArrayList<DataIdentifier> functionOutputs = getFunctionParameters(ctx.outputParams);
    functionStmt.setOutputParams(functionOutputs);
    // set function name
    functionStmt.setName(ctx.name.getText());
    if (ctx.body.size() > 0) {
        // handle function body
        // Create arraylist of one statement block
        ArrayList<StatementBlock> body = new ArrayList<>();
        for (StatementContext stmtCtx : ctx.body) {
            body.add(getStatementBlock(stmtCtx.info.stmt));
        }
        functionStmt.setBody(body);
        functionStmt.mergeStatementBlocks();
    } else {
        notifyErrorListeners("functions with no statements are not allowed", ctx.start);
        return;
    }
    ctx.info.stmt = functionStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
    ctx.info.functionName = ctx.name.getText();
}
Also used : ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement) FunctionStatement(org.apache.sysml.parser.FunctionStatement) DataIdentifier(org.apache.sysml.parser.DataIdentifier) ArrayList(java.util.ArrayList) StatementBlock(org.apache.sysml.parser.StatementBlock) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Example 14 with StatementContext

use of org.apache.sysml.parser.pydml.PydmlParser.StatementContext in project systemml by apache.

the class PydmlSyntacticValidator method exitWhileStatement.

@Override
public void exitWhileStatement(WhileStatementContext ctx) {
    WhileStatement whileStmt = new WhileStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    whileStmt.setPredicate(predicate);
    whileStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.body.size() > 0) {
        for (StatementContext stmtCtx : ctx.body) {
            whileStmt.addStatementBlock(getStatementBlock(stmtCtx.info.stmt));
        }
        whileStmt.mergeStatementBlocks();
    }
    ctx.info.stmt = whileStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : WhileStatement(org.apache.sysml.parser.WhileStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Aggregations

FunctionStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext)14 StatementContext (org.apache.sysml.parser.pydml.PydmlParser.StatementContext)14 AssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext)12 ForStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext)12 FunctionCallAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext)12 FunctionCallMultiAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext)12 IfStatementContext (org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext)12 IfdefAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext)12 ImportStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext)12 ParForStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext)12 PathStatementContext (org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext)12 WhileStatementContext (org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)12 ConditionalPredicate (org.apache.sysml.parser.ConditionalPredicate)6 DataIdentifier (org.apache.sysml.parser.DataIdentifier)6 BinaryExpression (org.apache.sysml.parser.BinaryExpression)4 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)4 Expression (org.apache.sysml.parser.Expression)4 IfStatement (org.apache.sysml.parser.IfStatement)4 IterablePredicate (org.apache.sysml.parser.IterablePredicate)4 ParForStatement (org.apache.sysml.parser.ParForStatement)4