Search in sources :

Example 1 with OutputStatement

use of org.apache.sysml.parser.OutputStatement 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) {
        String fileName = currentFile;
        int line = ctx.start.getLine();
        int col = ctx.start.getCharPositionInLine();
        HashMap<String, Expression> varParams = new HashMap<String, Expression>();
        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(DataOp.WRITE, varParams, fileName, line, col, line, col);
        info.stmt = new OutputStatement((DataIdentifier) paramExpression.get(0).getExpr(), DataOp.WRITE, fileName, line, col, line, col);
        setFileLineColumn(info.stmt, ctx);
        ((OutputStatement) info.stmt).setExprParams(dataExpression);
    } else {
        notifyErrorListeners("incorrect usage of write function", ctx.start);
    }
}
Also used : DataExpression(org.apache.sysml.parser.DataExpression) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) 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) OutputStatement(org.apache.sysml.parser.OutputStatement)

Aggregations

HashMap (java.util.HashMap)1 BinaryExpression (org.apache.sysml.parser.BinaryExpression)1 BooleanExpression (org.apache.sysml.parser.BooleanExpression)1 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)1 DataExpression (org.apache.sysml.parser.DataExpression)1 DataIdentifier (org.apache.sysml.parser.DataIdentifier)1 Expression (org.apache.sysml.parser.Expression)1 OutputStatement (org.apache.sysml.parser.OutputStatement)1 ParameterExpression (org.apache.sysml.parser.ParameterExpression)1 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)1 RelationalExpression (org.apache.sysml.parser.RelationalExpression)1