[antlr-interest] Way to "cut" parsing?

Juancarlo Añez apalala at gmail.com
Mon Oct 15 18:23:50 PDT 2012

I've written a grammar for a programming language. An annoyance I've
encountered is that ANTLRv3.4.1 will report failure against the enclosing
structured statement (like WHILE) instead of against the particular
statement/phrase it failed to parse. It probably does so because the many
lookaheads and the backtracking they induce.

Is there a way to implement a "cut" meta-instruction with ANTLR, so the
parser does not backtrack after having parsed a given token?

Something like:

add: 'ADD' {cut()} .... ;

so the parser will ether finish parsing the ADD statement, or fail on
*that* rule.


Juancarlo *Añez*

More information about the antlr-interest mailing list