[antlr-interest] Compile Error When Rewriting Token Buffer in C#

Johannes Luber jaluber at gmx.de
Fri Aug 8 15:34:35 PDT 2008


Jones, Larry schrieb:
> I was attempting to rewrite the token buffer in-place using C#
>  
> My grammar is:
>  
> grammar Rewrite;
>  
> 
> options {
>   language=CSharp2;
>   output=template;
>   rewrite=true;
> }
>  
> // Match 'call foo;'
> r  : 'call' ID ';' ->
>    template(call={ $text }) "'<call>"
>   ;
> ID : 'a'..'z'+ ;
> WS : (' ' | '\t' | '\r' | '\n')+ { $channel=HIDDEN; } ;
> My driver program is:
>  
> using System;
>  
> using Antlr.Runtime;
>  
> namespace Rewrite {
>  class Program {
>   static void Main(string[] args) {
>    ANTLRStringStream input = new ANTLRReaderStream(Console.In);
>    RewriteLexer scanner = new RewriteLexer(input);
>    TokenRewriteStream tokens = new TokenRewriteStream(scanner);
>     RewriteParser parser = new RewriteParser(tokens);
>     parser.r();
>     Console.WriteLine("{0}", tokens.ToString());
>   }
>  }
> }
> When I compile the program, the compiler generates the following errors:
>  
> c:\home\jonesl\professional\projects\scratch-antlr\rewrite\RewriteParser.cs(113,45): 
> error CS1502: The best overloaded method match for 
> 'Antlr.Runtime.ITokenStream.ToString(int, int)' has some invalid arguments
> c:\home\jonesl\professional\projects\scratch-antlr\rewrite\RewriteParser.cs(113,60): 
> error CS1503: Argument '1': cannot convert from 'object' to 'int'
> c:\home\jonesl\professional\projects\scratch-antlr\rewrite\RewriteParser.cs(113,73): 
> error CS1503: Argument '2': cannot convert from 'Antlr.Runtime.IToken' 
> to 'int'
> I verified that this behavior occurs in the C# translation of the 
> example from _The Definitive ANTLR Reference_ 
> (templates/rewriter/1pass/CMinus); however, the error does NOT occur in 
> the simpler example grammars/rewrite/T.g. The only difference I could 
> see between the two is that the latter uses a "constant" template; 
> whereas the former actually uses template parameters.
>  
> What am I doing wrong?
>  
> Thanks.

Possibly it is a bug. Please send me a mail with both mentioned grammars 
attached, along with test input, so I can verify the cause.

Johannes


More information about the antlr-interest mailing list