Skip to content
GNU Emacs major mode for editing BNF grammars.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.

BNF Mode for GNU Emacs

A GNU Emacs major mode for editing BNF grammars.

“Precise language is not the problem. Clear language is the problem.”

Richard Feynman

Currently provides basic syntax and font-locking for BNF files. BNF notation is supported exactly form as it was first announced in the ALGOL 60 report. EBNF and ABNF are not supported but in my plans for the near future.

When developing this mode, the following documents were taken into account:


  • Basic syntax definition
  • Syntax highlighting


Known to work with GNU Emacs 24.3 and later. BNF Mode may work with older versions of Emacs, or with other flavors of Emacs (e.g. XEmacs) but this is not guaranteed. Bug reports for problems related to using BNF Mode with older versions of Emacs will most like not be addressed.

The master of all the material is the Git repository at .

NOTE: The master branch will always contain the latest unstable version. If you wish to check older versions or formal, tagged release, please switch to the relevant tag.


The best way of installing this major mode, at least for GNU Emacs 24, is to use the packaging system. Add MELPA or MELPA Stable to the list of repositories to access this mode. For those who want only formal, tagged releases use MELPA Stable:

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "") t)

For those who want rolling releases as they happen use MELPA:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "") t)

and then use M-x package-refresh-contents and M-x package-list-packages to get to the package listing and install bnf-mode from there. MELPA tracks this Git repository and updates relatively soon after each commit or formal release. For more detail on setting up see MELPA Getting Started.

You can install bnf-mode manually by adding following to your init file:

(unless (package-installed-p 'bnf-mode)
    (package-install 'bnf-mode))

Using Cask

Add following to your Cask file:

(source melpa)

(depends-on "bnf-mode")

Using use-package

Add following to your init file:

(use-package bnf-mode
  :ensure t
  :mode "\\.bnf\\'")


If you use el-get, just create a recipe file bnf.rcp:

(:name bnf-mode
       :website ""
       :description "BNF Mode: A major mode for editing BNF grammars"
       :type github
       :pkgname "sergeyklay/bnf-mode")

and add it to a directory present in el-get-recipe-path. Then, use M-x el-get-install <RET> bnf-mode or add:

(el-get-bundle bnf-mode)

to your init file.

Manual Install

  1. Download bnf-mode.el
  2. Put the file in your Elisp common folder like $HOME/.emacs.d/lisp/
  3. Then you can include like this:
    (add-to-list 'load-path
                 (expand-file-name "lisp" user-emacs-directory))
  4. Add either of the two following lines to your initialization file. The first only loads BNF Mode when necessary, the 2nd always during startup of GNU Emacs.
    (autoload 'bnf-mode "bnf-mode" nil t)
    ;; OR
    (require 'bnf-mode)
  5. Optionally byte compile bnf-mode.el for faster startup: M-x byte-compile


Interactive Commands

Command (For the M-x prompt.)Description
bnf-modeSwitches to BNF Mode.

Any file that matches the glob *.bnf is automatically opened in bnf-mode.


Feel free to ask question or make suggestions in our issue tracker .


To see what has changed in recent versions of BNF Mode, see the .

External Links


BNF Mode is open source software licensed under the GNU General Public Licence version 3 .

You can’t perform that action at this time.