public static void Term(GATNode node)
        {
            int     childnum = node.ChildCount();
            string  mulop    = "";
            GATNode child;

            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);

            child = node.getChild(0);
            node.SetProperty("value", child.GetProperty("value"));
            for (int i = 1; i < childnum; i++)
            {
                child = node.getChild(i);
                if (child.GetProperty("value") == "*")
                {
                    mulop = "*";
                }
                else if (child.GetProperty("value") == "/")
                {
                    mulop = "/";
                }
                else//有待解决如何记录结果
                {
                    CodeGenerator.AddCode(mulop, node.GetProperty("value"), child.GetProperty("value"), "T" + CodeGenerator.tempnum);
                    Console.WriteLine(mulop + " " + node.GetProperty("value") + " " + child.GetProperty("value") + " " + "T" + CodeGenerator.tempnum);
                    node.SetProperty("value", "T" + CodeGenerator.tempnum);
                    CodeGenerator.tempnum++;
                }
            }
        }
        public static GATNode _localDeclarations(this LL1Processor ll1)
        {
            var node   = new GATNode();
            var offset = 1;

            var next = WordContainer.GetWordType(offset);

            while (next == WordType.ID)
            {
                var varDeclaration = ll1._varDeclaration();
                node.AddChild(varDeclaration);
                next = WordContainer.GetWordType(offset);
            }

            if (node.ChildCount() == 0)
            {
                node.generator = LocalDeclarations2;
            }
            else
            {
                node.generator = LocalDeclarations1;
            }

            return(node);
        }
        public static void SelectionStmt(GATNode node)
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);
            var expression = node.getChild(0);

            switch (node.ChildCount())
            {
            case 4:
            {
                var falseLabel = node.getChild(3).GetProperty("LabelName");
                var jmpLine    = Int32.Parse(node.getChild(1).GetProperty("CodeLine"));
                CodeGenerator.SetCode(jmpLine, "je", expression.GetProperty("value"), "0", "0");
                CodeGenerator.PutLabel(falseLabel, jmpLine);
                break;
            }

            case 7:
            {
                var falseLabel = node.getChild(4).GetProperty("LabelName");
                var jmpLine    = Int32.Parse(node.getChild(1).GetProperty("CodeLine"));
                CodeGenerator.SetCode(jmpLine, "je", expression.GetProperty("value"), "0", "0");
                CodeGenerator.PutLabel(falseLabel, jmpLine);

                var endLabel    = node.getChild(6).GetProperty("LabelName");
                var trueEndLine = Int32.Parse(node.getChild(3).GetProperty("CodeLine"));
                CodeGenerator.SetCode(trueEndLine, "j", "#", "#", "#");
                CodeGenerator.PutLabel(endLabel, trueEndLine);
                break;
            }
            }
        }
Beispiel #4
0
        public static GATNode _args(this LL1Processor ll1)
        {
            var node = new GATNode();
            var next = WordContainer.GetWordType();

            if (ArgListProc.first.Contains(next))
            {
                var argList = ll1._argList();
                node.AddChild(argList);
            }

            if (node.ChildCount() == 0)
            {
                node.generator = Args2;
            }
            else
            {
                node.generator = Args1;
            }
            return(node);
        }
        public static void ReturnStmt(GATNode node)
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);

            if (node.ChildCount() == 0)
            {
                CodeGenerator.AddCode("ret", "#", "#", "#");
            }
            else
            {
                var tmpNode = "T" + CodeGenerator.tempnum++;
                CodeGenerator.AddCode("+", "EBP", "12", tmpNode);
                CodeGenerator.AddCode("*", tmpNode, "4", tmpNode);
                CodeGenerator.AddCode("+", "EBP", tmpNode, tmpNode);
                CodeGenerator.AddCode("+", tmpNode, "16", tmpNode);
                CodeGenerator.AddCode("[", tmpNode, "#", tmpNode);
                CodeGenerator.AddCode("[", tmpNode, "#", tmpNode);
                CodeGenerator.AddCode("]", node.getChild(0).GetProperty("value"), "#", tmpNode);
                CodeGenerator.AddCode("ret", "#", "#", "#");
            }
        }