[antlr-interest] Type cast exception in CSharp

Micheal J open.zone at virgin.net
Mon Jul 18 09:35:11 PDT 2005


> Hi,
> 
> The CSharp generator produces the following lines of code:
> 
> ...
> AST tmp1_AST = null;
> tmp1_AST = astFactory.create(LT(1)); 
> astFactory.makeASTRoot(currentAST, tmp1_AST); ...
> 
> My parser declaration have the following form:
> 
> ...
> class CommonParser extends Parser;
> options {
> 	k = 2;
> 	importVocab = CommonAgilePLC;
> 	classHeaderPrefix = "internal";
> 	buildAST = true;
> }
> ...
> 
> The AST factory creator throws the exception 
> "System.InvalidCastException". 
> Its factory operation seems to expect a parameter of type 
> IToken while the 
> CommonToken object returned by LT(1) does not implement this 
> interface.
> 
> Is here any Token subclass that implement IToken available in 
> the ANTLR's 
> API or do I miss some option in the parser declaration?

CommonToken does implement IToken afaik. What version are you using?. It
should be 2.7.5 and you should ensure that you've generated all the
lexer/parser/treeparser code for your project using it *and* you are using
it's own runtime files.

Cheers,

Micheal



More information about the antlr-interest mailing list