OCaml parser and structure of the grammar
Asked Answered
T

0

7

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?

Tallahassee answered 11/9, 2013 at 10:28 Comment(1)
Maybe you could try to use Menhir to debug your grammar ?Strontium

© 2022 - 2024 — McMap. All rights reserved.