Separating a list by eol when parsing ocaml

281 Views Asked by At

I have defined some statements followed by a list of expressions in my compiler. I am using Menhir for the parsing. Typically when lexing EOL it does this: | eol { incr_linenum lexbuf; read lexbuf } However, I would like to be able to parse this:

stmt;
stmt;
stmt;
expr
expr
expr

stmt is defined as follows:

stmt :
| ...
| stmt SEMICOLON

and my program as this:

prog :
| stmt; expr list

I would like the expr to be interpreted as a list of expr. Is there a way to do this? Or would my list have to be separated by other characters?

1

There are 1 best solutions below

0
On BEST ANSWER

As stated in the manual (section 5.4), you can specify a list without any separators easily:

prog:
| stmt; list(expr)