[antlr-interest] Can't see the wood (@init and @after)

Jim Idle jimi at temporal-wave.com
Thu Jul 19 10:09:28 PDT 2007


In the C target the @init code is gated from backtracking mode, however
in the Java target, it is not, but the action code is. Hence you are
seeing the @init code called every time backtracking pops in to say
hello.
 
Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Paul Keir
> Sent: Thursday, July 19, 2007 7:40 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Can't see the wood (@init and @after)
> 
> Hi Susan,
> 
> I tried it again just to be sure, and got the same result. If in the
> C.g
> file of the C project from the java ANTLR examples, I augment line
> 354's
> 'expression' rule with two println calls, i.e.
> 
> expression
> 
> @init { System.out.println("a"); }
>     : { System.out.println(" b"); } assignment_expression (','
> assignment_expression)*
>     ;
> 
> And then build and run the generated parser on the 'input' data, I
find
> that I get a lot more letter 'a's output than letter 'b's. I don't
> understand why that is, but at least I have this example to hopefully
> learn from.
> 
> It's interesting that you can't repeat this. Perhaps someone else can,
> or help me to an understanding.
> 
> Cheers,
> Paul



More information about the antlr-interest mailing list