Пример #1
0
        public void TestCalc()
        {
            NakoNode topNode;

            // 1
            topNode = compiler.ParseOnlyValue("1+2*3");
            Assert.IsTrue(topNode.hasChildren());
            Assert.IsTrue(topNode.Children.checkNodeType(
                              new NakoNodeType[] {
                NakoNodeType.CALC
            }));
            // 2
            topNode = compiler.ParseOnlyValue("(1+2)*3");
            Assert.IsTrue(topNode.hasChildren());
            Assert.IsTrue(topNode.Children.checkNodeType(
                              new NakoNodeType[] {
                NakoNodeType.CALC
            }));
            // 3
            topNode = compiler.Parse("A=5");
            Assert.IsTrue(topNode.hasChildren());
            Assert.IsTrue(topNode.Children.checkNodeType(new NakoNodeType[] {
                NakoNodeType.LET
            }));
        }
Пример #2
0
        public void TestInterpreter1()
        {
            NakoCompiler    ns     = new NakoCompiler();
            NakoInterpreter runner = new NakoInterpreter();
            object          o;

            // 1
            ns.source = "1+2*3";
            ns.Tokenize();
            ns.ParseOnlyValue();
            runner.Run(ns.WriteIL());
            o = runner.StackTop;
            Assert.IsNotNull(o);
            Assert.IsTrue(7 == NakoValueConveter.ToLong(o));

            // 2
            ns.source = "(1+2)*3";
            ns.Tokenize();
            ns.ParseOnlyValue();
            runner.Run(ns.WriteIL());
            o = runner.StackTop;
            Assert.IsNotNull(o);
            Assert.IsTrue(9 == NakoValueConveter.ToLong(o));

            // 3
            ns.source = "1+4/2";
            ns.Tokenize();
            ns.ParseOnlyValue();
            runner.Run(ns.WriteIL());
            o = runner.StackTop;
            Assert.IsNotNull(o);
            Assert.IsTrue(3 == NakoValueConveter.ToLong(o));
        }
Пример #3
0
        public void TestNakoILWriter1()
        {
            NakoCompiler ns     = new NakoCompiler();
            NakoILWriter writer = new NakoILWriter(null);
            bool         r;

            // (1)
            ns.source = "1+2*3";
            ns.Tokenize();
            ns.ParseOnlyValue();
            writer.Write(ns.TopNode);
            r = writer.Result.CheckTypes(new NakoILType[] {
                NakoILType.NOP,
                NakoILType.LD_CONST_INT,
                NakoILType.LD_CONST_INT,
                NakoILType.LD_CONST_INT,
                NakoILType.MUL,
                NakoILType.ADD
            });
            Assert.IsTrue(r);
        }