...
Secondly, a certain bug fix requires a C# 2 feature or the change of templates for each time it appears - and this has to be done by the user. The details of doing so are found in a section below #Known Issues. Thirdly, because the backwards compatibility sucks majorly, I want to deprecate it without forcing people to abandon .NET 1.1 compatibility immediately. The easiest way of doing so was to introduce a new target which allows me to change even the code generation templates. As working on further enhancements will at least break binary compatibility, most of the changes will be done for ANTLR v3.2. During the life-time of ANTLR v3.1, the public API of the C# target will be frozen. If you wish to future-proof your grammar, change them to the CSharp2
target. It is planned to remove the CSharp target for ANTLR v3.3.
...
Code Block |
---|
tree grammar MyGrammar; options { language=CSharp2; } @namespace { My.Custom.NameSpace.For.TreeParser } // rest of grammar follows .... |
Syntactic differences
...
compared to grammars and the Java target
ANTLR grammars refer often to attributes of the tokens and rules. These attributes do not change because their use in a grammar targeted for C#. But when accessing those attributes from driver programs and other support files, the names used in the ANTLR grammar won't work. The C# target uses language features like properties as the official coding guidelines which cause are different from the general documentation to differ from what can be really used for the C# target. The rule of thumb is, that the attributes of rules are accessed with a capital letter at the beginning. Nonetheless there are exceptions so the goal is to have a comprehensive overview. If there are any errors, please fix them or send an email to the mailing list.
...
.The following table details the status quo for ANTLR v3.1.
ANTLR | C# Syntax | Notes | |
---|---|---|---|
text | Text |
| |
start | Start | ||
stop | Stop | Untested | |
tree | Tree | ||
st | ST |
| |
type | Type | Untested | |
line | Line Untested | ||
pos | Pos | Untested CharPositionInLine | |
channel | Channel | Untested | |
$x.size() | $x.Count | size() is no grammar attribute, but still regularly used |
Known Issues
Another problem, you may encounter while using the CSharp
target, is that value types are initialized with null (happens e.g. while using labels). The cause lies in the following definition of CSharp.stg:
...