Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Map + Set
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-28 (01:38)
From: Josh Smith <josh@t...>
Subject: Re: [Caml-list] Camlp4 help/questions
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<b" but also "a<b<c" and so on. You can't use the same approach as for 
> 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<b<c".
> 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).


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 


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
if anyone is interested.

Thanks for the help.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: