C# Parser Generator

-- New : Added support for out and ref parameters, var definitions, using and lock blocks (12/4/2018).

-- Fixed support for lookahead tokens (3/25/2012).

-- Added support for foreach and properties (5/23/2010).

-- Parsing of repeats ('*'/'+') is now fixed (7/16/2009).

-- Here's a quick self-contained example of simple int lists: Plain JJ :: HTML JJ


Here's the (runnable) Jar and Sources
Jar Library
Java Source


CSJavaCC is a port of JavaCC 4.0 (just the javacc portion, i.e., no JJTree/JJDoc) that generates native C# parsers. It still runs in Java, but is essentially a modification of the most recently available JavaCC source (from here) to output C# code. This saves you (and others) the pain of changing, debugging, or working around other parser generators.

The project was started mainly to support the parsing of generics within DemFGen allowing C# class generation (DemFGenCS) with generic classes + parsing and printing. Other projects don't allow generics or require seperate lexers/structures/parsers. With DemFGenCS and CSJavaCC we get a full class/parser generation system with modular pieces.


(Almost) all of the features of JavaCC. With adaptation for C# specific syntax and features.

Most notably is the support for parsing generic classes. We can write rules like:

      public List<int> parse_int_List():{
         List<int> sup;
         (sup = parse_int_Cons()  { return sup; } | 
          sup = parse_int_Empty() { return sup; } )

      public List<double> parse_double_List():{
         List<double> sup;
         (sup = parse_double_Cons()  { return sup; } | 
          sup = parse_double_Empty() { return sup; } )
To parse different instantiations of the same generic class. This can be tedius, of course, so it's better to get DemFGenCS to do it for you :)

I haven't been able to test all the options, but if you find some settings/grammars that generate poor/incorrect C# classes please let me know. JavaCC seems to be the most widely used parser generator, so offering a simple C# port was (relatively) easy, and worth every penny (well, time is money I guess).


For now you can probably squint at the JavaCC documentation and examples with your C# colored glasses on... but I will post a few simple examples soon.