[antlr-interest] How to make the lexer thread-safe (C target)?

Jim Idle jimi at temporal-wave.com
Tue Jul 26 11:11:09 PDT 2011


Please read the docs and the previous answer to my message. However, I
think that something went wrong with the previous @section documentation
as it seems to be foreshortened. There will be updated docs for 3.4
shortly.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Gokulakannan Somasundaram
> Sent: Tuesday, July 26, 2011 7:05 AM
> To: Mu Qiao
> Cc: antlr-interest Interest
> Subject: Re: [antlr-interest] How to make the lexer thread-safe (C
> target)?
>
> Jim,
>    Have you thought about providing a way to include variables in the
> Lexer/Parser structure that gets created? Currently the Lexer/Parser
> structure that gets created because of the grammar only stores the
> function pointers.
>
> Thanks,
> Gokul.
>
> On Tue, Jul 26, 2011 at 9:51 PM, Gokulakannan Somasundaram <
> gokul007 at gmail.com> wrote:
>
> > I had a similar requirement. I maintained a class LexerContext in a
> > Thread local variable and accessed it and modified it. There might be
> > better solutions.
> >
> > Thanks,
> > Gokul.
> >
> >
> > On Tue, Jul 26, 2011 at 8:07 PM, Mu Qiao <qiaomuf at gmail.com> wrote:
> >
> >> Hello,
> >>
> >> My lexer has to rely on some internal status like the following:
> >>
> >> DQUOTE  :   '"' { if(LA(-1) != '\\') double_quoted = !double_quoted;
> >> };
> >> SQUOTE  :   { double_quoted }? => '\'';
> >> SINGLE_QUOTED_STRING_TOKEN  :   { !double_quoted }? => '\'' .* '\'';
> >>
> >> "double_quoted" is a bool variable declared in @member section. The
> >> generated code will declare it in global scope, which is not thread
> >> safe. I wonder if there is any way to make the lexer thread-safe?
> For
> >> example declare the variable in xxxLexer_Ctx_struct.
> >>
> >> --
> >> Best wishes,
> >> Mu Qiao
> >> GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1
> 57E9
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-email-
> addres
> >> s
> >>
> >
> >
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list