From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pAOG90dF000441 for ; Thu, 24 Nov 2011 17:09:00 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtMBAExrzk7RVaG2kGdsb2JhbABDmlw0h1wBh34IIgEBAQEJCQ0HFAQhgXIBAQEDARICExkBGxILAQMBCwYFCxohIQEBEQEFAQoSBhMIChCHYwiXYwqLY4JmhQY9iHECBQqDVYcDBIJchUWMKYpWgwI9hBQ X-IronPort-AV: E=Sophos;i="4.69,565,1315173600"; d="scan'208";a="132485886" Received: from mail-gx0-f182.google.com ([209.85.161.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Nov 2011 17:08:55 +0100 Received: by ggnk5 with SMTP id k5so4260778ggn.27 for ; Thu, 24 Nov 2011 08:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=1z6COdNsSso+bHKqHNmArWZASRIx/DXo3hSzLi2Leko=; b=eVM9LU6+bYndds7ycq3WQDLvqz3zvdwhKC7MYSWgPEeYMNIIHRtuVyyZtiVVzQ/JZ5 EZccqkh3VtEt6hZyo157N81/va198781dh2GYZagh1b6xNTI5F2iujdNQWBA21GxpBxv j+T8JrzhpNOhDgl5qq0cjOnmAg/zoia6S07Y0= MIME-Version: 1.0 Received: by 10.236.200.130 with SMTP id z2mr41923198yhn.25.1322150934212; Thu, 24 Nov 2011 08:08:54 -0800 (PST) Received: by 10.147.65.21 with HTTP; Thu, 24 Nov 2011 08:08:54 -0800 (PST) In-Reply-To: References: <4ECE614D.3040504@gmail.com> Date: Thu, 24 Nov 2011 11:08:54 -0500 Message-ID: From: bob zhang To: Gabriel Scherer Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=20cf305b088ec5ef4604b27d403d Subject: Re: [Caml-list] Weird behavior of Camlp4 Parser --20cf305b088ec5ef4604b27d403d Content-Type: text/plain; charset=ISO-8859-1 Thanks for quick reply. I have read Jake's camlp4 series carefully, unfortunately it does not cover my case :-( On Thu, Nov 24, 2011 at 10:47 AM, Gabriel Scherer wrote: > 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 : > > 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 "") "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 "") "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 > > > > > -- Best, bob --20cf305b088ec5ef4604b27d403d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for quick reply.=A0
I have read Jake's camlp4 series careful= ly, unfortunately it does not cover my case :-(

On Thu, Nov 24, 2011 at 10:47 AM, Gabriel Scherer = <gabriel.scherer@gmail.com<= /a>> wrote:
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: =A0
http://ambassadortothecomput= ers.blogspot.com/2010/05/reading-camlp4-part-6-parsing.html

2011/11/24 bob zhang <bobzhang= 1988@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 =3D MakeGram(Lexer) ;;
> EXTEND MGram
> GLOBAL: m_expr ;
> m_expr :
> [[ "foo"; f -> print_endline "first"
> | "foo" ; "bar"; "baz" -> print_endli= ne "second"]
> ];
> f : [["bar"; "baz" ]]; END;;
> MGram.parse_string m_expr (Loc.mk "<string>") "fo= o 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_endli= ne "second"]
> ];
> f : [["bar"; "baz" ]]; END;;
> - : unit =3D ()
> # 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. =A0Subscription 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
>
>



-- Best, bob
--20cf305b088ec5ef4604b27d403d--