[antlr-interest] Bug or badly written error case

Loring Craymer lgcraymer at yahoo.com
Mon Mar 3 15:48:15 PST 2008


This is another example of the combined grammar confusion.  Combined grammars generate separate two recognizers--a lexer and a parser; the lexer executes before the parser.  Your first "import" rule defines three lexer rules in addition to the parser rule:

IMPORT : 'import' ;
T_xxx2 : ' ' ;
T_xxx3: '\t' ;

(I assume that you have IMPORT = 'import'; in your tokens section, although maybe not given the exception raised.)

and even the "successful" case with import defined in terms of WS will not work as intended because the parser cannot encounter a WS token (the lexer moves these to the HIDDEN channel), so no input will match the import rule.

I do like the definition with WS as a possible syntax for dealing with hidden tokens, though, when they are required to be present.

--Loring

----- Original Message ----
> From: Benjamin Shropshire <shro8822 at vandals.uidaho.edu>
> To: Antlr Interest <antlr-interest at antlr.org>
> Sent: Monday, March 3, 2008 3:02:51 PM
> Subject: [antlr-interest] Bug or badly written error case
> 
> I have run into a case where some antler generated code goes into an 
> error state but gives little or no helpful information. The error was 
> cause by having these two rules in the same grammar:
> 
> WS        :    (' '|'\t')+ {Skip();} ;
> 
> import
>     : 'import' (' ' | '\t')+ FText eol_     -> ^(IMPORT FText)
>     ;
> 
> the error was removed by changeling this to
> 
> WS        :    (' '|'\t')+ {Skip();} ;
> 
> import
>     : 'import' WS FText eol_     -> ^(IMPORT FText)
>     ;
> 
> This error in my code seems to be exposing a bug (or what looks like 
> one) in antlr because it causes some of the C# antlr runtime to throw a 
> RewriteEmptyStreamException. This gives no useful information (with 
> regards to finding my error) and seems like it exposes to much of the 
> underlying runtime.
> 
> I hope this is useful.
> 
> --Benjamin Shropshire
> 
> 




      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping


More information about the antlr-interest mailing list