Exception thrown when using sablecc3.2-generated parser - 'java.lang.ClassCastException: java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn'

View: New views
3 Messages — Rating Filter:   Alert me  

Exception thrown when using sablecc3.2-generated parser - 'java.lang.ClassCastException: java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn'

by Andrew Sweet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi all,

 

I’m receiving a very odd error when running a parser created with sablecc3.2. The exception thrown is 'java.lang.ClassCastException: java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn' and is thrown from the following (generated) code in Parser.java:

 

    @SuppressWarnings("unchecked")

    ArrayList new2() /* reduce ACommaLabeled */

    {

        @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList();

 

        @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop();

        PAbsyn pabsynNode1;

        pabsynNode1 = (PAbsyn)nodeArrayList1.get(0); // ß THIS LINE

            nodeList.add(pabsynNode1);

        return nodeList;

    }

 

Where ‘PAbsyn’ is the ‘root’ node of by abstract syntax tree. I assume this error is to do with the way lists are handed in CST -> AST transformation and that my transformation specification is somehow invalid, but sablecc is letting it go through anyway. I’ve attempted to run sablecc3.1 over it and get a similar error with ‘TypedLinkedList’ instead. I’m at a loss as to the source of the problem.

 

I’ve attached my grammar file (it is quite extensive, I’m sorry). If anyone can help, you’ll have my eternal gratitude.

 

 

Thank you in advance,

Andrew Sweet


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Exception thrown when using sablecc3.2-generated parser - 'java.lang.ClassCastException: java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn'

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi Andrew,

Could you send the grammar? You forgot to attach it.

Etienne

Andrew Sweet wrote:

...

I’ve attached my grammar file (it is quite extensive, I’m sorry). If anyone can help, you’ll have my eternal gratitude.


-- 
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org
SableVM:                                            http://sablevm.org


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

signature.asc (265 bytes) Download Attachment

RE: Exception thrown when using sablecc3.2-generated parser- 'java.lang.ClassCastException:java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn'

by Andrew Sweet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Etienne,

 

My apologies. After a late night of hacking, I found the error. The part of the grammar causing the error was:

 

comma {-> absyn} = enlist1_commaitem_kw_comma {-> enlist1_commaitem_kw_comma.absyn};

 

enlist1_commaitem_kw_comma {-> absyn+} = …;

 

 

Hence, when the parser went to get the first parameters of the comma production, it was expecting a PAbsyn node but instead found a LinkedList. Adding a wrapper around enlist1_..., packing the list into a PAbsyn, solved the problem. However, this seems like a sablecc3.2 bug to me, since in my way of considering the problem, there’s a type mismatch in the production (given by the abstract syntax tree type annotations) but sablecc doesn’t pick up on it.

 

If you want any help reproducing the problem in the case you consider it to be a bug, then please contact me.

 

Thanks for your help and congratulations on producing such a well-thought-out, usable and productive tool!

 

Andrew

 


From: sablecc-discussion-bounces+aes53=cam.ac.uk@... [mailto:sablecc-discussion-bounces+aes53=cam.ac.uk@...] On Behalf Of Etienne M. Gagnon
Sent: 19 January 2008 13:36
To: Discussion mailing list for the SableCC project.
Subject: Re: Exception thrown when using sablecc3.2-generated parser- 'java.lang.ClassCastException:java.util.LinkedList cannot be cast to aldorlite.node.PAbsyn'

 

Hi Andrew,

Could you send the grammar? You forgot to attach it.

Etienne

Andrew Sweet wrote:

...

I’ve attached my grammar file (it is quite extensive, I’m sorry). If anyone can help, you’ll have my eternal gratitude.



-- 
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org
SableVM:                                            http://sablevm.org

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion
LightInTheBox - Buy quality products at wholesale price