[antlr-interest] Seperating grammar and actions

Johannes Luber JALuber at gmx.de
Thu Mar 5 07:08:53 PST 2009


> Hi, 
> 
> I have never considered using tree grammar earlier. But now I took a look
> at it as it sounded like a solution to my problem. But I still have one
> doubt. 
> 
> Suppose I write a grammar that parses the input file and constructs the
> AST. I have to next write a tree grammar that can operate on the generated
> AST (I guess this is called the tree walkers). My question is, is it possible
> to turn on rewrite in tree grammar?

You can use tree rewriting since 3.1.

> or it is necessary to describe the
> entire tree in the tree-grammar? I did some googling and found this page -
> http://www.antlr.org/wiki/display/~admin/2008/11/29/Woohoo%21+Tree+pattern+matching%2C+rewriting+a+reality
> . This sounds damn sexy! But has this been released? Does the latest
> release (3.1.2) include this?

The current snapshot should include the required facilities for the Java target. Other targets will officially support it in 3.2, but may already include it in 3.1.3. This will depend on time and effort. Currently I'm not aware of a target other than Java already having this support.

Johannes
> 
> Thanks, Indhu 
> 
> ----- Original Message ----- 
> From: Sam Harwell <sharwell at pixelminegames.com> 
> To: Indhu Bharathi <indhu.b at s7software.com>, antlr-interest at antlr.org 
> Sent: Thursday, March 5, 2009 8:34:25 AM GMT+0530 Asia/Calcutta 
> Subject: RE: [antlr-interest] Seperating grammar and actions 
> 
> 
> 
> 
> You have a few options: 
> 
> 
> 
> 1. Only build an AST in the parser, then use a tree walker to perform your
> needed operations. This is the “v3” way to do it, especially with the
> new filter-mode tree parsers on the way. 
> 
> 2. Call virtual functions from your actions, and implement those functions
> as empty stubs. Derive a class from the parser and implement the functions
> as necessary. This seems to be a “v2” way to do it, as it’s used in
> one of the v2 grammars in the ANTLR Tool. 
> 
> 
> 
> Sam 
> 
> 
> 
> 
> 
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Indhu Bharathi 
> Sent: Wednesday, March 04, 2009 8:44 PM 
> To: antlr-interest at antlr.org 
> Subject: [antlr-interest] Seperating grammar and actions 
> 
> 
> 
> Hi, 
> 
> 
> 
> Is there a way to separate grammar and actions into two different files?
> This will be helpful when multiple people are working with the same grammar
> file (each might write their own actions for the same production) and
> don’t want to create redundant copies of the grammar file. 
> 
> 
> 
> One way I thought was to implement observer pattern. The parser will be
> the subject and multiple observers can register to the same production and do
> different things. Another way would be to write a tool to separate the
> actions from the grammar file and reattach it. This way, actions can be
> separated out and maintained in a separate file and can be reattached when
> necessary and changes to grammar can be done in one centralized file. 
> 
> 
> 
> Is there any other way to do this? Any hint might be useful. 
> 
> 
> 
> Thanks, Indhu 
> 
> 
> 

-- 
Computer Bild Tarifsieger! GMX FreeDSL - Telefonanschluss + DSL
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a


More information about the antlr-interest mailing list