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=0.2 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id A4142BBE5 for ; Sun, 8 Mar 2009 00:47:13 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmIBAMSWsknUnwdkk2dsb2JhbACCHJMFAQEBAQkJCgkRBL1MhAUG X-IronPort-AV: E=Sophos;i="4.38,321,1233529200"; d="scan'208";a="24004923" Received: from relay.pcl-ipout02.plus.net ([212.159.7.100]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 08 Mar 2009 00:46:50 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvIEAMSWsknUnw6R/2dsb2JhbACCHNEPhAUG Received: from ptb-relay01.plus.net ([212.159.14.145]) by relay.pcl-ipout02.plus.net with ESMTP; 07 Mar 2009 23:46:49 +0000 Received: from [87.112.234.120] (helo=leper.local) by ptb-relay01.plus.net with esmtp (Exim) id 1Lg6EC-0005y1-VW for caml-list@yquem.inria.fr; Sat, 07 Mar 2009 23:46:49 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] camlp4 stream parser syntax Date: Sat, 7 Mar 2009 23:52:18 +0000 User-Agent: KMail/1.9.9 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903072352.18127.jon@ffconsultancy.com> X-Plusnet-Relay: 715e5a97858ad1c2f764a7e65f10ffd8 X-Spam: no; 0.00; camlp:01 parser:01 syntax:01 syntax:01 camlp:01 parser:01 ocaml:01 ocaml:01 denotes:01 expr:01 expr:01 2009:98 frog:98 token:01 parsed:01 On Saturday 07 March 2009 22:38:14 Joel Reymont wrote: > Where can I read up on the syntax of the following in a camlp4 stream > parser? > > | [<' INT n >] -> Int n > > For example, where are [< ... >] described and why is the ' needed in > between? The grammar is described formally here: http://caml.inria.fr/pub/docs/manual-camlp4/manual003.html You may find one of my free articles on parsing to be of interest because it covers the stream parser camlp4 extension: http://www.ffconsultancy.com/ocaml/benefits/parsing.html There is also a slightly bigger parser here: http://www.ffconsultancy.com/ocaml/benefits/interpreter.html The [< .. >] denote a stream when matching over one using the "parser" keyword and the tick ' denotes a kind of literal to identify a single token in the stream. So: | [< 'Kwd "if"; p=parse_expr; 'Kwd "then"; t=parse_expr; 'Kwd "else"; f=parse_expr >] -> uses ' to parse three individual keywords but also requests that parts of the stream are parsed using the parse_expr function and each result is named accordingly. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e