[antlr-interest] AST vs parse trees

Terence Parr parrt at cs.usfca.edu
Mon Nov 10 18:34:03 PST 2003


On Monday, November 10, 2003, at 06:29 PM, micheal_jor wrote:

> --- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...> wrote:
>
>>>> Howdy.  This is the old AST versus parse tree argument...Parse trees
>>>> are easy to generate (i.e., no cost to developer) but have way too
>>>> much
>>>> noise for tree transformation and also are sensitive to grammar
>>>> construction whereas ASTs are the canonical repr for a particular
>>>> language.
>>>
>>> Hmmm. If you are saying ANTLR generates a CST (aka. parse tree or
>>> concrete syntax tree) by default and the JJTree way is to generate an
>>> AST, you may be right Ter.
>>
>> Actually, antlr likes ASTs not parse trees though you could of course
>> build one.  In essence, I'm saying that ANTLR likes
>>
>>    +
>>   /  \
>> 3  4
>>
>> for "3+4" without any rule nodes in there like a parse tree has.
>
> Hmmm. That had the old grey matter twitching for a while ;-)
>
> OK. I needed to be clearer. In practical terms, ANTLR neither
> generates a CST nor an AST by default. It generates something in
> between. Sure the internal rule nodes are missing but, lots of other
> noise like semicolons and closing braces are present. Now, they have
> their uses (~100% lossless tranformations being one example) but they
> still represent noise in an optimized AST.

Actually I specifically remove ; and } etc... if you look at the java.g 
file.  An AST should have the minimum necessary information in there. :)

Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com pure link sharing




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list