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);
}
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);
}
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();
}
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);
}
Aggregations