convert to bison/flex (away from peg/leg)

Jim Meyering jim at meyering.net
Mon Oct 18 14:22:11 UTC 2010


Jim Meyering wrote:
> Jim Meyering wrote:
>> Jeff Darcy wrote:
>>> On 10/15/2010 09:27 AM, Jim Meyering wrote:
>>>> I've finished the conversion to bison and flex that Jeff started.
>>>> Well, not completely finished, but good enough for now.
>>>> There are still a few tasks remaining, but they can wait.
>>>
>>> The changes look OK to me.  I'd ACK, but you've mentioned that you have
>>> some %union and other changes still pending.  If you do plan to push
>>> those, I'd prefer that you not push these first.  Make sense?
>>
>> Sure.
>> Not relying on yytext in the qparser.y is worthwhile.
>> I'll finish that next week.
>
> I've done that and pushed the result to the rebased bison-flex branch.
> The result passes "make distcheck" with no "definite" leaks.
>
> Here are the resulting 8 additional change sets:
>
>       lex && and || as tokens, not "&" and "|"
>       add missing #define part of double-inclusion guard
>       query.h: use struct value_t (same name as typedef)
>       add beginnings of %union support
>       pure, almost
>       handle yylex_init failure
>       qlexer.l: rewrite not to need static var, at_eof.
>       now that lexer calls strdup, free those strings
>
...
> Subject: [PATCH 5/8] pure, almost
>
> ---
>  qlexer.l  |   26 +++++++++++++++++---------
>  qparser.y |   45 ++++++++++++++++++++-------------------------
>  2 files changed, 37 insertions(+), 34 deletions(-)
>
> diff --git a/qlexer.l b/qlexer.l
> index e394800..551d590 100644
> --- a/qlexer.l
> +++ b/qlexer.l
> @@ -1,4 +1,3 @@
> -%option warn nounput noinput noyywrap
>  %{
>  #include <config.h>
>  #include <stdio.h>
> @@ -9,17 +8,21 @@
>
>  #include "iwhd-qparser.h"
>  #undef YY_DECL
> -#define YY_DECL extern int yylex (YYSTYPE *lvalp)
> +#define YY_DECL extern int yylex (YYSTYPE *yylval_param, yyscan_t yyscanner)
>
>  static int at_eof = 0;
>  %}
>
> +%option warn nounput noinput noyywrap
> +%option bison-bridge reentrant
> +
>  %%
>
> -\"[^"]*\"	{ yytext[yyleng-1] = 0; yytext++; return T_STRING; }
> -~[^~]*~		{ return T_DATE; }
> -[0-9]+		{ return T_NUMBER; }
> -[a-z_]+		{ return T_ID; }
> +\"[^"]*\"	{ yytext[yyleng-1] = 0; yytext++;
> +		  yylval_param->str = strdup(yytext); return T_STRING; }
> +~[^~]*~		{ yylval_param->str = strdup(yytext); return T_DATE; }
> +[0-9]+		{ yylval_param->str = strdup(yytext); return T_NUMBER; }
> +[a-z_]+		{ yylval_param->str = strdup(yytext); return T_ID; }

I forgot to address failed strdup here.
Patch coming up.


More information about the iwhd-devel mailing list