Grammar Documentation
Grammar Reference
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. *)
(* The syntax of Extended BNF *)
(* The top-level rule. A grammar consists of one or more syntax rules. *)
Grammar definition
syntax = syntax rule, { syntax rule } ;Railroad diagram
References
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 '.'. *)
meta identifier, followed by '=', a definitions list, and a terminator
symbol ';' or '.'. *)
Grammar definition
syntax rule
= meta identifier, defining symbol,
definitions list, terminator symbol ;
Railroad diagram
Referenced by
References
definitions list
(* A list of alternative definitions separated by '|', '/' or '!'.
Each alternative is a single definition. *)
Each alternative is a single definition. *)
Grammar definition
definitions list
= single definition,
{ definition separator symbol, single definition } ;
Railroad diagram
Referenced by
References
single definition
(* A single alternative, consisting of one or more syntactic terms
concatenated together with ','. *)
concatenated together with ','. *)
Grammar definition
single definition
= syntactic term, { concatenate symbol, syntactic term } ;
Railroad diagram
Referenced by
References
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. *)
The exception, introduced by '-', excludes a subset of the factor's
language from the match. *)
Grammar definition
syntactic term
= syntactic factor, [ except symbol, syntactic exception ] ;
Railroad diagram
Referenced by
References
syntactic exception
(* The exception in a syntactic term. Must be expressible without
meta identifiers, ensuring the result remains a context-free grammar. *)
meta identifiers, ensuring the result remains a context-free grammar. *)
Grammar definition
syntactic exception = syntactic factor ;
Railroad diagram
Referenced by
References
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 primary. If an integer is given, the primary must match
exactly that many times. If omitted, it matches exactly once. *)
Grammar definition
syntactic factor
= [ integer, repetition symbol ], syntactic primary ;
Railroad diagram
Referenced by
References
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. *)
a rule reference, a literal string, a special sequence, or empty. *)
Grammar definition
syntactic primary
= optional sequence
| repeated sequence
| grouped sequence
| meta identifier
| terminal string
| special sequence
| empty sequence ;
Railroad diagram
Referenced by
References
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. *)
alternative delimiters are '(/' and '/)'. The start and end
delimiters may be mixed. The enclosed definitions list may
match once or not at all. *)
Grammar definition
optional sequence
= start option symbol, definitions list, end option symbol ;
Railroad diagram
Referenced by
References
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. *)
alternative delimiters are '(:' and ':)'. The start and end
delimiters may be mixed. The enclosed definitions list may
match zero or more times. *)
Grammar definition
repeated sequence
= start repeat symbol, definitions list, end repeat symbol ;
Railroad diagram
Referenced by
References
grouped sequence
(* A grouped expression enclosed in '(' and ')'. Used to override
default precedence by treating the enclosed definitions list
as a single unit. *)
default precedence by treating the enclosed definitions list
as a single unit. *)
Grammar definition
grouped sequence
= start group symbol, definitions list, end group symbol ;
Railroad diagram
Referenced by
References
empty sequence
(* The empty sequence. Matches the empty string, i.e. nothing.
Represented as an empty grouped sequence. *)
Represented as an empty grouped sequence. *)
Grammar definition
empty sequence = () ;
Railroad diagram
Referenced by
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. *)
by zero or more letters or digits. Words may be separated by spaces
within the grammar text. *)
Grammar definition
meta identifier = letter, { meta identifier character } ;Railroad diagram
Referenced by
References
meta identifier character
(* A single character within a meta identifier. Must be a letter or digit. *)
Grammar definition
meta identifier character = letter | decimal digit ;
Railroad diagram
Referenced by
References
integer
(* A positive integer, used to specify an explicit repetition count
in a syntactic factor. *)
in a syntactic factor. *)
Grammar definition
integer = decimal digit, { decimal digit } ;Railroad diagram
Referenced by
References
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. *)
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. *)
Grammar definition
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 ;
Railroad diagram
Referenced by
References
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. *)
the scope of the standard and may be interpreted freely by the
implementing tool. *)
Grammar definition
special sequence
= special sequence symbol,
{ terminal character - special sequence symbol },
special sequence symbol ;
Railroad diagram
Referenced by
References
terminal character
(* Any character that may appear in an EBNF grammar, including letters,
digits, operator symbols, and other printable characters. *)
digits, operator symbols, and other printable characters. *)
Grammar definition
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 ;
Railroad diagram
Referenced by
References
letterdecimal digitconcatenate symboldefining symboldefinition separator symbolend comment symbolend group symbolend option symbolend repeat symbolexcept symbolfirst quote symbolrepetition symbolsecond quote symbolspecial sequence symbolstart comment symbolstart group symbolstart option symbolstart repeat symbolterminator symbolother character
letter
(* The 52 upper and lower case Latin letters. *)
Grammar definition
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' ;
Railroad diagram
Referenced by
decimal digit
(* The ten decimal digits 0 through 9. *)
Grammar definition
decimal digit
= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7'
| '8' | '9' ;
Railroad diagram
Referenced by
concatenate symbol
(* The concatenation operator ','. Sequences two terms together. *)
Grammar definition
concatenate symbol = ',' ;
Railroad diagram
Referenced by
defining symbol
(* The definition operator '='. Separates a rule name from its definition. *)
Grammar definition
defining symbol = '=' ;
Railroad diagram
Referenced by
definition separator symbol
(* The alternation operator. Separates alternative definitions.
Primary form is '|'; '/' and '!' are alternative representations. *)
Primary form is '|'; '/' and '!' are alternative representations. *)
Grammar definition
definition separator symbol = '|' | '/' | '!' ;
Railroad diagram
Referenced by
end comment symbol
(* The closing delimiter of a comment. *)
Grammar definition
end comment symbol = '*)' ;
Railroad diagram
Referenced by
end group symbol
(* The closing delimiter ')' of a grouped sequence. Paired with '('. *)
Grammar definition
end group symbol = ')' ;
Railroad diagram
Referenced by
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. *)
Primary form is ']'; '/)' is an alternative representation.
May be paired with either '(' or '(/' as the opening delimiter. *)
Grammar definition
end option symbol = ']' | '/)' ;
Railroad diagram
Referenced by
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. *)
Primary form is '}'; ':)' is an alternative representation.
May be paired with either '{' or '(:' as the opening delimiter. *)
Grammar definition
end repeat symbol = '}' | ':)' ;
Railroad diagram
Referenced by
except symbol
(* The exception operator '-'. Excludes the right-hand syntactic factor
from the set of sequences matched by the left-hand syntactic factor. *)
from the set of sequences matched by the left-hand syntactic factor. *)
Grammar definition
except symbol = '-' ;
Railroad diagram
Referenced by
first quote symbol
(* The opening single quote delimiter of a terminal string. *)
Grammar definition
first quote symbol = "'" ;
Railroad diagram
Referenced by
repetition symbol
(* The repetition operator '*'. When preceded by an integer, specifies
an exact repetition count for the following syntactic primary. *)
an exact repetition count for the following syntactic primary. *)
Grammar definition
repetition symbol = '*' ;
Railroad diagram
Referenced by
second quote symbol
(* The opening double quote delimiter of a terminal string. *)
Grammar definition
second quote symbol = '"' ;
Railroad diagram
Referenced by
special sequence symbol
(* The opening and closing delimiter '?' of a special sequence. *)
Grammar definition
special sequence symbol = '?' ;
Railroad diagram
Referenced by
start comment symbol
(* The opening delimiter of a comment. *)
Grammar definition
start comment symbol = '(*' ;
Railroad diagram
Referenced by
start group symbol
(* The opening delimiter '(' of a grouped sequence. Paired with ')'. *)
Grammar definition
start group symbol = '(' ;Railroad diagram
Referenced by
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. *)
Primary form is '['; '(/' is an alternative representation.
May be paired with either ']' or '/)' as the closing delimiter. *)
Grammar definition
start option symbol = '[' | '(/' ;
Railroad diagram
Referenced by
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. *)
Primary form is '{'; '(:' is an alternative representation.
May be paired with either '}' or ':)' as the closing delimiter. *)
Grammar definition
start repeat symbol = '{' | '(:' ;Railroad diagram
Referenced by
terminator symbol
(* The rule terminator. Primary form is ';'; '.' is an alternative. *)
Grammar definition
terminator symbol = ';' | '.' ;
Railroad diagram
Referenced by
other character
(* Printable characters that are not letters, digits, or operator
symbols. May appear in terminal strings and special sequences. *)
symbols. May appear in terminal strings and special sequences. *)
Grammar definition
other character
= ' ' | ':' | '+' | '_' | '%' | '@' | '&'
| '#' | '$' | '<' | '>' | '\' | '^' | '`' | '~' ;
Railroad diagram
Referenced by