diff options
Diffstat (limited to 'src/constexp.l')
-rw-r--r-- | src/constexp.l | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/src/constexp.l b/src/constexp.l index aa6c4cc..f5862c7 100644 --- a/src/constexp.l +++ b/src/constexp.l @@ -18,38 +18,24 @@ %option never-interactive %option prefix="constexpYY" %option nounput +%option reentrant bison-bridge +%option extra-type="struct constexpYY_state *" %{ #include "constexp.h" #include "cppvalue.h" -#include "ce_parse.h" // generated header file +#include "ce_parse.hpp" // generated header file #include "message.h" #define YY_NO_INPUT 1 #define YY_NO_UNISTD_H 1 - -QCString g_strToken; -CPPValue g_resultValue; -int g_constExpLineNr; -QCString g_constExpFileName; -static const char *g_inputString; -static int g_inputPosition; -#undef YY_INPUT -#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size); +static int yyread(char *buf,int max_size,yyscan_t yyscanner); -static int yyread(char *buf,int max_size) -{ - int c=0; - while( c < max_size && g_inputString[g_inputPosition] ) - { - *buf = g_inputString[g_inputPosition++] ; - c++; buf++; - } - return c; -} +#undef YY_INPUT +#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size,yyscanner); %} @@ -83,44 +69,66 @@ CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?) "(" { return TOK_LPAREN; } ")" { return TOK_RPAREN; } "'"(([^\'\n\r\\]+)|(\\(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'" { - g_strToken=yytext; + yyextra->g_strToken=yytext; return TOK_CHARACTER; } -0[0-7]*{CONSTSUFFIX}? { g_strToken=yytext; +0[0-7]*{CONSTSUFFIX}? { yyextra->g_strToken=yytext; return TOK_OCTALINT; } -[1-9][0-9]*{CONSTSUFFIX}? { g_strToken=yytext; +[1-9][0-9]*{CONSTSUFFIX}? { yyextra->g_strToken=yytext; return TOK_DECIMALINT; } -(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { g_strToken=yytext+2; +(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { yyextra->g_strToken=yytext+2; return TOK_HEXADECIMALINT; } (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? { - g_strToken=yytext; return TOK_FLOAT; + yyextra->g_strToken=yytext; return TOK_FLOAT; } ([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? { - g_strToken=yytext; return TOK_FLOAT; + yyextra->g_strToken=yytext; return TOK_FLOAT; } . \n %% +static int yyread(char *buf,int max_size,yyscan_t yyscanner) +{ + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + int c=0; + while( c < max_size && yyextra->g_inputString[yyextra->g_inputPosition] ) + { + *buf = yyextra->g_inputString[yyextra->g_inputPosition++] ; + c++; buf++; + } + return c; +} + + +static yyscan_t yyscanner; +static struct constexpYY_state constexpYY_extra; + bool parseconstexp(const char *fileName,int lineNr,const QCString &s) { + constexpYYlex_init_extra(&constexpYY_extra, &yyscanner); + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + + yyextra->g_constExpFileName = fileName; + yyextra->g_constExpLineNr = lineNr; + yyextra->g_inputString = s; + yyextra->g_inputPosition = 0; + constexpYYrestart( yyin, yyscanner ); + printlex(yy_flex_debug, TRUE, __FILE__, fileName); //printf("Expression: `%s'\n",s.data()); - g_constExpFileName = fileName; - g_constExpLineNr = lineNr; - g_inputString = s; - g_inputPosition = 0; - constexpYYrestart( constexpYYin ); - constexpYYparse(); + + constexpYYparse(yyscanner); + //printf("Result: %ld\n",(long)g_resultValue); printlex(yy_flex_debug, FALSE, __FILE__, fileName); - return (long)g_resultValue!=0; + return (long)yyextra->g_resultValue!=0; } extern "C" { - int constexpYYwrap() { return 1; } + int constexpYYwrap(yyscan_t yyscanner) { return 1; } } |