private static CrawlParser.Translation_unitContext ParseFile(Stream file)
        {
            //First we need to open specified file.
            AntlrInputStream fs = new AntlrInputStream(file);
            //An ITokenSource lets us get the tokens one at a time.
            ITokenSource ts = new CrawlLexer(fs);
            //An ITokenStream lets us go forwards and backwards in the token-series.
            ITokenStream tstream = new CommonTokenStream(ts);
            //That's what our parser wants.
            CrawlParser parser = new CrawlParser(tstream);

            return(parser.translation_unit());
        }
        public static ParseTreeData ReadFileToPt(string path, SideeffectHelper helper)
        {
            ICharStream  charStream  = new AntlrFileStream(path, Encoding.UTF8);
            CrawlLexer   tokenSource = new CrawlLexer(charStream);
            ITokenStream tokenStream = new CommonTokenStream(tokenSource);

            CompilationMessageErrorListner cm = new CompilationMessageErrorListner(helper.CompilationMessages, path);

            CrawlParser parser = new CrawlParser(tokenStream);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(cm);

            CrawlParser.Translation_unitContext translationUnit = parser.translation_unit();

            return(new ParseTreeData(tokenStream, translationUnit, path));
        }
        public static CrawlSyntaxTree ReadFile(string filename)
        {
            ICharStream  charStream  = new AntlrFileStream(filename, Encoding.UTF8);
            CrawlLexer   tokenSource = new CrawlLexer(charStream);
            ITokenStream tokenStream = new CommonTokenStream(tokenSource);
            CrawlParser  parser      = new CrawlParser(tokenStream);


            //The translation_unit is the top rule in our grammar.
            //Asking the parser to match that from the token stream leaves us at the top of the parse tree.
            CrawlParser.Translation_unitContext rootContext = parser.translation_unit();


            TranslationUnitNode node = ParseTreeParser.ParseTranslationUnit(rootContext);

            node.OwningTree.CompilationUnitName = filename;

            return(node.OwningTree);
        }