Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException("Invalid params count");
            }
            Console.WriteLine("Cool Compiler");
            var input  = args[0];
            var output = args[1];
            //var input = "C:\\Users\\Kike-PC\\Desktop\\CoolCompiler\\TestCases\\CodeGeneration\\hello_world.cl";
            //var output = "C:\\Users\\Kike-PC\\Desktop\\CoolCompiler\\TestCases\\CodeGeneration\\hello.s";
            DirectoryInfo dirInfo = new DirectoryInfo(input);
            //FileInfo files = dirInfo.GetFiles();

            FileInfo             file        = new FileInfo(input);
            ASTNode              root        = ParseInput(file.FullName);
            Scope                scope       = new Scope();
            List <SemanticError> errors      = new List <SemanticError>();
            ProgramNode          rootProgram = root as ProgramNode;

            SemanticCheck.CheckAST(rootProgram, errors, scope);
            if (errors.Count > 0)
            {
                foreach (SemanticError error in errors)
                {
                    Console.WriteLine(error.Type);
                    Console.WriteLine(error.Line + ":" + error.Column);
                }
            }
            else
            {
                var bc = new BuildICCode(rootProgram, scope);
                var s  = WMIPS.Generate(bc.GetIntCode());
                File.WriteAllText(output, s);
            }
            Console.WriteLine("Finished:");
        }