Eiffel programming language syntax

The syntax specification shown here is a less complete and less formal version of that which is in the Eiffel ISO/ECMA standard document. The format is BNF-E. The Language Specification section of the standard document includes an overview of BNF-E.

There are a few parts of the syntax that are either non-production or non-representable in BNF-E. Some of these have been omitted from the following specification. These omitted parts of the syntax definition add to the precision of the specification, but knowledge of them is not always vital for developers.

In the BNF-E representation, generally non-terminals which are defined in the same group of productions in which they are used are not linked. However when a non-terminal is defined outside a group in which it is used, it is linked to the group in which it is defined.

The following section contains those non-production elements of the specification that are used later in the BNF-E specification.

Eiffel non-production elements

Identifiers

An identifier is a sequence of one or more alphanumeric characters of which the first is a letter.

The definition is augmented by the rule that Identifiers are not valid if they are the same as one of the language's reserved words.

Characters

Characters are either:

  • All 32-bit, corresponding to Unicode and to the Eiffel type CHARACTER_32.
  • All 8-bit, corresponding to 8-bit extended ASCII and to the Eiffel type CHARACTER_8

Reals

A real -- specimen of Real -- is made of the following elements, in the order given:

  • An optional decimal Integer, giving the integral part.
  • A required "." (dot).
  • An optional decimal Integer, giving the fractional part.
  • An optional exponent, which is the letter e or E followed by an optional Sign and a decimal Integer.

No intervening character (blank or otherwise) is permitted between these elements. The integral and fractional parts may not both be absent.

Strings

A string -- specimen of construct String -- is a sequence of zero or more manifest characters.

Simple strings

A simple string -- specimen of Simple_string -- is a String consisting of at most one line (that is to say, containing no embedded new-line manifest character), possibly containing codes for special characters.

Special characters

