0

I would like to parse "[a;b;c;d;e;f;g]" as "a::b::c::d::e::f::g::[]" In my part of my parser I have

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

and I have this further down.

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

But I'm not sure how to get it to read the list between the "[" and "]" as having a "::[]" at the end of it. Any ideas?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281

1 Answers1

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!

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108