Reputation: 1
I am using bison + flex to write a parser now.
For bison and flex, the generated parser and scanner manage their memory with malloc, realloc and free.
But I want to use my own implementation for malloc, realloc and free inside bison + flex.
According to another post:
Being C, the generated parser and scanner manage their memory with
malloc
,realloc
andfree
. They are good enough to expose hooks allowing me to submit my own implementations of these functions.
Where are those hooks and how do I use them?
Upvotes: 0
Views: 707
Reputation: 241911
The flex overrides are described in the flex manual. In summary, you need to define the functions yyalloc
, yyfree
and yyrealloc
(whose prototypes are unsurprising, but read the manual if you are using a reentrant scanner), and also tell flex not to generate the functions:
%option noyyalloc noyyfree noyyrealloc
For bison, if you are using the standard C skeleton, you can define the macros YYMALLOC
and YYFREE
, whose default values are malloc
and free
. bison does not (by default) use realloc
. I presume this is not documented because it is dependent on the skeleton used.
Upvotes: 0