Camlp4 performs grammar factorizations that make its behavior non strictly LL(k).
I never bothered to learn the exact semantics of Camlp4 grammar rules; they're complex and, I suspect, possibly fragile. If you avoid being clever with ambiguities, you can get away with the gory details. You should have a look at Jake Donham excellent blog series about Camlp4: http://ambassadortothecomputers.blogspot.com/2010/05/reading-camlp4-part-6-parsing.html 2011/11/24 bob zhang <bobzhang1...@gmail.com>: > Hi List, > I have came across a strange behavior of the camlp4 parser, (maybe not > that weird due to my limited knowledge of the parser) > The contrived mini-examples as follows : > module MGram = MakeGram(Lexer) ;; > EXTEND MGram > GLOBAL: m_expr ; > m_expr : > [[ "foo"; f -> print_endline "first" > | "foo" ; "bar"; "baz" -> print_endline "second"] > ]; > f : [["bar"; "baz" ]]; END;; > MGram.parse_string m_expr (Loc.mk "<string>") "foo bar baz ";; > second (** choose the second branch, maybe the token rule has a higher > priority *) > > MGram.Entry.clear m_expr;; > EXTEND MGram > GLOBAL: m_expr ; > m_expr : > [[ "foo"; f -> print_endline "first" > | "foo" ; "bar"; "bax" -> print_endline "second"] > ]; > f : [["bar"; "baz" ]]; END;; > - : unit = () > # MGram.parse_string m_expr (Loc.mk "<string>") "foo bar baz ";; > first (** here choose the first branch, but the token rule can consume > one token, I thought this should fail *) > > Many Thanks > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs