[antlr-interest] Empty ifs in Java

Bart Kiers bkiers at gmail.com
Sat Nov 5 05:45:03 PDT 2011


Hi Patrick,

The range operator, `..`, only works in lexer rules, not in parser rules as
you're doing. Capitalize the `letter` rule to make it a lexer rule:

grammar failuretest;
start:          letter+;
Letter:         'A' .. 'B'; // or did you mean 'A'..'Z'?

and then try again.

Regards,

Bart.


On Sat, Nov 5, 2011 at 1:41 PM, Patrick Zimmermann <patrick at zakweb.de>wrote:

> Hello,
>
> I'm new to this mailing list, so hello everyone.
>
> I currently try to create a grammar to parse a textual wiki syntax.
> I'm using ANTLR 3.4 and the Java generator.
>
> I've reached a situation where ANTLR creates empty ifs in the generated
> Java
> code and I boiled it down to the following grammar:
>
> grammar failuretest;
> start:          letter+;
> letter:         'A' .. 'B';
>
> The resulting Java code contains the following statements:
> ...
> if ( () ) {
> ...
> if (  ) {
> ...
>
> As far as I know this is no legal Java. And the grammar looks fine to me,
> apart
> from that the second rule should probably be a lexer rule.
>
> So could this actually be a bug in antlr?
>
>
> Many thanks in advance,
> Patrick Zimmermann
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list