Special Characters and Their Codes
Character Code Mnemonic name
@ %A At-sign
BS %B Backspace
^ %C Circumflex
$ %D Dollar
FF %F Form feed
\ %H Backslash
~ %L Tilde
NL (LF) %N Newline
` %Q Backquote
CR %R Carriage return
# %S Sharp
HT %T Horizontal tab
NUL %U Null
| %V Vertical bar
% %% Percent
' %' Single quote
" %" Double quote
[ %( Opening bracket
] %) Closing bracket
{ %< Opening brace
} %> Closing brace

  • %/123/ represents the character with decimal code 123 .
  • And only for manifest character (for now)
    • '%/0x2200/' represents the character with hexadecimal code U+2200 = '∀' (note '%/0x2200/' = '%/8704/' )
    • '%/0c21000/' in octal
    • '%/0b10001000000000/' in binary

Line wrapping parts

A sequence of characters consisting of the following, in order:

  • % (percent character)
  • Zero or more blanks or tabs
  • New line (Line feed)
  • Zero or more blanks or tabs
  • % (percent character)

Line wrapping parts are used as separators between one Simple_string and the next in a Basic_manifest_string so that the string can be split across lines.

New line

A specimen of New_line is a New Line.

Eiffel BNF-E Syntax

Class names

Class_name ::= Identifier

Class declarations

Class_declaration ::= [Notes] Class_header [Formal_generics]

[Obsolete]

[Inheritance]

[Creators]

[Converters]

[Features]

[Notes]

[Invariant]

[Notes]

end

Notes

Notes ::= note Note_list

Note_list ::= {Note_entry ";" ...}*

Note_entry ::= Note_name Note_values

Note_name ::= Identifier ":"

Note_values ::= {Note_item ","...}+

Note_item ::= Identifier | Manifest_constant

Class headers

Class_header ::= [Header_mark] class Class_name

Header_mark ::= deferred | expanded | frozen

Obsolete marks

Obsolete ::= obsolete Message

Message ::= Manifest_string

Feature parts

Features ::= Feature_clause+

Feature_clause ::= feature [Clients] [Header_comment] Feature_declaration_list

Feature_declaration_list ::= {Feature_declaration ";" ...}*

Header_comment ::= Comment

Feature declarations

Feature_declaration ::= New_feature_list Declaration_body

Declaration_body ::= [Formal_arguments] [Query_mark] [Feature_value]

Query_mark ::= Type_mark [Assigner_mark]

Type_mark ::= ":" Type

Feature_value ::= [Explicit_value] [Obsolete] [Header_comment] [Attribute_or_routine]

Explicit_value ::= "=" Manifest_constant

New feature lists

New_feature_list ::= {New_feature "," ...}+

New_feature ::= [frozen] Extended_feature_name

Feature bodies

Attribute_or_routine ::= [Precondition] [Local_declarations] Feature_body [Postcondition] [Rescue] end

Feature_body ::= Deferred | Effective_routine | Attribute

Feature names

Extended_feature_name ::= Feature_name [Alias]

Feature_name ::= Identifier

Alias ::= alias '"' Alias_name '"' [convert]

Alias_name ::= Operator | Bracket

Bracket ::= "[ ]"

Operators

Operator ::= Unary | Binary

Unary ::= not | "+" | "-" | Free_unary

Binary ::= "+" | "-" | "*" | "/" | "//" | "\\" | "^" | ".." | "<" | ">" | "<=" | ">=" | and | or | xor | and then | or else | implies | Free_binary

Note: Free_unary and Free_binary are free operators that are distinct from (respectively) the standard unary and binary operators (one- or two-character symbols) explicitly listed in the Unary and Binary productions. See Definition: Free operator in the standard for more precision.

Assigner marks

Assigner_mark ::= assign Feature_name

Inheritance parts

Inheritance ::= Inherit_clause+

Inherit_clause ::= inherit [Non_conformance] Parent_list

Non_conformance ::= "{" NONE "}"

Parent_list ::= {Parent ";" ...}+

Parent ::= Class_type [Feature_adaptation]

Feature_adaptation ::= [Undefine] [Redefine] [Rename] [New_exports] [Select] end

Rename clauses

Rename ::= rename Rename_list

Rename_list ::= {Rename_pair "," ...}+

Rename_pair ::= Feature_name as Extended_feature_name

Clients

Clients ::= "{" Class_list "}"

Class_list ::= {Class_name "," ...}+

Export adaptation

New_exports ::= export New_export_list

New_export_list ::= {New_export_item ";" ...}+

New_export_item ::= Clients [Header_comment] Feature_set

Feature_set ::= Feature_list | all

Feature_list ::= {Feature_name "," ...}+

Formal argument and entity declarations

Formal_arguments ::= "(" Entity_declaration_list ")"

Entity_declaration_list ::= {Entity_declaration_group ";" ...}+

Entity_declaration_group ::= Identifier_list Type_mark

Identifier_list ::= {Identifier "," ...}+

Routine bodies

Deferred ::= deferred

Effective_routine ::= Internal | External

Internal ::= Routine_mark Compound

Routine_mark ::= do | Once

Once ::= once [ "("Key_list ")" ]

Key_list ::= {Manifest_string "," ...}+

Local variable declarations

Local_declarations ::= local [Entity_declaration_list]

Instructions

Compound ::= {Instruction ";" ...}*

Instruction ::= Creation_instruction | Call | Assignment | Assigner_call | Conditional | Multi_branch | Loop | Debug | Precursor | Check | Retry

Assertions

Precondition ::= require [else] Assertion

Postcondition ::= ensure [then] Assertion [Only]

Invariant ::= invariant Assertion

Assertion ::= {Assertion_clause ";" ...}*

Assertion_clause ::= [Tag_mark] Unlabeled_assertion_clause

Unlabeled_assertion_clause ::= Boolean_expression | Comment | class

Tag_mark ::= Tag ":"

Tag ::= Identifier

Note: Unlabeled_assertion_clause of the form class can be used only in a postcondition. It marks a feature that does not depend on object state and can be called without a target object using non-object call of the form {CLASS_NAME}.feature_name (arguments).

"Old" postcondition expressions

Old ::= old Expression

"Only" postcondition clauses

Only ::= only [Feature_list]

Check instructions

Check ::= check Assertion [Notes] end

Variants

Variant ::= variant [Tag_mark] Expression

Precursor

Precursor ::= Precursor [Parent_qualification] [Actuals]

Parent_qualification ::= "{" Class_name "}"

Redefinition

Redefine ::= redefine Feature_list

Undefine clauses

Undefine ::= undefine Feature_list

Types

Type ::= Class_or_tuple_type | Formal_generic_name | Anchored

Class_or_tuple_type ::= Class_type | Tuple_type

Class_type ::= [Attachment_mark] Class_name [Actual_generics]

Attachment_mark ::= "?" | "!"

Anchored ::= [Attachment_mark] like Anchor

Anchor ::= Feature_name | Current

Actual generic parameters

Actual_generics ::= "[" Type_list "]"

Type_list ::= {Type "," ...}+

Formal generic parameters

Formal_generics ::= "[" Formal_generic_list "]"

Formal_generic_list ::= {Formal_generic ","...}+

Formal_generic ::= [frozen] Formal_generic_name [Constraint]

Formal_generic_name ::= [?] Identifier

Generic constraints

Constraint ::= "->" Constraining_types [Constraint_creators]

Constraining_types ::= Single_constraint | Multiple_constraint

Single_constraint ::= Type [Renaming]

Renaming ::= Rename end

Multiple_constraint ::= "{" Constraint_list "}"

Constraint_list ::= {Single_constraint "," ...}+

Constraint_creators ::= create Feature_list end

Manifest arrays

Manifest_array ::= [Manifest_array_type] << Expression_list >>

Manifest_array_type ::= { Type }

Expression_list ::= {Expression , ...}*

Tuple types

Tuple_type ::= TUPLE [Tuple_parameter_list]

Tuple_parameter_list ::= "[" Tuple_parameters "]"

Tuple_parameters ::= Type_list | Entity_declaration_list

Manifest tuples

Manifest_tuple ::= "[" Expression_list "]"

Converter clauses

Converters ::= convert Converter_list

Converter_list ::= {Converter ","...}+

Converter ::= Conversion_procedure | Conversion_query

Conversion_procedure ::= Feature_name "(" "{" Type_list "}" ")"

Conversion_query ::= Feature_name ":" "{" Type_list "}"

Select clauses

Select ::= select Feature_list

Conditionals

Conditional ::= if Then_part_list [Else_part] end

Then_part_list ::= {Then_part elseif ...}+

Then_part ::= Boolean_expression then Compound

Else_part ::= else Compound

Conditional_expression ::= if Then_part_expression_list else Expression end

Then_part_expression_list ::= {Then_part_expression elseif ...}+

Then_part_expression ::= Boolean_expression then Expression

Multi-branch instructions

Multi_branch ::= inspect Expression [When_part_list] [Else_part] end

When_part_list ::= When_part+

When_part ::= when Choices then Compound

Choices ::= {Choice "," ...}+

Choice ::= Constant | Manifest_type | Constant_interval | Type_interval

Constant_interval ::= Constant ".." Constant

Type_interval ::= Manifest_type ".." Manifest_type

Loops

Loop ::=
      [Iteration]
      [Initialization]
      [Invariant]
      [Exit_condition]
      Loop_body
      [Variant]
      end

Iteration ::= across Expression as Identifier

Initialization ::= from Compound

Exit_condition ::= until Boolean_expression

Loop_body ::=
      loop Compound |
      all Boolean_expression |
      some Boolean_expression

Debug instructions

Debug ::= debug [ "("Key_list ")" ] Compound end

Attribute bodies

Attribute ::= attribute Compound

Entities and variables

Entity ::= Variable | Read_only

Variable ::= Variable_attribute | Local

Variable_attribute ::= Feature_name

Local ::= Identifier | Result

Read_only ::= Formal | Constant_attribute | Current

Formal ::= Identifier

Constant_attribute ::= Feature_name

Creators parts

Creators ::= Creation_clause+

Creation_clause ::= create [Clients] [Header_comment] Creation_procedure_list

Creation_procedure_list ::= {Creation_procedure ","...}+

Creation_procedure ::= Feature_name

Creation instructions

Creation_instruction ::= create [Explicit_creation_type] Creation_call

Explicit_creation_type ::= "{" Type "}"

Creation_call ::= Variable [Explicit_creation_call]

Explicit_creation_call ::= "." Unqualified_call

Creation expressions

Creation_expression ::= create Explicit_creation_type [Explicit_creation_call]

Equality expressions

Equality ::= Expression Comparison Expression

Comparison ::= "=" | "/=" | "~" | "/~"

Assignments

Assignment ::= Variable ":=" Expression

Assigner calls

Assigner_call ::= Expression ":=" Expression

Feature calls

Call ::= Object_call | Non_object_call

Object_call ::= [Target "."] Unqualified_call

Unqualified_call ::= Feature_name [Actuals]

Target ::= Local | Read_only | Call | Parenthesized_target

Parenthesized_target ::= ( Expression )

Non_object_call ::= "{" Type "}" "." Unqualified_call

Actual arguments

Actuals ::= "(" Actual_list ")"

Actual_list ::= {Expression "," ...}+

Object test

Object_test ::= "{" Identifier ":" Type "}" Expression

Rescue clauses

Rescue ::= rescue Compound

Retry ::= retry

Agents

Agent ::= Call_agent | Inline_agent

Call_agent ::= agent Call_agent_body

Inline_agent ::= agent [Formal_arguments] [Type_mark] [Attribute_or_routine] [Agent_actuals]

Call agent bodies

Call_agent_body ::= Agent_qualified | Agent_unqualified

Agent_qualified ::= Agent_target ". " Agent_unqualified

Agent_unqualified ::= Feature_name [Agent_actuals]

Agent_target ::= Entity | Parenthesized | Manifest_type

Agent_actuals ::= "(" Agent_actual_list ")"

Agent_actual_list ::= {Agent_actual "," ...}+

Agent_actual ::= Expression | Placeholder

Placeholder ::= [Manifest_type] "?"

Expressions

Expression ::= Basic_expression | Special_expression

Basic_expression ::= Read_only | Local | Call | Precursor | Equality | Parenthesized | Old | Operator_expression | Bracket_expression | Creation_expression | Conditional_expression

Special_expression ::= Manifest_constant | Manifest_array | Manifest_tuple | Agent | Object_test | Once_string | Address

Parenthesized ::= "(" Expression ")"

Address ::= "$" Variable

Once_string ::= once Manifest_string

Boolean_expression ::= Basic_expression | Boolean_constant | Object_test

Operator expressions

Operator_expression ::= Unary_expression | Binary_expression

Unary_expression ::= Unary Expression

Binary_expression ::= Expression Binary Expression

Bracket expressions

Bracket_expression ::= Bracket_target "[" [[#Actual arguments|Actuals]] "]"

Bracket_target ::= Target | Once_string | Manifest_constant | Manifest_tuple

Constants

Constant ::= Manifest_constant | Constant_attribute

Constant_attribute ::= Feature_name

Manifest constants

Manifest_constant ::= [Manifest_type] Manifest_value

Manifest_type ::= "{" Type "}"

Manifest_value ::= Boolean_constant | Character_constant | Integer_constant | Real_constant | Manifest_string | Manifest_type

Sign ::= "+" | "-"

Integer_constant ::= [Sign] Integer

Character_constant ::= " ' " Character " ' "

Boolean_constant ::= True | False

Real_constant ::= [Sign] Real

Manifest strings

Manifest_string ::= Basic_manifest_string | Verbatim_string

Basic_manifest_string ::= ' " ' String_content ' " '

String_content ::= {Simple_string Line_wrapping_part ...}+

Verbatim_string ::= Verbatim_string_opener Line_sequence Verbatim_string_closer

Verbatim_string_opener ::= ' " ' [Simple_string] Open_bracket

Verbatim_string_closer ::= Close_bracket [Simple_string] ' " '

Open_bracket ::= "[" | "{"

Close_bracket ::= "]" | "}"

Line_sequence ::= {Simple_string New_line ...}+

Note: Exactly the same Simple_string (including embedded white space, if any) should be used in Verbatim_string_opener and Verbatim_string_closer of the same verbatim string.

External routines

External ::= external External_language [External_name]

External_language ::= Unregistered_language | Registered_language

Unregistered_language ::= Manifest_string

External_name ::= alias Manifest_string

Note: If the inline keyword is used in the Registered_language part, then External_name part is the inline code on the specified language.

Registered languages

Registered_language ::= C_external | C++_external | DLL_external

External signatures

External_signature ::= signature [External_argument_types] [: External_type]

External_argument_types ::= "(" External_type_list ")"

External_type_list ::= {External_type "," ...}*

External_type ::= Simple_string

External file use

External_file_use ::= use External_file_list

External_file_list ::= {External_file "," ... }+

External_file ::= External_user_file | External_system_file

External_user_file ::= ' " ' Simple_string ' " '

External_system_file ::= "<" Simple_string ">"

C externals

C_external ::= ' " ' C [inline] [ External_signature ] [ External_file_use ] ' " '

C++ externals

C++_external ::= ' " ' C++ inline [ External_signature ] [ External_file_use ] ' " '

DLL externals

DLL_external ::= ' " ' dll [windows] DLL_identifier [DLL_index] [[ External_signature ] [ External_file_use ] ' " '

DLL_identifier ::= Simple_string

DLL_index ::= Integer

Comments

Comment ::= "- -" {Simple_string Comment_break ...}*

Comment_break ::= New_line [Blanks_or_tabs] "- -"

Integers

Integer ::= [Integer_base] Digit_sequence

Integer_base ::= "0" Integer_base_letter

Integer_base_letter ::= "b" | "c" | "x" | "B" | "C" | "X"

Digit_sequence ::= Digit+

Digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F" | "_"

cached: 12/12/2024 5:00:38.000 PM