OCaml parser and structure of the grammar

458 views Asked by At

I have been developing a parser for a tiny language whose syntax is the following

P::= 1 | 0 | P+P | P and P | P wait(d) P 

Here is the code that i have written 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 doesn't parse strings like

.act abort WAIT(4) :act close

becouse the rule for the WAIT construct expects a proc as the first argument.

How can i fix this?

0

There are 0 answers