[antlr-interest] Possible bug: C# (& C++ maybe also): TreeParser doesn't have setMaxNodeType() called

Barry Kelly barry.j.kelly at gmail.com
Tue Oct 26 08:18:21 PDT 2004


In ordinary C# lexer parsers which have the buildAST option set to
true, a method called initialize() is generated, which calls a
generated initializeFactory() method, which calls a generated
initializeASTFactory(ASTFactory) method, which calls
factory.setMaxNodeType(int) with a ANTLR-tool calculated value, equal
to the integer value of the highest token.

This permits creation of nodes using the normal #[xxx] (or [xxx]
inside #()) without having to specify an AST class for xxx - it uses
the default factory and default AST type, CommonAST.

However, when a tree parser is created, there is no initialize()
method, and there is no call to setMaxNodeType(int). This means that
AST node constructors of the #[xxx] style throw exceptions due to not
having a known node type. Specifically, there's a Debug.Assert() call
in the C# generator which performs a range check of xxx's integer
value. If the code got past the Assert call (as it would in a
non-debug build), the hashtable determining the correct node type
returns null and a default (CommonAST) node would be created.

Either the code generator for C# tree parsers should call
setMaxNodeType(int) like it does for ordinary parsers, or the runtime
library shouldn't use a Debug.Assert() range check and let a default
node be created.

The Java code generator doesn't appear to call setMaxNodeType(int) at
all, judging from my very brief scan of the source. The other
generator(s) may be out of sync with the runtime code in this case,
however - I do not use Java, and thus cannot verify.

-- Barry Kelly


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list