Exemplo n.º 1
0
        //
        // Function
        //

        public override Expression VisitFunction(ExprParser.FunctionContext context)
        {
            string type = GetType(context.type()); // Return type
            string name = GetName(context.name()); // Function name

            ExpressionScope e = new ExpressionScope();

            e.Name          = name;
            e.Operation     = Operation.FUNCTION;
            e.OutputSetName = type;

            // Find all parameter declarations and store them as operands of the expression
            int paramCount = context.parameter().Count();

            for (int i = 0; i < paramCount; i++)
            {
                Expression paramExpr = Visit(context.parameter(i));
                if (i == 0)
                {
                    e.Input = paramExpr;
                }
                else
                {
                    e.AddOperand(paramExpr);
                }
            }

            // Find all statements and store them in the expression
            int stmtCount = context.statement().Count();

            for (int i = 0; i < stmtCount; i++)
            {
                ExpressionScope stmtExpr = (ExpressionScope)Visit(context.statement(i));
                if (stmtExpr == null)
                {
                    continue;
                }

                e.AddStatement(stmtExpr);
            }

            return(e);
        }