[antlr-interest] Java AST Grammar

Adam Cooney ad_cooney at hotmail.com
Tue Mar 4 14:41:07 PST 2008


John, thank you so much so far for letting me use your JavaAST grammar. It has been extremely useful and I have been able to generate AST's, split the AST into relative sub-trees and use these to compare the two files based on a formula.  I do however, have one very small problem. It seems I get the following error:Exception in thread 'main' java.lang.ClassCastException: JavaASTParser$block_return cannot be cast to org.antlr.runtime.tree.Tree        at org.antlr.runtime.tree.BaseTreeAdaptor.addChild(BaseTreeAdaptor.java:77)        at JavaASTParser.statement(JavaASTParser.java:12708)        at JavaASTParser.blockStatement(JavaASTParser.java:11750)        at JavaASTParser.block(JavaASTParser.java:11613)        at JavaASTParser.methodBody(JavaASTParser.java:8974)        at JavaASTParser.voidMethodDeclaratorRest(JavaASTParser.java:5581)        at JavaASTParser.memberDecl(JavaASTParser.java:4093)        at JavaASTParser.classBodyDeclaration(JavaASTParser.java:3977)        at JavaASTParser.classBody(JavaASTParser.java:3628)        at JavaASTParser.normalClassDeclaration(JavaASTParser.java:1809)        at JavaASTParser.classDeclaration(JavaASTParser.java:1644)        at JavaASTParser.classOrInterfaceDeclaration(JavaASTParser.java:1120)        at JavaASTParser.typeDeclaration(JavaASTParser.java:1006)        at JavaASTParser.compilationUnit(JavaASTParser.java:609)        at BuildAST.GetAST(BuildAST.java:36)        at BuildAST.main(BuildAST.java:18)This error (so far in my testing) only occurs when there is a try catch block. I have enclosed 2 test files:
Partition.java is written with a FNFE and IOE error as a Try/Catch block. Partition2.java is written with a FNFE and IOE thrown on the functions instead and runs without an error.
 
Is there anyway you could fix this (or that somehow i've managed to do this?). I'd be very grateful.
Thanks
Adam


CC: john at jacelridge.comFrom: john at jacelridge.comTo: ad_cooney at hotmail.comSubject: Re: [antlr-interest] Java AST GrammarDate: Fri, 22 Feb 2008 12:31:54 -0500No problem.  I'm glad to hear it's working.  Do let me know of any problems you run into. 

Peace
- John



On Feb 21, 2008, at 1:50 PM, Adam Cooney wrote:

Sigh, nevermind. I should have paid more attention to the 'ANTLRInputStream input = new ANTLRInputStream(System.in);'. I did it quickly before I left and didnt have time to notice. Sorry for wasting your time, works fine :) ty


From: ad_cooney at hotmail.comTo: antlr-interest at antlr.orgDate: Thu, 21 Feb 2008 18:28:08 +0000Subject: Re: [antlr-interest] Java AST GrammarThanks John. I'm having a slight problem running it on a Java file though (problem as in, it seems to take a LONG time compiling, and by along, the source file I've ran (frm the Java examples) hasn't finished compiling yet. heres my console:C:\antlr-3.0b7\lib\Java\eg\ast>java org.antlr.Tool JavaAST.gANTLR Parser Generator  Version 3.1b1 (??)  1989-2007C:\antlr-3.0b7\lib\Java\eg\ast>java org.antlr.Tool JavaPrinterTree.gANTLR Parser Generator  Version 3.1b1 (??)  1989-2007C:\antlr-3.0b7\lib\Java\eg\ast>javac *.javaNote: Some input files use unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.C:\antlr-3.0b7\lib\Java\eg\ast>java Test input (note: input is of type File). Could you please send me an example one (preferably that doesnt take long to compile:)) or correct me if im trying to do this wrong - i am basing it off how I have ran others via ANTLR. Sorry to be such a novice at this stuff.Thanks Adam 

