0

我想在我的我的解析器的一部分

listOps:
   | combOps COLONCOLON listOps { Bin($1,Cons,$3) }
   | combOps SEMI listOps       { Bin($1,Cons,$3) }
   | combOps                    { $1 }
;

我有这个更进一步。

   | LBRAC RBRAC                { NilExpr }
   | LBRAC listOps RBRAC        { $2 }

但我不确定如何让它读取“[”和“]”之间的列表,因为它的末尾有一个“::[]”。有任何想法吗?

4

1 回答 1

2

Your grammar as given doesn't look quite right to me. In essence it treats :: and ; identically. So it would treat [a::b] and [a;b] as the same. If you figure out how to handle the two cases differently, you'll probably find a place handle the [] at the end of a list specified with ::.

As a side comment, if you allow a :: b :: [] you are allowing the right side of :: to be a non-empty list. So you might want a :: [b] to be allowed, as it is in OCaml. Or maybe you'd rather not, it's your grammar!

于 2013-02-19T01:18:47.103 回答