I made a very small calculator in Sedlex and Menhir: GitHub - chengtie/sedlex-menhir. Now, I would like to make the calculator be able to parse expressions like 1+. So I modified parser.mly to
If the error token is used to survive an error and continue parsing, then the legacy strategy should be selected.
--strategy strategy. This switch selects an error-handling strategy, to be used by the code back-end, the table back-end, and the reference interpreter. The available strategies are legacy and simplified.
Grammars that make more complex use of the error token, and therefore
need the legacy strategy, cannot be compiled by the new code back-end.
As a workaround, it is possible to switch to the table back-end (using
–table --strategy legacy) or to the ancient code back-end (using
–code-ancient). In the long run, we recommend abandoning the use of
the error token. Support for the error token may be removed
entirely at some point in the future.
This way of doing will most likely not work in a near future but it does for now and it appeared to be the simplest way of doing what OP asked.