Heap processing in a clean bison parser

Is it possible to specify custom allocator / dellocator functions for heap management instead of malloc () / free () for a pure parser in a bison?

+6
c language-design bison parser-generator
source share
1 answer

Most Bison memory allocations can be redirected using macros - in the prolog (between %{ and %} ) you can write

 #define YYMALLOC mymalloc #define YYFREE myfree 

and Bison will then call mymalloc and myfree instead of malloc and free . However, he expects that any functions you provide should have exactly the same type signature as the standard malloc and free ; There is no way to make it pass additional / different arguments. And I would not use functional macros if I were you. Even worse, in my copy (Bison 2.4.1), yypstate_new calls malloc directly, without overriding - this is probably a mistake.

+3
source share

All Articles