Friday, 15 April 2011

Ocaml Parsing a list -



Ocaml Parsing a list -

hi guys parse "[a;b;c;d;e;f;g]" "a::b::c::d::e::f::g::[]" in part of parser have

listops: | combops coloncolon listops { bin($1,cons,$3) } | combops semi listops { bin($1,cons,$3) } | combops { $1 } ;

and have farther down.

| lbrac rbrac { nilexpr } | lbrac listops rbrac { $2 }

but i'm not sure how read list between "[" , "]" having "::[]" @ end of it. ideas?

your grammar given doesn't quite right me. in essence treats :: , ; identically. treat [a::b] , [a;b] same. if figure out how handle 2 cases differently, you'll find place handle [] @ end of list specified ::.

as side comment, if allow a :: b :: [] allowing right side of :: non-empty list. might want a :: [b] allowed, in ocaml. or maybe you'd rather not, it's grammar!

list parsing ocaml lexing cons

No comments:

Post a Comment