Grammar Documentation
Grammar Reference
Generated May 6, 2026 · 38 rules · EBNF · Generated by DevDiagrams

syntax

entry point
(* ISO/IEC 14977 : 1996(E) - Section 8.1 *)
(* The syntax of Extended BNF *)
(* The top-level rule. A grammar consists of one or more syntax rules. *)
syntax = syntax rule, { syntax rule } ;
syntax rule syntax rule

syntax rule

(* A single rule definition. A rule names a non-terminal symbol via a
meta identifier, followed by '=', a definitions list, and a terminator
symbol ';' or '.'. *)
syntax rule
= meta identifier, defining symbol,
definitions list, terminator symbol ;
meta identifier defining symbol definitions list terminator symbol

definitions list

(* A list of alternative definitions separated by '|', '/' or '!'.
Each alternative is a single definition. *)
definitions list
= single definition,
{ definition separator symbol, single definition } ;
single definition definition separator symbol single definition

single definition

(* A single alternative, consisting of one or more syntactic terms
concatenated together with ','. *)
single definition
= syntactic term, { concatenate symbol, syntactic term } ;
syntactic term concatenate symbol syntactic term

syntactic term

(* A syntactic term is a syntactic factor with an optional exception.
The exception, introduced by '-', excludes a subset of the factor's
language from the match. *)
syntactic term
= syntactic factor, [ except symbol, syntactic exception ] ;
syntactic factor except symbol syntactic exception

syntactic exception

(* The exception in a syntactic term. Must be expressible without
meta identifiers, ensuring the result remains a context-free grammar. *)
syntactic exception = syntactic factor ;
syntactic factor

syntactic factor

(* A syntactic factor is an optional repetition count followed by a
syntactic primary. If an integer is given, the primary must match
exactly that many times. If omitted, it matches exactly once. *)
syntactic factor
= [ integer, repetition symbol ], syntactic primary ;
integer repetition symbol syntactic primary

syntactic primary

(* The basic unit of a grammar expression. Can be a grouping construct,
a rule reference, a literal string, a special sequence, or empty. *)
syntactic primary
= optional sequence
| repeated sequence
| grouped sequence
| meta identifier
| terminal string
| special sequence
| empty sequence ;
optional sequence repeated sequence grouped sequence meta identifier terminal string special sequence empty sequence

optional sequence

(* An optional expression. Primary delimiters are '[' and ']';
alternative delimiters are '(/' and '/)'. The start and end
delimiters may be mixed. The enclosed definitions list may
match once or not at all. *)
optional sequence
= start option symbol, definitions list, end option symbol ;
start option symbol definitions list end option symbol

repeated sequence

(* A repeated expression. Primary delimiters are '{' and '}';
alternative delimiters are '(:' and ':)'. The start and end
delimiters may be mixed. The enclosed definitions list may
match zero or more times. *)
repeated sequence
= start repeat symbol, definitions list, end repeat symbol ;
start repeat symbol definitions list end repeat symbol

grouped sequence

(* A grouped expression enclosed in '(' and ')'. Used to override
default precedence by treating the enclosed definitions list
as a single unit. *)
grouped sequence
= start group symbol, definitions list, end group symbol ;
start group symbol definitions list end group symbol

empty sequence

(* The empty sequence. Matches the empty string, i.e. nothing.
Represented as an empty grouped sequence. *)
empty sequence = () ;

meta identifier

(* The name of a non-terminal symbol. Begins with a letter, followed
by zero or more letters or digits. Words may be separated by spaces
within the grammar text. *)
meta identifier = letter, { meta identifier character } ;
letter meta identifier character

meta identifier character

(* A single character within a meta identifier. Must be a letter or digit. *)
meta identifier character = letter | decimal digit ;
letter decimal digit

integer

(* A positive integer, used to specify an explicit repetition count
in a syntactic factor. *)
integer = decimal digit, { decimal digit } ;
decimal digit decimal digit

terminal string

(* A quoted literal string. May use single quotes or double quotes.
Must contain at least one character. The quote style used to open
must be used to close, and that quote character may not appear
within the string. *)
terminal string
= first quote symbol, terminal character - first quote symbol,
{ terminal character - first quote symbol }, first quote symbol
| second quote symbol, terminal character - second quote symbol,
{ terminal character - second quote symbol }, second quote symbol ;
first quote symbol terminal character except first quote symbol terminal character except first quote symbol first quote symbol second quote symbol terminal character except second quote symbol terminal character except second quote symbol second quote symbol

special sequence

