-
Notifications
You must be signed in to change notification settings - Fork 170
[ fix #349 ] Make parser reentrant by using reentrant lexer #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tested in linux/x64/gcc and macos/arm64/clang random errors when run my test cases I tried Typical errors from MacOS/ARM64
Typical errors from Linux/x64
From the errors, it seems double free issue, some pointer might be freed twice. |
I realized there is still a global variable in the lexer for lexing strings, it is |
@wangjia184: I updated the PR to remove a global variable in the lexer I had overlooked previously. Could you please test again? |
@andreasabel still same error. Just make sure I updated my BNFC |
@wangjia184 : Thanks, yes this was the last change I did. I am a bit out of ideas now how to proceed, since I don't have some infrastructure for running the parser in parallel.
|
d3e1c59
to
f825515
Compare
This project spilled over to the C++ backends. Since the work on the C backend broke the C++ backends, I took the forward route to (re)integrate the C++ lexer/parser generators into the C backend. This way, we also get reentrant parsers for C++. |
Use INITIAL instead of defining our own YYINITIAL. Saves us the initial BEGIN, works also for reentrant lexer.
Reorganized the input for bison a bit, to prepare for removal of global YY_RESULT variables. Got rid of the forward declaration for yyerror. Entrypoints can be at the end of the file, since nothing depends on them.
This is more robust than using global variables, prepares for making parser reentrant.
Parser.h defined things that are only for internal use in the lexer. These can be automatically defined by bison using the %defines pragma.
Phew! That took me a whole day to figure out, but in the end, there aren't too many changes. UPDATE: also use yyextra argument in lexer instead of global variable literal_buffer.
The C variants are now parametrized to also cover the C++ backends.
[ fix #349 ] Make parser reentrant by using reentrant lexer
Further:
let bison generate Bison.h, to slim down Parser.h
Parser.h defined things that are only for internal use in the lexer.
These can be automatically defined by bison using the %defines pragma.
C parser: return parse result in parameter to yyparse
This is more robust than using global variables, prepares for making
parser reentrant.
C parser: code segment after %union, entrypoints in the end
Reorganized the input for bison a bit, to prepare for removal of
global YY_RESULT variables.
Got rid of the forward declaration for yyerror.
Entrypoints can be at the end of the file, since nothing depends on them.
C lexer: use flex's predefined start state INITIAL
Use INITIAL instead of defining our own YYINITIAL.