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 pAOHVtfQ002948 for ; Thu, 24 Nov 2011 18:31:55 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AigBAAp/zk7RVaG2kGdsb2JhbABDmxCHXYd+CCIBAQEBCQkNBxQEIYFyAQEBAwESAhMZARsdAQMBCwYFBAcNLiEBAREBBQEcBhMIGodjCJdpCotjgmaEez2IcQIFCopYBIghjCmKVoMCPYQU X-IronPort-AV: E=Sophos;i="4.69,565,1315173600"; d="scan'208";a="132499472" 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 18:31:50 +0100 Received: by ggnk5 with SMTP id k5so4373991ggn.27 for ; Thu, 24 Nov 2011 09:31:49 -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=U37cKINFynDDQiDE7o9UR0bSd8Xb5fO7dCJ4j+AyHMQ=; b=qAmNl+DvXnEO6zIvmSys+8sKbbrViRgvYmCf3LWEcX59stkxggsM9uVQUisqXIeEuM IuIwcYxWIPHmDaNMZLB5A/ZAslY06p1MenkLXpRZsK/qUfcafp+Xu926ptZNsxXKZCmJ EhbdDwTvMQPYbhsi4kUsiI9J5uGUWHAclTyrs= MIME-Version: 1.0 Received: by 10.236.92.168 with SMTP id j28mr2371505yhf.59.1322155909391; Thu, 24 Nov 2011 09:31:49 -0800 (PST) Received: by 10.147.65.21 with HTTP; Thu, 24 Nov 2011 09:31:49 -0800 (PST) In-Reply-To: References: <4ECE614D.3040504@gmail.com> Date: Thu, 24 Nov 2011 12:31:49 -0500 Message-ID: From: bob zhang To: Joel Reymont Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=20cf301afb3551263704b27e6927 Subject: Re: [Caml-list] Weird behavior of Camlp4 Parser --20cf301afb3551263704b27e6927 Content-Type: text/plain; charset=ISO-8859-1 Hi, Joel, camlp4 will do the left factorization automatically. It's weird because after factorization the order of the rule is changed and no documentation specify how the rules will be re-organized 2011/11/24 Joel Reymont > Bob, > > On Nov 24, 2011, at 3:22 PM, bob zhang wrote: > > > m_expr : > > [[ "foo"; f -> print_endline "first" > > | "foo" ; "bar"; "baz" -> print_endline "second"] > > ]; > > > Since camlp4 is a recursive-descent parser, I don't think you can have > "foo"; ... | "foo"; "bar". > > I would suggest having a single "foo" in the rule above and have a > separate rule that branches depending on whether "bar" is found. > > -------------------------------------------------------------------------- > - for hire: mac osx device driver ninja, kernel extensions and usb drivers > ---------------------+------------+--------------------------------------- > http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont > ---------------------+------------+--------------------------------------- > > -- Best, bob --20cf301afb3551263704b27e6927 Content-Type: text/html; charset=ISO-8859-1 Hi, Joel, camlp4 will do the left factorization automatically.
It's weird because after factorization the order of the rule is changed and no documentation specify how the rules will be re-organized

2011/11/24 Joel Reymont <joelr1@gmail.com>
Bob,

On Nov 24, 2011, at 3:22 PM, bob zhang wrote:

> m_expr :
> [[ "foo"; f -> print_endline "first"
> | "foo" ; "bar"; "baz" -> print_endline "second"]
> ];


Since camlp4 is a recursive-descent parser, I don't think you can have "foo"; ... | "foo"; "bar".

I would suggest having a single "foo" in the rule above and have a separate rule that branches depending on whether "bar" is found.

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------




--
Best, bob
--20cf301afb3551263704b27e6927--