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?
As stated in the manual (section 5.4), you can specify a list without any separators easily:
prog:
| stmt; list(expr)