コード例 #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 ast        = parser.Program();
                Console.WriteLine("Syntax OK.");

                var semantic = new SemanticAnalyzer();
                semantic.Visit((dynamic)ast);
                Console.WriteLine("Semantics OK.");
                var codeGenerator = new CILGenerator(semantic.funcs, semantic.localvars, semantic.global_vars);
                File.WriteAllText(
                    outputPath,
                    codeGenerator.Visit((dynamic)ast));
                Console.WriteLine(
                    "Generated CIL code to '" + outputPath + "'.");
                Console.WriteLine();
            } catch (Exception e) {
                if (e is FileNotFoundException ||
                    e is SyntaxError ||
                    e is SemanticError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                throw;
            }
        }
コード例 #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.");

                var semantic = new SemanticAnalyzer();
                semantic.Visit((dynamic)program);

                Console.WriteLine("Semantics OK.");
                Console.WriteLine();
                Console.WriteLine("Symbol Table");
                Console.WriteLine("============");
            } catch (Exception e) {
                if (e is FileNotFoundException ||
                    e is SyntaxError ||
                    e is SemanticError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                throw;
            }
        }