Syntax Notation |
This section describes the notation used in the Eiffel syntax specification.
Every construct is either a terminal or a non-terminal. A terminal construct has no further syntactical structure. In contrast, a non-terminal construct is defined in terms of other constructs. There is three kinds of terminals: reserved words, symbols and variable tokens.
Reserved words are keywords or predefined names such as inherit or Result. In productions they are shown literally in boldface such as in:
- Inheritance
- inherit Parent_list
Symbols are made of one or more characters with no intervening blank or other characters, such as + or ?=. In productions they appear literally in boldface as in the following example:
- Assignment_attempt
- Writable ?= Expression
The notation described here has its own symbols as well. To avoid any confusion between symbols from the notation and Eiffel symbols, the notation's symbols are displayed in red, as in:
- New_feature_list
- { New_feature , ... }+
The comma is an Eiffel symbol whereas the opening and closing braces, the three dots and the plus sign are part of the notation.
Variable tokens are terminal constructs such as Integer or Identifier. They are described in plain English as shown below:
- Identifier
- An identifier is a sequence of one or more characters, of which the first is a letter (a to z and A to Z) and each of the subsequent ones, if any, is a letter, a decimal digit (0 to 9) or an underscore character (_).
To understand a non-terminal, a formal description of the structure of this construct is needed. Such a description is called the production for the construct. A production has the form:
- Construct
- right-hand-side
Every non-terminal construct appears on the left-hand side of exactly one such production. The right-hand-side of the production describes the structure of the left-hand-side construct. Non-terminal constructs in the right-hand-side are clickable to have access to their respective productions. Three forms of right-hand-side are available: aggregates, choices and repetitions.
Aggregates describe constructs made of a fixed number of parts (some of which may be optional) to be concatenated in a given order. An aggregate right-hand-side is a non-empty sequence of constructs such as in the following example:
- Binary_expression
- Expression Infix_operator Expression
An Binary_expression is made of the concatenation of an expression, an infix operator and another expression.
If the aggregate contains optional constructs, they are enclosed in red square brackets [].
- New_feature
- [ frozen ] Feature_name
In the above example the keyword frozen is optional.
Choices describe constructs having a number of given variants. A choice right-hand-side is a non-empty sequence of constructs separated by red vertical bars |:
- Feature_name
- Identifier | Prefix | Infix
A Feature_name is either an Identifier, a Prefix or an Infix.
Repetitions describe constructs made of a variable number of parts, which are all of the same given construct. A repetition right-hand-side is one of the two forms:
{ Construct Separator ... } { Construct Separator ... }+
where Separator is usually, but not necessarily, a terminal construct. This states that the construct described consists of zero or more specimens of Construct separated, if more than one, by the separator. In the first form, without a +, the specimens of the construct described may be empty; in the second form, with a +, they must include a least one Construct.
Annotations are not part of the described syntax. They provide the reader with some known tips and tricks concerning a particular construct or set of constructs. Annotations are indented and displayed in green:
- Interval
- Choice_constant .. Choice_constant
Note: The lexical analyzer has to be smart enough in the following example:
inspect expr when 1..2 then ...Indeed, '1..2' should be recognized as the two integer constants '1' and '2' separated by the Eiffel symbol '..', instead of as two consecutive real constants '1.' and '.2'.
Copyright © 1998, Eric
Bezault mailto:ericb@gobosoft.com http://www.gobosoft.com Last Updated: 25 March 1998 |