[antlr-interest] Strategy for generating text pattern for a decrementing value
Felix Dorner
felix_do at web.de
Tue Apr 22 10:59:52 PDT 2008
Simon Woods wrote:
> Hi
>
> I am translating a language into a new form, so I have a grammar, tree
> walker and several templates.
>
> In the original language, there may be an occurance of a particular
> expression which contains a number, N. If this expression occurs,
> based on the value this number, I want to generate a text pattern
> something like
>
> "mytextpattern-(N) OR mytextpattern-(N-1) OR mytextpattern-(N-2) OR
> mytextpattern-(N-3) ..." until N = 0
Today I had my first amazing StringTemplate experience. I am amazed,
although I don't know if thats the way to go, I find this really freaky
myNrule: NUMBER {
StringTemplate s = new StringTemplate("mytextpattern-($number; separator
= )OR$)");
int i = Integer.parseInt($Number.text);
for (; i >= 0; i--){
s.setAttribute("number", new Integer(i)) // need to pass an object
}
}
There may be syntax errors, I really dont get along with all those rule
attributes.
More information about the antlr-interest
mailing list