Search in sources :

Example 26 with Expression

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

the class DmlSyntacticValidator method exitBuiltinFunctionExpression.

@Override
public void exitBuiltinFunctionExpression(BuiltinFunctionExpressionContext ctx) {
    // Double verification: verify passed function name is a (non-parameterized) built-in function.
    String[] names = getQualifiedNames(ctx.name.getText());
    if (names == null) {
        notifyErrorListeners("incorrect function name (only namespace " + namespaceResolutionOp() + " 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);
    castAsScalarDeprecationCheck(functionName, ctx);
    ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, ctx.name);
    if (convertedSyntax == null) {
        return;
    } else {
        functionName = convertedSyntax.functionName;
        paramExpression = convertedSyntax.paramExpression;
    }
    final ExpressionInfo info = ctx.info;
    Action f = new Action() {

        @Override
        public void execute(Expression e) {
            info.expr = e;
        }
    };
    boolean validBIF = buildForBuiltInFunction(ctx, functionName, paramExpression, f);
    if (validBIF)
        return;
    notifyErrorListeners("only builtin functions allowed as part of expression", ctx.start);
}
Also used : Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ExpressionInfo(org.apache.sysml.parser.common.ExpressionInfo)

Example 27 with Expression

use of org.apache.sysml.parser.Expression in project incubator-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;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) StrictParameterizedExpressionContext(org.apache.sysml.parser.dml.DmlParser.StrictParameterizedExpressionContext) IterablePredicate(org.apache.sysml.parser.IterablePredicate) ParForStatement(org.apache.sysml.parser.ParForStatement) ImportStatementContext(org.apache.sysml.parser.dml.DmlParser.ImportStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.IfdefAssignmentStatementContext) FunctionStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext) AccumulatorAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AccumulatorAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.dml.DmlParser.ForStatementContext) AssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.dml.DmlParser.IfStatementContext) PathStatementContext(org.apache.sysml.parser.dml.DmlParser.PathStatementContext) WhileStatementContext(org.apache.sysml.parser.dml.DmlParser.WhileStatementContext) ParForStatementContext(org.apache.sysml.parser.dml.DmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallAssignmentStatementContext) StatementContext(org.apache.sysml.parser.dml.DmlParser.StatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext)

Example 28 with Expression

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

the class DmlSyntacticValidator method exitMultiIdExpression.

