Difference between revisions of "Syntax diagrams"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
(No difference)

Revision as of 22:16, 4 March 2013

Syntax diagrams for the whole Eiffel language.

All items in alphabetical order: Assignment, Assertion, Binary_operator, Call, Check, Class_declaration, Class_name, Class_type, Clients, Comment, Compound, Create_expression, Create_instruction, Creation_clause, Current, Debug, Entity_declaration_list, Expression, Feature_clause, Feature_declaration, Feature_name, Formal_generic_list, If_then_else, Infix_operator, Inspect, Instruction, Loop, Manifest_notation, Manifest_string, New_export_item, Parent_list, Prefix_operator, Result, Routine, Routine_body, Type, Unary_operator, Unqualified_call, Writable.



A comment is made of one or more line segments, each beginning with two consecutive dash characters -- and extending to the end of the line:

Comment

Inside the comment, the convention to denote Eiffel entities (i.e. variables, arguments or other features as well) is to enclose the corresponding name between ` and ' as follows:

-- Here `my_variable' is supposed to be bla bla bla ...

This convention allows some tools like Eiffeldoc or Short or emacs as well to use a different character font or color to emphasize the fact that my_variable refers to some existing entity of the Eiffel code. Previous convention must not be used for class names which are to be typed normally in comments as:

-- My FOO clas is bla bla bla bla ...

Also note that an URL inside the comment is also made automatically clickable by Eiffeldoc. This way, each time some class of our library needs a long explanation that does not reasonably fit in the Eiffel comment itself, we just add the URL into the comment. As an example, the following comment displayed by Eiffeldoc would bring you back here :

-- See also http://smarteiffel.loria.fr/wiki/en/index.php/Syntax_diagrams#Comment

Class declaration

Class_declaration

Related items: Assertion, Class_name, Creation_clause, Feature_clause, Formal_generic_list, Manifest_string, Parent_list.

Formal generic list

Formal_generic_list

To be used only when the class is generic. The Identifier is not the name of an existing class, but usually, just a simple upper case letter (see also Class_name). The Class_type part, when used, is the generic constraint.

Related items: Class_type, Identifier.

Parent list

Parent_list

Related items: Feature_name, New_export_item.

New export item

New_export_item

Related items: Class_name.

Creation clause

Creation_clause

Related items: Feature_name, Comment.

Feature clause

Feature_clause

Related items: Clients, Comment, Feature_declaration.

Clients

Clients

Related items: Class_name.

Feature declaration

Feature_declaration

Where the Manifest_constant can only be selected in the following set: { BOOLEAN, CHARACTER, INTEGER_8, INTEGER_16, INTEGER_32, INTEGER, INTEGER_64, REAL_32, REAL_64, REAL, REAL_80, REAL_128, REAL_EXTENDED, STRING, UNICODE_STRING }. See the file SmartEiffel/tutorial/manifest_notation.e to have a detailed explaination plus examples about all available notations for constants.

Related items: Entity_declaration_list, Feature_name, Routine, Type.

Routine

Routine

Related items: Assertion, Compound, Entity_declaration_list, Feature_name, Manifest_string.

Routine body

Routine_body

Related items: Compound, Manifest_string.

Entity declaration list

Entity_declaration_list

This notation is used for local variable list declaration as well as for formal argument list of routines.

Related items: Identifier, Type.

Type

Type

Related items: Class_type, Formal_generic_name, Identifier.

Class name

A class name must use only upper case letters plus the '_' underscore character. A class name must start with a letter, an upper case letter as all other letters used in that name. The usage is not to use two consecutive '_' underscore character, nor to end by an underscore character (by convention we keep simple names with a trailing underscore character, like O_ as a formal parameter type of a generic type). Some examples of valid class names: ARRAY, ANY, LINKED_LIST.

Class type

Class_type

A class type does not use anchored types.

Related items: Class_name.

Binary operator

Following operators can be redefined in your own class:

Binary_operator

Infix operator

Infix_operator

Related items: Binary_operator, Free_operator.

Prefix operator

Prefix_operator

Related items: Unary_operator, Free_operator.

Unary operator

Unary_operator

Writable

What we call Writable here is what can be for example on the left-hand-side of the := assignment operator. You have only 3 choices:

  • the name of one local variable of the enclosing method,
  • the Result variable used to prepare the return value of the enclosing function,
  • the name of one writable attribute of Current.

