how to read a BNF Grammar

 

Overview

The ability to read a BNF grammar is important to anyone interested in web design or computer programming.

Computer language specifications and regex specifications are written as a(n) [E]BNF Grammar, such as Javascript/ECMAScript, Regular expressions, etc.

if you can read a(n) [E]BNF grammar document, you can read pretty much any language specification and work with any document you choose.

how to read a BNF grammar (syntax specification)

it's basically a matter of making a lot of substitutions and following rules to put things together (assemble or follow a syntax).

the basis of this is : or ::= and each block of stuff is a production, and I forgot what they call the identifier to the left of the : or ::= (think of it like a variable) is composed of everything in the list below separated by invisible OR.

everything on one line is a sequence.

bold things are actual characters(tokens).

you look up any non-bold "variables" you find below in the rest of the spec to find out how to expand them and it just becomes a big substitution job.

YOU choose what comes next by choosing the line that matches your input.

Glossary

BNF
Backus Naur Form. a type of grammar used to specify the syntax of a language (but not its semantics).
EBNF
Extended Backus Naur Form. a type of grammar used to specify the syntax of a language (but not its semantics).
grammar:
syntax. how a sentence is laid out.
semantics:
meaning of a sentence.