| CARVIEW |
What is the BNF Converter?
The BNF Converter is a compiler construction tool generating a compiler front-end from a Labelled BNF grammar. It is currently generating code for the target languages Haskell, Agda, C, C++, Java, and OCaml, as well as XML representations and Pygment syntax highlighters.
Given a Labelled BNF grammar the tool produces:
- an abstract syntax implementation in the target language,
- a case skeleton for the abstract syntax in the target language,
- a pretty-printer in the target language,
- an Alex, JLex, Ocamllex or Flex lexer generator file ,
- a Happy, CUP, Ocamlyacc, Menhir, ANTLR or Bison parser generator file, and
- a LaTeX file containing a readable specification of the language.
Download
Install via stack from Stackage:
$ stack install BNFC
Install by Cabal from Hackage:
$ cabal install BNFC
Current development version (source repository on GitHub)
$ git clone https://github.com/BNFC/bnfc
News
Find the latest releases at https://github.com/BNFC/bnfc/releases.
BNFC release 2.9.6.1 2025-08-14
BNFC release 2.9.6 2025-08-10
BNFC release 2.9.5 2023-07-26
BNFC release 2.9.4.1 2022-12-17
BNFC release 2.9.4 2022-02-17
BNFC release 2.9.3 2021-10-01
BNFC release 2.9.2 2021-06-13
BNFC release 2.9.1 2021-03-01
BNFC release 2.9.0 2020-12-28
BNFC release 2.8.4 2020-10-10
Resources
Documentation
- User Manual on Read the Docs (HTML)
- Tutorial (a bit dated) (Files)
- LBNF Reference Manual (also as PDF from 2005)
- IPL book
Mailing list
Send questions, bug reports, usage news, etc, to our Google group.
Book
Implementing Programming Languages, a compiler book using BNFC.
A small example
Calc.cf:
| -- Calc.cf: A grammar for arithmetical expressions | ||||||
| EAdd. | Exp | ::= | Exp | "+" | Exp1 | ; |
| ESub. | Exp | ::= | Exp | "-" | Exp1 | ; |
| EMul. | Exp1 | ::= | Exp1 | "*" | Exp2 | ; |
| EDiv. | Exp1 | ::= | Exp1 | "/" | Exp2 | ; |
| EInt. | Exp2 | ::= | Integer | ; | ||
| coercions | Exp | 2 | ; | |||
bnfc --haskell -d -m Calc.cf && make
bnfc --agda -d -m Calc.cf && make
bnfc --c -m Calc.cf && make
bnfc --cpp -m Calc.cf && make
bnfc --java -m Calc.cf && make
bnfc --java-antlr -m Calc.cf && make
bnfc --ocaml -m Calc.cf && make
bnfc --ocaml-menhir -m Calc.cf && make
echo "1 + 2 * 3 - 4 / 5" | Calc/Test
Large examples
A grammar of C with an example C file.
A grammar of Alfa with an example Alfa file. (For more details, see the Alfa home page.)
A grammar of LBNF.
It is at the same time an example LBNF file.
The development version
of this grammar is used in the implementation of the BNF Converter.
A grammar of Java 1.1 developed by Mike Rainey.
Authors
© Andreas Abel, Jonas Almström Duregård, Krasimir Angelov, Jean-Philippe Bernardy, Björn Bringert, Johan Broberg, Kyle Butt, Paul Callaghan, Grégoire Détrez, Markus Forsberg, Ola Frid, Peter Gammie, Thomas Hallgren, Pascal Hof, Simon Huber, Patrik Jansson, Kristofer Johannisson, Antti-Juhani Kaijanaho, Andreas Lööw, Justin Meiners, Kent Mein, Ulf Norell, Gabriele Paganelli, Michael Pellauer, Fabian Ruch, and Aarne Ranta 2002 - 2021.License
Free software under the BSD 3-clause license.
Versions until 2.8.4 released under the
GNU General Public License
(GPL).
