OCaml解析器和语法结构

时间:2013-09-11 10:28:56

标签: parsing ocaml camlp4

我一直在为一种语言开发解析器,其语法如下

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

这是我用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)]   
  ];

但遗憾的是,解析器不解析像

这样的字符串
.act abort WAIT(4) :act close

因为WAIT构造的规则要求proc作为第一个参数。

我该如何解决这个问题?

0 个答案:

没有答案