Java Reference
In-Depth Information
2.4. Grammar Notation
Terminal symbols are shown in
fixed width
font in the productions of the lexical and syn-
tactic grammars, and throughout this specification whenever the text is directly referring to
such a terminal symbol. These are to appear in a program exactly as written.
Nonterminal symbols are shown in
italic
type. The definition of a nonterminal is introduced
by the name of the nonterminal being defined followed by a colon. One or more alternative
right-hand sides for the nonterminal then follow on succeeding lines.
For example, the syntactic definition:
IfThenStatement:
if (
Expression
)
Statement
states that the nonterminal
IfThenStatement
represents the token
if
, followed by a left
parenthesis token, followed by an
Expression
, followed by a right parenthesis token,
followed by a
Statement
.
As another example, the syntactic definition:
ArgumentList:
Argument
ArgumentList
,
Argument
states that an
ArgumentList
may represent either a single
Argument
or an
Argu-
mentList
, followed by a comma, followed by an
Argument
. This definition of
Argu-
mentList
is
recursive
, that is to say, it is defined in terms of itself. The result is that an
ArgumentList
may contain any positive number of arguments. Such recursive defini-
tions of nonterminals are common.
The subscripted suffix “
opt
”, which may appear after a terminal or nonterminal, indicates
an
optional symbol
. The alternative containing the optional symbol actually specifies two
right-hand sides, one that omits the optional element and one that includes it.
This means that:
BreakStatement:
break
Identifier
opt
;
is a convenient abbreviation for: