[antlr-interest] Available: a prototype for a console application that will transform Java output from Antlr to C#

Liviu U liviu.u at gmail.com
Tue Mar 20 13:59:32 PDT 2007

Hi guys,

Out of the frustration of not being able to have C# code generation working
with antlr 3 beta and direct from ANTLR
I post here a first try of a tool that translates the xxxLexer.java and
xxxParser.java into cs files.

Usage: antlrJavatoCs.exe fileName

fileName must contain "Lexer" or "Parser" substring. It generates files with
the same name but cs extension, compatible with .NET 2.0.

The application has 2 helper files: Rules.txt and UserRules.txt.
The first contains replacements that can be reduced to regular expressions.
The other is for user extensibility, if any new version appears only
Rules.txt must be overriden.
Hardcoded in the application are following transformation rules that do not
map to a regular expression ( the code must be split in blocks and subblocks

0) A preprocessing phase where comments and strings are identified, to avoid
parsing rules in the wrong place.
1)  labeled loop and break label statements
2)  default case for switch should contain a break statement if there is no
one present and no throw.

I did not try it against bigger grammars, just some smaller ones, but I have
the intention to maintain and extend it if necessary, first because i need
If anyone needs this approach i am open to suggestions.

Liviu Uba
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070320/238dbfd0/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AntlrJavaToCs.rar
Type: application/octet-stream
Size: 9867 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070320/238dbfd0/attachment.obj 

More information about the antlr-interest mailing list