[antlr-interest] parsing java 1.5

Terence Parr parrt at cs.usfca.edu
Wed Oct 4 10:12:32 PDT 2006


On Oct 4, 2006, at 9:06 AM, Koen Vanderkimpen wrote:

> Hello,
>
> I'm having trouble parsing a Java-file with antlr.
>
> I'm using the Java 1.5 grammar by Terence Parr found on http:// 
> www.antlr.org/grammar/1152141644268/java.g
> I compiled this grammar using antlr 3.0b4 and tried reading in some  
> files in the same way it is done in the antlr v3 sample grammars  
> (java subdirectory).
>
> About 100 files parsed without error, the only exception was a  
> class in which the method below exists.
> The error occurs on lines 164 and 166 of the method, and I believe  
> it might have something to do with the generic classcasts.
> I looked at the grammar but it seemed ok to me. I included the  
> output by the parser.
>
> Does anyone know what's wrong and how to solve this?
>
>
>
> public final <T extends Element> List<T> getDescendants(Class<T> c)  
> {    //this is line 163
>         List<Element> tmp = (List<Element>)getChildren();

Somehow this line is not recognized by the current grammar.  I did  
not test the template part of this grammar very much at all.  You  
will have to figure out why that is not parsed properly.  You can do  
this using ANTLRWorks most effectively.

Ter


More information about the antlr-interest mailing list