Exemplo n.º 1
0
        //-----------------------------------------------------------
        void Run(string[] args)
        {
            PrintAppHeader();
            Console.WriteLine();
            PrintReleaseIncludes();
            Console.WriteLine();

            if (args.Length != 2)
            {
                Console.Error.WriteLine("Please specify the name of the input and output files.");
                Environment.Exit(1);
            }

            try {
                var inputPath  = args[0];
                var outputPath = args[1];
                var input      = File.ReadAllText(inputPath);

                var parser  = new Parser(new Scanner(input).Start().GetEnumerator());
                var program = parser.Program();
                Console.WriteLine("Syntax OK");
                Console.Write(program.ToStringTree());

                //pruebas de la table symboltable (globales)
                var semantic = new SemanticAnalyzer();
                semantic.Visit((dynamic)program);
                semantic.Visit((dynamic)program);
                if (semantic.isSemanticCorrect())
                {
                    //Console.WriteLine();
                    Console.WriteLine("____________________________________________");
                    Console.WriteLine();
                    Console.WriteLine("Semantic OK");
                    Console.WriteLine("____________________________________________");
                    Console.WriteLine();
                    Console.WriteLine();
                }

                var    CILgeneration = new CILGenerator();
                string finalCode     = CILgeneration.Visit((dynamic)program);

                Console.WriteLine(finalCode);

                //se guarda el archivo que se desea
                File.WriteAllText(
                    outputPath,
                    finalCode);
                //se termina de guardar el archivo
            } catch (Exception e) {
                if (e is FileNotFoundException || e is SyntaxError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------
        void Run(string[] args)
        {
            PrintAppHeader();
            Console.WriteLine();
            PrintReleaseIncludes();
            Console.WriteLine();

            if (args.Length != 1)
            {
                Console.Error.WriteLine("Please specify the name of the input file.");
                Environment.Exit(1);
            }

            try {
                var inputPath = args[0];
                var input     = File.ReadAllText(inputPath);

                var parser  = new Parser(new Scanner(input).Start().GetEnumerator());
                var program = parser.Program();
                Console.WriteLine("Syntax OK");
                Console.Write(program.ToStringTree());

                //pruebas de la table symboltable (globales)
                var semantic = new SemanticAnalyzer();
                semantic.Visit((dynamic)program);
                semantic.Visit((dynamic)program);
                if (semantic.isSemanticCorrect())
                {
                    Console.WriteLine();
                    Console.WriteLine("____________________________________________");
                    Console.WriteLine();
                    Console.WriteLine("Semantic OK");
                    Console.WriteLine("____________________________________________");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine(semantic.GlobalSymbols.ToString());
                    Console.WriteLine(semantic.Functions.ToString());
                }
            } catch (Exception e) {
                if (e is FileNotFoundException || e is SyntaxError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                throw;
            }
        }