[antlr-interest] LPG WAS Retaining comments

Andy Tripp antlr at jazillian.com
Thu Mar 13 11:50:06 PDT 2008


Thanks, Pete.

Yes, I can certainly now see how your translator is "non-trivial" and 
doesn't need an AST.

Looks like maybe the situation is similar to IDL for CORBA, where the 
input language is
nicely defined as a subset of several other languages and then used to 
generate those
other languages.

So rather than "trivial" or not, the issue is whether or not the "from" 
language was really designed
so that it could be translated to the "to" language.

Thanks again for posting this...I wasn't picturing this sort of case at 
all. An AST might help,
but it might not.

Good luck with it, and I hope I didn't offend you or anything. Just 
picture me working
to replace C pointers with Java and C++ templates with Java generics all 
day and you
can imagine where my incredulous attitude comes from :)

Andy

siemsen at ucar.edu wrote:
>
> On Mar 13, 2008, at 11:06 AM, Jim Idle wrote:
>
>>> Andy Tripp wrote:
>>> The "Trust me, I translate from one non-trivial language to 
>>> another without needing an AST,
>>> but I wont give any details at all" thread from someone else is 
>>> really bugging me, too.
>>
>> Well, all the poster was saying (I think) is that he was able to 
>> write a translator by just using actions in the parser. I have done 
>> the same thing in the past. However, what Loring was trying to say 
>> (and most would agree I think), is that as soon as you get to a 
>> non-trivial case, while you can probably find a way to do without, 
>> you will find it better on many levels to construct an AST. I don't 
>> think that that is in any way a contentious statement.
>
> That poster was me.  To give Andy some details, my translator reads 
> ~1250 files written in an abstract language called MOF and writes 
> ~1250 Java files.  MOF is Managed Object Format, a language used to 
> define the Common Information Model, which is a object-oriented 
> standard for representing computers and networks.  The Common 
> Information Model is defined by the Distributed Management Task Force. 
>  The MOF files are available at 
> http://www.dmtf.org/standards/cim/cim_schema_v2171/.  The DMTF wanted 
> to define an object-oriented model while staying language-agnostic, so 
> they use MOF.  MOF isn't wildly different than Java, hence my 
> translator qualifies as "trivial" as Loring defined trivial: 
>
> "Trivial translations--A source to B source for languages in which 
> language B can straightforwardly express the paradigms of language 
> A--can be done without intermediate analysis.  Even there, an AST is 
> helpful and aids maintainability."
>
> Perhaps the negative connotation of the word "trivial" has made this 
> into more of an argument than it's worth.  At first I assumed that 
> "trivial" meant "small" or "for teaching purposes" or something. My 
> translator seems nontrivial to me.  The grammar has ~900 lines, yet no 
> AST.  I built it by reading the ANTLR book, learning as I went, and 
> didn't encounter a need for an AST.  Others might have a similar 
> experience, so I posted to learn why ASTs should be used.  As a result 
> of this thread, I now think an AST might improve my translator 
> somewhat.  I plan to add one to get separation-of-concerns and to 
> perhaps discover the "helpful and aids maintainability" benefits that 
> Loring mentioned.
>
> So Andy, I hope you aren't still bugged by this, but I remain 
> unconvinced that every useful (nontrivial) translation needs an AST.
>
> -- Pete
>
>
>
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080313/cb046931/attachment.html 


More information about the antlr-interest mailing list