> Le 12 févr. 2019 à 17:38, Akim Demaille <a...@lrde.epita.fr> a écrit : > >> I’d like to know what is the best way to structure the parsing code. Given >> a lot of code of bash started 30 years ago, I’d expect at least some part >> of the code is not the best according to today’s standard. I’d like to >> know anything that can improve it.
Actually, you might be interested in looking at push parsers. They are very well suited for interactive usage. By default we generate pull parsers: you call yyparse once, and they drain the input by repeated calls to yylex. This can be annoying for interactive shells: the parser is, in a way, the main loop. Push parsers reverse the control: _you_ call yylex by hand, and then feed the token to yyparse, which will do all it can, and then return some status (success, failure, or need more tokens). This frees you from leaving the control to yyparse: your main loop is elsewhere. I'm not saying you must do this. I'm saying push parsers offer an API which is often more convenient for interaction, so it might be a good option for bash. I don't know. We should probably offer an example of a pull parser in examples/c. Have a look at the documentation to have an idea of what I mean. _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison