Difference between revisions of "Syntax diagrams"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
m
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Syntax diagrams for the whole LibertyEiffel language.
+
Syntax diagrams for the whole Liberty Eiffel language.
   
 
All items in alphabetical order:
 
All items in alphabetical order:
Line 48: Line 48:
 
<div id="Notes">
 
<div id="Notes">
 
==Notes==
 
==Notes==
  +
A Notes section might be used at the beginning and end of a file to define notes on a class (e. g. for documentation, version management, license information, etc.). They have no influence on the execution semantics.
<ebnf> "Notes" { Notes = "note" Note_list.
 
  +
<ebnf> "Notes" {Notes = "note" Note_list.
 
Note_list = Note_entry ";" [Note_list] .
 
Note_list = Note_entry ";" [Note_list] .
 
Note_entry = Note_name Note_values .
 
Note_entry = Note_name Note_values .
Line 390: Line 391:
   
 
By writing no <TT>else</TT> part at all (no keyword <TT>else</TT> used),
 
By writing no <TT>else</TT> part at all (no keyword <TT>else</TT> used),
you state that ''Expression'' doe NEVER take a value not covered by the inspect constants.
+
you state that ''Expression'' does NEVER take a value not covered by the inspect constants.
 
If your expectations prove wrong, the effect is to trigger a run-time error
 
If your expectations prove wrong, the effect is to trigger a run-time error
when the code is compiled with appropriate options, in boost mode the behavior is unspecified. Therefore it is suggested to always write an else clause as defensive programming.
+
when the code is compiled with appropriate options, in boost mode the behavior is unspecified. Therefore, it is suggested to always write an else clause as defensive programming.
   
 
'''Related items''':
 
'''Related items''':

Latest revision as of 19:43, 28 February 2022

Syntax diagrams for the whole Liberty 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, Digit, Digit_sequence, 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, Notes, Parent_list, Prefix_operator, Result, Routine, Routine_body, Type, Unary_operator, Unqualified_call, Writable.



Comment

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" { Comment =  "--" {String} {Newline}.}
+%22Comment%22+%7B+Comment+%3D+%22--%22+%7BString%7D+%7BNewline%7D.%7D

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://wiki.liberty-eiffel.org/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

'is' is now optional, and the choice after 'is' now could include 'attribute' diagram requires update...

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" {
   Routine_body  =  ( "deferred" | "do" compound | "once" compound | 
                      "external_string" Manifest_string "Alias" Manifest_string ).
}
+%22Routine+body%22+%7B+Routine_body+%3D+%28+%22deferred%22+%7C+%22do%22+compound+%7C+%22once%22+compound+%7C+%22external_string%22+Manifest_string+%22Alias%22+Manifest_string+%29.+%7D

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 convention is to not use two consecutive '_' underscore characters, nor to end a class name 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.

Digit

 "Digit" {
Digit = ("0"|"1"|"..."|"9"|"a"|"b"|"..."|"f"|"A"|"B"|"..."|"F"|"_" ). }
+%22Digit%22+%7B+Digit+%3D+%28%220%22%7C%221%22%7C%22...%22%7C%229%22%7C%22a%22%7C%22b%22%7C%22...%22%7C%22f%22%7C%22A%22%7C%22B%22%7C%22...%22%7C%22F%22%7C%22_%22+%29.+%7D+

Digit_sequence

 "Digit_sequence" {
Digit_sequence = Digit {Digit}.
}
+%22Digit_sequence%22+%7B+Digit_sequence+%3D+Digit+%7BDigit%7D.+%7D+

Binary operator

Following operators can be redefined in your own class:

 "Binary operator" {
   Binary_operator = (("+"|"-"|"*"|"/"|"//"|"\\")| 
                      ("<"|">"|"<="|">=")|
                      ("and"|"or"|"xor")| 
                      ("and then"|"or else"|"implies")).}
+%22Binary+operator%22+%7B+Binary_operator+%3D+%28%28%22%2B%22%7C%22-%22%7C%22%2A%22%7C%22%2F%22%7C%22%2F%2F%22%7C%22%5C%5C%22%29%7C+%28%22%3C%22%7C%22%3E%22%7C%22%3C%3D%22%7C%22%3E%3D%22%29%7C+%28%22and%22%7C%22or%22%7C%22xor%22%29%7C+%28%22and+then%22%7C%22or+else%22%7C%22implies%22%29%29.%7D


Infix operator

 "Infix operator" {
   Infix_operator = (Binary_operator|Free_operator).}
+%22Infix+operator%22+%7B+Infix_operator+%3D+%28Binary_operator%7CFree_operator%29.%7D

Related items: Binary_operator, Free_operator.


Prefix operator

 "Prefix operator" {
   Prefix_operator = (Unary_operator|Free_operator).}
+%22Prefix+operator%22+%7B+Prefix_operator+%3D+%28Unary_operator%7CFree_operator%29.%7D

Related items: Unary_operator, Free_operator.


Unary operator

 "Unary operator" {
   Unary_operator = ("+"|"-"|"not").}
+%22Unary+operator%22+%7B+Unary_operator+%3D+%28%22%2B%22%7C%22-%22%7C%22not%22%29.%7D


Free operator

"Free_Operator"  { Free_Operator = ( "+" | "-" | "*" | "/" | "\" | "=" |
                   "<" | ">" | "@" | "#" | "|" |"&" | "~") { Free_Operator }.}
+%22Free_Operator%22+%7B+Free_Operator+%3D+%28+%22%2B%22+%7C+%22-%22+%7C+%22%2A%22+%7C+%22%2F%22+%7C+%22%5C%22+%7C+%22%3D%22+%7C+%22%3C%22+%7C+%22%3E%22+%7C+%22%40%22+%7C+%22%23%22+%7C+%22%7C%22+%7C%22%26%22+%7C+%22%7E%22%29+%7B+Free_Operator+%7D.%7D+

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 Expression does NEVER take 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, in boost mode the behavior is unspecified. Therefore, it is suggested to always write an else clause as defensive programming.

Related items: Expression, Compound.

Create instruction

 "Create_Instruction" {
Create_Instruction = create ["{"Type"}"] writable ["." Unqualified_call].
}
+%22Create_Instruction%22+%7B+Create_Instruction+%3D+create+%5B%22%7B%22Type%22%7D%22%5D+writable+%5B%22.%22+Unqualified_call%5D.+%7D+

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" {
Check = "check" Assertion "end".
}
+%22Check%22+%7B+Check+%3D+%22check%22+Assertion+%22end%22.+%7D+

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" {Retry = "retry".}
+%22Retry%22+%7BRetry+%3D+%22retry%22.%7D


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" { Current = "current". } 
+%22Current%22+%7B+Current+%3D+%22current%22.+%7D+


The Result variable

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

 "Result" { Result = "result". }
+%22Result%22+%7B+Result+%3D+%22result%22.+%7D


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" { Manifest_string = '"' string '"' . } 
+%22Manifest+string%22+%7B+Manifest_string+%3D+%27%22%27+string+%27%22%27+.+%7D+

Create expression

 "Create expression" {
     Create_expression =  create "{" type "}"  [ "." Unqualified_call ].
}
+%22Create+expression%22+%7B+Create_expression+%3D+create+%22%7B%22+type+%22%7D%22+%5B+%22.%22+Unqualified_call+%5D.+%7D+

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.