[antlr-interest] Where to add data conversion routines

Ted Villalba tedv at esrconsulting.com
Wed Jun 6 12:41:37 PDT 2007


 
Answering my own question here, the place to add conversion routines would
be in the embedded actions of the rules in the Tree Grammar, before calling
the string template to emit the translation.
 
TV
  _____  

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Ted Villalba
Sent: Wednesday, June 06, 2007 6:32 AM
To: ANTR Interest
Subject: [antlr-interest] Where to add data conversion routines
 
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/2d118bd4/attachment.html 


More information about the antlr-interest mailing list