Versions Compared

Key

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

...

Microsoft Visual Studio 2003, 2005 and 20052008
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 targetsto be very competitive with the other targets.

Source Code and Binaries

For ANTLR 3.0.x there is no C# target source code available. ANTLR 3.1.x has the files under the runtime/CSharp directory. Binaries are currently (especially for betas) included in the bin directory, but will be moved later to the ANTLR download page as an extra item. Available are the files in the official releases, in daily builds and for the head of the repo on the FishEye site (not reliable) or ask Terence Parr for a Perforce account.

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.

...

For an example grammar named MyGrammar, the following table list the files that would be generated by ANTLR 3.1+ 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

Under ANLTR 3.0.x:
MyGrammarLexer.cs

Panel
bgColor#FFFFFF
titleMyGrammar.g
borderStylenone
Code Block
parser grammar MyGrammar;

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

MyGrammar.cs

Under ANLTR 3.0.x:
MyGrammarParser.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

...

In addition to the the use of the @members block to define class members inline within the grammar file, the CSharp2 target also supports the use of the C# v2 partial classes feature. This has the additional advantage that you can use your favourite editor for C# to define class members since ANTLRworks doesn't support syntax highlighting for target languages.

Also using a partial class allows to define the same using alias-directives with different classes than the ones defined in the generated code, as aliases are confined to the current file. If you use this feature, beware to point this difference out!

Syntactic differences compared to grammars and the Java target

...

  1. Generate a debuggable version of your recognizer by specifying the -debug option to ANTLR
  2. Create a driver program that creates your recognizer and runs some test input through it (see the examples-v3 archive for sample driver programs)
  3. Compile your driver and recognizer to produce your executable file(s)
  4. Execute your driver program (it will launch your recognizer and appear to hang - it's just waiting for ANTLRWorks to connect)
  5. Start ANTLRWorks (or switch to it if it is already running) and click the menu Debugger|Debug Remote...
  6. Click Connect to accept the default host and port values (localhost and 49153 respectively)
  7. ANTLRWorks should now start debugging your recognizer!
    Warning
    titleWarning

    ANTLRWorks remote debugging has only been tested for C# Parsers. TreeParsers and Lexers should work but...

    Note
    titleANTLRWorks and ANTLR version compatibility

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

...