Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added list of files generated

...

...

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

...

This section is NOT a tutorial on how to use either C# or ANTLR v3.x. It assumes that you are familiar with the concepts involved in developing ANTLR v3.x grammars and, in building and using C# programs and assemblies.

Specify that C# code should be generated for 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 CSharp2 (or CSharp for ANTLR version v3.0.x) as shown below:

Code Block
grammar MyGrammar;

options
{
    language=CSharp2;
}

// rest of grammar follows
....

For the example grammar named MyGrammar above, the grammar file would typically be named MyGrammar.g. The grammar filename (excluding the extension) must match the grammar name as declared with the grammar directive in the file.

Note
titleANTLR v3.0.x users

For If you are still using ANTLR version v3.0.x , please use the CSharp target as the then you can only specify CSharp as your target. The CSharp2 target is only supported for by ANTLR v3.1.x and later.

...

List of generated C# source files

For an example grammar named MyGrammar, the following table list the files that would be generated by ANTLR using the CSharp2 (and CSharp) target.

Panel
bgColor#FFFFFF
titleMyGrammar.g
borderStylenone
Code Block

grammar MyGrammar;

options
{
    language=CSharp2;
}
// rest of grammar follows
....
Panel
bgColor#FFFFFF
borderStylenone

MyGrammarLexer.cs
MyGrammarParser.cs

Panel
bgColor#FFFFFF
titleMyGrammar.g
borderStylenone
Code Block

lexer grammar MyGrammar;

options
{
    language=CSharp2;
}
// rest of grammar follows
....
Panel
bgColor#FFFFFF
borderStylenone

MyGrammar.cs

Panel
bgColor#FFFFFF
titleMyGrammar.g
borderStylenone
Code Block

parser grammar MyGrammar;

options
{
    language=CSharp2;
}
// rest of grammar follows
....
Panel
bgColor#FFFFFF
borderStylenone

MyGrammar.cs

Panel
bgColor#FFFFFF
titleMyGrammar.g
borderStylenone
Code Block

tree grammar MyGrammar;

options
{
    language=CSharp2;
}
// rest of grammar follows
....
Panel
bgColor#FFFFFF
borderStylenone

MyGrammar.cs

Specify a C# namespace for your recognizer

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

...

Note
titleANTLRWorks and ANTLR version compatibility

ANTLRWorks v1.1.x is required for only compatible with recognizers created with ANTLR v3.0.x only. For recognizers created with ANTLR v3.1.x, you will need ANTLRWorks v1.2.x.

...