[antlr-interest] parsing java 1.5

Koen Vanderkimpen koen.vanderkimpen+antlr at cs.kuleuven.be
Wed Oct 4 09:06:06 PDT 2006


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();
        new TypePredicate<Element, T>(c).filter(tmp);
        List<T> result = (List<T>)tmp;
        for (Element e : getChildren()) {
            result.addAll(e.getDescendants(c));
        }
        return result;
}


[compilationUnit, typeDeclaration, classOrInterfaceDeclaration, classDeclaration, normalClassDeclaration, classBody, classBodyDeclaration, memberDecl, genericMethodOrConstructorDecl, genericMethodOrConstructorRest, methodDeclaratorRest, methodBody, block, blockStatement, statement]: line 164:23 mismatched token: [@555,3760:3760='=',<44>,164:23]; expecting type ';'
[compilationUnit, typeDeclaration, classOrInterfaceDeclaration, classDeclaration, normalClassDeclaration, classBody, classBodyDeclaration, memberDecl, genericMethodOrConstructorDecl, genericMethodOrConstructorRest, methodDeclaratorRest, methodBody, block, blockStatement, statement, statementExpression, expression, conditionalExpression, conditionalOrExpression, conditionalAndExpression, inclusiveOrExpression, exclusiveOrExpression, andExpression, equalityExpression, instanceOfExpression, relationalExpression, shiftExpression, additiveExpression, multiplicativeExpression, unaryExpression, unaryExpressionNotPlusMinus, primary, parExpression]: line 164:38 mismatched token: [@560,3775:3775='>',<35>,164:38]; expecting type ')'
[compilationUnit, typeDeclaration, classOrInterfaceDeclaration, classDeclaration, normalClassDeclaration, classBody, classBodyDeclaration, memberDecl, genericMethodOrConstructorDecl, genericMethodOrConstructorRest, methodDeclaratorRest, methodBody, block, blockStatement, statement]: line 166:21 mismatched token: [@587,3864:3864='=',<44>,166:21]; expecting type ';'
[compilationUnit, typeDeclaration, classOrInterfaceDeclaration, classDeclaration, normalClassDeclaration, classBody, classBodyDeclaration, memberDecl, genericMethodOrConstructorDecl, genericMethodOrConstructorRest, methodDeclaratorRest, methodBody, block, blockStatement, statement, statementExpression, expression, conditionalExpression, conditionalOrExpression, conditionalAndExpression, inclusiveOrExpression, exclusiveOrExpression, andExpression, equalityExpression, instanceOfExpression, relationalExpression, shiftExpression, additiveExpression, multiplicativeExpression, unaryExpression, unaryExpressionNotPlusMinus, primary, parExpression]: line 166:30 mismatched token: [@592,3873:3873='>',<35>,166:30]; expecting type ')'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061004/e98fe905/attachment.html 


More information about the antlr-interest mailing list