caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Define parser and printer consistently
@ 2010-12-09  4:47 Dawid Toton
  2010-12-09  4:56 ` [Caml-list] " Ashish Agarwal
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dawid Toton @ 2010-12-09  4:47 UTC (permalink / raw)
  To: caml-list

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.

Dawid


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Define parser and printer consistently
  2010-12-09  4:47 Define parser and printer consistently Dawid Toton
@ 2010-12-09  4:56 ` Ashish Agarwal
  2010-12-09 11:25 ` Romain Bardou
  2010-12-09 19:28 ` Yitzhak Mandelbaum
  2 siblings, 0 replies; 5+ messages in thread
From: Ashish Agarwal @ 2010-12-09  4:56 UTC (permalink / raw)
  To: Dawid Toton; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

Maybe you will find Pickler Combinators useful:
http://research.microsoft.com/en-us/um/people/akenn/fun/picklercombinators.pdf


On Wed, Dec 8, 2010 at 11:47 PM, Dawid Toton <d0@wp.pl> 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.
>
> Dawid
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 1879 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Define parser and printer consistently
  2010-12-09  4:47 Define parser and printer consistently Dawid Toton
  2010-12-09  4:56 ` [Caml-list] " Ashish Agarwal
@ 2010-12-09 11:25 ` Romain Bardou
  2010-12-09 19:28 ` Yitzhak Mandelbaum
  2 siblings, 0 replies; 5+ messages in thread
From: Romain Bardou @ 2010-12-09 11:25 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Define parser and printer consistently
  2010-12-09  4:47 Define parser and printer consistently Dawid Toton
  2010-12-09  4:56 ` [Caml-list] " Ashish Agarwal
  2010-12-09 11:25 ` Romain Bardou
@ 2010-12-09 19:28 ` Yitzhak Mandelbaum
  2 siblings, 0 replies; 5+ messages in thread
From: Yitzhak Mandelbaum @ 2010-12-09 19:28 UTC (permalink / raw)
  To: Dawid Toton; +Cc: caml-list

PADS/ML can do that for you, and more. You can find information about the PADS languages and tools here: 

http://www.padsproj.org

including papers and a manual. The website doesn't have the most recent release of PADS/ML -- i plan to put it up on Github shortly -- but if you're interested, i'm happy to send you a tarball.

The basic idea is that you specify your grammar as a type-like declaration.  Then, pads/ml generates an AST, parser, printer and some more stuff for you.  The generated parser is like a PEG parser, but with support context-sensitive parsing. That is, it is deterministic, with ordered choice; and, it is scannerless. So, the grammars-writing style has some significant differences from ocamllex and ocamlyacc.

PADS/ML has an Eclipse license.

Cheers,
Yitzhak


On Dec 8, 2010, at 11:47 PM, 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.
> 
> Dawid
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

-----------------------------
Yitzhak Mandelbaum




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Define parser and printer consistently
       [not found] <20101209110003.3C0B3BBAF@yquem.inria.fr>
@ 2010-12-09 11:11 ` CUOQ Pascal
  0 siblings, 0 replies; 5+ messages in thread
From: CUOQ Pascal @ 2010-12-09 11:11 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]


>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?

Take a look at Boomerang: http://www.seas.upenn.edu/~harmony/

>From the overview:

Boomerang is a programming language for writing lenses—well-behaved bidirectional transformations—that operate on ad-hoc, textual data formats. Every lens program, when read from left to right, describes a function that maps an input to an output; when read from right to left, the very same program describes a "backwards" function that maps a modified output, together with the original input, back to a modified input.

Lenses have been used to solve problems across a wide range of areas in computing including: [...] in parsers and pretty printers

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 3143 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-12-09 19:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09  4:47 Define parser and printer consistently Dawid Toton
2010-12-09  4:56 ` [Caml-list] " Ashish Agarwal
2010-12-09 11:25 ` Romain Bardou
2010-12-09 19:28 ` Yitzhak Mandelbaum
     [not found] <20101209110003.3C0B3BBAF@yquem.inria.fr>
2010-12-09 11:11 ` CUOQ Pascal

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