示例#1
0
        private static void Compile(IList<string> args)
        {
            var scan = new Scanner();
            scan.SetSource(GetSource(args), 0);

            var parser = new Parser(scan);
            if (!parser.Parse())
            {
                Console.WriteLine("Parsing failed!");
                return;
            }

            var root = parser.SyntaxTreeRoot;
            Console.WriteLine(root.Print(0));

            RunSemanticPasses(root);
            GenerateIntermediateCode(args[0], root);

            Console.Read();
        }
        private bool Parse(string source)
        {
            var scan = new Scanner();
            scan.SetSource(File.ReadAllText(source), 0);

            var parser = new Parser(scan);
            return parser.Parse();
        }
        private static void CompileAndBuildExecutable()
        {
            var scan = new Scanner();
            scan.SetSource(File.ReadAllText(FILE_LOCATION), 0);

            var parser = new Parser(scan);
            parser.Parse();

            var root = parser.SyntaxTreeRoot;
            var mgr = new ScopeManager();

            var first = new FirstPass(root, mgr);
            var second = new SecondPass(root, mgr);
            first.Run();
            second.Run();

            const string asmName = "sample1-test";
            var cg = new CodeGenerator(asmName);
            cg.Generate(root);
            cg.WriteAssembly();
        }