English 中文(简体)
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.

最佳回答

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.

问题回答

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.

May be you ll find this tool useful: Gold Parser Builder

Unfortunally it is windows only.

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.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签