[antlr-interest] ANTLR3 with C# generates code that does not compile

Arto Viitanen arto.viitanen at pp4.inet.fi
Wed Nov 28 11:12:53 PST 2007


I use Antlr3.Tool.exe to generate C# code from .g files. I started to
use StreamTemplates, and following code
fragment:

-------------
tree grammar ForceTemplate;

options {
    tokenVocab=Force; // Import tokens from Force.g
    ASTLabelType=CommonTree;
    language=CSharp;
    output=template;
}

@header {
  using SymbolTable;
  using Force;
  using System.Globalization;
}
----------

generates following C# code:

---------
// $ANTLR 3.0 C:\\Documents and Settings\\Administrator\\My
Documents\\Visual Studio 2008\\Projects\\Force\\Force\\ForceTemplate.g
2007-11-28 20:48:01

  using SymbolTable;
  using Force;
  using System.Globalization;

using System;
using Antlr.Runtime;
using Antlr.Runtime.Tree;using IList         = System.Collections.IList;
using ArrayList     = System.Collections.ArrayList;
using Stack         = Antlr.Runtime.Collections.StackList;

using IDictionary    = System.Collections.IDictionary;
using Hashtable     = System.Collections.Hashtable;


using Antlr.StringTemplate;
using Antlr.StringTemplate.Language;
using Hashtable = System.Collections.Hashtable;
---------

Problem is, line "using Hashtable = System.Collections.Hashtable;" is
twice, and at least the new Visual Studio 2008
Express Edition does not like it. I guess the problem is, both
"language=CSharp;" and "output=template;" generate
the Hashtable -line.

How can I drop the second line (other than editing the .cs file by hand
:-( )

--
Arto Viitanen


More information about the antlr-interest mailing list