[Haskell-cafe] Generating Source Code with Haskell

Bjorn Bringert bringert at cs.chalmers.se
Tue Jan 2 16:41:18 EST 2007

On Jan 2, 2007, at 0:08 , Martin Huschenbett wrote:

> Hi,
> my aim is to transform an XML file into C++ source code with a  
> Haskell program. The part that parses the XML is already finished  
> (using HaXML) but the part that generates the C++ code is still  
> remaining. Is there already any work on this topic? Maybe even on  
> generating Java or any other object oriented or imperative language.
> My first approach was to simply generate the C++ code as text using  
> a pretty printing library but this becomes ugly very fast. Next I  
> thought about generating and rendering the AST of the resulting C++  
> code. But I don't want to reinvent the wheel.

When I want to generate source code, I often write a grammar for the  
language fragment that I need and use BNFC (http://www.cs.chalmers.se/ 
~markus/BNFC/) to make a pretty-printer. If you want nicely indented  
output, you sometimes have to tweak the generated pretty-printer a bit.


More information about the Haskell-Cafe mailing list