[antlr-interest] Problem with rewrite rule: DebugTokenStream cannot be cast to TokenRewriteStream

Martin Brousseau Martin.Brousseau at nstein.com
Tue Jan 13 08:07:51 PST 2009


Hi!

I am testing the rewriting sample from “The Definitive ANTLR Reference” (page 125).

With the last version of ANTLRworks used in debugging mode, I get the following stack trace as output:

 

_____________________________________________________________________

Exception in thread "main" java.lang.ClassCastException: org.antlr.runtime.debug.DebugTokenStream cannot be cast to org.antlr.runtime.TokenRewriteStream

      at TParser.type(TParser.java:198)

      at TParser.decl(TParser.java:110)

      at __Test__.main(__Test__.java:14)

______________________________________________________________________

 

Any idea about the cause?

Any help would be greatly appreciated.

Thanks.

 

More info:

I get exactly the same when I try to parse the grammar in a Java main with parser.prog();

 

…

// Create a stream of tokens fed by the lexer

CommonTokenStream tokens = new CommonTokenStream(lexer);

// Create a parser that feeds off the token stream

FactorParser parser = new FactorParser(tokens); // create parser

      

//To use inline rewrite rules

parser.prog();

…

 

 

The grammar used is the following.

 

grammar T;

options {output=template; rewrite=true;}

decl: type ID ';' ; // no translation here

type: 'int' -> template() "Integer" // translate int to Integer

| ID // leave this alone

;

 

ID    :     ('a'..'z'|'A'..'Z')+ ;

WS    :     (' '|'\t'|'\n'|'\r')+ {skip();} ; 

 

 

_______________________________________________

 

Martin Brousseau
Product Designer - Semantic Intelligence
T. 514.908.5406 / 1.877.nstein1 x222
F. 514.908.5407
M. 514.513.7118
W. www.nstein.com <http://www.nstein.com/> 
Powering Digital Publishing

This message (including any attachments) may contain confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message and contact the sender.
Ce message (incluant tout document joint) peut contenir de l’information confidentielle destinée à un individu en particulier dans un but précis; il est protégé par la loi. Si vous n’êtes pas le destinataire de ce message, veuillez le détruire et en aviser son destinateur.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090113/0fd33a21/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 2094 bytes
Desc: image001.gif
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090113/0fd33a21/attachment.gif 


More information about the antlr-interest mailing list