caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Romain Bardou <Romain.Bardou@lri.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Define parser and printer consistently
Date: Thu, 09 Dec 2010 12:25:37 +0100	[thread overview]
Message-ID: <4D00BCB1.5030902@lri.fr> (raw)
In-Reply-To: <4D005F51.8070701@wp.pl>

On 09/12/2010 05:47, Dawid Toton wrote:
> I'm going to define a parser and a printer for a simple grammar.
> Is there a way to define both of them in a single construct using some
> existing OCaml tool?
>
> For example, I have a keyword "function". The usual parser would contain
> a mapping like:
> "function" -> `Function
> and the straightforward printer would do:
> `Function -> "function"
>
> What is the best way to combine these definitions, so that duplication
> would be minimized?
> To be precise, avoiding duplication is not exactly what I need. I'm
> looking for something that would prevent making inconsistent changes to
> the parser and the printer.

I'm writing a tool called Parsini which, maybe, does what you're looking 
for. Parsini stands either for "parsing is not interesting" (i.e.: let's 
have a tool which does it quickly for us and move on to interesting 
things such as code generation) or for "parser houdini" or something :p

 From a simple grammar, the tool :
- infers and produces an AST ;
- produces an ocamlyacc source ;
- produces an ocamllex source (optional - you can use your own lexer) ;
- produces a main file with :
   * functions to read your main entries easily from a channel, a file, 
a string...
   * functions to pretty-print your AST.
Your AST is pretty-printed with the Ocaml syntax, not the syntax of your 
own language, which I do not know how to do.

I have not released the tool yet, so nothing is official nor documented 
but you might want to take a look. License will be BSD. I've copied the 
darcs repository on my website :

http://romain.bardou.fr/parsini

So you should be able to download it easily with :

darcs get http://romain.bardou.fr/parsini

Have fun,

-- 
Romain Bardou


  parent reply	other threads:[~2010-12-09 11:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-09  4:47 Dawid Toton
2010-12-09  4:56 ` [Caml-list] " Ashish Agarwal
2010-12-09 11:25 ` Romain Bardou [this message]
2010-12-09 19:28 ` Yitzhak Mandelbaum

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=4D00BCB1.5030902@lri.fr \
    --to=romain.bardou@lri.fr \
    --cc=caml-list@yquem.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).