0

I am implementing a small programming language. Here is the codebase. The program is built with ocamlbuild. I added a parser using menhir. When I compile and run the program, I got the following message.

❱ ./main.byte 
Fatal error: exception Parser.MenhirBasics.Error

I am trying to find more details by passing the explain to the _tag file

true: color(always), explain

but there doesn't seem to be any difference. How to I make menhir to generate a logging file through ocamlbuild? or other ways to debug?

Kabocha Porter
  • 301
  • 3
  • 8
  • You can get a stack trace by running `ocamlrun -b main.byte`, which might point to something useful. – glennsl Dec 29 '21 at 07:25

1 Answers1

3

This is syntax error raised by the parser generated by menhir.

Your build system is irrelevant (nevertheless, you should use dune for a new project and not ocamlbuild).

Similarly, the --explain flag of menhir is only useful for generating conflict explanations when generating the parser. It doesn't add syntax error explanation to syntax error.

If you want to debug a menhir grammar, you can use menhir intepreter mode with menhir --interpret

menhir --interpret parser.mly

or list all possible syntax errors in your grammar with menhir --list-errors.

menhir --list-errors parser.mly

Both options should make the reason why `"hi." is a syntax error in your grammar relatively clear.

octachron
  • 17,178
  • 2
  • 16
  • 23
  • Thanks. I am having trouble figuring out how to pass those flags to `menhir` through `ocamlbuild` since they are tool-specific commands. It seems I have to write a `myocamlbuild` file to introduce those commands like [this](https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#flag-declarations)? – Kabocha Porter Dec 29 '21 at 17:00
  • 1
    You should call `menhir` on your `parser.mly` file directly, since it is more a question of analyzing your grammar than something that should be part of the regular build process. I edited the answer to mention this. – octachron Dec 29 '21 at 17:13