use of org.apache.sysml.parser.Expression in project systemml by apache.
the class CommonSyntacticValidator method exitAssignmentStatementHelper.
protected void exitAssignmentStatementHelper(ParserRuleContext ctx, String lhs, ExpressionInfo dataInfo, Token lhsStart, ExpressionInfo rhs, StatementInfo info) {
if (lhs.startsWith("$")) {
notifyErrorListeners("assignment of commandline parameters is not allowed. (Quickfix: try using someLocalVariable=ifdef(" + lhs + ", default value))", ctx.start);
return;
}
DataIdentifier target = null;
if (dataInfo.expr instanceof DataIdentifier) {
target = (DataIdentifier) dataInfo.expr;
Expression source = rhs.expr;
try {
info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
} catch (LanguageException e) {
// TODO: extract more meaningful info from this exception.
notifyErrorListeners("invalid assignment", lhsStart);
return;
}
} else {
notifyErrorListeners("incorrect lvalue in assignment statement", lhsStart);
return;
}
}
use of org.apache.sysml.parser.Expression in project 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.Expression in project 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);
}
use of org.apache.sysml.parser.Expression in project systemml by apache.
the class DmlSyntacticValidator method exitIfdefAssignmentStatement.
@Override
public void exitIfdefAssignmentStatement(IfdefAssignmentStatementContext ctx) {
if (!ctx.commandLineParam.getText().startsWith("$")) {
notifyErrorListeners("the first argument of ifdef function should be a commandline argument parameter (which starts with $)", ctx.commandLineParam.start);
return;
}
if (ctx.targetList == null) {
notifyErrorListeners("ifdef assignment needs an lvalue ", ctx.start);
return;
}
String targetListText = ctx.targetList.getText();
if (targetListText.startsWith("$")) {
notifyErrorListeners("lhs of ifdef function cannot be a commandline parameters. Use local variable instead", ctx.start);
return;
}
DataIdentifier target = null;
if (ctx.targetList.dataInfo.expr instanceof DataIdentifier) {
target = (DataIdentifier) ctx.targetList.dataInfo.expr;
Expression source = null;
if (ctx.commandLineParam.dataInfo.expr != null) {
// Since commandline parameter is set
// The check of following is done in fillExpressionInfoCommandLineParameters:
// Command line param cannot be empty string
// If you want to pass space, please quote it
source = ctx.commandLineParam.dataInfo.expr;
} else {
source = ctx.source.info.expr;
}
try {
ctx.info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
} catch (LanguageException e) {
notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
return;
}
} else {
notifyErrorListeners("incorrect lvalue in ifdef function ", ctx.targetList.start);
return;
}
}
use of org.apache.sysml.parser.Expression in project systemml by apache.
the class DmlSyntacticValidator method exitParForStatement.
@Override
public void exitParForStatement(ParForStatementContext ctx) {
ParForStatement parForStmt = new ParForStatement();
DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
HashMap<String, String> parForParamValues = new HashMap<>();
if (ctx.parForParams != null && ctx.parForParams.size() > 0) {
for (StrictParameterizedExpressionContext parForParamCtx : ctx.parForParams) {
String paramVal = parForParamCtx.paramVal.getText();
if (argVals.containsKey(paramVal))
paramVal = argVals.get(paramVal);
parForParamValues.put(parForParamCtx.paramName.getText(), paramVal);
}
}
// 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);
parForStmt.setPredicate(predicate);
if (ctx.body.size() > 0) {
for (StatementContext stmtCtx : ctx.body) {
parForStmt.addStatementBlock(getStatementBlock(stmtCtx.info.stmt));
}
parForStmt.mergeStatementBlocks();
}
ctx.info.stmt = parForStmt;
}
Aggregations