From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pAOFm7Sq031808 for ; Thu, 24 Nov 2011 16:48:07 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABAK1mzk5KfVI0imdsb2JhbABDmlyQDggiAQEBCgkNBxIGIYFyAQEBBBICExkBGxILAQMMBgULGiEhAQERAQUBChIGExIQh2uXawqLY4JmhQg9iHECBQqDVYcDBJRKilaDAj2Ddw X-IronPort-AV: E=Sophos;i="4.69,565,1315173600"; d="scan'208";a="120743241" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Nov 2011 16:47:37 +0100 Received: by wwg5 with SMTP id 5so2806806wwg.9 for ; Thu, 24 Nov 2011 07:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=m9yIiSskANgnopZG/Qf82bFRTWYZHBZpQiuJR8e+LRI=; b=t7WloSWaXUkkApuu9X8lj7KT65zqsqs7PsC8S0uVNSlpf4N8ZNQk8yFEq5F4aUMsye BSV6Fd81No6YeLD3s2eNwShVZgzyb0QYnHcumIWAD+NgWy17nstF6bgj990kr9KSbpwK 4tXoqGX5Vl6KA9fO8G/LHSOkY7vEaNbINRUBg= Received: by 10.227.208.81 with SMTP id gb17mr1206937wbb.26.1322149657026; Thu, 24 Nov 2011 07:47:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.203.134 with HTTP; Thu, 24 Nov 2011 07:47:15 -0800 (PST) In-Reply-To: <4ECE614D.3040504@gmail.com> References: <4ECE614D.3040504@gmail.com> From: Gabriel Scherer Date: Thu, 24 Nov 2011 16:47:15 +0100 Message-ID: To: bob zhang Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id pAOFm7Sq031808 Subject: Re: [Caml-list] Weird behavior of Camlp4 Parser 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 > >