[antlr-interest] Where to add data conversion routines

Ted Villalba ted.villalba at gmail.com
Wed Jun 6 06:32:19 PDT 2007


Hi,
I'm writing a translator in ANTLR v3,and not sure where to put the logic for
modifying some values of LanguageA before (or while) they are translated to
LanguageB.
For instance LanguageA accepts dates in format YYYY, but LanguageB requires
dates to be in format YYYY-MM-DD.
Where should I test for this input and convert to the new format while
trying to adhere to the MVC principles?

I have defined the grammar, created a tree traverser, and am using string
templates for the output.
For instance in the Grammar def'n I have:
    expression: tag '=' value+ -> ^('=' tag value+)
In the Treetraverser I have:
   expression: ^('=' tag (v+=value)+) -> ST1(tag={fieldMap.get
($tag.text)},values={$v})

Now I want to be able to say something like:
if ($tag.text="date" AND $v.length=4) { $v = convertDate($v);}

Butm I don't know where to add this code. As an action before the template
call?
What's the protocol for this conversion?
Any similar examples someone can point me to?

Thanks for the assist.

Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070606/20741a79/attachment-0001.html 


More information about the antlr-interest mailing list