예제 #1
0
        public override DynObj VisitFunctionCallExpr([NotNull] KittenGrammarParser.FunctionCallExprContext context)
        {
            var name = context.ID().Symbol.Text;

            if (!memory.ContainsKey(name))
            {
                ReportError("UnrecognizedIdentifierError", $"identifier name {name} not found in the context", context.start.Line);
            }
            var paraList  = memory[name].FuncVal.parameters;
            var valueList = new List <DynObj>();

            if (context.exprList() != null)
            {
                foreach (var item in context.exprList().expr())
                {
                    valueList.Add(Visit(item));
                }
            }
            if (memory[name].FuncVal.t == function.funcType.User)
            {
                if (paraList.Count != valueList.Count)
                {
                    ReportError("ArgumentNumberMismatchError", $"expected {paraList.Count}, but called with {valueList.Count}", context.start.Line);
                }
                Dictionary <string, DynObj> contextMem = new Dictionary <string, DynObj>();
                for (int i = 0; i < paraList.Count; i++)
                {
                    contextMem.Add(paraList[i], valueList[i]);
                }
                var funcVisitor = new KittenVisitor(contextMem);
                return(funcVisitor.Visit(memory[name].FuncVal.IMP));
            }
            if (memory[name].FuncVal.t == function.funcType.Builtin)
            {
                return(memory[name].FuncVal.BuiltinIMP(valueList));
            }
            return(base.VisitFunctionCallExpr(context));
        }
 /// <summary>
 /// Exit a parse tree produced by the <c>functionCallExpr</c>
 /// labeled alternative in <see cref="KittenGrammarParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFunctionCallExpr([NotNull] KittenGrammarParser.FunctionCallExprContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>functionCallExpr</c>
 /// labeled alternative in <see cref="KittenGrammarParser.expr"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitFunctionCallExpr([NotNull] KittenGrammarParser.FunctionCallExprContext context)
 {
     return(VisitChildren(context));
 }