[antlr-interest] Something in my little grammar throws an Unable to cast CommonTree to type GrammarAST

Arturo Hernandez arthernan at hotmail.com
Wed Jun 8 11:09:00 PDT 2011











Thanks Jim,
I looked at " XMLParser.g:29:11" before doing the first post. That pointed me to "returns" in this rule. My only idea is that there is something I need to do at the top of the grammar definition, like set output to AST. Before using "returns". At that point I started to "backtrack" and looked at the rest of the stack.
I am still stuck.
attribute returns [string cl]	: GENERIC_ID ATTR_EQ ATTR_VALUE


> From: jimi at temporal-wave.com
> Date: Wed, 8 Jun 2011 09:01:44 -0700
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Something in my little grammar throws an Unable to cast CommonTree to type GrammarAST
> 
> You are looking too far down the error message list. Fix the error at:
> 
> 
> > error(100): XMLParser.g:29:11: syntax error: antlr:
> 
> 
> First.
> 
> Jim
> 
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Arturo Hernandez
> > Sent: Wednesday, June 08, 2011 7:21 AM
> > To: AN TLR
> > Subject: [antlr-interest] Something in my little grammar throws an
> > Unable to cast CommonTree to type GrammarAST
> >
> >
> > This is a modified version of the xml example from the ANTLR website.
> > Eventually I want to extract data from XHTML.
> > I probably just need a second to spot a simple mistake. I have the
> > reference book, not finished it yet, but did spend plenty of time on
> > this and I am stuck.
> > error(100): XMLParser.g:29:11: syntax error: antlr:
> > NoViableAltException(72@[475:4: ( ( id ( ASSIGN | PLUS_ASSIGN ) ( atom
> > | block ) ) (sub= ebnfSuffix[root_0,false] )? |a= atom (sub2=
> > ebnfSuffix[$a.tree,false] )? | ebnf | FORCED_ACTION | ACTION |p=
> > SEMPRED ( IMPLIES )? |t3= tree_ )])error(100): XMLParser.g:29:11:
> > syntax error: antlr: NoViableAltException(72@[475:4: ( ( id ( ASSIGN |
> > PLUS_ASSIGN ) ( atom | block ) ) (sub= ebnfSuffix[root_0,false] )? |a=
> > atom (sub2= ebnfSuffix[$a.tree,false] )? | ebnf | FORCED_ACTION |
> > ACTION |p= SEMPRED ( IMPLIES )? |t3= tree_ )])error(100):
> > XMLParser.g:0:1: syntax error: assign.types:
> > MismatchedTreeNodeException(0!=32)error(100): XMLParser.g:0:1: syntax
> > error: assign.types: MismatchedTreeNodeException(3!=33)error(100):
> > XMLParser.g:0:1: syntax error: assign.types:
> > MismatchedTreeNodeException(3!=34)error(10):  internal error:
> > XMLParser.g : System.InvalidCastException: Unable to cast object of
> > type 'Antlr.Runtime.Tree.CommonTree' to type 'Antlr
> > 3.Tool.GrammarAST'.
> >
> >
> > parser  grammar XMLParser;options{    language=CSharp3;
> > tokenVocab=XMLLexer;}
> > @header {using System;}@namespace { XMLParserN } document  : element ;
> > element    : startTag         (element        | PCDATA        )*
> > endTag    | emptyElement    ;
> > startTag  	: TAG_START_OPEN GENERIC_ID {Console.Write(@"<" +
> > $GENERIC_ID.text); }	  (attribute {if $attribute.cl!=@"" then
> > Console.Write(@" class=\"" + $attribute.cl + @"\"");}	  	)*
> > TAG_CLOSE {Console.Write(@">" + $GENERIC_ID.text); }
> > attribute returns [string cl]	: GENERIC_ID ATTR_EQ ATTR_VALUE
> > 	{ if ($GENERIC_ID.text==@"class") $cl = $ATTR_VALUE.text else $cl
> > = @""; } ;
> > endTag 	: TAG_END_OPEN GENERIC_ID TAG_CLOSE
> {Console.Write(@"</" +
> > $GENERIC_ID.text + @">"); };
> > emptyElement : TAG_START_OPEN GENERIC_ID  (attribute)* TAG_EMPTY_CLOSE
> > ;
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
> 
> 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