コード例 #1
0
ファイル: FuncCallExpr.cs プロジェクト: pema99/PemaLang
        public override void Evaluate(Runtime Runtime)
        {
            FuncExpr.Evaluate(Runtime);
            if (!(Runtime.Register is FuncInfo))
            {
                if (FuncExpr is VarExpr)
                {
                    throw new Exception("Runtime error. \'" + (FuncExpr as VarExpr).Identifier + "\' is not a function.");
                }
                else
                {
                    throw new Exception("Runtime error. Attempt to call non-function.");
                }
            }
            FuncInfo Function = (FuncInfo)Runtime.Register;

            if (Function.Parameters.Count != Parameters.Count)
            {
                //Parameter mismatch
                throw new Exception("Invalid amount of parameters for function \'" + Function.Identifier + "\' Found " + Parameters.Count + ", expected " + Function.Parameters.Count);
            }

            Runtime.RunScope(Function.Body, Parameters);
            if (Runtime.Returning)
            {
                Runtime.Returning = false;
            }

            //Return null from function if no return statement was present
            else
            {
                Runtime.Register = null;
            }
        }
コード例 #2
0
        public override IExpr Build(BuildContext ctx, IExprBuilder initiator, Func <IExpr> next)
        {
            if (ctx.Token is LiteralToken t)
            {
                var func = Env.GetFunc(t.String);
                if (func == null)
                {
                    throw new CodeBuildEx(t.IdxS, t.IdxE,
                                          string.Format(
                                              tr.the_name__0__does_not_exist_in_the_current_environment,
                                              t.String
                                              ));
                }

                ctx.NextIndex();

                var funcExpr = new FuncExpr(Env)
                {
                    Token = t, Func = func
                };

                ThrowIf(ctx.Token, token => !(ctx.Token is ParenthesisToken openT) || !openT.IsOpen);

                funcExpr.ArgsBlockOpenToken = (ParenthesisToken)ctx.Token;

                ctx.NextIndex();

                IExpr expr;
                while (true)
                {
                    expr = next();
                    ThrowIfExprIsNull(expr, ctx.Token);

                    if (ctx.Token is ParenthesisToken token && !token.IsOpen)
                    {
                        funcExpr.Args.Add(expr);
                        funcExpr.ArgsBlockCloseToken = token;
                        break;
                    }

                    if (ctx.Token is SeparatorToken)
                    {
                        funcExpr.Args.Add(expr);
                        ctx.NextIndex();
                        continue;
                    }

                    ctx.PushExpr(expr);
                }

                func.ValidateArgs(Env, funcExpr.Args);

                ctx.NextIndex();

                return(funcExpr);
            }

            return(null);
        }
コード例 #3
0
        public override object VisitFuncExpr([NotNull] SQLiteParser.FuncExprContext context)
        {
            List <Expr> args = new List <Expr>();

            foreach (var v in context.arith_expr())
            {
                args.Add(Visit(v) as Expr);
            }
            return(FuncExpr.BuildFuncExpr(context.function_name().GetText(), args));
        }
コード例 #4
0
 void IVisitor.VisitBefore(FuncExpr expr)
 {
     this.ParentExists(expr);
 }
コード例 #5
0
 void IVisitor.VisitAfter(FuncExpr expr)
 {
     this.ParentExists(expr);
 }
コード例 #6
0
ファイル: Excutor.cs プロジェクト: nttlong/SqlBuilder
 public string Compile(FuncExpr funcExpr, List <XSqlCommandParam> Params)
 {
     throw new NotImplementedException();
 }