[antlr-interest] Recovering from partial rule matches

Yuri Tijerino yuri at tijerino.net
Mon Nov 10 11:36:09 PST 2008


Hi All,

I have been working with ANTLR for about 3.5 months on a domain-specific 
language for a very constrained domain in natural language, English.  I 
have created a fairly complex EBNF grammar for this.  Thus far I have 
been able to solve most of my questions through documentation and 
looking at the mailing list archives.

One of the requirements for this parser is that it goes through any 
English sentence and extract only the phrases that match the parsing 
rules, while skipping others.  The problem I have found with this, is 
that when the rules (parser or lexer), do not match anything in an 
sentence and then encounter something that matches, it works great with 
the automatic error recovery strategy in ANTLR, however, when there is a 
partial match of a parser rule, I get an "required (..)+ loop did not 
match anything at input" exception. 

Is there anyway to throw away the token that caused this exception and 
continue with the rest of the input? 

Currently I am handling most of these problems by creating an additional 
rule where all the alternatives are the single tokens at the beginning 
of the rules that cause the problem above.  This works fine, but 
increases the complexity of the DFA and causes munch unwanted 
ambiguities.  There has got to be a better way.

I am using ANTLR 3.1.1 and my target language is Java.

Any help is very much appreciated.

Yuri Tijerino


More information about the antlr-interest mailing list