[antlr-interest] How to extend the CommonTree without getting aclasscastexcpetion in the generated code?

Sam Harwell sharwell at pixelminegames.com
Mon Aug 3 16:28:41 PDT 2009


1. Derive a class CustomizedErrorNode from your class CustomizedNode.

2. Derive a class CustomizedTreeAdaptor from CommonTreeAdaptor. In it,
override create(Token) to return a CustomizedNode, and override
errorNode(TokenStream,Token,Token,RecognitionException) to return a
CustomizedErrorNode.

Set your parser to use this tree adaptor instead of the default one.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Marwan Ajraoui
Sent: Monday, August 03, 2009 3:47 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] How to extend the CommonTree without getting
aclasscastexcpetion in the generated code?

Hi there;

I did define a customized node, extending a commonTree, defined an
adaptor extending a  CommonTreeAdaptor, for my semantic analysis.
Nevertheless, I'm getting a classCastException, when the parser find
the first sintax error.

The reason is that it can not cast CommonErrorNode to my customized
node, since both extend CommonTree.

I'm interested on reporting all parser errores no just the first one.
What is the better aproach, dealing with this expcetion so it doesn't
stop the execution?

Thx in advance for any help,

Cheers

-- 
Marouane

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