Ejemplo n.º 1
0
        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++;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Call(GATNode node)
        {
            //TODO:支持参数表,栈帧处理
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);

            var processName = node.getChild(0).GetProperty("value");

            var args   = node.getChild(1);
            var argNum = args.ChildCount();

            if (argNum == 0)
            {
                CodeGenerator.CallFunction(processName, new List <string>());
                node.SetProperty("value", "void");
            }
            else
            {
                var paramList = new List <string>();
                var argList   = args.getChild(0);
                for (int i = 0; i < argList.ChildCount(); i++)
                {
                    paramList.Add(argList.getChild(i).GetProperty("value"));
                }
                var retNode = CodeGenerator.CallFunction(processName, paramList);
                node.SetProperty("value", retNode);
            }
        }
Ejemplo n.º 3
0
        public static void Var(GATNode node)
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);
            GATNode IDnode = node.getChild(0);

            node.SetProperty("value", IDnode.GetProperty("value"));
        }
        public static void varDeclaration(GATNode node)
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName);

            string type, id;

            type = node.getChild(0).GetProperty("value");
            id   = node.getChild(1).GetProperty("value");
            node.SetProperty("value", id);
            node.SetProperty("type", type);
            GATNode process = node.GetParent();

            while (process.name == "")
            {
                process = process.GetParent();
            }
            CodeGenerator.AddSymbol(node.GetProperty("value"), process.name, null);
        }
Ejemplo n.º 5
0
        public static void Expression1(GATNode node)
        {
            //simple expression
            GATNode child;

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

            child = node.getChild(0);
            node.SetProperty("value", child.GetProperty("value"));
        }
Ejemplo n.º 6
0
        public static void Expression2(GATNode node)
        {
            //var = expression
            GATNode left, right;

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

            left  = node.getChild(0);
            right = node.getChild(1);

            node.SetProperty("value", left.GetProperty("value"));

            CodeGenerator.AddCode("=", right.GetProperty("value"), null, left.GetProperty("value"));
            Console.WriteLine("=" + " " + right.GetProperty("value") + " " + "\t" + " " + left.GetProperty("value"));
        }
Ejemplo n.º 7
0
 public static void typeSpecifier2(GATNode node)
 {
     node.SetProperty("value", "VOID");
     Console.WriteLine("typeSpecifier2");
 }