[antlr-interest] Reverse Iterate over String Template
Graham Wideman
gwlist at grahamwideman.com
Wed Jun 3 13:37:23 PDT 2009
Hi Christian:
> Is there a way to iterate over a string template in reverse order?
Until Ter implements list reverse, you might try something like this to apply a template to a list in reverse order:
----------------------------------
maintemplate(arg1) ::= <<
<rev(arg1)>
>>
rev(argR) ::= <<
<usefultemplate(last(argR))>
<if(trunc(argR))>
<rev(trunc(argR))>
<endif>
>>
usefultemplate(argA) ::= <<
SomethingUseful: <argA>
>>
-----------------------------------
Basically, template rev() applies your useful template to the last() item in the list, and recurses on the remainder of the list, stopping when the list is empty.
-- Graham
More information about the antlr-interest
mailing list