westes / flex

The Fast Lexical Analyzer - scanner generator for lexing in C and C++
Other
3.64k stars 537 forks source link

Making flex re-entrant and releasing all acquired resources at the end #675

Open mingodad opened 1 month ago

mingodad commented 1 month ago

This is an experiment that replace all globals by a dynamic allocated structure to hold the state that is passed everywhere and also releasing all acquired resources (memory/file handles) at the end.

The main drive behind this changes is to create something like https://mingodad.github.io/parsertl-playground/playground/ using this fork and https://github.com/mingodad/lalr-parser-test/tree/main/byacc (also with globals replaced) or doing a similar work with bison.

If anything here is useful to the original project feel free to grab it.

All tests are passing.

If someone want to try build this branch be aware that the build will fail when trying to parse the generated parse.c at that point you need to change to the src folder and issue this command make fix-parse then again make and make check to see hopefully all tests passing.

Mightyjo commented 1 month ago

Flex itself is a compiler-like tool. It isn't meant to be re-entrant. The code it generates is re-entrant, though.

We collected the state into structures a few years ago. That was good. I'm not seeing the value in allocating that state dynamically and changing every prototype in the code base.

westes commented 1 month ago

Please let us know when your build process runs successfully.