Error in menhir manual: semicolon in production with old syntax

While reading the menhir manual, I came across an example which uses semicolon in the argument of a parameterized non-terminal symbol application:

list (  e = expression; SEMICOLON { e }  )

Notice the ; character in the argument of the parameterized non-terminal list.

According to the syntax of grammar specifications (figure 1), a semicolon is not allowed in production rules with the old syntax. It seems to be allowed only with the new syntax for rules.

I have tried something similar with menhir (version 20181113):

%token X COMMA

%start <unit> s


s: list(X; COMMA) {}

It fails with the messages:

$ menhir test1.mly
File "test1.mly", line 7, characters 16-17:
Error: syntax error after 'COMMA' and before ')'.
Ill-formed production.
A production is a sequence of producers, followed with a semantic action.
Examples of well-formed producers:
  separated_list(COMMA, expr)
  e = expr
  ds = declaration*
  es = list(terminated(expr, SEMI))
  es = list(e = expr SEMI { e })
  xs = list(x = var { Some x } | WILDCARD { None })
  expr [@cost 0]

Is the example found in the menhir documentation really invalid?

Even when the semicolon is removed, the error persists.

How would it be fixed, so that one can use a sequence of producers as an argument of a parameterized non-terminal, with the old syntax?

It does seem a bit odd that semicolon is not present in the grammar, assuming I read it correctly.

But anyhow, if you add a {} after X; COMMA, then it should work (menhir version 20181113).

That is:

%token X COMMA

%start <unit> s


s: list(X; COMMA {}) {}

Right the use of semicolons is mentioned at the Lexical conventions section.

An old-style rule (§4.2) may be terminated with a semicolon. Also, within an old-style rule, each producer (§4.2.3) may be terminated with a semicolon.

1 Like