(* An extension point enclosed in '?' and '?'. The content is outside
the scope of the standard and may be interpreted freely by the
implementing tool. *)
special sequence
= special sequence symbol,
{ terminal character - special sequence symbol },
special sequence symbol ;
special sequence symbol terminal character except special sequence symbol special sequence symbol

terminal character

(* Any character that may appear in an EBNF grammar, including letters,
digits, operator symbols, and other printable characters. *)
terminal character
= letter | decimal digit
| concatenate symbol | defining symbol
| definition separator symbol
| end comment symbol | end group symbol
| end option symbol | end repeat symbol
| except symbol | first quote symbol
| repetition symbol | second quote symbol
| special sequence symbol
| start comment symbol | start group symbol
| start option symbol | start repeat symbol
| terminator symbol | other character ;
letter decimal digit concatenate symbol defining symbol definition separator symbol end comment symbol end group symbol end option symbol end repeat symbol except symbol first quote symbol repetition symbol second quote symbol special sequence symbol start comment symbol start group symbol start option symbol start repeat symbol terminator symbol other character

letter

(* The 52 upper and lower case Latin letters. *)
letter
= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h'
| 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p'
| 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x'
| 'y' | 'z'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H'
| 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P'
| 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X'
| 'Y' | 'Z' ;
'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'

decimal digit

(* The ten decimal digits 0 through 9. *)
decimal digit
= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7'
| '8' | '9' ;
'0' '1' '2' '3' '4' '5' '6' '7' '8' '9'

concatenate symbol

(* The concatenation operator ','. Sequences two terms together. *)
concatenate symbol = ',' ;
','

defining symbol

(* The definition operator '='. Separates a rule name from its definition. *)
defining symbol = '=' ;
'='

definition separator symbol

(* The alternation operator. Separates alternative definitions.
Primary form is '|'; '/' and '!' are alternative representations. *)
definition separator symbol = '|' | '/' | '!' ;
'|' '/' '!'

end comment symbol

(* The closing delimiter of a comment. *)
end comment symbol = '*)' ;
'*)'

end group symbol

(* The closing delimiter ')' of a grouped sequence. Paired with '('. *)
end group symbol = ')' ;
')'

end option symbol

(* The closing delimiter of an optional sequence.
Primary form is ']'; '/)' is an alternative representation.
May be paired with either '(' or '(/' as the opening delimiter. *)
end option symbol = ']' | '/)' ;
']' '/)'

end repeat symbol

(* The closing delimiter of a repeated sequence.
Primary form is '}'; ':)' is an alternative representation.
May be paired with either '{' or '(:' as the opening delimiter. *)
end repeat symbol = '}' | ':)' ;
'}' ':)'

except symbol

(* The exception operator '-'. Excludes the right-hand syntactic factor
from the set of sequences matched by the left-hand syntactic factor. *)
except symbol = '-' ;
'-'

first quote symbol

(* The opening single quote delimiter of a terminal string. *)
first quote symbol = "'" ;
"'"

repetition symbol

(* The repetition operator '*'. When preceded by an integer, specifies
an exact repetition count for the following syntactic primary. *)
repetition symbol = '*' ;
'*'

second quote symbol

(* The opening double quote delimiter of a terminal string. *)
second quote symbol = '"' ;
'"'

special sequence symbol

(* The opening and closing delimiter '?' of a special sequence. *)
special sequence symbol = '?' ;
'?'

start comment symbol

(* The opening delimiter of a comment. *)
start comment symbol = '(*' ;
'(*'

start group symbol

(* The opening delimiter '(' of a grouped sequence. Paired with ')'. *)
start group symbol = '(' ;
'('

start option symbol

(* The opening delimiter of an optional sequence.
Primary form is '['; '(/' is an alternative representation.
May be paired with either ']' or '/)' as the closing delimiter. *)
start option symbol = '[' | '(/' ;
'[' '(/'

start repeat symbol

(* The opening delimiter of a repeated sequence.
Primary form is '{'; '(:' is an alternative representation.
May be paired with either '}' or ':)' as the closing delimiter. *)
start repeat symbol = '{' | '(:' ;
'{' '(:'

terminator symbol

(* The rule terminator. Primary form is ';'; '.' is an alternative. *)
terminator symbol = ';' | '.' ;
';' '.'

other character

(* Printable characters that are not letters, digits, or operator
symbols. May appear in terminal strings and special sequences. *)
other character
= ' ' | ':' | '+' | '_' | '%' | '@' | '&'
| '#' | '$' | '<' | '>' | '\' | '^' | '`' | '~' ;
' ' ':' '+' '_' '%' '@' '&' '#' '$' '<' '>' '\' '^' '`' '~'