[antlr-interest] LPG WAS Retaining comments

Loring Craymer lgcraymer at yahoo.com
Tue Mar 18 19:22:51 PDT 2008


Formally, a context-free grammar is the tuple (N, T, P, S) where N is a set of non-terminal symbols, T is a set of terminal symbols with N and T being disjoint, P is a set of productions defining the non-terminals in terms of other symbols (both terminal and non-terminal), and S is a unique start symbol (non-terminal).  A parse tree is constructed by adding nodes for each matched symbol from an input source, with non-terminals inserted as the parent nodes of matched productions.

The classic abstract syntax tree is the parse tree built from processing a grammar according to a BNF grammar.  Modern usage has morphed this to accept Ter's usage.

Since parse trees capture the input grammar's non-terminals and productions, they are less than ideal for any but the simplest of translations.  The ANTLR approach is to design an AST for output processing and to toss out irrelevant assumptions about the input (i. e., the choice of productions and non-terminals in the input grammar).

--Loring

----- Original Message ----
From: Olivier Lefevre <lefevrol at yahoo.com>
To: antlr-interest at antlr.org
Sent: Tuesday, March 18, 2008 3:46:42 PM
Subject: Re: [antlr-interest] LPG WAS Retaining comments

Andy Tripp wrote:
> Olivier Lefevre wrote:
>> Another possible answer is that a parse tree is what you get by default, 
> 
> Not with ANTLR, you don't. There's one call to the parser to get the
> AST, and a whole different approach to getting the parse tree.

OK but by "taking charge" I meant shaping the tree yourself: when using 
ParseTreeBuilder, you are not doing that since it's a built-in. I still 
think it useful to think of the parse tree as something the tool will build 
for you automatically (if you ask it to) whereas the AST is something _you_ 
must build, making _all_ the decisions.

-- O.L.








      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080318/553c7a13/attachment-0001.html 


More information about the antlr-interest mailing list