2.10 Extended Backus–Naur Form
Extended Backus–Naur Form (EBNF) includes the following syntactic extensions to BNF.
Note that we have already encountered the extension to BNF for alternation (using |). Consider the following context-free grammar defined in BNF:
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:
We can express r2 more concisely using the extension for an optional item:
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.