[antlr-interest] Composing tree grammars

Sam Harwell sharwell at pixelminegames.com
Fri Feb 6 12:15:19 PST 2009


Hi Andreas,

 

Make the actions in your tree grammar call virtual/abstract functions. Then derive a new all-code class from the tree grammar class that overrides those functions to provide the action implementation. The ANTLR Tool itself uses this pattern in the AssignTokenTypesWalker tree grammar.

 

Sam

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andreas Meyer
Sent: Friday, February 06, 2009 1:01 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Composing tree grammars

 

Hi!

 

I am using ANTLR 3.1 and I want to compose tree grammars in a way, that I have one "base" grammar that contains all rules, in order to define a traversal, but without actions/rewrites. Then, a second grammar imports the "base" grammar, and overrides only some rules. Now, if I try to use the second grammar on the input, the ANTLR runtimes complain about mismatched input: it seems that internally, the walker does not consume enough tokens, so that it expects the tokens "behind" the current token. FYI, I used the java/simplecTreeWalker example from the antlr 3.1 distribution and basically copied the walker, spelled "import ..." and removed all but one rule from the copy.

 

Did I use composite tree grammars in a wrong way? If so, how can I define multiple tree grammars for only small parts of the grammar?

Andreas Meyer
Developer
_____
smartShift
smartShift GmbH
Willy-Brandt-Platz 6
68161 Mannheim
T +49 (0)621 / 400 676-09
F +49 (0)621 / 400 676-06
E: andreas.meyer at smartShift.de <mailto:katja.reinig at smarshift.de> 

smartshift.de <http://www.smartshift.de/> 

Information contained in this message is confidential and may be legally privileged. If you are not the addressee indicated in this message (or responsible for the delivery of the message to such person), you may not copy, disclose or deliver this message or any part of it to anyone, in any form. In such case, you should delete this message and kindly notify the sender by reply Email. 
Opinions, conclusions and other information in this message that does not relate to the official business of smartShift shall be understood as neither given nor endorsed by it.

 



__________ Hinweis von ESET Smart Security, Signaturdatenbank-Version 3834 (20090206) __________

E-Mail wurde geprüft mit ESET Smart Security.

http://www.eset.com

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


More information about the antlr-interest mailing list