[antlr-interest] C# Target Unreachable Code

Benjamin Niemann pink at odahoda.de
Sat Nov 1 02:52:06 PDT 2008


Hi Ben,

I'd had to see the grammar rule that generates this code to judge if
it is really an error, but I really doubt it is.
Although ANTLR tries to generate readable code, it will never come to
the level of (good) human written code. In this specific case, the
'true' might come from action/predicate code - ANTLR would have to
understand C# (and any other target language) in order to omit the
trailing else block. Even if it could optimize that block away, it's
probably not worth the effort because the compiler already does it.
So unless you're sure your grammar is correct, but the generate code
doesn't work as it should do (i.e. you're trying to debug a bug of the
code generator), it is save to disable such compiler warnings.

- (the other) Ben

On Sat, Nov 1, 2008 at 12:47 AM, Ben Gillis <wbgillis at gmail.com> wrote:
> why the unreachable code generation?
>
> ...
> else if ( (true) )
> {
>     alt8 = 3;
> }
> else
> {
>     if ( state.backtracking > 0 ) {state.failed = true; return retval;}
>     NoViableAltException nvae_d8s1 =
>     new NoViableAltException("", 8, 1, input);
>     throw nvae_d8s1;
> }
>
> It seems fairly harmless to disable 0219 (unused variables), but disabling
> unreachable code warnings perhaps not.
>
> Regards,
> Ben
>
>
> 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