I am developing a parser for a tiny language whose syntax is as follows
P::= 1 | 0 | P+P | P and P | P wait(d) P
Here is the code I wrote in Ocaml camlp4
action: [ ["act"; a = LIDENT -> Act(a)] | ["coact"; a = LIDENT -> Act2(a)] ]; proc: [ [ "ZERO" -> Zero] | RIGHTA ["."; l = action; p = SELF -> Now(l,p)] | RIGHTA [":"; l = action; p = SELF -> Delay(l,p)] | LEFTA [p1 = SELF; "+"; p2 = SELF -> Plus(p1,p2)] |RIGHTA [p1 = SELF; "WAIT"; "("; d = INT; ")"; p2 = SELF -> Wait(p1,d,p2)] | [ x = UIDENT -> Proc(x)] ];
But unfortunately, the parser does not parse strings such as
.act abort WAIT(4) :act close
because the rule for the WAIT construct expects proc to be the first argument.
How can i fix this?
parsing ocaml camlp4
David link
source share