[antlr-interest] Imaginary Node with Constructor Syntax, broken Java code generated?
Michael Nygard
mtnygard at gmail.com
Sat Mar 12 20:06:02 PST 2011
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
More information about the antlr-interest
mailing list