Kabocha Porter
Kabocha Porter

Reputation: 301

debugging code with menhir and ocamlbuild

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?

Upvotes: 1

Views: 1376

Answers (1)

octachron
octachron

Reputation: 18912

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.

Upvotes: 4

Related Questions