Search in sources :

Example 1 with AssignmentStatement

use of org.apache.sysml.parser.AssignmentStatement in project incubator-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;
        int line = ctx.start.getLine();
        int col = ctx.start.getCharPositionInLine();
        try {
            info.stmt = new AssignmentStatement(target, source, line, col, line, col);
            setFileLineColumn(info.stmt, ctx);
        } 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;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) DataIdentifier(org.apache.sysml.parser.DataIdentifier) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement) MultiAssignmentStatement(org.apache.sysml.parser.MultiAssignmentStatement)

Example 2 with AssignmentStatement

use of org.apache.sysml.parser.AssignmentStatement in project incubator-systemml by apache.

the class CommonSyntacticValidator method setAssignmentStatement.

protected void setAssignmentStatement(ParserRuleContext ctx, StatementInfo info, DataIdentifier target, Expression expression) {
    try {
        info.stmt = new AssignmentStatement(target, expression, ctx.start.getLine(), ctx.start.getCharPositionInLine(), ctx.start.getLine(), ctx.start.getCharPositionInLine());
        setFileLineColumn(info.stmt, ctx);
    } catch (LanguageException e) {
        // TODO: extract more meaningful info from this exception.
        notifyErrorListeners("invalid function call", ctx.start);
        return;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement) MultiAssignmentStatement(org.apache.sysml.parser.MultiAssignmentStatement)

Example 3 with AssignmentStatement

use of org.apache.sysml.parser.AssignmentStatement in project incubator-systemml by apache.

the class PydmlSyntacticValidator method exitIgnoreNewLine.

// -----------------------------------------------------------------
//        PyDML Specific
// -----------------------------------------------------------------
@Override
public void exitIgnoreNewLine(IgnoreNewLineContext ctx) {
    // This is later ignored by PyDMLParserWrapper
    try {
        ctx.info.stmt = new AssignmentStatement(null, null, 0, 0, 0, 0);
        ctx.info.stmt.setEmptyNewLineStatement(true);
    } catch (LanguageException e) {
        e.printStackTrace();
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement)

Example 4 with AssignmentStatement

use of org.apache.sysml.parser.AssignmentStatement in project incubator-systemml by apache.

the class PydmlSyntacticValidator 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("incorrect lvalue in ifdef function ", 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;
        }
        int line = ctx.start.getLine();
        int col = ctx.start.getCharPositionInLine();
        try {
            ctx.info.stmt = new AssignmentStatement(target, source, line, col, line, col);
            setFileLineColumn(ctx.info.stmt, ctx);
        } catch (LanguageException e) {
            notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
            return;
        }
    } else {
        notifyErrorListeners("incorrect lvalue in ifdef function ", ctx.targetList.start);
        return;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) DataIdentifier(org.apache.sysml.parser.DataIdentifier) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement)

Example 5 with AssignmentStatement

use of org.apache.sysml.parser.AssignmentStatement in project incubator-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;
        }
        int line = ctx.start.getLine();
        int col = ctx.start.getCharPositionInLine();
        try {
            ctx.info.stmt = new AssignmentStatement(target, source, line, col, line, col);
            setFileLineColumn(ctx.info.stmt, ctx);
        } catch (LanguageException e) {
            notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
            return;
        }
    } else {
        notifyErrorListeners("incorrect lvalue in ifdef function ", ctx.targetList.start);
        return;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) DataIdentifier(org.apache.sysml.parser.DataIdentifier) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement)

Aggregations

AssignmentStatement (org.apache.sysml.parser.AssignmentStatement)5 LanguageException (org.apache.sysml.parser.LanguageException)5 DataIdentifier (org.apache.sysml.parser.DataIdentifier)3 Expression (org.apache.sysml.parser.Expression)3 ParameterExpression (org.apache.sysml.parser.ParameterExpression)3 BinaryExpression (org.apache.sysml.parser.BinaryExpression)2 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)2 MultiAssignmentStatement (org.apache.sysml.parser.MultiAssignmentStatement)2 BooleanExpression (org.apache.sysml.parser.BooleanExpression)1 DataExpression (org.apache.sysml.parser.DataExpression)1 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)1 RelationalExpression (org.apache.sysml.parser.RelationalExpression)1