views:

317

answers:

3

I'm working on a new language and while writting the grammar I'd like to be able to test the grammar for completeness, conflicts and similar. I'm not really concern about the underlaying parser generator (but one for .NET would be preferrable)

So feature list in short would be:

  • text editor build functionality
  • syntax/sematics error reporting
  • conflicts reporting
  • grammar test functionality (i.e. window for writting code in the intended grammar to verify the correctness of the grammar definition)

A CodePlex project called Irony does have something simlar to what I'm asking for but does not support writing the grammar as BNF which is required.

+4  A: 

I would recommend ANTLR as a parser generator. It's very feature complete and supports C# as well as a host of other target languages.

For IDEs, there's a plugin for Eclipse called ANTLR IDE and a standalone IDE called ANTLRWorks, both of which work well.

Note, however, that ANTLR uses an LL(*) algorithm instead of a LR(k) algorithm. Still, it's very nice and ANTLRWorks can do most of the necessary left factoring.

Kaleb Pederson
+2  A: 

When "working on a new language" and trying to get a reference BNF right, you probably don't want to bias your reference grammar towards any particular parser generator. One of the troubles with writing a test grammar for Bison (LALR(1)) or ANTLR(LL*) is you do just exactly that. You also don't want to get hung up in "how do I code the BNF rules in such a way as make it actually parse" presumably because you are interested in working on the grammar, not working on the parser generator.

So I'd recommend using a full context free parser generator. This will let you write the grammar in the most natural form with the least effort. This might mean giving up "text editor", "editor test window", ... but in my experience (check my stack overflow bio) using a context free parser generator overwhelms those niceties completely. Edit-save-parse just doesn't take a lot of effort.

I understand Bison has a GLR option which would provide context-free parser generation, and is open source, and so it might do for just the testing out the grammar.

The DMS Software Reengineering Toolkit is commercial and also provides a GLR parser, which has been used to implement some 30+ full langauges including C, C++, and COBOL in a number of dialects as well as more modern languages such as Python, Ruby, PHP, ....

The difference between DMS and Bison is that DMS is designed to support all aspects of the construction of a full language analyzer/translator (Unicode lexing, GLR parsing with error reporting and recovery, automatic tree construction, symbol table construction, control and data flow analysis, transformations, prettyprinting, ...). If you wanted to seriously evaluate your "new langauge", you'll eventually need to do all this stuff, and Bison is only a tiny step along this road. DMS will carry you the whole way.

Ira Baxter
A very informative answer thank you. I'm end the end aiming for a specific parser generator (fsyacc) part of the task I've set before me self is to learn F# and since I had to write a compiler I thought that would be the perfect project to learn a functional language (though f# strictly speaking is multi-paradigm not just functional), So I actually look forward to doing the stuff DMS would otherwise have supplied. fsyacc ius LALR(1) so the ANTLRworks is only of little help in the end but autocompletion and such still makes it faster than a simple text editor
Rune FS
A: 

Have a look at BNFC, which can generate working code and the makefile, from labled BNF, for a number of target languages like: Haskell, OCaml, C, C++, and Java. You get a pretty printer, abstract syntax checker/printer, skeleton code for your own compiler or interpreter, and postcript language documentation.

Tom Young