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

Juancarlo Añez apalala at gmail.com
Mon Oct 15 21:34:02 PDT 2012


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
target.

Thanks again,

-- 
Juancarlo *Añez*


More information about the antlr-interest mailing list