[antlr-interest] Imaginary Node with Constructor Syntax, broken Java code generated?

Terence Parr parrt at cs.usfca.edu
Sun Mar 13 10:40:20 PDT 2011


Boy that sure seems like a bug..weird. adding. can I link to that page you sent or will it disappear sometime in the future?

Ter

On Mar 12, 2011, at 8:06 PM, Michael Nygard wrote:

> Hi all,
> 
> Here's a small fragment of an AST grammar:
> 
> qualifiedNameList 
>    :   qnames+=qualifiedName (',' qnames+=qualifiedName )*
>        -> ^(TYPEREF[$qnames.text])+
>    ;
> 
> qualifiedName
>    :   IDENTIFIER ('.' IDENTIFIER )* 
>        -> {new CommonTree(new CommonToken(QNAME, $qualifiedName.text))}
>    ;
> 
> I'm trying to manipulate the tree so it's easy to process from Clojure, by reducing some AST nodes down to text. ANTLR seems OK with this construct, but the code that it generates won't compile:
> 
> /Users/mtnygard/work/atg-xref/indexer/src/gen-java/ImaginaryNodeBugParser.java:139: illegal start of expression
>                if ( !() ) {
>                       ^
> /Users/mtnygard/work/atg-xref/indexer/src/gen-java/ImaginaryNodeBugParser.java:142: illegal start of expression
>                while (  ) {
>                         ^
> 
> Sure enough, when I check the generated code, I see conditionals that are completely empty! Is this a bug in codegen for the Java runtime, or am I doing something wrong with my cardinality?
> 
> The whole grammar, the generated parser source, and the errors are visible at https://gist.github.com/867853.
> 
> Cheers,
> -Michael Nygard
> 
> 
> 
> Michael T. Nygard
> mtnygard at gmail.com
> http://www.michaelnygard.com/
> 
> Release It! Design and Deploy Production-Ready Software
> http://bit.ly/ReleaseIt
> 
> Beautiful Architecture
> http://bit.ly/BeautifulArchitecture
> 
> 97 Things Every Software Architect Should Know
> http://bit.ly/97Things
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list