Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Menhir 20211230 #407

Closed
k4rtik opened this issue Dec 31, 2021 · 3 comments · Fixed by #408
Closed

Error with Menhir 20211230 #407

k4rtik opened this issue Dec 31, 2021 · 3 comments · Fixed by #408
Assignees
Milestone

Comments

@k4rtik
Copy link
k4rtik commented Dec 31, 2021

With the latest release of menhir that requires type information in the source or inference enabled:

The code back-end now needs type information. This means that either Menhir's type inference mechanism must be enabled (the easiest way of enabling it is to use Menhir via dune and to check that the dune-project file says (using menhir 2.0) or later) or the type of every nonterminal symbol must be explicitly given via a %type declaration.

The menhir backend for BNFC currently fails as follows:

❯ cat > Sum.cf
EInt.  Exp ::= Integer;
EPlus. Exp ::= Exp "+" Integer;
/tmp
❯ bnfc -m Sum.cf --ocaml-menhir &&  make
2 rules accepted

writing new file ./AbsSum.ml
writing new file ./LexSum.mll
writing new file ./ParSum.mly
writing new file ./SkelSum.ml
writing new file ./PrintSum.ml
writing new file ./ShowSum.ml
writing new file ./TestSum.ml
writing new file ./BNFC_Util.ml
writing new file ./Makefile
menhir ParSum.mly
File "ParSum.mly", line 14, characters 14-22:
Warning: the token TOK_Char is unused.
File "ParSum.mly", line 15, characters 15-25:
Warning: the token TOK_Double is unused.
File "ParSum.mly", line 13, characters 16-25:
Warning: the token TOK_Ident is unused.
File "ParSum.mly", line 17, characters 16-26:
Warning: the token TOK_String is unused.
Error: the code back-end requires the type of every nonterminal symbol to be
known. Please specify the type of every symbol via %type declarations, or
enable type inference (look up --infer in the manual).
Type inference is automatically enabled when Menhir is used via Dune,
provided the dune-project file says (using menhir 2.0) or later.
The types of the following nonterminal symbols are unknown:
exp
int
make: *** [all] Error 1
/tmp
@andreasabel
Copy link
Member

A simple fix is to annotate each non-terminal with its ML-type in the generated parser description (.mly file). This is compatible with ocamlyacc.

@andreasabel
Copy link
Member

PR #408 fixes the OP, but menhir-2021-12-30 has a regression in error handling, see https://gitlab.inria.fr/fpottier/menhir/-/issues/62.

@k4rtik
Copy link
Author
k4rtik commented Jan 4, 2022

Thanks, @andreasabel for fixing this issue so quickly. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants