[antlr-interest] 2.7.1 -> 2.7.2 ASTFactory bug

Kristian G. Kvilekval kris at cs.ucsb.edu
Tue Aug 12 19:02:51 PDT 2003


I think there is a bug when using heterogeneous trees
with the new ASTFactory class.

Explanation:
create(Token tok, String className) is called whenever <AST=className>
occurs in the grammar.   The constructor className(Token tok) usually
would set the AST type and possibly the text using setType and setText
to the constructed node.   The 2.7.2  behavior would re-initialize
the newly constructed AST with the token text and type.

The patched version will only initialize the constructed
AST when the default constructor is used (i.e. className() ).
Even this might be considered incorrect.  

An alternate would be to require heterogeneous AST nodes
ignore the "initialize" call.

 
$ diff -u antlr-2.7.2/antlr/ASTFactory.java  antlr-2.7.2.mod/antlr/ASTFactory.java
--- antlr-2.7.2/antlr/ASTFactory.java   2003-01-19 16:37:58.000000000 -0800
+++ antlr-2.7.2.mod/antlr/ASTFactory.java       2003-08-12 18:53:37.000000000 -0700
@@ -208,9 +208,6 @@
         */
        public AST create(Token tok, String className) {
         AST t = createUsingCtor(tok,className);
-        if ( t!=null ) {
-                       t.initialize(tok);
-               }
         return t;
     }
  
@@ -245,6 +242,9 @@
                                // just do the regular thing if you can't find the ctor
                                // Your AST must have default ctor to use this.
                                t = create(c);
+                if ( t!=null ) {
+                    t.initialize(token);
+                }
                        }
                }
                catch (Exception e) {





-- 
email:kris at cs.ucsb.edu office:(805)893-4276 http://www.cs.ucsb.edu/~kris


 

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




More information about the antlr-interest mailing list