From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 31A94BB88 for ; Tue, 19 Jul 2005 21:20:39 +0200 (CEST) Received: from corwin.easynet.fr (smarthost160.mail.easynet.fr [212.180.1.160]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6JJKcK1029523 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Tue, 19 Jul 2005 21:20:39 +0200 Received: from asi-62.asi256ip.easynet.fr ([212.180.39.62] helo=micro) by corwin.easynet.fr with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1Duxds-0004Re-4v; Tue, 19 Jul 2005 21:20:36 +0200 Received: from gildor by micro with local (Exim 4.50) id 1Duxdm-0006kX-19; Tue, 19 Jul 2005 21:20:30 +0200 Date: Tue, 19 Jul 2005 21:20:29 +0200 To: "Nathaniel J. Gaylinn" Cc: OCaml Mailing List Subject: Re: [Caml-list] parsing OCaml code Message-ID: <20050719192029.GA25903@gallu.homelinux.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i From: Sylvain LE GALL X-Miltered: at nez-perce with ID 42DD5286.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 parsing:01 ocaml:01 le-gall:01 ocaml:01 syntax:01 ocamlc:01 parsing:01 grammar:01 le-gall:01 cmo:01 ...:98 wrote:01 functions:01 lex:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, On Tue, Jul 19, 2005 at 01:05:58PM -0400, Nathaniel J. Gaylinn wrote: > > I'm trying to figure out a nice way to parse OCaml code in a C++ program. > All I need is a very basic parse tree for use in syntax highlighting and > indenting OCaml code. > > I would love to make use of some of the programs that already come with > OCaml. For instance, ocamlc and camlp4 can both output OCaml parse trees > already! The only problem is the formats that these programs output are > (to my knowledge) completely undocumented. > > If I don't use these programs, I could always try using Lex and Yacc to do > the job, but I'm completely unfamiliar with these utilities and it would > take me quite some time to write input for parsing OCaml. > > Does anyone know where I could find reference to the various OCaml parse > tree formats? Does anyone know where I could find Yacc grammar > descriptions of OCaml, or would I have to write them myself? Does anyone > have any other suggestions of how to tackle the parsing problem? > You should have a look to ocaml-ast-analyze (http://www.carva.org/sylvain.le-gall/ocaml-ast-analyze.html). It is a module build around camlp4 which can overridde the output of camlp4 (ie it can replace pr_dump.cmo for example). I use it to analyze ocaml code in order to find functions (which are "s_", "f_"... ) followed by a string (s_ 'Coucou') and output only the string ("msgstrid 'Coucou'). I think it is very useful to do analysis on Ocaml AST. There is no documentation, but i am planning to write some. Kind regard Sylvain Le Gall