There is a very small calculator in Sedlex and Menhir. Now, I would like to make the calculator to be able to parse expressions like 1+
. So I modified parser.mly
to
... ...
main:
expr EOL { $1 }
;
expr [@recovery (E_int 0)]:
INT { E_int $1 }
| BOOL { E_bool $1 }
... ...
But evaluating 1+
still returned an error Fatal error: exception Parser.MenhirBasics.Error
.
Could anyone help?
Augmented summary of my comments:
[@recovery ...]
is a construct specific to Merlinerror
token like this:From menhir's manual:
From OCaml weekly news:
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.