[antlr-interest] Bug in dynamic scopes in C target
Jim Idle
jimi at temporal-wave.com
Sun Mar 29 09:42:51 PDT 2009
Kay Röpke wrote:
> Hi Jim!
>
> I've noticed that the a rule like this will crash when targetting C
> (ANTLR 3.1.3):
>
> rule
> @scope { int foo; }
> @after { $rule::foo = 1; }
> : 'bar';
>
> It's ok with Java and is due to the order of clean up performed at
> rule exit (the @after action will deref the freed scope top).
> See the templates rule(), ruleCleanUp() and scopeClean() in C.stg.
>
> It's probably very simple to fix by making ruleCleanUp() not call
> scopeClean() directly, but only do it after the @after action is done.
> That is what Java.stg does.
Not quite that simple I am afraid.
>
> I'll work around it for the time being by tweaking the template :)
>
> cheers,
> -k
>
> P.S.: I haven't checked any other targets, so the other authors might
> want to check with theirs :)
It's not so much a buig as that I don't support @after yet ;-)
The issue (and I have a JIRA for it) is that certain combinations, such
as backtracking and @init mean that as it stands there is no good way to
make it work for everything just by reordering the string template. Ter
is using the after clause of the exception and I don't have such a
thing. So, what I will need to do is introduce a flag I think. I just
have not had time to dive into this and the last 3 times I tried to fix
this generically I broke the existing stuff tha tis out there :-(
Jim
More information about the antlr-interest
mailing list