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

Mu Qiao qiaomuf at gmail.com
Tue Jul 26 05:07:34 PDT 2011


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


More information about the antlr-interest mailing list