From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7D0A4BBAF for ; Tue, 10 Mar 2009 22:48:18 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUGALR8tknRVd2CdWdsb2JhbACUbz8BDAoLBxGtD49NAQMBA4QJBoUm X-IronPort-AV: E=Sophos;i="4.38,337,1233529200"; d="scan'208";a="36369138" Received: from mail-qy0-f130.google.com ([209.85.221.130]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Mar 2009 22:48:17 +0100 Received: by qyk36 with SMTP id 36so1871099qyk.1 for ; Tue, 10 Mar 2009 14:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=38hmNaaGKD/4s19r8P4IERiRzXu35e9Q8EwSXCUsguc=; b=Jrp5rejuI+SqSlN2XM0XjnPWvnWRWGhc3AGvfABOHVNVF2hdiFUQuCz7Y/mjzWSGVQ oQf03EL7gbQ8ah1Oz6jMSuYxwWQXGTX30YzUWJ4qdaJYsEEblGPdhd0XM8kOEd7eR1/5 ME70Bsx2OGhU8q0GwkYR/0oETBUlXGdY/rj8E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=X+YrnM8XbCPlxA4Rwc7fS8kXpJ5V/DxF98U3+oss6oW8TbwXVVqrB56n9LakyrVMLA bBNNIgnhD5KwkNlDpaCxjKgTQlkORWT/2e1R7857ttkomVmFnY7qE72fVOhDn5mtZb+C Ll7NVq1R2U6s02R2S9o98tWdUJevUQfll54So= MIME-Version: 1.0 Sender: jake.donham@gmail.com Received: by 10.224.29.3 with SMTP id o3mr10119954qac.102.1236721694675; Tue, 10 Mar 2009 14:48:14 -0700 (PDT) In-Reply-To: <6485A041-8698-471F-9D9C-BF3DFF0D3018@gmail.com> References: <6485A041-8698-471F-9D9C-BF3DFF0D3018@gmail.com> Date: Tue, 10 Mar 2009 14:48:14 -0700 X-Google-Sender-Auth: dcc945f4975f7d3d Message-ID: Subject: Re: [Caml-list] camlp4 grammar and LIST1 From: Jake Donham To: Joel Reymont Cc: "O'Caml Mailing List" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 wiki:01 annotations:01 camlp:01 parsers:01 backtracking:01 10,:98 2009:98 token:01 token:01 wrote:01 parsing:01 caml-list:01 grammar:02 grammar:02 On Tue, Mar 10, 2009 at 11:41 AM, Joel Reymont wrote: > inputDeclarations: > [ > [ "Input"; ":"; > l = LIST1 inputDeclaration SEP "," -> l > ] > ]; > > Is it always necessary to write [ x = inputDeclaration -> x ] instead of > just inputDeclaration? I don't think this is ever necessary (although in the back of my mind I have a fuzzy recollection that somewhere in the docs / wiki it says that it is). I can't say why you got a type error one way but not the other. For debugging types, you might find it helpful to look at the output of the preprocessing step, which has various type annotations. > By the same token, can I shorten the gramar below to just [ openStatement | > closedStatement ]? > > statement: [ [ s = openStatement -> s | s = closedStatement -> s ] ]; Syntactically it is fine but I don't think this is going to do what you want. Camlp4 parsers aren't backtracking; you have to distinguish openStatement from closedStatement by parsing a token. Otherwise you'll always follow the openStatement branch, then get a parse error if the stream wasn't actually parseable as an openStatement. (I think this is correct but it has been a few months since I worked on a grammar, sorry if I remembered it wrong.) Jake