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

Jim Idle jimi at temporal-wave.com
Mon Oct 15 22:48:49 PDT 2012

Without backtracking, then the techniques I explain in the article I sent to
you will work for this. Give it a try. You may also be using to heavy handed
lookaheads. A lot of people will write:

(rule)=>rule when they in fact only need (X|Y|Z)=>rule


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Juancarlo Añez
Sent: Tuesday, October 16, 2012 12:34 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Way to "cut" parsing?

If you are using the backtrack = true option, then that is how it works.

I'm not using the bactrack option, but a lot of backtracking goes on when I
look at the trace output.

I'm using the Python target.

As I mentioned, the grammar makes heavy use of ()=> lookaheads to resolve
the many ambiguities in the language.

The language is AG Natural, in which there are no statement terminators
except for some statements that contain other statements, and in which 4 out
of 5 keywords in a statement are optional.

The parser is complete as of the current test harness. I need to make it
behave more reasonably before new test cases arrive.

I wish to be able to tell the parser to stop looking for alternatives after
a given set of keywords have been scanned. If it wend down from the
"statement" rule, into the "upload" rule, it should fail if can't parse the
phrase after the "UPLOAD" keyword, and not backtrack to tell me that the
enclosing "IF" did not parse.

When I wrote grammars in Prolog, I could resource to the "!" (cut, or
"commit to this rule") expression to ease the parser's work. I'm looking for
something like that in ANTLR. I don't care about error recovery. Having an
error message exactly at the point on which the parser couldn't go on would
be perfect. I have a ~3000 LOC grammar, and test cases on the 500-1000LOC. I
need the parser to be efficient and pragmatic.

... and, I can't port to ANTLRv4 until there's news about it's Python

Thanks again,

Juancarlo *Añez*

List: http://www.antlr.org/mailman/listinfo/antlr-interest

More information about the antlr-interest mailing list