[antlr-interest] V3 BUG in C# generator (3.0b5)

Terence Parr parrt at cs.usfca.edu
Sat Dec 16 12:51:25 PST 2006


ooops.  Fixed in wiki: $channel = HIDDEN;

Ter
On Dec 16, 2006, at 12:00 PM, Bill Mayfield wrote:

> Howdy,
>
> Sorry if this isn't the right place to report bugs but I don't know  
> where else to go with it so...
>
> Following rule in the 5 minute introduction sample grammar ( http:// 
> www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR 
> +3 ) produces this C# error upon compilation.
>
>
> Rule: WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+      
> { channel = 99; } ;
> Compilation Error: The name channel does not exist in the current  
> context.
>
>
>
> I guess channel = 99 should be _channel=99? But is this a bug in  
> the C# generator or in the grammer?
>
>
>
>
>
>
>
> Below is the generated code for clarity:
>
>
>
>
>    // $ANTLR start WHITESPACE
>    public void mWHITESPACE() // throws RecognitionException [2]
>    {
>        try
>        {
>            ruleNestingLevel++;
>            int _type = WHITESPACE;
>            int _start = CharIndex;
>            int _line = Line;
>            int _charPosition = CharPositionInLine;
>            int _channel = Token.DEFAULT_CHANNEL;
>            // c:\\antlr\\work\\simplecalc\\SimpleCalc.g:46:14:  
> ( ( ('\\t'|' '|'\\r'|'\\n'|'\\u000C'))+ )
>            // c:\\antlr\\work\\simplecalc\\SimpleCalc.g:46:14: ( ('\ 
> \t'|' '|'\\r'|'\\n'|'\\u000C'))+
>            {
>                // c:\\antlr\\work\\simplecalc\\SimpleCalc.g:46:14:  
> ( ('\\t'|' '|'\\r'|'\\n'|'\\u000C'))+
>                int cnt2 = 0;
>                do
>                {
>                    int alt2 = 2;
>                    int LA2_0 = input.LA(1);
>                    if ( ((LA2_0 >= '\t' && LA2_0 <= '\n') || (LA2_0  
> >= '\f' && LA2_0 <= '\r') || LA2_0 == ' ') )
>                    {
>                        alt2 = 1;
>                    }
>                                                    switch (alt2)
>                    {
>                        case 1 :
>                            // c:\\antlr\\work\\simplecalc\ 
> \SimpleCalc.g:46:16: ('\\t'|' '|'\\r'|'\\n'|'\\u000C')
>                            {
>                                if ( (input.LA(1) >= '\t' && input.LA 
> (1) <= '\n') || (input.LA(1) >= '\f' && input.LA(1) <= '\r') ||  
> input.LA(1) == ' ' )
>                                {
>                                    input.Consume();
>                                                              }
>                                else
>                                {
>                                    MismatchedSetException mse =
>                                        new MismatchedSetException 
> (null,input);
>                                    Recover(mse);    throw mse;
>                                }
>
>                                                      }
>                            break;
>                                      default:
>                            if ( cnt2 >= 1 ) goto loop2;
>                                EarlyExitException eee =
>                                    new EarlyExitException(2, input);
>                                throw eee;
>                    }
>                    cnt2++;
>                } while (true);
>                              loop2:
>                    ;    // Stops C# compiler whinging that label  
> 'loop2' has no statements
>
>                 channel = 99;
>                      }
>                                  if ( (token == null) &&  
> (ruleNestingLevel == 1) )
>                    {
>                        Emit(_type, _line, _charPosition, _channel,  
> _start, CharIndex-1);
>                    }
>                                  }
>        finally
>        {
>            ruleNestingLevel--;
>        }
>    }
>    // $ANTLR end WHITESPACE



More information about the antlr-interest mailing list