use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method setOutputStatement.
protected void setOutputStatement(ParserRuleContext ctx, ArrayList<ParameterExpression> paramExpression, StatementInfo info) {
if (paramExpression.size() < 2) {
notifyErrorListeners("incorrect usage of write function (at least 2 arguments required)", ctx.start);
return;
}
if (paramExpression.get(0).getExpr() instanceof DataIdentifier) {
HashMap<String, Expression> varParams = new HashMap<>();
varParams.put(DataExpression.IO_FILENAME, paramExpression.get(1).getExpr());
for (int i = 2; i < paramExpression.size(); i++) {
// DataExpression.FORMAT_TYPE, DataExpression.DELIM_DELIMITER, DataExpression.DELIM_HAS_HEADER_ROW, DataExpression.DELIM_SPARSE
varParams.put(paramExpression.get(i).getName(), paramExpression.get(i).getExpr());
}
DataExpression dataExpression = new DataExpression(ctx, DataOp.WRITE, varParams, currentFile);
info.stmt = new OutputStatement(ctx, (DataIdentifier) paramExpression.get(0).getExpr(), DataOp.WRITE, currentFile);
((OutputStatement) info.stmt).setExprParams(dataExpression);
} else {
notifyErrorListeners("incorrect usage of write function", ctx.start);
}
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method functionCallAssignmentStatementHelper.
protected void functionCallAssignmentStatementHelper(final ParserRuleContext ctx, Set<String> printStatements, Set<String> outputStatements, final Expression dataInfo, final StatementInfo info, final Token nameToken, Token targetListToken, String namespace, String functionName, ArrayList<ParameterExpression> paramExpression, boolean hasLHS) {
ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, nameToken);
if (convertedSyntax == null) {
return;
} else {
namespace = convertedSyntax.namespace;
functionName = convertedSyntax.functionName;
paramExpression = convertedSyntax.paramExpression;
}
// For builtin functions without LHS
if (namespace.equals(DMLProgram.DEFAULT_NAMESPACE) && !functions.contains(functionName)) {
if (printStatements.contains(functionName)) {
setPrintStatement(ctx, functionName, paramExpression, info);
return;
} else if (outputStatements.contains(functionName)) {
setOutputStatement(ctx, paramExpression, info);
return;
}
}
DataIdentifier target = null;
if (dataInfo instanceof DataIdentifier) {
target = (DataIdentifier) dataInfo;
} else if (dataInfo != null) {
notifyErrorListeners("incorrect lvalue for function call ", targetListToken);
return;
}
// For builtin functions with LHS
if (namespace.equals(DMLProgram.DEFAULT_NAMESPACE) && !functions.contains(functionName)) {
Expression e = buildForBuiltInFunction(ctx, functionName, paramExpression);
if (e != null) {
setAssignmentStatement(ctx, info, target, e);
return;
}
}
// handle user-defined functions
setAssignmentStatement(ctx, info, target, createFunctionCall(ctx, namespace, functionName, paramExpression));
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitForStatement.
@Override
public void exitForStatement(ForStatementContext ctx) {
ForStatement forStmt = new ForStatement();
DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
HashMap<String, String> parForParamValues = null;
// 1/-1
Expression incrementExpr = null;
if (ctx.iterPred.info.increment != null) {
incrementExpr = ctx.iterPred.info.increment;
}
IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile);
forStmt.setPredicate(predicate);
if (ctx.body.size() > 0) {
for (StatementContext stmtCtx : ctx.body) {
forStmt.addStatementBlock(getStatementBlock(stmtCtx.info.stmt));
}
forStmt.mergeStatementBlocks();
}
ctx.info.stmt = forStmt;
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitSimpleDataIdentifierExpression.
@Override
public void exitSimpleDataIdentifierExpression(SimpleDataIdentifierExpressionContext ctx) {
// This is either a function, or variable with namespace
// By default, it assigns to a data type
ctx.dataInfo.expr = new DataIdentifier(ctx.getText());
setFileLineColumn(ctx.dataInfo.expr, ctx);
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitFunctionCallMultiAssignmentStatement.
@Override
public void exitFunctionCallMultiAssignmentStatement(FunctionCallMultiAssignmentStatementContext ctx) {
String[] names = getQualifiedNames(ctx.name.getText());
if (names == null) {
notifyErrorListeners("incorrect function name (only namespace.functionName allowed. Hint: If you are trying to use builtin functions, you can skip the namespace)", ctx.name);
return;
}
String namespace = names[0];
String functionName = names[1];
ArrayList<ParameterExpression> paramExpression = getParameterExpressionList(ctx.paramExprs);
ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, ctx.name);
if (convertedSyntax == null) {
return;
} else {
namespace = convertedSyntax.namespace;
functionName = convertedSyntax.functionName;
paramExpression = convertedSyntax.paramExpression;
}
FunctionCallIdentifier functCall = new FunctionCallIdentifier(paramExpression);
functCall.setFunctionName(functionName);
functCall.setFunctionNamespace(namespace);
final ArrayList<DataIdentifier> targetList = new ArrayList<>();
for (DataIdentifierContext dataCtx : ctx.targetList) {
if (dataCtx.dataInfo.expr instanceof DataIdentifier) {
targetList.add((DataIdentifier) dataCtx.dataInfo.expr);
} else {
notifyErrorListeners("incorrect type for variable ", dataCtx.start);
return;
}
}
if (namespace.equals(DMLProgram.DEFAULT_NAMESPACE)) {
Expression e = buildForBuiltInFunction(ctx, functionName, paramExpression);
if (e != null) {
setMultiAssignmentStatement(targetList, e, ctx, ctx.info);
return;
}
}
// Override default namespace for imported non-built-in function
String inferNamespace = (sourceNamespace != null && sourceNamespace.length() > 0 && DMLProgram.DEFAULT_NAMESPACE.equals(namespace)) ? sourceNamespace : namespace;
functCall.setFunctionNamespace(inferNamespace);
setMultiAssignmentStatement(targetList, functCall, ctx, ctx.info);
}
Aggregations