[antlr-interest] LPG WAS Retaining comments
siemsen at ucar.edu
siemsen at ucar.edu
Thu Mar 13 10:54:38 PDT 2008
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/aec09438/attachment-0001.html
More information about the antlr-interest
mailing list