Notational conventions
From Ruby Standard Wiki
5.1 Syntax
The syntax of the language is presented as a series of productions. Each production consists of the name of the nonterminal symbol being defined followed by "::", followed by one or more alternatives separated by "|".
Terminal symbols are shown in typewriter face, and represent sequences of characters as they appear in a program text. Non-terminal symbols are shown in italic face.
Each alternative in a production consists of a sequence of terminal and/or nonterminal symbols separated by whitespace.
If the same nonterminal symbol occurs on the right side of a production more than once, each occurrence is subscripted with a number to distinguish it from the other occurrences of the same name.
An optional symbol is denoted by postfixing the symbol with "?".
A sequence of zero or more repetitions of a symbol is denoted by postfixing the symbol with "*".
A sequence of one or more repetitions of a symbol is denoted by postfixing the symbol with "+".
Parentheses are used to treat a sequence of symbols as a single symbol.
A symbol followed by the phrase but not and another symbol represents all sequences of characters represented by the first symbol except for sequences of characters represented by the second symbol.
EXAMPLE 1 The following example means that non-escaped-character is any member of source-character except escape-character:
non-escaped-character ::
source-character but not escape-character
Text enclosed by "[" and "]" is used to describe a sequence of characters or a location in a program text.
EXAMPLE 2 The following example means that source-character is any character specified in ISO/IEC 646:
source-character ::
[ any character in ISO/IEC 646 ]
In particular, the notation "[lookahead ∉ set]" indicates that the token immediately following the notation shall not begin with a sequence of characters represented by one of the members of set. The set is represented as a list of one or more terminal symbols separated by commas, and the list is enclosed by "{" and "}".
EXAMPLE 3 The following example means that the argument following the method-modifier shall not begin with "{":
command ::
method-identifier [ lookahead ∉ { { } ] argument
In this document, use of the words of and in, when expressing a relationship between nonterminal symbols, has the following meanings:
- X of Y
- refers to the X occurring directly in a production defining Y.
- X in Y
- refers to any X occurring in a sequence which is derived directly or indirectly from Y.
5.2 Conceptual name
A conceptual name is a common name given to a set of semantically related nonterminal symbols in the grammar in order to refer to this set in a semantic description. A conceptual name is defined by a conceptual name definition. A conceptual name definition consists of the conceptual name to be defined followed by "::=", followed by one or more nonterminal symbols or conceptual names, separated by "|".
EXAMPLE The following example defines the conceptual name assignment, which can be used to refer either assignment-expression or assignment-statement.
assignment ::=
assignment-expression
| assignment-statement
Previous: 4. Terms and definitions Next: 6. Objects