[antlr-interest] NQOT: Grammar meta-programming

Steve Bennett stevagewp at gmail.com
Thu Dec 6 21:30:31 PST 2007


On 12/7/07, Austin Hastings <Austin_Hastings at yahoo.com> wrote:
> It occurs to me that this is boilerplate. Yes, there are operators. Yes,
> they are the standard ones. Yes there is precedence. Yes, the precedence
> levels are standard. Why do I have to type this?

I was wondering about this too. It occurred to me that virtually any
language that anyone is willing to programming in bears a striking
similarity to most other languages out there. The difficulty of
switching from imperative to functional paradigms sort of bears that
out.

So it would really seem obvious to have some kind of grammar
generator. I was picturing a GUI, but a language would be fine too. In
my imagined GUI, you select options like "Uses blocks" (yes),
"Supported blocks" (if/then/else, while, procedure declaration...),
"Blocks look like" ("{..}") etc.

Such a thing would probably rapidly get you to about 90% of what's
required to parse some language. But how would you specify the other
10%? How do you specify the tiny freaky detail that makes language Foo
totally distinct from every other language? Do you end up simply
generating the grammar once, then hand-editing it? Is there an
extension mechanism?

One could start by assembling a family of languages which ought to be
parseable by some meta grammar parser. You could start with
object-oriented languages like Java, Object Pascal, VB, and work out
all the features they have in common, and ways of parameterising them.
Then possibly expand to all imperative languages. But being generic
enough to include functional and declarative languages like Haskell
and Prolog...ugh. That sounds hard.

I'd love to hear how far people have gone on this. I have a vague
dream of one day being able to whip up an interpreter for an esoteric
language in an hour or less...

Steve

Steve


More information about the antlr-interest mailing list