[antlr-interest] NQOT: Grammar meta-programming

Austin Hastings Austin_Hastings at Yahoo.com
Thu Dec 6 11:31:33 PST 2007


Howdy,

This isn't quite off topic, nor quite on topic. I thought I'd throw it 
out here since there are probably some researchy types reading.

I'm in the middle of yet another implementation of an expression 
language. This time it's for strings. So far I've got '+' for 
catenation, and various unary operators. I've recently had to do a 
c-like arithmetic expression sublanguage a couple of times.

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?

More to the point, what do I have to type to NOT have to type all this 
cruft? What feature does ANTLR need that will support grammar metacoding 
so that I can compactly declare the entire arithmetic or string 
expression aspect of my language?

Is there a notion of an "abstract grammar"? Is there a "generic 
grammar"? Is there an "interface GrammarWithArithmethicExpressions" that 
my grammar can implement?

Of course, the fact that Antlr's lookahead wants to know about the 
tokens that may start or end an expression will interfere, but does it 
have to interfere that much? What kind of "token set" would I have to 
declare to enable Antlr to 'bolt on' a sub-grammar? What information 
would be needed to 'extend' a base grammar? Is anything necessary in 
order to disable certain operators, or re-cast them to a different 
precedence or associativity? What about converting an operator from 
binary to unary, or vice-versa?

In short, what's the state of research on grammar meta-programming, and 
who's going to advance it?

=Austin



More information about the antlr-interest mailing list