Exemplo n.º 1
0
        public void ToRPNFloat(List <StructExpr> exp)
        {
            Output.Clear();
            dynamic av = null;

            for (int i = 0; i < exp.Count; i++)
            {
                switch (exp[i].Type)
                {
                case ExprType.ClassVar:

                    dynamic basev = null;
                    foreach (var cve in exp[i].Expr)
                    {
                        if (basev == null)
                        {
                            basev = ManagedHost.CurrentScope.FindVar(cve.VarName, true);
                            if (basev == null)
                            {
                                Console.WriteLine("No var:" + cve.VarName);
                                while (true)
                                {
                                }
                            }
                        }
                        else
                        {
                            basev = basev.Value.FindVar(cve.VarName);
                        }
                    }

                    var cv = new StructExpr();
                    cv.floatV = basev.Value;
                    Output.Add(cv);

                    break;

                case ExprType.VarValue:
                    try
                    {
                        if (av == null)
                        {
                            av = ManagedHost.CurrentScope.FindVar(exp[i].VarName, true);
                            if (av.Value is StructModule || av.Value is Module)
                            {
                            }
                            else
                            {
                                var nnn = new StructExpr();
                                nnn.floatV = av.Value;
                                Output.Add(nnn);
                            }
                        }
                        else
                        {
                            if (av.Value is Module)
                            {
                                if (av.Value.CMod != null)
                                {
                                    if (av.Value.CMod.HasStaticVar(exp[i].VarName))
                                    {
                                        av = av.Value.CMod.GetStaticValue(exp[i].VarName);
                                        var ne = new StructExpr();
                                        ne.floatV = av;
                                        Output.Add(ne);
                                    }
                                }
                            }
                            else if (av.Value is StructModule)
                            {
                                if (av.Value.IsFunc(exp[i].VarName))
                                {
                                    if (exp[i].CallPars != null)
                                    {
                                        dynamic[] pars = new dynamic[exp[i].CallPars.Pars.Count];
                                        for (int cpi = 0; cpi < exp[i].CallPars.Pars.Count; cpi++)
                                        {
                                            pars[cpi] = exp[i].CallPars.Pars[cpi].Exec();
                                        }

                                        av = av.Value.ExecFunc(exp[i].VarName, pars);
                                    }
                                    else
                                    {
                                        av = av.Value.ExecFunc(exp[i].VarName, null);
                                    }
                                    var fr = new StructExpr();
                                    fr.floatV = av;
                                    Output.Add(fr);
                                }
                                else
                                {
                                    av = av.Value.FindVar(exp[i].VarName);
                                    if (av.Value is int)
                                    {
                                        var ni = new StructExpr();
                                        ni.floatV = av.Value;
                                        Output.Add(ni);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Variable retrival error.");
                        ManagedHost.RaiseError("Variable retrival error.");
                    }
                    break;

                case ExprType.SubExpr:
                    var ns = new StructExpr();
                    ns.floatV = exp[i].Exec();
                    Output.Add(ns);
                    break;

                case ExprType.FloatValue:
                    Output.Add(exp[i]);
                    break;

                case ExprType.Operator:
                    while (Stack.Count > 0 && Priority(Stack.Peek()) >= Priority(exp[i]))
                    {
                        Output.Add(Stack.Pop());
                    }
                    Stack.Push(exp[i]);
                    //{
                    //   o
                    //}
                    break;
                }
            }
            while (Stack.Count > 0)
            {
                Output.Add(Stack.Pop());
            }
        }
Exemplo n.º 2
0
        public void ToRPNInt(List <StructExpr> exp)
        {
            Output.Clear();
            dynamic av = null;

            for (int i = 0; i < exp.Count; i++)
            {
                switch (exp[i].Type)
                {
                case ExprType.Call:

                    break;

                case ExprType.ClassVar:

                    dynamic basev = null;
                    foreach (var cve in exp[i].Expr)
                    {
                        if (basev == null)
                        {
                            if (Vivid.SynWave.SynHost.Active.HasSysFunc(cve.VarName))
                            {
                                basev = Vivid.SynWave.SynHost.Active.RunSysFunc(cve.VarName, cve.CallPars == null ? null : cve.CallPars.Exec());
                                Var nv1 = new Var();
                                nv1.Value = basev;
                                if (basev is int)
                                {
                                    nv1.Type = VarType.Int;
                                }
                                else if (basev is object)
                                {
                                    //nv1.Type = VarType.Class;
                                }

                                basev = nv1;
                            }
                            else
                            {
                                basev = Vivid.SynWave.SynHost.Active.FindVar(cve.VarName);
                            }

                            if (basev == null)
                            {
                                Console.WriteLine("No link:");
                            }
                        }
                        else
                        {
                            basev = basev.Value.FindVar(cve.VarName);
                        }
                    }

                    var cv = new StructExpr();
                    if (basev != null)
                    {
                        if (basev.Value is StructModule)
                        {
                            cv.Obj = basev.Value;
                            Output.Add(cv);
                            break;
                        }
                    }
                    cv.Obj  = null;
                    cv.intV = basev.Value;

                    Output.Add(cv);

                    break;

                case ExprType.VarValue:
                    try
                    {
                        if (av == null)
                        {
                            av = Vivid.SynWave.SynHost.Active.FindVar(exp[i].VarName);
                            if (av.Value is StructModule || av.Value is Module)
                            {
                            }
                            else
                            {
                                var nnn = new StructExpr();
                                nnn.intV = (int)av.Value;
                                Output.Add(nnn);
                            }
                        }
                        else
                        {
                            if (av.Value is Module)
                            {
                                if (av.Value.CMod != null)
                                {
                                    if (av.Value.CMod.HasStaticVar(exp[i].VarName))
                                    {
                                        av = av.Value.CMod.GetStaticValue(exp[i].VarName);
                                        var ne = new StructExpr();
                                        ne.intV = av;
                                        Output.Add(ne);
                                    }
                                }
                            }
                            else if (av.Value is StructModule)
                            {
                                if (av.Value.IsFunc(exp[i].VarName))
                                {
                                    if (exp[i].CallPars != null)
                                    {
                                        dynamic[] pars = new dynamic[exp[i].CallPars.Pars.Count];
                                        for (int cpi = 0; cpi < exp[i].CallPars.Pars.Count; cpi++)
                                        {
                                            pars[cpi] = exp[i].CallPars.Pars[cpi].Exec();
                                        }

                                        av = av.Value.ExecFunc(exp[i].VarName, pars);
                                    }
                                    else
                                    {
                                        av = av.Value.ExecFunc(exp[i].VarName, null);
                                    }
                                    var fr = new StructExpr();
                                    fr.intV = av;
                                    Output.Add(fr);
                                }
                                else
                                {
                                    av = av.Value.FindVar(exp[i].VarName);
                                    if (av.Value is int)
                                    {
                                        var ni = new StructExpr();
                                        ni.intV = av.Value;
                                        Output.Add(ni);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Variable retrival error.");
                        ManagedHost.RaiseError("Variable retrival error.");
                    }
                    break;

                case ExprType.SubExpr:
                    var ns = new StructExpr();
                    ns.intV = exp[i].Exec();
                    Output.Add(ns);
                    break;

                case ExprType.IntValue:
                    Output.Add(exp[i]);
                    break;

                case ExprType.Operator:
                    while (Stack.Count > 0 && Priority(Stack.Peek()) >= Priority(exp[i]))
                    {
                        Output.Add(Stack.Pop());
                    }
                    Stack.Push(exp[i]);
                    //{
                    //   o
                    //}
                    break;
                }
            }
            while (Stack.Count > 0)
            {
                Output.Add(Stack.Pop());
            }
        }