Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any BNF IDE with test features

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.

like image 541
Rune FS Avatar asked Jan 11 '10 22:01

Rune FS


2 Answers

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.

like image 199
Kaleb Pederson Avatar answered Oct 06 '22 17:10

Kaleb Pederson


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.

Our 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.

like image 42
Ira Baxter Avatar answered Oct 06 '22 18:10

Ira Baxter