[antlr-interest] Simple Grammar breaks ANTLRWorks Interpreter & Debugger?

David-Sarah Hopwood david-sarah at jacaranda.org
Sun Aug 16 19:01:03 PDT 2009


consiliens at gmail.com wrote:
> On 09-08-16 07:08 PM, David-Sarah Hopwood wrote:
>> consiliens at gmail.com wrote:
>>> I looked at ANTLRStringStreams consume() method and noticed that it
>>> checks for a '\n'. In the current grammar I'm skip()ing newlines,
>>> instead of placing them on a hidden channel.
>>>
>>> I made the following modification to the grammar in ANTLRWorks which
>>> promptly broke the compiler.
>>> fragment NEWLINE : '\n' '\r'? {$channel=HIDDEN;};
>>> fragment WS      : ('\n'|'\r'|'\t'|' ')+ {$channel=HIDDEN;};
>>>
>>> The error message is "cannot find symbol : variable _channel".
>> That's quite strange; I'm using $channel = HIDDEN in ANTLRWorks (version
>> 1.2.3) with no problems. Could something be wrong with your ANTLR/ANTLRWorks
>> installation?
>>
>> Can you reduce the grammar to the minimum necessary to reproduce the above
>> error message, and post it here?
> 
> I tested on ANTLRWorks 1.2.3 also and the same error occurs. I don't 
> think there's anything wrong with my ANTLRWorks installation? java -jar 
> antlrworks-1.2.3.jar
> 
> grammar bug;
> bug	:	 EOF;
> fragment NEWLINE : '\n' '\r'? {$channel=HIDDEN;};
> 
> Console:
> [19:14:16] /output/bugLexer.java:50: cannot find symbol
> [19:14:16] symbol  : variable _channel
> [19:14:16] location: class bugLexer
> [19:14:16]             _channel=HIDDEN;
> [19:14:16]             ^
> [19:14:16] 1 error

OK, I can reproduce that using
  java org.antlr.Tool bug.g
  javac bug*.java
so we can eliminate ANTLRWorks.


The generated code for mNEWLINE does not contain

    int _channel = DEFAULT_TOKEN_CHANNEL;
    ...
    state.channel = _channel;

as I would expect it to. Someone with a deeper knowledge of ANTLR internals
will have to investigate why not.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list