[antlr-interest] Generated code causes InvalidCastException
Adam Connelly
adam.rpconnelly at googlemail.com
Sat Dec 29 23:34:35 PST 2007
Hi,
I'm trying to write a simple language to use for code generation. So far
I've got a working recogniser, and am working on a tree parser. My parser
grammar simply builds an AST and doesn't have any actions - I was going to
do the work in the tree parser. The problem I'm having is that I have a
rule as follows:
project: ^(PROJECT ID template+) { Console.WriteLine("project " +
$ID.text + " {"); }
;
PROJECT and ID are tokens from my parser grammar. The grammar generates
fine, but when I try to use the tree parser to parse an AST created by my
parser, I get an InvalidCastException which says that it can't cast a
CommonTree to a CommonToken. The offending line is in project() and is as
follows:
ID1 = (CommonToken)input.LT(1);
I'm using the runtime from the Antlr 3.0.1 Source Distribution and the C#
target, and I created and generated both my parsers using ANTLRWorks 1.1.5.
Any help would be appreciated.
Cheers,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071230/1647a28e/attachment.html
More information about the antlr-interest
mailing list