[antlr-interest] Syntactic Predicate gating and @init

Christian Schladetsch christian.schladetsch at gmail.com
Sat Apr 19 19:14:11 PDT 2008


Hi Jim,

On Sun, Apr 20, 2008 at 5:39 AM, Jim Idle <jimi at temporal-wave.com> wrote:

>  Rather than use the @init, why not just use an action:
>

No. Most of my work is done in actions, yes. But there are places (like
compound blocks, arg lists etc) that need to change the scope. That has to
be done in @init before the subrules are matched at all. Otherwise the
subrules write their code to the wrong scope. Maybe I'm DoingItWrong, but
the solution I found was:

compound_something:
   @init { if (BACKTRACKING == 0) PushScope(); }
   : '{' ..subrules that write to this scope... '}' { ...PopScope(); }

subrule : whatever { ...write code into current scope... };

Anyway, it works. Thanks everyone for your help and to Terr et al for a
great tool. I now have a language system that works:

> foo = int a, string s -> string,int { return s+s,a*3; }
> foo(2,"spam");
*[**"spamspam", **6]
*
Regards,
Christian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080420/e34d679a/attachment.html 


More information about the antlr-interest mailing list