Add one-line comment support and make some semi-column optional
Make possible the parsing of the counting example of *Clock-directed Modular Code Generation for Synchronous Data-flow Languages* (https://www.di.ens.fr/~pouzet/bib/lctes08a.pdf). ``` -- count the number of top between two tick node counting (tick:bool; top:bool) returns (o: int) var v: int; let o = if tick then v else 0 -> pre o + v; v = if top then 1 else 0; tel; ``` The one-line comment rule was inspired from https://mukulrathi.com/create-your-own-programming-language/parsing-ocamllex-menhir/. Note their typo using `single_line_comment` instead of `read_single_line_comment`.
This commit is contained in:
@@ -62,6 +62,11 @@ rule token = parse
|
||||
| '/' { BO_div }
|
||||
| '%' { BO_mod }
|
||||
| "->" { BO_arrow }
|
||||
| "--" { read_single_line_comment lexbuf }
|
||||
| eof { EOF }
|
||||
| _ { raise (Lexing_error (Format.sprintf "Error when seeing %s" (lexeme lexbuf)))}
|
||||
|
||||
and read_single_line_comment = parse
|
||||
| '\n' { token lexbuf }
|
||||
| eof { EOF }
|
||||
| _ { read_single_line_comment lexbuf }
|
||||
|
Reference in New Issue
Block a user