views:

470

answers:

4

I'm looking for anyone with some experience using a parser generator that is either design for or has C# available as a target language.

What seems to be the standard?

Some of the options I have found:

  • ANTLR - Seems widely used, yet people often complain it is "over complicated" or "strange".
  • Coco/R - Another common one I have run into in my search. I don't know much about Coco.
  • TinyPG - CodeProject hosted Parser Generator. Not sure on the maturity of this one, but maybe others here have used it?
  • Others?

I'm looking to go with the most stable, widely used option for this project. Does anyone have any suggestions in terms of parser-generators with C# as a target language?

+3  A: 

Everything I've done or used that needed a parser used good old ANTLR.
Its slightly over complicated, but it doesn't leave you wanting.

DevelopingChris
+1  A: 

I don't know about widest, but I'm very fond of ANTLR and I've had good results.

Promit
+2  A: 

I've had some success with Irony, which lets you define your grammars in C#:

var program = new NonTerminal("program");
var cameraSize = new NonTerminal("cameraSize");
var cameraPosition = new NonTerminal("cameraPosition");
var commandList = new NonTerminal("commandList");
var command = new NonTerminal("command");
var direction = new NonTerminal("direction");
var number = new NumberLiteral("number");

// <Program> ::= <CameraSize> <CameraPosition> <CommandList>
program.Rule = cameraSize + cameraPosition + commandList;

// <CameraSize> ::= "set" "camera" "size" ":" <number> "by" <number> "pixels" "."
cameraSize.Rule = Symbol("set") + "camera" + "size" + ":" + 
                  number + "by" + number + "pixels" + ".";

// <CameraPosition> ::= "set" "camera" "position" ":" <number> "," <number> "."
cameraPosition.Rule = Symbol("set") + "camera" + "position" + 
                      ":" + number + "," + number + ".";

// <CommandList> ::= <Command>+
commandList.Rule = MakePlusRule(commandList, null, command);

// <Command> ::= "move" <number> "pixels" <Direction> "."
command.Rule = Symbol("move") + number + "pixels" + direction + ".";

// <Direction> ::= "up" | "down" | "left" | "right"
direction.Rule = Symbol("up") | "down" | "left" | "right";
Erik Forbes
+1  A: 

I've used Coco/R to create a parser for JOVIAL and it worked fine. I found learning Coco quicker than ANTLR.