Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            List <string> options         = new List <string>();
            List <string> arguments       = new List <string>();
            string        ast_output_file = null;

            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                arguments       = o.CFiles.ToList();
                options         = o.CompilerOptions.ToList();
                ast_output_file = o.AstOutFile;
            })
            .WithNotParsed(a =>
            {
                System.Console.Error.WriteLine(a);
            });

            Runtime.Redirect r = null;
            if (ast_output_file != null)
            {
                r = new Runtime.Redirect(ast_output_file);
            }

            foreach (var filename in arguments)
            {
                var include_dirs = CPP.tokenFactory.IncludeDirs;
                CPP.tokenFactory.pushFilename(filename);
                var ts = CPP.load(filename, include_dirs);
                System.Console.Error.WriteLine(String.Join("\n", ts.Select(x => x.ToString())));
                PreprocessedCharStream cinput = new PreprocessedCharStream(ts);
                var clexer = new gcpp.CPP14Lexer(cinput);
                // force creation of CPPTokensm set file,line
                clexer.TokenFactory = new CTokenFactory(cinput);
                CommonTokenStream ctokens = new CommonTokenStream(clexer);
                var cparser = new gcpp.CPP14Parser(ctokens);
                cparser.RemoveErrorListeners();
                cparser.AddErrorListener(new CErrorListener());
                var t   = cparser.translationunit();
                var sb  = new StringBuilder();
                var ser = new Runtime.AstHelpers();
                ser.ParenthesizedAST(sb, filename, t, ctokens);
                System.Console.WriteLine(sb.ToString());
            }
            if (r != null)
            {
                r.Dispose();
            }
        }
Ejemplo n.º 2
0
 public CTokenFactory(PreprocessedCharStream cinput)
 {
     this.cinput = cinput;
 }