Repository navigation
Closed
Description
ocamlyacc produces ill-formed .ml files if a grammar has 128 or more entrypoints.
This generated .ml file was produced by ocamlyacc from a BNFC-generated .mly file:
...
let pSuper (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
(Parsing.yyparse yytables 126 lexfun lexbuf : Abstest.super)
let pSwitch (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
(Parsing.yyparse yytables 127 lexfun lexbuf : Abstest.switch)
let pSynchronized (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
(Parsing.yyparse yytables -128 lexfun lexbuf : Abstest.synchronized)
let pTemplate (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
(Parsing.yyparse yytables -127 lexfun lexbuf : Abstest.template)
...ocamlc reports a type error:
File "Partest.ml", line 5129, characters 4-28:
5129 | (Parsing.yyparse yytables -128 lexfun lexbuf : Abstest.synchronized)
^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type
int -> (Lexing.lexbuf -> 'a) -> Lexing.lexbuf -> 'b
but an expression was expected of type int
The buggy .ml code is produced by this print statement:
Lines 1701 to 1703 in 4e6e912
| fprintf(entry_file, | |
| "let %s (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =\n (Parsing.yyparse yytables %d lexfun lexbuf : %s)\n", | |
| bp->name, bp->entry, bp->tag); |
Seems like the
entry component of the bucket type was (needlessly?) dimensioned to bytesize, not catering for values >=128:Lines 137 to 150 in 4e6e912
| struct bucket | |
| { | |
| struct bucket *link; | |
| struct bucket *next; | |
| char *name; | |
| char *tag; | |
| short value; | |
| short index; | |
| short prec; | |
| char class; | |
| char assoc; | |
| char entry; | |
| char true_token; | |
| }; |
I attach a .mly file created from this MWE BNFC file:
EInt. Exp ::= Integer;
coercions Exp 127;
Metadata
Metadata
Assignees
Labels
No labels
Activity
nojb commentedon Dec 24, 2019
Thanks for the report. Did you try patching
ocamlyaccby changingchar entrytoshort entryand trying it on your grammar? I'm wondering if there are more places where this assumption on the number of entries is made...dra27 commentedon Dec 24, 2019
In this use case, are you able to use Menhir instead? Unless the fix is trivial, it’d seem better to alter ocamlyacc merely to display an error message if an attempt is made to generate more than 127 entry points.
andreasabel commentedon Dec 24, 2019
If I supply a grammar with 256 entry points (or more)
ocamlyacccomplains:(Note the slight in accuracy in the error message: correct would be
more than 255entry points.)Thus, it seems that the idea was to allow 255 entry points, but printing
charas a signed byte with%dbelow reduces this to 127 entry points.ocaml/yacc/reader.c
Lines 1701 to 1703 in 4e6e912
Well, I stumbled on this problem while trying to make BNFC more robust. BNFC's ocaml backend currently only targets ocamllex/ocamlyacc, writing a new backend to target Menhir is probably the long-term viable process.
No, I have not familiarized myself with the ocaml build process...
nojb commentedon Dec 24, 2019
It is actually quite easy:
(
ocamlyacclives in theyaccsubdirectory). The above creates anyacc/ocamlyaccexecutable. If you modify the source in theyaccdirectory just repeat themakestep (in theyaccsubdirectory) to rebuild theocamlyaccexecutable.andreasabel commentedon Dec 25, 2019
Thanks, I will work on a PR then.
Fixed ocaml#9207: ocamlyacc can now handle 255 entry points
Fix Changes entry for #9207 #9210
Make sure ocamlyacc can handle 255 entry points (ocaml#9210)
Fix Changes entry for ocaml#9207 ocaml#9210