[antlr-interest] init bug

Douglas Godfrey douglasgodfrey at gmail.com
Tue Nov 15 08:44:49 PST 2011


create a testParser.cpp file which consists of 1 line
#include "testParser.c"

When your project compiles testParser.cpp the generated code for declaring
flag will work.

NOTE: you cannot use the variable flag in any predicate or production
before the first token is consumed.
      code before the first token may be "hoisted" into the parent rule
and the local variable flag will
      not be defined in the parent rule context.

On 11/7/11 9:26 AM, "yushang" <yusunn at gmail.com> wrote:

>Hi , everyone,
>I found varibale put in init section will raise compiler error , for
>example
>test
>@init{
>int flag=0;
>}
> :  expr -> ^(EXPR expr)
> ;
>will generate following code fragment
>...
>root_0 = NULL;
>int flag = 0;
>...
>this will be error by C compiler , because C language do not allow
>variable
>declaration middle of block.
>BTW I'm using ANTLR v3.4 and C runtime v3.4
>Many thanks
>
>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