[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 21:57:18 PDT 2011
Came home and tried again with a clearer head.
And this time I found my missing ';' plus many other syntax errors ;)
The build action for VS2010 MSBuild works great too!!! All compiled and executed perfectly!!
parser grammar XMLParser;options{ language=CSharp3; tokenVocab=XMLLexer;}
@header {using System;}@namespace { XMLParserN }
public document : element ;
element : startTag (element | PCDATA )* endTag | emptyElement ;
startTag : TAG_START_OPEN GENERIC_ID {Console.Write(@"<" + $GENERIC_ID.text); } (attribute )* TAG_CLOSE {Console.Write(@">"); } ;
attribute : GENERIC_ID ATTR_EQ ATTR_VALUE { if ($GENERIC_ID.text=="class") Console.Write(@" class=" + $ATTR_VALUE.text); } ;
endTag : TAG_END_OPEN GENERIC_ID TAG_CLOSE {Console.WriteLine(@"</" + $GENERIC_ID.text + @">"); } ;
emptyElement : TAG_START_OPEN GENERIC_ID (attribute)* TAG_EMPTY_CLOSE ;
> From: arthernan at hotmail.com
> To: antlr-interest at antlr.org
> Date: Wed, 8 Jun 2011 13:09:00 -0500
> Subject: Re: [antlr-interest] Something in my little grammar throws an Unable to cast CommonTree to type GrammarAST
>
>
> 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
>
>
More information about the antlr-interest
mailing list