When we implement a programming language, we usually have to write parser and a pretty-printer. However, manually writing both programs is not only tedious but also error-prone; it may happen that a pretty-printed result is not correctly parsed.
FliPpr, which is a program transformation system that uses program inversion to produce a CFG parser from a pretty-printer, will solve the problem. Thanks to the program inversion, the consistency between a given pretty-printer and the derived parser is guaranteed. The advantages of our system are:
we can write a program that traverses on structured ASTs (pretty-printer) rather than structure-less strings (parser),
as a result, we have fine-grained control on pretty-printing,
and we can reuse existing efficientimplementations of pretty-printers and parsers.
FliPpr requires GHC, alex and happy. These programs will be installed if you install Haskell Platform.
We have tested GHC 7.4.1, alex 3.0.1, and happy 1.18.9.
make
$ ./FliPpr INPUTFILE > OUTPUTFILE
The OUTPUTFILE contains a definition of a pretty-printer copied from INPUTFILE and a parser. For a pretty-printing function f
, which must be declared in topmost line, a parsing function parse_f
is generated.
Examples directory contains a few examples.
NB: The current implementation is hardwired to use Examples/Defs.hs
for input datatypes and so on, which will be fixed in some future.
The current implement is prototype. It needs much more effort to be a practical tool, especially, in the following points.
Currently, it generates parsers only for Haskell. Although it has a potential power to produce parsers for other languages like ocaml, some Haskell-specific code is hard-wired.
The source code itself is not well structured;)
There may be a lot of bugs!