[antlr-interest] match parser rule inside every rule (compile time reflections)
Alexander Herz
alexander.herz at mytum.de
Fri Jan 7 04:58:34 PST 2011
Hi,
I'm trying to implement compile time reflections, so inside the language
(imagine java) there is a preprocessor like language which can access
static properties of elements defined in the language:
Example:
class Test
{
int i,j;
Test()
{
//iterates over all members of Test
#for_all($m,Test at members)
{
$m=0;
}
//will be evaluated to:
i=0;
j=0;
}
}
It doesn't make sense to implement this in a preprocessor since the full
AST is needed to process the #for_all directive.
Therefore, I'd like to implement it in the grammar of the language. Now,
the problem is that the #for_all (and other related directives) can be
placed anywhere (outside of classes, etc). So I would need to put the
rule for #for_all into all the rules inside my grammar which seems ugly
and cumbersome.
Any ideas how to solve this?
Thx,
Alex
More information about the antlr-interest
mailing list