[antlr-interest] Can an Antlr Parser return a TreeNodeStream so as to not have to parse the whole file at once?

Burton Samograd burton.samograd at markit.com
Mon Apr 16 12:03:19 PDT 2012

In the following Antlr example, the parser is used to generate an AST which is then converted into a CommonTreeNodeStream, which is then passed to the checker.
public static void main(String[] args) {

CalcLexer  lex  = new CalcLexer(
                        new ANTLRInputStream(System.in));
CommonTokenStream tokens = new CommonTokenStream(lex);
CalcParser parser = new CalcParser(tokens);

CalcParser.program_result result = parser.program();
CommonTree tree = (CommonTree) result.getTree();

CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
CalcChecker checker = new CalcChecker(nodes);

CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
CalcInterpreter interpreter = new CalcInterpreter(nodes);
Is it possible to get the parser to return a CommonTreeNodeStream that can be then passed to the Checker so that the whole file does not have to be lexed and parsed at once and rather as a stream of tokens and then tree nodes?
I ask because we are running into a problem with an extremely large file being passed into our Antlr parser and it is causing memory exhaustion in the parsing phase. I am thinking that using a TreeNodeStream would solve this problem if it is even possible.
Burton Samograd

This e-mail, including accompanying communications and attachments, is strictly confidential and only for the intended recipient. Any retention, use or disclosure not expressly authorised by Markit is prohibited. This email is subject to all waivers and other terms at the following link: http://www.markit.com/en/about/legal/email-disclaimer.page

Please visit http://www.markit.com/en/about/contact/contact-us.page? for contact information on our offices worldwide.

More information about the antlr-interest mailing list