views:

1452

answers:

6

I am trying to write a grammar in EBNF (barring a really good reason, it has to be EBNF) and am looking for a couple of utilities for it - if there's a GUI interface that can make one, that would be great, but the thing I'm looking for most is something that can check the grammar, for instance to see if it is LALR(n), and if so, what the value of n is. Do such utilities exist? Are there any other useful grammar-writing tools I should know about (I'm not looking for parser generators).

A: 

I use notepad(+) for EBNF projects. Normally that is not a problem. Besides that I use my own program to convert the EBNF to xhtml for easy reading.

Gamecat
+1  A: 

To check whether a grammar allows a certain parser algorithm, just put it into the parser generator. In case of LALR(1), pass the grammar to YACC to see whether it detects conflicts.

Martin v. Löwis
A: 

ANTLR is a GUI parser generator in Java that has extensive capabilities for grammar analysis and factoring. Check the FAQ; it might support what you're looking for.

Steven Dee
+2  A: 

Taking Steven Dee's suggestion one step further, you might want to check out ANTLRWorks, which is an interactive GUI development tool for ANTLR grammars.

joel.neely
+2  A: 

Use TinyPG! Its an amazing all-in-one compiler compiler with a lightweight GUI, where you build your parser with RegEx, EBNF, and write C#/VB code to do something with the parse tree!

Here's a short and informative summary that I did earlier, which also links you to the downloads.


My understandings of TinyPG:

TinyPG allows you to write & develop:

It has an in-built IDE, Windows Only (created in C#.NET, open source).

It allows you to try out & preview Regular Expressions using the inbuilt RegEx tool. RegEx syntax is supported in .NET which means that even your outputted parser code uses .NET's Regular Expressions.

You write EBNF to describe the language of your choice (Here are some freely available BNF Grammers that describe modern programming languages (C, Java, JavaScript, C#, VB.NET, SQL-89)

Using TinyPG, your RegEx along with your EBNF outputs a parse-tree (see this diagram).

Now what do you do with the parse-tree? You write C#/VB code (within TinyPG, per BNF grammer rule) for your Compiler/Interpreter/Translator. (inside TinyPG, open the "simple expression2.tpg" file within the provided Samples to see a demo of a calculator 'compiler')

TinyPG allows you to Compile and Test your tokenizer+parser+complier, within the TinyPG IDE, and it finally outputs the parser source code in C#.NET or VB.NET (your choice), with ready-to-use classes.

An excellent All-in-one Compiler Compiler for the masses. Enjoy!

PS: Correct me if I'm wrong on any of this.

Jenko
great answer, cheers.
dr. evil
A: 

TinyPG also lets you quickly Compile (test) and debug your EBNF grammer and RegEx expressions.

Jenko