CC: john at jacelridge.com; antlr-interest at antlr.orgFrom: john at jacelridge.comTo: ad_cooney at hotmail.comSubject: Re: [antlr-interest] Java AST GrammarDate: Tue, 19 Feb 2008 19:53:57 -0500Yes, you need 3.0b7 won't work, but, actually, neither will 3.0.1.  There is a bug in 3.0.1 (fixed in current beta releases of 3.1) that causes certain things not to work (they're marked with something like <---- trouble here in the grammar).  Get the latest release of 3.1beta and you'll be much happier.  (With 3.0.1 it will compile, it will just fail at runtime or give you a bad AST.) 


I have to say that I was very impressed; when I pointed the bug out to Terence he got a new version with the fix out in a few (maybe one) days.

Peace
- John



On Feb 19, 2008, at 5:12 PM, Adam Cooney wrote:

Hi John, I've been having some trouble running your grammar. I keep getting the following error: C:\antlr-3.0b7\lib\Java\eg\ast>java org.antlr.Tool JavaAST.gANTLR Parser Generator  Version 3.0b7 (April 12, 2007)  1989-2007error(100): JavaAST.g:709:53: syntax error: antlr: JavaAST.g:709:53: unexpectedtoken: ?error(100): JavaAST.g:710:61: syntax error: antlr: JavaAST.g:710:61: unexpectedtoken: ?error(100): JavaAST.g:711:51: syntax error: antlr: JavaAST.g:711:51: unexpectedtoken: ?error(100): JavaAST.g:712:58: syntax error: antlr: JavaAST.g:712:58: unexpectedtoken: ?error(100): JavaAST.g:0:0: syntax error: assign.types: <AST>:0:0: unexpected end of subtreeerror(10):  internal error: JavaAST.g : java.lang.ClassCastException: antlr.ASTNULLType cannot be cast to org.antlr.tool.GrammarASTorg.antlr.tool.AssignTokenTypesWalker.block(AssignTokenTypesWalker.java:1215)org.antlr.tool.AssignTokenTypesWalker.rule(AssignTokenTypesWalker.java:1030)org.antlr.tool.AssignTokenTypesWalker.rules(AssignTokenTypesWalker.java:610)org.antlr.tool.AssignTokenTypesWalker.grammarSpec(AssignTokenTypesWalker.java:492)org.antlr.tool.AssignTokenTypesWalker.grammar(AssignTokenTypesWalker.java:363)org.antlr.tool.Grammar.setGrammarContent(Grammar.java:539)org.antlr.tool.Grammar.<init>(Grammar.java:448)org.antlr.Tool.getGrammar(Tool.java:331)org.antlr.Tool.process(Tool.java:267)org.antlr.Tool.main(Tool.java:70) Any idea what could be causing it? I'm pretty new to ANTLR, but the stringtemplate and antlr JARs are in the classpath, and I ran the example treeparsers fine. Could it be due to using antlr-3.0b7 rather than antlr-3.0.1? I was using 3.0.1 but after installing it and resetting the classpaths for some reason i got a Java classloader error even after restarting the computer, and so I just reverted back to this one.


CC: john at jacelridge.com; antlr-interest at antlr.orgFrom: john at jacelridge.comTo: ad_cooney at hotmail.comSubject: Re: [antlr-interest] Java AST GrammarDate: Tue, 12 Feb 2008 17:41:05 -0500I have been working on a Java grammar that produces an AST; and a companion tree grammar that produces equivalent Java code from an AST.  This is still a work-in-progress, but you're welcome to what I have. 

Please let me know if you run into any problems with this, as I'm trying to make it work nicely.

Peace
- John




She said what? About who? Shameful celebrity quotes on Search Star!

She said what? About who? Shameful celebrity quotes on Search Star!

She said what? About who? Shameful celebrity quotes on Search Star!
_________________________________________________________________
Free games, great prizes - get gaming at Gamesbox. 
http://www.searchgamesbox.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080304/6f748f2b/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Partition2.java
Type: application/octet-stream
Size: 2256 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080304/6f748f2b/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Partition.java
Type: application/octet-stream
Size: 2182 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080304/6f748f2b/attachment-0001.obj 


More information about the antlr-interest mailing list