Version

Improve EBNF Files Readability (Syntax Parsing Engine)

Topic Overview

Purpose

This topic describes how to improve EBNF file readability.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the Syntax Parsing Engine.

This topic explains a grammar’s non-terminal symbols.

This topic explains how to create productions for a non-terminal symbol.

Non-Terminal Symbols Definition

Summary

The following are some techniques for improving your EBNF code readability:

Begin each non-terminal symbol on its own line at the left side with each root-level choice on its own indented line:

Start =
    [UsingStatements], (NamespaceDeclaration | TypeDeclaration);
TypeDeclaration =
    ClassDeclaration
    | StructDeclaration
    | InterfaceDeclaration
    | EnumDeclaration
    | DelegateDeclaration;

If one of those root level choices consists of a long series of concatenations, move part of the series to the next line and insert another indent being careful to ensure that each term remains on 1 line:

ClassDeclaration =
    [Attributes], [Modifiers], [PartialKeyword], ClassKeyword, Identifier,
        [TypeParameterList], [BaseList], [TypeParameterConstraintClauses],
        OpenBrace, ClassMembers, CloseBrace, [Semicolon]
    | …
    | …;

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to optimize your non-terminal symbol definitions in order to minimize the number of productions.

This topic explains how to write operator precedence rules correctly.

This topic explains the benefits of using the SymbolNames constants.