Exemple #1
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="FaParser.function_call"/>.
 /// <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 VisitFunction_call([NotNull] FaParser.Function_callContext context)
 {
     return(VisitChildren(context));
 }
Exemple #2
0
    public override object VisitFunction_call(FaParser.Function_callContext context)
    {
        String id       = context.ID().GetText();
        object instance = Exist(id);

        if (context.expression() != null)
        {
            int nparams = context.expression().Length;

            if (instance is MyFunction)
            {
                MyFunction func = (MyFunction)instance;

                if (nparams == func.nparams)
                {
                    Dictionary <string, Instance> memAmbit = new Dictionary <string, Instance>();
                    for (int i = 0; i < nparams; i++)
                    {
                        object     value = Visit(context.expression(i));
                        MyVariable xvar  = new MyVariable(func.namesParams.ElementAt(i), getType(value), value);
                        memAmbit.Add(func.namesParams.ElementAt(i), xvar);
                    }
                    queue.AddLast(memAmbit);
                    // Tebug.Log("queue: "+ PrintQueue(queue)) ;
                    object res = Visit((IParseTree)func.instructions);
                    // Tebug.Log(" EVALUADO 3 : " + (string)res);
                    queue.RemoveLast();
                    return(res == null ? (object)"nada" : res);
                }
                else
                {
                    Debug.LogError("Esta funcion recibe un número diferente de parametros");
                    // Console.WriteLine("Esta funcion recibe un número diferente de parametros");
                    MyConsole.main.AppendText("Esta funcion recibe un número diferente de parametros");
                }
            }
            else
            {
                Debug.LogError("Este ID no pertenece a una funcion");
                // Console.WriteLine("Este ID no pertenece a una funcion");
                MyConsole.main.AppendText("Este ID no pertenece a una funcion");
            }
        }
        else
        {
            if (instance is MyFunction)
            {
                MyFunction func = (MyFunction)instance;
                if (func.nparams == 0)
                {
                    Dictionary <string, Instance> memAmbit = new Dictionary <string, Instance>();
                    queue.AddLast(memAmbit);
                    object res = Visit((IParseTree)func.instructions);
                    // Tebug.Log(" EVALUADO 4	 : " + res);
                    queue.RemoveLast();
                    return(res == null ? (object)"nada" : res);
                }
                else
                {
                    Debug.LogError("Se esperaban cero parametros para esta func.");
                    // Console.WriteLine("Se esperaban cero parametros para esta func.");
                    MyConsole.main.AppendText("Se esperaban cero parametros para esta func.");
                }
            }
            else
            {
                Debug.LogError("No ha sido declarada una funcion con este nombre");
                // Console.WriteLine("No ha sido declarada una funcion con este nombre");
                MyConsole.main.AppendText("No ha sido declarada una funcion con este nombre");
            }
        }
        return(null);
    }