The Backus-Naur Form: A Discrete Pillar of Computer Programming

The Backus-Naur Form: A Discrete Pillar of Computer Programming

· updated on 8 August 2026
#bnf #programming #syntax #computerscience #formalgrammar

Discover the Backus-Naur Form (BNF), an essential tool for defining the syntax of computer languages and their formal structure.

The Backus-Naur Form: A Language for Describing Languages

In the world of computing, how programming languages are structured and understood is fundamental. To precisely define the syntax of these languages, a powerful and elegant tool emerged: the Backus-Naur Form, more commonly known as BNF.

BNF is a meta-syntactic notation, meaning it's a language used to describe another language. It allows for an unambiguous specification of the grammatical structure of computer languages, mathematical expressions, or any other system based on formal rules. Originally developed by John Backus and Peter Naur to describe the ALGOL 60 programming language, BNF has become a de facto standard for syntax definition in many areas of computer science.

Key Components of BNF

BNF relies on a few simple yet powerful elements:

  • Terminals: These are the basic symbols of the language that cannot be further broken down. In the context of a programming language, these could be keywords (like "if", "while"), operators (+, -, *), parentheses, semicolons, etc.
  • Non-terminals: These are symbols that represent more complex grammatical constructs and can be replaced by a sequence of terminals and/or other non-terminals. They are typically represented between angle brackets, for example, <expression> or <statement>.
  • Production rules: These are the definitions that specify how non-terminals can be replaced. A typical production rule is written in the form: <non-terminal> ::= <sequence of symbols>. The symbol ::= means "can be defined as". The vertical bar | is used to indicate alternatives.

A Simplified Example

To illustrate, let's consider a very simplified definition of an arithmetic expression with addition and multiplication:

<expression> ::= <expression> + <term> | <term> <term> ::= <term> * <factor> | <factor> <factor> ::= ( <expression> ) | number

In this example:

  • <expression>, <term>, and <factor> are non-terminals.
  • +, *, (, ), and number (which represents a sequence of digits) are terminals.

These rules indicate that an expression can be an expression followed by a plus and a term, or simply a term. Similarly, a term can be a term multiplied by a factor, or a factor. A factor can be an expression in parentheses, or a number.

The Impact of BNF

BNF has had a considerable impact on the development of computer science. It has enabled:

  • Clear and rigorous syntax definition: This facilitates the understanding and implementation of languages.
  • The design of parsers: Compilers and interpreters use algorithms based on BNF to verify if a program adheres to the defined syntax and to transform it into an intermediate representation.
  • Automatic code generation: The formal structure described by BNF can be used to automatically generate parts of the code, such as the parsers themselves.

Although variants like Extended Backus-Naur Form (EBNF) exist to simplify certain notations, the fundamental principle of BNF remains a discreet yet essential pillar in the creation and understanding of the languages that shape our digital world.

University of Illinois Chicago - Backus-Naur Form (BNF) (in English)

IETF Memo : Routing Backus-Naur Form (RBNF): A Syntax Used to Form Encoding Rules in Various Routing Protocol Specifications