Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Kunle Odutola
kunle UNDERSCORE odutola AT hotmail.com

Micheal Jordan

Contents

Status

As of April 2007, the C# code generator and runtime are compatible with ANTLR v3.0b8. As before, development progress is likely to be sporadic.

...

UPDATE: Some of the other targets apparently have some automated unit tests already. Hopefully this can suggest an approach that is applicable to the C# target too.

Architecture

As with all other targets, the C# code generation and runtime are modelled on the Java version. This means the C# target supports features such as grammar development/prototyping and remote debugging with the AntlrWorks GUI which is very important for ANTLR users. Developing radically different code output is left as an exercise to the reader (wink)

Target Platforms

Microsoft .NET v1.1 and v2.0
Mono

Supported build tools

Microsoft Visual Studio 2003 and 2005
Nant v0.85

Performance

The V3 target generates code that is easily faster than that generated by the V2 target (especially the lexers). We probably won't be able to match the bare-metal performance of the code generated by Jim Idle's C target or Ric Klaren's C++ target but, we expect to be very competitive with the other targets.

Usage

Generating C# code from a grammar

To specify that the ANTLR tool should generate C# code (rather than the default of generating Java code) for a grammar, set the grammar-level option named language to the value CSharp as shown below:

Code Block
grammar MyGrammar;

options
{
    language=CSharp;
}

// rest of grammar follows
....

Specifying the namespace for your recognizer

You can specify that your generated recognizer should be declared within a specific namespace as ahown below. By default all recognizers are generated as top-level types with no enclosing namespace.

Code Block
@lexer::namespace {
	My.Custom.NameSpace.For.Lexers
}

@parser::namespace {
	My.Custom.NameSpace.For.ParsersInclTreeParsers
}

Debugging with ANTLRWorks

The ANTLRWorks tool is written in Java and is only able to debug Java recognizers directly. Nevertheless, you can debug your C# recognizers with ANTLRWorks by using the Remote Debugging feature of ANTLRWorks. In ANTLRWorks, Remote Debugging works by connectiong to a running instance of a debug-instrumented recognizer (generated with the -debug switch to ANTLR) over the network.

...