try {
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(in);
ToolANTLRLexer lexer = new ToolANTLRLexer(in, this);
CommonTokenStream tokens = new CommonTokenStream(lexer);
lexer.tokens = tokens;
ToolANTLRParser p = new ToolANTLRParser(tokens, this);
p.setTreeAdaptor(adaptor);
try {
ParserRuleReturnScope r = p.grammarSpec();
GrammarAST root = (GrammarAST)r.getTree();
if ( root instanceof GrammarRootAST) {
((GrammarRootAST)root).hasErrors = lexer.getNumberOfSyntaxErrors()>0 || p.getNumberOfSyntaxErrors()>0;
assert ((GrammarRootAST)root).tokenStream == tokens;
if ( grammarOptions!=null ) {
((GrammarRootAST)root).cmdLineOptions = grammarOptions;
}
return ((GrammarRootAST)root);