Friday, November 05, 2004

Bleary eyed and grumpy

A little more on languages. The language I create will have a well defined grammar, and I'll be writing forms of it for tools like ANTLR, JavaCC, Bison, and so on. It's very important to have this as opposed to a haphazard language with features thrown in at random. These tools are well established and very stable, and they can generate code reliably. It's much more difficult to write refactoring tools for a language when the parse tree is ill defined.

There should be a way to use a grammar to not only create a parser for a given language, but also a code generator for it as well. If a parser creates a parse tree, you should be able to feed that tree into a code generator and generate equivalent code. (Not necessarily identical code, because formatting will undoubtably be lost, but you could certainly regenerate most comments, especially comments used as documentation or similar special features.) You also can parse code, manipulate the tree, and generate resultant source code, and that ability is needed for refactoring tools. Many optimizers operate on the tree automagically, too. So, anyway, I've seen plenty of tools that create a parser given a grammar, but none so far that create a generator given that same grammar. I'd like to write one. It would wind up being very similar to CodeDOM, but specific to a given language, and you could generate the entire program-space the grammar defines.

No comments: