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

Jones, Larry Larry.Jones at aspentech.com
Fri Aug 8 15:15:11 PDT 2008


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.
 
--

Lawrence Allan Jones
Senior Developer / Technical Advisor
Aspen Technology, Inc.
2500 CityWest Blvd. Suite 1500
Houston, Texas 77042
USA
281-504-3324 (work)
281-504-3395 (fax)
larry.jones at aspentech.com
www.aspentech.com <http://www.aspentech.com/> 

 
 	
 

This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email, and any attachments thereto, is strictly prohibited. If you receive this email in error please immediately notify the sender and permanently delete the original copy and any copy of any e-mail, and any printout thereof.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080808/bda588c5/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 2078 bytes
Desc: email_2_03.gif
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080808/bda588c5/attachment.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 200 bytes
Desc: email_2_04.gif
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080808/bda588c5/attachment-0001.gif 


More information about the antlr-interest mailing list