...
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.
|
|
| |||||||||||||||||||||
|
| Under ANLTR 3.0.x: | |||||||||||||||||||||
|
| Under ANLTR 3.0.x: | |||||||||||||||||||||
|
|
|
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
...
- Generate a debuggable version of your recognizer by specifying the
-debug
option to ANTLR - Create a driver program that creates your recognizer and runs some test input through it (see the examples-v3 archive for sample driver programs)
- Compile your driver and recognizer to produce your executable file(s)
- Execute your driver program (it will launch your recognizer and appear to hang - it's just waiting for ANTLRWorks to connect)
- Start ANTLRWorks (or switch to it if it is already running) and click the menu Debugger|Debug Remote...
- Click Connect to accept the default host and port values (
localhost
and49153
respectively) - ANTLRWorks should now start debugging your recognizer!
Warning title Warning ANTLRWorks remote debugging has only been tested for C# Parsers. TreeParsers and Lexers should work but...
Note title ANTLRWorks 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.
...