Feature name

Feature_name

Related items: Infix_operator, Prefix_operator.

Compound

Compound

Related items: Instruction.

Instruction

Instruction

Related items: Assignment, Call, Check, Create_instruction, Debug, If_then_else, Inspect, Loop, Retry.

Assignment

Assignment

Related items: Expression, Writable.

Procedure call or function call

Call

Related items: Expression, Unqualified_call.

Loop: the only construct for iterative computation

Loop

Related items: Assertion, Compound, Expression.

If then else statement

If_then_else

Related items: Assertion, Compound, Expression.

Inspect: the multi-branch selection statement

Inspect

The order in which the when branches are written does not influence the effect of an inspect instruction.

Also note that the Expression can only be of type INTEGER, CHARACTER or STRING. All used Constants must have the same type as the type of Expression. Furthermore, all constants must be statically computable in order to allow the compiler to check for disjunction of various when parts (only one Compound is ever selected).

By writing no else part at all (no keyword else used), you state that you do not expect the Expression ever to take on a value not covered by the inspect constants. If your expectations prove wrong, the effect is to trigger a run-time error when the code is compiled with appropriate options.

Related items: Expression, Compound.

Create instruction

Create_instruction

See also the Create_expression variant form.

Related items: Type, Unqualified_call, Writable.

Check list

A check instruction helps express a property that you believe will be satisfied whenever system execution reaches this instruction.

check

Related items: Assertion.

Debug only compound

The Debug instruction serves to request the conditional execution of a certain sequence of Instructions, depending on a compilation option.

Debug

Related items: Compound, Instruction.

Retry for exceptions

The retry instruction is only for exceptions purpose and the retry statement is valid only when used inside the rescue clause of some enclosing routine. The form of this instruction is just:

Retry

The effect of a the retry instruction is to restart nearly from scratch the execution of the enclosing routine. Actually, even the require assertion of the routine is re-checked. Only local variables (including Result) are not reset to the default value.

Expression

Expression

Related items: Binary_operator, Call, Current, Manifest_notation, Result, Type, Unary_operator, Writable.

Current is an expression

And this Expression denotes the Current object. The notation is simply:

Current

The Result variable

The Result variable is valid only inside the definition of some function. The notation is simply:

Result

The purpose of the Result variable is to prepare the result of the enclosing function. Actually, the Result variable behave like an ordinary local variable. Like a local variable, the Result variable is automatically initialized with the default value of the corresponding type. Using the Result variable does not makes you returns from the enclosing function: it is just like a local variable.


Manifest notation

Manifest notation includes:

  • True and False for BOOLEAN,
  • 'A', 'B', 'C', ... for CHARACTER
  • 1, 2, 3, ... for INTEGER
  • ...

See the file SmartEiffel/tutorial/manifest_notation.e to have a detailed explaination plus examples about all available notations for constants of types: BOOLEAN, CHARACTER, INTEGER, REAL, STRING and UNICODE_STRING.

Furthermore, the file , SmartEiffel/tutorial/manifest_notation.e also explain how to create explicitely objects of types ARRAY, FAST_ARRAY, LINKED_LIST, DICTIONARY, SET, etc., ...


Manifest string

Manifest_string

Create expression

Create_expression

See also the Create_instruction variant form.

Related items: Type, Unqualified_call.

Unqualified call

Unqualified_call

Where Identifier_1 is the name of the feature which is called. So Identifier_1 can be the name of some attribute only when no parenthesis are used just after Identifier_1. When parenthesis are used after Identifier_1, it must be a routine name.

The Identifier_2 used together with the $ character indicates that the address of Identifier_2 is passed to the callee. Thus, Identifier_2 can be either some local variable name or the name of some attribute of Current. This $ facility is not supposed to be used in your every day life, but for some external interface facility.

Related items: Expression.

Assertion

Assertion

Here, the Identifier is just a name given to the assertion. This optional name which is supposed to explain the Expression is printed too in case of error at run-time. The syntax to use for the Identifier is the same used for local variables, attributes or argument names: only lower case letters plus the _ underscore character.

The Expression must be of type BOOLEAN. When the Expression is replaced by a Comment (which is bad news) this Comment is considered equivalent to True. Finally, the semicolon used to separate the next Assertion can be considered as the and operator.

Related items: Comment, Expression.