[ragel-users] union operator and thread-local variables
Devin Bayer
web at t-0.be
Wed Oct 28 18:48:19 UTC 2009
On Wed, 2009-10-28, at 19:20, Adrian Thurston wrote:
>> That's why I thought about thread-local variables. If we have local
>> error actions can't we export some local context?
>
> Ragel builds DFAs from the grammar, so the 'threads' are switched
> between at each character. Any kind of local context switch that
> occurs
> on each state change would be way too costly.
I think it would only involve setting one integer before each action,
and this doesn't seem costly at first glance. For this example,
action 'c' would be called twice, and 'thread' would be set to 1 or
2. When we finish one alternative, the correct value of 'c' is used.
action c { c[thread] += fc; }
action a { puts c[thread]; }
action b { puts c[thread]; }
c = any any $act;
a = c "Y";
b = c "X";
main : thread=1 a %out
| thread=2 b %out
;
Comments?
> Better to try to parse pattern one, stop, rewind, try pattern two,
> and so on or to make the
> 'threads' use different data.
This could work, but
(1) requires more boilerplate
(2) is less efficient
(3) doesn't work in a sub-machine, since it requires fcall/fgoto
- Devin
More information about the ragel-users
mailing list