This allows the final program to be 100% "valgrind clean", (freeing
all memory that it allocates). This will make it much easier to ensure
that any allocation that parser actions perform are also cleaned up.
#include "glcpp-parse.h"
%}
-%option noyywrap
+%option reentrant noyywrap
%%
#define YYSTYPE int
void
-yyerror (const char *error);
+yyerror (const char *error, void *scanner);
%}
+%parse-param {void *scanner}
+%lex-param {void *scanner}
+
%token TOKEN
%%
%%
void
-yyerror (const char *error)
+yyerror (const char *error, void *scanner)
{
fprintf (stderr, "Parse error: %s\n", error);
}
int
main (void)
{
- return yyparse ();
+ int ret;
+ void *scanner;
+
+ yylex_init (&scanner);
+ ret = yyparse (scanner);
+ yylex_destroy (scanner);
+
+ return ret;
}