コード例 #1
0
ファイル: NewBehaviourScript.cs プロジェクト: elkawee/UShell
        void Start()
        {
            foreach (var name in SGA.MembAC(typeof(Transform), "p", SuggestionTree.MembK.Any()).Select(mi => mi.Name))
            {
                Debug.Log(name);
            }

            // ----------------------------------------

            var GE = new GrammarEntry()
            {
                StartProd      = TestGrammar.StartProd,
                TR_constructor = (nn) => new StartTU((TestGrammar.StartNode)nn)
            };
            var TLHS = new TranslateLHS()
            {
                preCH_LHS = null,
                scope     = new CH_closedScope()
            };
            var compilat = TranslateEntry.TranslateFully(">> :Transform ..position ", GE, TLHS);
            var MM       = new MemMapper();
            var res      = Evaluate.Eval(compilat, MM);

            Analyz0r.A.JsonifyEval(compilat, MM);
            Analyz0r.A.JsonifyCompilat(compilat);
            Debug.Log("DIIIIIIIIIIIIIIIInGs" + string.Join("--", res.values.Select(_ => _.ToString()).ToArray()));
        }
コード例 #2
0
        public static void Test4_still_fanning_and_analyz0r(bool analyz0r = false)
        {
            var lhsCH = new TypedSingleCH <TestcasesLHSType>();

            var FanGE = new GrammarEntry {
                StartProd      = MG.Fan,
                TR_constructor = (nnode) => new FanTU(new adapter_preCH(lhsCH), (MG.FanNode)nnode)
            };
            var trslLHS = new TranslateLHS {
                preCH_LHS = new adapter_preCH(lhsCH),
                scope     = new CH_closedScope()
            };

            var compilat = TranslateEntry.TranslateFully_incomplete_tolerant(" { ..intMem1 -> x <- @4 ->x2  , ..intMem2  <- $x2 }  ", FanGE, trslLHS);

            if (analyz0r)
            {
                Analyz0r.A.JsonifyCompilat(compilat, "_Test4_still_fanning");
            }

            var MM         = new MemMapper();
            var LHS_column = MM.get(lhsCH);

            LHS_column.AddVal(new TestcasesLHSType());
            LHS_column.AddVal(new TestcasesLHSType());
            LHS_column.AddVal(new TestcasesLHSType());
            Evaluate.Eval(compilat, MM);

            if (analyz0r)
            {
                Analyz0r.A.JsonifyEval(compilat, MM, "_Test4_still_fanning");
            }
        }
コード例 #3
0
        public static ShellCommon.EVAL_Resp EVAL_stateless(ShellCommon.EVAL_Req eval_req, bool analyz0r = false)
        {
            // fetch evaluation entry from the current junkjard that is EvaluatorTests_and_random_fux0ring.cs

            GrammarEntry GE = new GrammarEntry {
                StartProd      = MG.ProvStart,
                TR_constructor = NN => new TranslateAndEval.ProvStartTU((MG.ProvStartNode)NN)
            };

            TranslateLHS TLHS = new TranslateLHS {
                preCH_LHS = null,
                scope     = new TranslateAndEval.CH_closedScope()
            };
            Compilat compilat;

            try {
                compilat = TranslateEntry.TranslateFully_incomplete_tolerant(eval_req.expr, GE, TLHS);
            } catch (Exception e) {
                return(new ShellCommon.EVAL_Resp {
                    success = false,
                    msg = "translate ERROR : " + e.Message + "\n" + e.StackTrace,
                    result = new SObject[0]
                });
            }

            if (analyz0r)
            {
                Analyz0r.A.JsonifyCompilat(compilat);
            }

            var MM = new TranslateAndEval.MemMapper();

            TranslateAndEval.Column resultColumn;
            try {
                resultColumn = Evaluate.Eval(compilat, MM);
            } catch (Exception e) {
                return(new ShellCommon.EVAL_Resp {
                    success = false,
                    msg = "eval ERROR : " + e.Message + "\n" + e.StackTrace,
                    result = new SObject[0]
                });
            }

            try {
                if (analyz0r)
                {
                    Analyz0r.A.JsonifyEval(compilat, MM);
                }
            } catch (Exception) {}   // TODO - write a message to the file about how this crashed

            var resp = new ShellCommon.EVAL_Resp {
                success = true,
                msg     = "OK",
                result  = resultColumn.values.ToArray()     // <- current serialization (ShellNetworkGlue.cs) simply does a ToString() for all Objects
            };

            return(resp);
        }
コード例 #4
0
        public static Column DummyEval(string expr)     // condense all the junk in plumbing
        {
            CH_closedScope dummy_out_scope = null;


            // todo: this goes to a variant of parse that silently drops unconsumed tokens in those cases where there is no full parse of the entire token sequence
            return(Evaluate.Eval(expr,
                                 startProdGE,
                                 new TranslateLHS {
                preCH_LHS = null,                                                              // not needed for start prod
                scope = new CH_closedScope()
            },
                                 new MemMapper(),
                                 out dummy_out_scope));
        }
