caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Josh Smith <josh@trdlnk.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4 help/questions
Date: Tue, 27 Jul 2004 20:38:17 -0500	[thread overview]
Message-ID: <20040728013816.GC7950@trdlnk.com> (raw)
In-Reply-To: <200407272307.50167.jon@jdh30.plus.com>

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).

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


  parent reply	other threads:[~2004-07-28  1:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-25  8:17 [Caml-list] Map + Set Martin Jambon
2004-07-25 16:26 ` Matt Gushee
2004-07-25 17:01 ` Brian Hurt
2004-07-26 10:40   ` Matthieu Sozeau
2004-07-26 15:25     ` Brian Hurt
2004-07-26 15:47       ` Martin Jambon
2004-07-26 16:26         ` Brian Hurt
2004-07-26  7:43 ` Diego Olivier Fernandez Pons
2004-07-26 16:24   ` Martin Jambon
2004-07-26 16:52     ` Diego Olivier Fernandez Pons
2004-07-27 21:45   ` [Caml-list] Camlp4 help/questions Josh Smith
2004-07-27 22:11     ` Brian Hurt
2004-07-28  1:15       ` Josh Smith
     [not found]     ` <200407272307.50167.jon@jdh30.plus.com>
2004-07-28  1:38       ` Josh Smith [this message]
2004-07-28  8:03     ` Pierre Weis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040728013816.GC7950@trdlnk.com \
    --to=josh@trdlnk.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).