From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id DAA20843; Wed, 28 Jul 2004 03:38:40 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA21104 for ; Wed, 28 Jul 2004 03:38:39 +0200 (MET DST) Received: from trdlnk.com ([208.252.163.7]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6S1cbSH030583 for ; Wed, 28 Jul 2004 03:38:38 +0200 Received: from minglewood.chicago.trdlnk.com (minglewood [10.10.1.79]) by trdlnk.com (8.12.10+Sun/8.12.9) with ESMTP id i6S1cH9o013839 for ; Tue, 27 Jul 2004 20:38:17 -0500 (CDT) Received: from minglewood.chicago.trdlnk.com (localhost [127.0.0.1]) by minglewood.chicago.trdlnk.com (8.12.10+Sun/8.12.9) with ESMTP id i6S1cHrO009197 for ; Tue, 27 Jul 2004 20:38:17 -0500 (CDT) Received: (from josh@localhost) by minglewood.chicago.trdlnk.com (8.12.10+Sun/8.12.9/Submit) id i6S1cHuE009196 for caml-list@inria.fr; Tue, 27 Jul 2004 20:38:17 -0500 (CDT) Date: Tue, 27 Jul 2004 20:38:17 -0500 From: Josh Smith To: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4 help/questions Message-ID: <20040728013816.GC7950@trdlnk.com> References: <20040727214504.GA7950@trdlnk.com> <200407272307.50167.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200407272307.50167.jon@jdh30.plus.com> User-Agent: Mutt/1.4.1i X-Miltered: at concorde with ID 4107039D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 camlp:01 2004:99 camlp:01 descent:01 developement:01 lalr:01 inequality:01 fragile:01 parses:01 compiler:01 compilers:01 ocaml:01 ocaml:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Jul 27, 2004 at 11:07:50PM +0100, Jon Harrop wrote: > > > the unasked question here is "Is this the right way to go?" I mean, is > > Camlp4 the tool I should be using? I think it is, because the top down, > > recursive descent parsing is what Spirit does, but maybe I've just confused > > things. > > I am no expert on parser technology but I've written a few interpreters and > compilers in OCaml now and it is an excellent language for this kind of > stuff. that's what I've read, but I've yet to be able to do work myself. >Coming from a C++ background I can also say that C++ would be an awful > language for this and, as for template metaprogramming, well... :-) Spirit is great. The template metaprograming, from a user-developers standpoint isn't so bad. But it is one of the reasons I'd like to move all of my developement to Ocaml. > I've only used yacc, so only LALR(1) grammars. I'm not sure if this is > formally correct, but in a lot of cases you can get extended functionality by > parsing what you can and then manipulating the resulting data structures. For > example, in my latest compiler I need a parser which can understand not only > "a addition ("a+b+c" = "(a+b)+c") so I parse into an intermediate representation > "Inequality[a, Less, b, Less, c]" which I postprocess into the equivalent of > "a > You may find that, with similar tricks, you can parse what you need using > yacc. this may be exactly what I need to do. You don't have to do this in Spirit. Not that that changes anything, I'm just noting it. > Do you have a specification for the grammar? Can you give examples of input > and the corresponding data structure you would like? Kinda. I don't have an EBNF for it, but I do have input and desired output for one of the sets (this is the simplest, but it's indicitive of what is ussually there). Input: a23fassssadfj4532|10,2;13,3;20;20|10|20|30|B Desired output (in Oaml'ish): type origination = B | S | T | A;; type pattern = {score:int;weight:int};; type item = {id:string;patterns:pattern list;max:int;min:int;time:int;origin:origination } So, a23fassssadfj4532|10,2;13,3;20;20|10|20|30|B would be id:a23fassssadfj4532 patterns:[{10,2};{13,3};{20,20}] max:10 min:20 time:30 origin:B It has also been noted that I could just use a combination of splits to accomplish this, but I've found that approch to be fragile and slow. I've also got some ocamlyacc/ocamllex code that works (it parses a subset of the desired input), but doesn't do what I want yet (it's mostly just cut/paste from the manual). I've that at http://www.bad-poetry.net/ocaml/ if anyone is interested. Thanks for the help. -jbs ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners