2.10 Extended Backus–Naur Form

Extended Backus–Naur Form (EBNF) includes the following syntactic extensions to BNF.

The list is as follows. A vertical line means alternation. X between brackets means X is optional. X between curly braces followed by an asterisk means zero or more of X. X between curly braces followed by superscript plus means one or more of x. X between curly braces asterisk superscript c means zero or more of X separated by Cs. X between curly braces superscript plus c means one or more of X separated by Cs.

Note that we have already encountered the extension to BNF for alternation (using |). Consider the following context-free grammar defined in BNF:

A list of six context-free grammar defined in B N F.
Description

which can be used to derive the following sentences: x, (x, y, z), ((x)), and (((x)), ((y), (z))). We can reexpress this grammar in EBNF using alternation as follows:

Description

We can express r2 more concisely using the extension for an optional item:

Description ...

Get Programming Languages: Concepts and Implementation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.