Exemple #1
0
        public static void Debug_CILProgram(string text)
        {
            var root     = BuildAST_Cool.BUILD(text);
            var cil_root = CILCompiler.Build(root);
            var sem      = SemanticType.BuildAllType(root.class_list);
            var solve    = CIL_Execute.Execute(cil_root, sem);

            Console.WriteLine(solve);
        }
Exemple #2
0
        public static void Debug_ASTCIL(string text, string path = "cil.il")
        {
            var    root     = BuildAST_Cool.BUILD(text);
            var    cil_root = CILCompiler.Build(root);
            string s        = cil_root.ToString();
            var    w        = new StreamWriter(path);

            w.Write(s);
            w.Close();
        }
Exemple #3
0
        public static void Debug_Mips(string text, string path = "mips.s")
        {
            var root     = BuildAST_Cool.BUILD(text);
            var cil_root = CILCompiler.Build(root);
            var sem      = SemanticType.BuildAllType(root.class_list);
            //var solve = CIL_Execute.Execute(cil_root, sem);
            var    prog = new MipsCompiler(cil_root, sem);
            string s    = (prog.Visit(cil_root));
            //Console.WriteLine(s);
            var w = new StreamWriter(path);

            w.Write(s);
            w.Close();
        }
Exemple #4
0
        static void Compilator(string path, string dest, string mips)
        {
            var r = new StreamReader(path);

            var text = r.ReadToEnd();

            var root = BuildAST_Cool.BUILD(text);

            if (root == null)
            {
                return;
            }

            var result = SemanticChecking(root);

            if (result.Item1)
            {
                var    cil_root = CILCompiler.Build(root);
                string s        = cil_root.ToString();
                var    w        = new StreamWriter(dest);
                //Console.WriteLine(s);
                w.Write(s);
                w.Close();
                var sem = SemanticType.BuildAllType(root.class_list);
                //var solve = CIL_Execute.Execute(cil_root, sem);
                var prog = new MipsCompiler(cil_root, sem);
                s = (prog.Visit(cil_root));
                //Console.WriteLine(s);
                var t = new StreamWriter(mips);
                //Console.WriteLine(s);
                t.Write(s);
                t.Close();
            }
            else
            {
                Console.WriteLine("There are some errors!!!");
                foreach (var item in result.Item2.Log)
                {
                    Console.WriteLine(item);
                }
            }
        }
Exemple #5
0
        private static IMachineFactory CreateMachineFactory(string pattern, RegexOptions options)
        {
            Parser            psr = new Parser();
            RegularExpression re  = psr.ParseRegularExpression(pattern, options);

#if NET_2_1
            ICompiler cmp = new PatternCompiler();
#else
            ICompiler cmp;
            if (!old_rx)
            {
                if ((options & RegexOptions.Compiled) != 0)
                {
                    cmp = new CILCompiler();
                }
                else
                {
                    cmp = new RxCompiler();
                }
            }
            else
            {
                cmp = new PatternCompiler();
            }
#endif

            re.Compile(cmp, (options & RegexOptions.RightToLeft) != 0);

            IMachineFactory machineFactory = cmp.GetMachineFactory();
            Hashtable       mapping        = new Hashtable();
            machineFactory.Gap          = psr.GetMapping(mapping);
            machineFactory.Mapping      = mapping;
            machineFactory.NamesMapping = GetGroupNamesArray(machineFactory.GroupCount, machineFactory.Mapping);

            return(machineFactory);
        }