@Override
public void exitMultiIdExpression(MultiIdExpressionContext ctx) {
    ArrayList<Expression> values = new ArrayList<>();
    for (ExpressionContext elem : ctx.targetList) {
        values.add(elem.info.expr);
    }
    ctx.info.expr = new ExpressionList(values);
}
Also used : Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) CommandlinePositionExpressionContext(org.apache.sysml.parser.dml.DmlParser.CommandlinePositionExpressionContext) IterablePredicateSeqExpressionContext(org.apache.sysml.parser.dml.DmlParser.IterablePredicateSeqExpressionContext) MultiIdExpressionContext(org.apache.sysml.parser.dml.DmlParser.MultiIdExpressionContext) ConstFalseExpressionContext(org.apache.sysml.parser.dml.DmlParser.ConstFalseExpressionContext) IterablePredicateColonExpressionContext(org.apache.sysml.parser.dml.DmlParser.IterablePredicateColonExpressionContext) SimpleDataIdentifierExpressionContext(org.apache.sysml.parser.dml.DmlParser.SimpleDataIdentifierExpressionContext) ParameterizedExpressionContext(org.apache.sysml.parser.dml.DmlParser.ParameterizedExpressionContext) MatrixMulExpressionContext(org.apache.sysml.parser.dml.DmlParser.MatrixMulExpressionContext) MultDivExpressionContext(org.apache.sysml.parser.dml.DmlParser.MultDivExpressionContext) ConstStringIdExpressionContext(org.apache.sysml.parser.dml.DmlParser.ConstStringIdExpressionContext) UnaryExpressionContext(org.apache.sysml.parser.dml.DmlParser.UnaryExpressionContext) ConstIntIdExpressionContext(org.apache.sysml.parser.dml.DmlParser.ConstIntIdExpressionContext) BuiltinFunctionExpressionContext(org.apache.sysml.parser.dml.DmlParser.BuiltinFunctionExpressionContext) ExternalFunctionDefExpressionContext(org.apache.sysml.parser.dml.DmlParser.ExternalFunctionDefExpressionContext) CommandlineParamExpressionContext(org.apache.sysml.parser.dml.DmlParser.CommandlineParamExpressionContext) AtomicExpressionContext(org.apache.sysml.parser.dml.DmlParser.AtomicExpressionContext) ModIntDivExpressionContext(org.apache.sysml.parser.dml.DmlParser.ModIntDivExpressionContext) IndexedExpressionContext(org.apache.sysml.parser.dml.DmlParser.IndexedExpressionContext) ConstDoubleIdExpressionContext(org.apache.sysml.parser.dml.DmlParser.ConstDoubleIdExpressionContext) BooleanAndExpressionContext(org.apache.sysml.parser.dml.DmlParser.BooleanAndExpressionContext) InternalFunctionDefExpressionContext(org.apache.sysml.parser.dml.DmlParser.InternalFunctionDefExpressionContext) BooleanNotExpressionContext(org.apache.sysml.parser.dml.DmlParser.BooleanNotExpressionContext) ConstTrueExpressionContext(org.apache.sysml.parser.dml.DmlParser.ConstTrueExpressionContext) ExpressionContext(org.apache.sysml.parser.dml.DmlParser.ExpressionContext) PowerExpressionContext(org.apache.sysml.parser.dml.DmlParser.PowerExpressionContext) RelationalExpressionContext(org.apache.sysml.parser.dml.DmlParser.RelationalExpressionContext) DataIdExpressionContext(org.apache.sysml.parser.dml.DmlParser.DataIdExpressionContext) StrictParameterizedExpressionContext(org.apache.sysml.parser.dml.DmlParser.StrictParameterizedExpressionContext) AddSubExpressionContext(org.apache.sysml.parser.dml.DmlParser.AddSubExpressionContext) BooleanOrExpressionContext(org.apache.sysml.parser.dml.DmlParser.BooleanOrExpressionContext) ArrayList(java.util.ArrayList) ExpressionList(org.apache.sysml.parser.ExpressionList)

Example 29 with Expression

use of org.apache.sysml.parser.Expression 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;
        }
        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;
    }
}
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)

Example 30 with Expression

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

the class PydmlSyntacticValidator 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;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : 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) IterablePredicate(org.apache.sysml.parser.IterablePredicate) ParForStatement(org.apache.sysml.parser.ParForStatement) ForStatement(org.apache.sysml.parser.ForStatement) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Aggregations

Expression (org.apache.sysml.parser.Expression)40 ParameterExpression (org.apache.sysml.parser.ParameterExpression)40 BinaryExpression (org.apache.sysml.parser.BinaryExpression)27 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)27 DataIdentifier (org.apache.sysml.parser.DataIdentifier)24 LanguageException (org.apache.sysml.parser.LanguageException)15 ArrayList (java.util.ArrayList)12 BooleanExpression (org.apache.sysml.parser.BooleanExpression)12 DataExpression (org.apache.sysml.parser.DataExpression)12 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)12 RelationalExpression (org.apache.sysml.parser.RelationalExpression)12 IterablePredicate (org.apache.sysml.parser.IterablePredicate)8 ParForStatement (org.apache.sysml.parser.ParForStatement)8 HashMap (java.util.HashMap)6 AssignmentStatement (org.apache.sysml.parser.AssignmentStatement)6 ExpressionInfo (org.apache.sysml.parser.common.ExpressionInfo)6 ForStatement (org.apache.sysml.parser.ForStatement)4 FunctionCallIdentifier (org.apache.sysml.parser.FunctionCallIdentifier)4 IndexedIdentifier (org.apache.sysml.parser.IndexedIdentifier)4 ParseException (org.apache.sysml.parser.ParseException)4