From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 4DA86BC57 for ; Thu, 23 Sep 2010 18:29:06 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AisFAHccm0yty1O7/2dsb2JhbACDG5EhjXZxtEmSNoEigyxzBIROiGg X-IronPort-AV: E=Sophos;i="4.57,224,1283724000"; d="scan'208";a="64349635" Received: from elehack.net ([173.203.83.187]) by mail2-smtp-roc.national.inria.fr with ESMTP; 23 Sep 2010 18:29:05 +0200 Received: from [134.84.75.20] (x-134-84-75-20.uofm-secure.wireless.umn.edu [134.84.75.20]) by elehack.net (Postfix) with ESMTPSA id 3B177C8994 for ; Thu, 23 Sep 2010 11:30:45 -0500 (CDT) Subject: Re: [Caml-list] what do I need to know to understand camlp4 From: Michael Ekstrand To: caml-list@inria.fr In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Thu, 23 Sep 2010 11:28:44 -0500 Message-ID: <1285259324.1820.16.camel@knine> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 0200,:01 camlp:01 syntax:01 context-free:01 grammars:01 wikipedia:01 syntax:01 ocaml:01 parser:01 ocaml:01 wikipedia:01 wiki:01 context-free:01 blog:98 On Thu, 2010-09-23 at 16:56 +0200, ben kuin wrote: > Could someone give any idea how I can begin to understand how to write > simple camlp4 extensions? Shameless self-plug, but I wrote a blog post this summer about my experience figuring out how to do it. I provide a walk-through and explanation of a minimal syntax extension which adds lazy list pattern matching support based on Batteries. The URL: http://www.elehack.net/michael/blog/2010/06/ocaml-syntax-extension I do assume a basic knowledge of parsing context-free grammars, but a generic tutorial on parsing with a tool such as Yacc can fill in that gap. The Wikipedia article[1] may also be helpful. Once you've lept the hurdle of figuring out what pieces you need to write and build a syntax extension, the remaining tricky part is to figure out what pieces of the grammar you need to extend to accomplish your objective. For that, I consult the definition of the OCaml parser in Camlp4OCamlParser.ml in the OCaml source tree. - Michael 1. http://en.wikipedia.org/wiki/Context-free_grammar -- Web/blog: http://elehack.net/michael Jabber/Google Talk: this e-mail address Twitter: http://twitter.com/elehack mouse, n: a device for pointing at the xterm in which you want to type