コード例 #5
0
    public void Eval_Upper_Test()
    {
        string_float[] testData = new string_float[]
        {
            new string_float("mAx(1,3)", 3),
            new string_float("miN(1, 3)", 1),
            new string_float("MIn(Max(1 * 3, 3 * 5) , 7 * 5)", 15),
            new string_float("min(  MaX(1, 3 ) ,  MAX(5 , 7 ))", 3),
        };

        foreach (string_float currentData in testData)
        {
            Assert.AreEqual(currentData.value, Evaluate.Eval(currentData.str));
        }
    }
コード例 #6
0
        public static void GreenCameraTest()
        {
        #if NetworklessShell
            Console.WriteLine(" --- GreenCameraTest() ---");
            var go_foo_cam = new GameObject();
            go_foo_cam.AddComponent <Camera>();
            go_foo_cam.GetComponent <Camera>().name = "foo";

            var go_other_cam = new GameObject();
            go_other_cam.AddComponent <Camera>();

            Resources.roots = new [] { go_foo_cam, go_other_cam };


            var query = ">> :Camera .%projectionMatrix <- @[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]";

            var GramE = new GrammarEntry {
                StartProd      = MG.ProvStart,
                TR_constructor = (prov_start_node) => new ProvStartTU((MG.ProvStartNode)prov_start_node)
            };
            var transl_LHS = new TranslateLHS {
                preCH_LHS = null,
                scope     = new CH_closedScope()
            };

            var compilat1 = TranslateEntry.TranslateFully_incomplete_tolerant(query, GramE, transl_LHS);

            var MM  = new MemMapper();
            var res = Evaluate.Eval(compilat1, MM);

            Console.WriteLine(res);
            var query2    = ">> :Camera {.name == @\"foo\"} .projectionMatrix <- @[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]";
            var compilat2 = TranslateEntry.TranslateFully_incomplete_tolerant(query2, GramE, transl_LHS);

            Analyz0r.A.JsonifyCompilat(compilat2, "_GreenCam_with_fan");

            var res2 = Evaluate.Eval(compilat2, MM);
            Console.WriteLine(res2);

            Analyz0r.A.JsonifyEval(compilat2, MM, "_GreenCam_with_fan");

            Console.WriteLine(" --- GreenCameraTest() done ---");
        #endif
        }
コード例 #7
0
ファイル: EvaluateTest.cs プロジェクト: Hengle/Unity-Eveluate
    public void Eval_Test()
    {
        string_float[] testData = new string_float[]
        {
            new string_float("1 + 2", 3),
            new string_float("2 * 3", 6),
            new string_float("( 1 + 2 ) * 3", 9),
            new string_float("1 + ( 3 / 2 ) * 7 + 3", 14.5f),
            new string_float("1 max 3", 3),
            new string_float("1 min 3", 1),
            new string_float("1 * 3 max 3 * 5 min 7 * 5", 15),
            new string_float("( 1 max 3 ) min ( 5 max 7 )", 3),
        };

        foreach (string_float currentData in testData)
        {
            Assert.AreEqual(currentData.value, Evaluate.Eval(currentData.str));
        }
    }
コード例 #8
0
    public void Eval_Normal_Test()
    {
        string_float[] testData = new string_float[]
        {
            new string_float("1 + 2", 3),
            new string_float("2 * 3", 6),
            new string_float("( 1 + 2 ) * 3", 9),
            new string_float("1 + ( 3 / 2 ) * 7 + 3", 14.5f),
            new string_float("max ( 1 , 3 )", 3),
            new string_float("min ( 1 , 3 )", 1),
            new string_float("min ( max (1 * 3,  3 * 5) , 7 * 5)", 15),
            new string_float("min(  MaX(1, 3 ) ,  MAX(5 , 7 ))", 3),
            new string_float("min ( max( 1 , 3) , max ( 5 , 7) )", 3),
        };

        foreach (string_float currentData in testData)
        {
            Assert.AreEqual(currentData.value, Evaluate.Eval(currentData.str));
        }
    }
コード例 #9
0
    public void Eval_Space_Test()
    {
        string_float[] testData = new string_float[]
        {
            new string_float("1   +  2", 3),
            new string_float("2* 3", 6),
            new string_float("(1+2)*3", 9),
            new string_float("1 + ( 3 / 2 ) * 7 + 3", 14.5f),
            new string_float("max   (1   , 3)     ", 3),
            new string_float("min(1,3)", 1),
            new string_float("1   * 3 max 3 * 5 min 7 * 5", 15),
            new string_float("min  (max(1 * 3,  3 * 5) , 7 * 5)", 15),
            new string_float("min(max( 1 , 3)  ,max (5,7) )", 3),
            new string_float("1+2", 3),
            new string_float("1.568*2.598", 4.073664f),
            new string_float("1.568*-2.598", -4.073664f),
            new string_float("((-7.25+6.25)*(7.6/96.4)+1576.2)*3.5", 5516.42406639f),
        };

        foreach (string_float currentData in testData)
        {
            Assert.AreEqual(currentData.value, Evaluate.Eval(currentData.str));
        }
    }