Annotation tool for ANTLR (was: RE: [antlr-interest] Language Preprocessor.)

Bogdan Mitu bogdan_mt at yahoo.com
Tue Apr 16 06:37:39 PDT 2002


For all interested, 

I uploaded on ANTLR Yahoo group a simple tool that I found useful in the
development/maintenance of multiple versions of the same main grammar. 
The tool is here: 
http://groups.yahoo.com/group/antlr-interest/files/AnnotationTool/
together with some examples.

You can find below a description of the tool. If you give it a try, 
I will be happy to hear your comments.

Best regards,
Bogdan

===================================

  Annotation tool for ANTLR files

===================================

This tool allows the creation of a family of related ANTLR grammars 
from a single source. This situation is common in practice:

. When using the same grammar for multiple runtime environments 
  (Java/C++/...) you end up with grammars identical except for embedded 
  actions.
. When working with lexers, sometimes you want whitespace to be ignored,
  other times you want them to be passed forward as hidden tokens. 
. Parsers can have embedded code for the construction of a Symbol Table,
  or can be plain parsers for source validation.
. When working with tree parsers, it is common to have a series of 
  tree parsers with the same structure but with different embedded 
  actions.

The tool lets you loose the coupling between actual grammars and embedded
actions. You can define insertion points in the main grammar using a simple
mark-up of the form:

rule: <init> (alfa beta <action>)+ ;

and define in a separate file what <init> and <action> mean. Using different
definition files, you can get different varieties of the main grammar. If a 
definition is missing, the correspondent mark is ignored.

Having only one main source makes the maintenance of a grammar easier.
The cluttering is also reduced, making the sources more readable.

For examples of using the tool, see the folder examples in the distribution.
To run the examples cd to /examples, then type:

java -classpath ..annotation.jar;%ANTLR_HOME% annotation.Insert -s
arith_expr.ag -i plain.ins -d plain.g
java -classpath ..annotation.jar;%ANTLR_HOME% annotation.Insert -s
arith_expr.ag -i print.ins -d print.g
java -classpath ..annotation.jar;%ANTLR_HOME% annotation.Insert -s
arith_expr.ag -i calc.ins -d calc.g

arith_expr.ag is the annotated grammar for a simple arithmetic expressions
treewalker. 
Using 3 different insert files, we get:
. a plain tree grammar
. a grammar with embedded actions for printing back the tree
. a grammar with embedded actions for evaluating the expression

The tool is PUBLIC DOMAIN.
Enjoy it.



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

 

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



More information about the antlr-interest mailing list