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

Loring Craymer lgcraymer at yahoo.com
Thu Jul 19 10:05:54 PDT 2007


This is a design feature:  most actions are not
executed in guessing mode, but init actions are
executed to establish semantic context.  That way,
semantic predicates can be made to work even when
guessing.  Likewise, it may be necessary to reset
semantic context on exiting a rule.  Ter probably has
this clearly documented somewhere--someone else can
cite the references.

--Loring


--- Paul Keir <paul at paulkeir.com> wrote:

> 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
> 
> 



       
____________________________________________________________________________________
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing.
http://new.toolbar.yahoo.com/toolbar/features/mail/index.php


More information about the antlr-interest mailing list