コード例 #1
0
        static void Test3()
        {
            Compiler      c     = new Compiler();
            List <string> lVars = new List <string>();

            lVars.Add("var int x;");
            lVars.Add("var int y;");
            lVars.Add("var int z;");
            List <VarDeclaration> vars = c.ParseVarDeclarations(lVars);

            string       s          = "let x = ((x + 5) + (y - z));";
            List <Token> lTokens    = c.Tokenize(s, 0);
            LetStatement assignment = c.ParseStatement(lTokens);

            List <LetStatement> lSimple   = c.SimplifyExpressions(assignment, vars);
            List <string>       lAssembly = c.GenerateCode(lSimple, vars);

            CPUEmulator cpu = new CPUEmulator();

            InitLCL(lAssembly);
            cpu.Code = lAssembly;
            cpu.Run(1000, false);
            if (cpu.M[20] != 5)
            {
                Console.WriteLine("BUGBUG");
            }
        }
コード例 #2
0
        static void Test2()
        {
            Compiler      c     = new Compiler();
            List <string> lVars = new List <string>();

            lVars.Add("var int x;");
            lVars.Add("var int y;");
            lVars.Add("var int z;");
            List <VarDeclaration> vars = c.ParseVarDeclarations(lVars);

            List <string> lAssignments = new List <string>();

            lAssignments.Add("let x = 10;");
            lAssignments.Add("let y = 15;");
            lAssignments.Add("let z = (x + y);");

            List <LetStatement> ls = c.ParseAssignments(lAssignments);


            List <string> lAssembly = c.GenerateCode(ls, vars);
            CPUEmulator   cpu       = new CPUEmulator();

            InitLCL(lAssembly);
            cpu.Code = lAssembly;
            cpu.Run(1000, false);
            if (cpu.M[22] != 25)
            {
                Console.WriteLine("BUGBUG");
            }
        }
コード例 #3
0
        static void Test1()
        {
            Compiler      c     = new Compiler();
            List <string> lVars = new List <string>();

            lVars.Add("var int x;");
            List <VarDeclaration> vars = c.ParseVarDeclarations(lVars);

            string       s          = "let x = 5;";
            List <Token> lTokens    = c.Tokenize(s, 0);
            LetStatement assignment = c.ParseStatement(lTokens);

            if (assignment.ToString() != s)
            {
                Console.WriteLine("BUGBUG");
            }


            List <LetStatement> l = new List <LetStatement>();

            l.Add(assignment);
            List <string> lAssembly = c.GenerateCode(l, vars);
            CPUEmulator   cpu       = new CPUEmulator();

            InitLCL(lAssembly);
            cpu.Code = lAssembly;
            cpu.Run(1000, false);
            if (cpu.M[20] != 5)
            {
                Console.WriteLine("BUGBUG");
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: orelkakon/SimpleComiler
        static void Test4()
        {
            Compiler c = new Compiler();

            List <string> lVars = new List <string>();

            lVars.Add("var int x;");
            lVars.Add("var int y;");
            lVars.Add("var int z;");
            List <VarDeclaration> vars = c.ParseVarDeclarations(lVars);

            List <string> lAssignments = new List <string>();

            lAssignments.Add("let x = (+ (- 53 12) (- 467 3));");
            lAssignments.Add("let y = 3;");
            lAssignments.Add("let z = (+ (- x 12) (+ y 3));");

            List <LetStatement>      ls      = c.ParseAssignments(lAssignments);
            Dictionary <string, int> dValues = new Dictionary <string, int>();

            dValues["x"] = 0;
            dValues["y"] = 0;
            dValues["z"] = 0;

            CPUEmulator cpu = new CPUEmulator();

            cpu.Compute(ls, dValues);

            List <LetStatement> lSimple = c.SimplifyExpressions(ls, vars);

            Dictionary <string, int> dValues2 = new Dictionary <string, int>();

            dValues2["x"] = 0;
            dValues2["y"] = 0;
            dValues2["z"] = 0;

            cpu.Compute(lSimple, dValues2);

            foreach (string sKey in dValues.Keys)
            {
                if (dValues[sKey] != dValues2[sKey])
                {
                    Console.WriteLine("BGUBGU");
                }
            }

            List <string> lAssembly = c.GenerateCode(lSimple, vars);

            InitLCL(lAssembly);
            cpu.Code = lAssembly;
            cpu.Run(1000, false);
            if (cpu.M[20] != dValues2["x"])
            {
                Console.WriteLine("BGUBGU");
            }
        }
コード例 #5
0
        static void Test4()
        {
            Compiler c = new Compiler();

            List <string> lVars = new List <string>();

            lVars.Add("var int x1;");
            lVars.Add("var int x2;");
            lVars.Add("var int x3;");
            lVars.Add("var int x4;");
            lVars.Add("var int x5;");
            List <VarDeclaration> vars = c.ParseVarDeclarations(lVars);


            List <string> lAssignments = new List <string>();

            lAssignments.Add("let x1 = 1;");
            lAssignments.Add("let x2 = 3;");
            lAssignments.Add("let x3 = (((x1 + 1) - 4) + ((x2 + x1) - 2));"); // 0
            lAssignments.Add("let x4 = ((x2 + x3) - (x2 -7));");              // 7
            lAssignments.Add("let x5 = (1000 - ((x1 + (((((x2 + x3) - x4) + x1) - x2) + x3)) - ((x1 - x2) + x4)));");

            List <LetStatement>      ls      = c.ParseAssignments(lAssignments);
            Dictionary <string, int> dValues = new Dictionary <string, int>();

            dValues["x1"] = 0;
            dValues["x2"] = 0;
            dValues["x3"] = 0;
            dValues["x4"] = 0;
            dValues["x5"] = 0;

            CPUEmulator cpu = new CPUEmulator();

            cpu.Compute(ls, dValues);

            List <LetStatement> lSimple = c.SimplifyExpressions(ls, vars);

            Dictionary <string, int> dValues2 = new Dictionary <string, int>();

            dValues2["x1"] = 0;
            dValues2["x2"] = 0;
            dValues2["x3"] = 0;
            dValues2["x4"] = 0;
            dValues2["x5"] = 0;

            cpu.Compute(lSimple, dValues2);

            foreach (string sKey in dValues.Keys)
            {
                if (dValues[sKey] != dValues2[sKey])
                {
                    Console.WriteLine("BGUBGU");
                }
            }

            List <string> lAssembly = c.GenerateCode(lSimple, vars);

            InitLCL(lAssembly);
            cpu.Code = lAssembly;
            cpu.Run(1000, false);
            if (cpu.M[24] != dValues2["x5"])
            {
                Console.WriteLine("BUGBUG");
            }
        }