示例#1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                DisplayDirections();
            }
            else if (!File.Exists(args[0]))
            {
                Console.WriteLine("Could not find parser script '{0}'", args[0]);
                Environment.Exit(1);
            }
            else if (args[1].Any(Path.GetInvalidPathChars().Contains))
            {
                Console.WriteLine("Invalid output file '{0}'", args[1]);
                Environment.Exit(1);
            }

            string code = "";

            try
            {
                code = File.ReadAllText(args[0]);
                Console.WriteLine("Parsing input file");
                var ast = AphidParser.Parse(code);
                var macroMutator = new AphidMacroMutator();
                var pipelineMutator = new PipelineToCallMutator();
                ast = macroMutator.MutateRecursively(pipelineMutator.Mutate(ast));
                Console.WriteLine("Generating parser");
                var parserGenerator = new ParserGenerator();
                var s = parserGenerator.Generate(ast);
                File.WriteAllText(args[1], s);
                Console.WriteLine("Parser written to '{0}'", args[1]);
            }
            catch (AphidParserException exception)
            {
                Console.WriteLine(ParserErrorMessage.Create(code, exception));
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unexpected exception\r\n\r\n{0}\r\n", exception.Message);
            }
        }
示例#2
0
文件: Program.cs 项目: 5l1v3r1/Aphid
        private static void GenerateParser(string code, string dir, string outFile)
        {
            Console.WriteLine("Parsing input file");
            var ast             = AphidParser.Parse(code);
            var includeMutator  = new IncludeMutator(dir);
            var idMutator       = new AphidPreprocessorDirectiveMutator();
            var macroMutator    = new AphidMacroMutator();
            var pipelineMutator = new PipelineToCallMutator();

            ast = idMutator.MutateRecursively(
                macroMutator.MutateRecursively(
                    pipelineMutator.Mutate(
                        includeMutator.MutateRecursively(ast))));

            Console.WriteLine("Generating parser");
            var parserGenerator = new ParserGenerator();
            var s = parserGenerator.Generate(ast, code);

            File.WriteAllText(outFile, s);
            Console.WriteLine("Parser written to '{0}'", outFile);
        }