views:

627

answers:

5

I want to describe a complex script and possibly programming language. i was thinking of describing it in Backus-Naur Form before doing anything (excluding dummy/sample script code)

Is there another form to describe a language then Backus-Naur Form? What alternatives should i consider?

+1  A: 

BNF is a good start, there are several parser generators that can use it as input. Boost.Spirit is a good example, if you're planning to use C++.

soulmerge
+4  A: 

It depends on how formal you wish to describe the language. Backus-Naur Form is meant to describe context-free grammars. So if you want to describe a context-free grammar Backus-Naur Form is probably the way to go as it is the most widespread known form of describing these.

However, if you wish to describe your semantics or more complex grammars you'll need to use other means. If you want to describe your semantics as well you need to choose between small-step or big-step semantics, based on language characteristics such as use of recursion.

Note that if your grammar cant be expressed using a context-free grammar then BNF wont be sufficient to express your language at all and you might have to consider describing your language in a context-sensitive grammar.

Per Stilling
+4  A: 

The obvious alternative would be extended Backus-Naur form, however there are few others that can be used, and I found a couple of links with some quick searching:

Augmented BNF

Wirth syntax notation

Van Wijngaarden grammar

Personally I would stick with BNF / EBNF due to the prevalence of information and tools which use it in some form. Tools like bison or yacc can help with the generation of a parser from such a grammar and make it quite trivial to produce an interpreter.

jheriko
A: 

You may want to look at "M" from Microsoft. This is a language/syntax which allows you to describe another language (as does BNF). This is being used as the basis for developing your own domain driven language.

"M" from Microsoft

Jon Simpson
A: 

You could also consider using ANTLR, which uses a syntax/formal language close to BNF. It'll help you with the construction of a interpreter/compiler.

David Klein