BNF syntax

From Nemerle Homepage

EBNF

We use an extension for mediawiki to render EBNF grammars. It uses <bnf> tag. For example

<bnf>
palin = '0' palin '0' | '1' palin '1'
</bnf>

gives:

<palin> ::=
    '0' <palin> '0'
|   '1' <palin> '1'


Terminals are enclosed in ' '. To put real single quote please use '&#39;'. Nonterminals don't use any special markers -- anything that isn't a terminal, or a special symbol is nonterminal.

Special symbols are:

  • = used to start a rule
  • | used to separate options of given rule
  • []{} used for optional and repeated syntax elements

Namespaces

To allow splitting grammar definition over multiple files the bnf extension support namespaces. If you write non terminal like Namespace:something, then it will link to /Namespace#something, so Namespace should be a wiki page with grammar entry something. Namespace is not displayed.

To save you typing, if you use at least once Foo:bar (within a given <bnf> entry) as non-terminal, all occurrences of bar will be replaced with Foo:bar.

For example:

<bnf>
foo = '-' [ bar ]
qux = '+' [ Non_existent_wiki_page:bar ]
</bnf>

gives:

<foo> ::=
    '-' { <bar> }
<qux> ::=
    '+' [ <bar> ]


Contact

If you would like to access bnf source code, please contact User:Malekith.

That's all folks!

remember
You are very welcome to contribute to the documentation here!