Difference between revisions of "Syntax diagrams"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
(typos + details about class name of formal parameter types)
m
 
(146 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
Syntax diagrams for the whole Liberty Eiffel language.
[[Category:Book]]
 
Syntax diagrams for the whole Eiffel language.
 
   
 
All items in alphabetical order:
 
All items in alphabetical order:
 
[[#Assignment|Assignment]],
 
[[#Assignment|Assignment]],
[[#Binary|Binary]],
+
[[#Assertion|Assertion]],
  +
[[#BinaryOperator|Binary_operator]],
 
[[#Call|Call]],
 
[[#Call|Call]],
  +
[[#Check|Check]],
 
[[#ClassDeclaration|Class_declaration]],
 
[[#ClassDeclaration|Class_declaration]],
 
[[#ClassName|Class_name]],
 
[[#ClassName|Class_name]],
  +
[[#ClassType|Class_type]],
 
[[#Clients|Clients]],
 
[[#Clients|Clients]],
 
[[#Comment|Comment]],
 
[[#Comment|Comment]],
 
[[#Compound|Compound]],
 
[[#Compound|Compound]],
  +
[[#CreateExpression|Create_expression]],
  +
[[#CreateInstruction|Create_instruction]],
 
[[#CreationClause|Creation_clause]],
 
[[#CreationClause|Creation_clause]],
[[#ElsePart|Else_part]],
+
[[#Current|Current]],
  +
[[#Debug|Debug]],
  +
[[#Digit|Digit]],
  +
[[#Digit_sequence|Digit_sequence]],
 
[[#EntityDeclarationList|Entity_declaration_list]],
 
[[#EntityDeclarationList|Entity_declaration_list]],
 
[[#Expression|Expression]],
 
[[#Expression|Expression]],
Line 19: Line 26:
 
[[#FeatureName|Feature_name]],
 
[[#FeatureName|Feature_name]],
 
[[#FormalGenericList|Formal_generic_list]],
 
[[#FormalGenericList|Formal_generic_list]],
  +
[[#IfThenElse|If_then_else]],
 
[[#InfixOperator|Infix_operator]],
 
[[#InfixOperator|Infix_operator]],
  +
[[#Inspect|Inspect]],
 
[[#Instruction|Instruction]],
 
[[#Instruction|Instruction]],
 
[[#Loop|Loop]],
 
[[#Loop|Loop]],
  +
[[#ManifestNotation|Manifest_notation]],
 
[[#ManifestString|Manifest_string]],
 
[[#ManifestString|Manifest_string]],
 
[[#NewExportItem|New_export_item]],
 
[[#NewExportItem|New_export_item]],
  +
[[#Notes|Notes]],
 
[[#ParentList|Parent_list]],
 
[[#ParentList|Parent_list]],
 
[[#PrefixOperator|Prefix_operator]],
 
[[#PrefixOperator|Prefix_operator]],
  +
[[#Result|Result]],
 
[[#Routine|Routine]],
 
[[#Routine|Routine]],
 
[[#RoutineBody|Routine_body]],
 
[[#RoutineBody|Routine_body]],
 
[[#Type|Type]],
 
[[#Type|Type]],
[[#Unary|Unary]],
+
[[#UnaryOperator|Unary_operator]],
 
[[#UnqualifiedCall|Unqualified_call]],
 
[[#UnqualifiedCall|Unqualified_call]],
[[#WhenPart|When_part]].
+
[[#Writable|Writable]].
   
 
<HR><BR>
 
<HR><BR>
  +
<div id="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.
  +
Note_list = Note_entry ";" [Note_list] .
  +
Note_entry = Note_name Note_values .
  +
Note_name = Identifier ":".
  +
Note_values = Note_item "," [Note_value].
  +
Note_item = Identifier | Manifest_constant.
  +
}</ebnf>
   
  +
</div>
 
<div id="Comment">
 
<div id="Comment">
  +
 
==Comment==
 
==Comment==
</div>
 
 
A comment is made of one or more line segments, each beginning with two consecutive
 
A comment is made of one or more line segments, each beginning with two consecutive
 
dash characters <TT>--</TT> and extending to the end of the line:
 
dash characters <TT>--</TT> and extending to the end of the line:
   
  +
<ebnf> "Comment" { Comment = "--" {String} {Newline}.}</ebnf>
[[Image:SyntaxDiagramOf_Comment.png|Comment]]
 
   
 
Inside the comment, the convention to denote Eiffel entities (i.e. variables,
 
Inside the comment, the convention to denote Eiffel entities (i.e. variables,
Line 50: Line 73:
 
as well to use a different character font or color to emphasize the fact that
 
as well to use a different character font or color to emphasize the fact that
 
<TT>my_variable</TT> refers to some existing entity of the Eiffel code.
 
<TT>my_variable</TT> refers to some existing entity of the Eiffel code.
  +
Previous convention must not be used for [[#Class_name|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
 
Also note that an URL inside the comment is also made automatically clickable
Line 58: Line 84:
 
As an example, the following comment displayed by Eiffeldoc would
 
As an example, the following comment displayed by Eiffeldoc would
 
bring you back here :
 
bring you back here :
-- See also http://smarteiffel.loria.fr/wiki/en/index.php/Syntax_diagrams#Comment
+
-- See also http://wiki.liberty-eiffel.org/index.php/Syntax_diagrams#Comment
 
 
<div id="ClassDeclaration">
 
<div id="ClassDeclaration">
   
Line 75: Line 100:
 
[[#Parent_list|Parent_list]].
 
[[#Parent_list|Parent_list]].
   
<div id="ParentList">
+
<div id="FormalGenericList">
  +
==Formal generic list==
  +
</div>
  +
[[Image:SyntaxDiagramOf_Formal_generic_list.png|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 [[#ClassName|Class_name]]).
  +
The ''Class_type'' part, when used, is the generic constraint.
  +
  +
'''Related items''': [[#ClassType|Class_type]], [[#Identifier|Identifier]].
  +
  +
<div id="ParentList">
 
==Parent list==
 
==Parent list==
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Parent_list.png|Parent_list]]
 
[[Image:SyntaxDiagramOf_Parent_list.png|Parent_list]]
  +
  +
'''Related items''': [[#FeatureName|Feature_name]], [[#NewExportItem|New_export_item]].
   
 
<div id="NewExportItem">
 
<div id="NewExportItem">
Line 85: Line 123:
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_New_export_item.png|New_export_item]]
 
[[Image:SyntaxDiagramOf_New_export_item.png|New_export_item]]
  +
  +
'''Related items''': [[#ClassName|Class_name]].
   
 
<div id="CreationClause">
 
<div id="CreationClause">
Line 90: Line 130:
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Creation_clause.png|Creation_clause]]
 
[[Image:SyntaxDiagramOf_Creation_clause.png|Creation_clause]]
  +
  +
'''Related items''': [[#FeatureName|Feature_name]], [[#Comment|Comment]].
   
 
<div id="FeatureClause">
 
<div id="FeatureClause">
Line 95: Line 137:
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Feature_clause.png|Feature_clause]]
 
[[Image:SyntaxDiagramOf_Feature_clause.png|Feature_clause]]
  +
  +
'''Related items''': [[#Clients|Clients]], [[#Comment|Comment]], [[#FeatureDeclaration|Feature_declaration]].
   
 
<div id="Clients">
 
<div id="Clients">
Line 100: Line 144:
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Clients.png|Clients]]
 
[[Image:SyntaxDiagramOf_Clients.png|Clients]]
  +
  +
'''Related items''': [[#ClassName|Class_name]].
   
 
<div id="FeatureDeclaration">
 
<div id="FeatureDeclaration">
 
==Feature declaration==
 
==Feature declaration==
 
</div>
 
</div>
  +
'is' is now optional, and the choice after 'is' now could include 'attribute' diagram requires update...
 
[[Image:SyntaxDiagramOf_Feature_declaration.png|Feature_declaration]]
 
[[Image:SyntaxDiagramOf_Feature_declaration.png|Feature_declaration]]
  +
  +
Where the ''Manifest_constant'' can only be selected in the following set:
  +
<TT>{</TT>
  +
<TT>BOOLEAN</TT>,
  +
<TT>CHARACTER</TT>,
  +
<TT>INTEGER_8</TT>,
  +
<TT>INTEGER_16</TT>,
  +
<TT>INTEGER_32</TT>,
  +
<TT>INTEGER</TT>,
  +
<TT>INTEGER_64</TT>,
  +
<TT>REAL_32</TT>,
  +
<TT>REAL_64</TT>,
  +
<TT>REAL</TT>,
  +
<TT>REAL_80</TT>,
  +
<TT>REAL_128</TT>,
  +
<TT>REAL_EXTENDED</TT>,
  +
<TT>STRING</TT>,
  +
<TT>UNICODE_STRING</TT>
  +
<TT>}</TT>.
  +
See the file <TT>SmartEiffel/tutorial/manifest_notation.e</TT> to have a
  +
detailed explaination plus examples about all available notations for
  +
constants.
  +
  +
'''Related items''': [[#EntityDeclarationList|Entity_declaration_list]], [[#FeatureName|Feature_name]], [[#Routine|Routine]],
  +
[[#Type|Type]].
   
 
<div id="Routine">
 
<div id="Routine">
  +
 
==Routine==
 
==Routine==
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Routine.png|Routine]]
 
[[Image:SyntaxDiagramOf_Routine.png|Routine]]
  +
  +
'''Related items''': [[#Assertion|Assertion]], [[#Compound|Compound]], [[#EntityDeclarationList|Entity_declaration_list]],
  +
[[#FeatureName|Feature_name]], [[#ManifestString|Manifest_string]].
  +
  +
<div id="RoutineBody">
  +
==Routine body==
  +
</div>
  +
<ebnf> "Routine body" {
  +
Routine_body = ( "deferred" | "do" compound | "once" compound |
  +
"external_string" Manifest_string "Alias" Manifest_string ).
  +
}</ebnf>
  +
  +
'''Related items''': [[#Compound|Compound]], [[#ManifestString|Manifest_string]].
   
 
<div id="EntityDeclarationList">
 
<div id="EntityDeclarationList">
  +
 
==Entity declaration list==
 
==Entity declaration list==
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Entity_declaration_list.png|Entity_declaration_list]]
 
[[Image:SyntaxDiagramOf_Entity_declaration_list.png|Entity_declaration_list]]
   
  +
This notation is used for local variable list declaration as well
<div id="Class_name">
 
  +
as for formal argument list of routines.
==Class name==
 
  +
  +
'''Related items''': [[#Identifier|Identifier]], [[#Type|Type]].
  +
  +
<div id="Type">
  +
  +
==Type==
  +
</div>
  +
[[Image:SyntaxDiagramOf_Type.png|Type]]
  +
  +
'''Related items''': [[#ClassType|Class_type]], [[#FormalGenericName|Formal_generic_name]], [[#Identifier|Identifier]].
  +
  +
<div id="ClassName">
  +
===Class name===
 
</div>
 
</div>
 
A class name must use '''only upper case letters''' plus the '_' underscore character.
 
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
 
A class name must start with a letter, an upper case letter as all other letters used in
 
that name.
 
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 <TT>O_</TT> as a formal parameter type of a generic type).
+
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 <TT>O_</TT> as a formal parameter type of a generic type).
 
Some examples of valid class names:
 
Some examples of valid class names:
 
<TT>ARRAY</TT>,
 
<TT>ARRAY</TT>,
Line 128: Line 228:
 
<TT>LINKED_LIST</TT>.
 
<TT>LINKED_LIST</TT>.
   
<div id="Type">
+
<div id="ClassType">
   
==Type==
+
===Class type===
 
</div>
 
</div>
[[Image:SyntaxDiagramOf_Type.png|Type]]
+
[[Image:SyntaxDiagramOf_Class_type.png|Class_type]]
   
  +
A class type does not use anchored types.
<div id="Binary">
 
==Binary==
 
</div>
 
[[Image:SyntaxDiagramOf_Binary.png|Binary]]
 
   
  +
'''Related items''': [[#ClassName|Class_name]].
   
<div id="Instruction">
+
<div id="BinaryOperator">
  +
==Instruction==
 
  +
==Digit==
  +
<ebnf> "Digit" {
  +
Digit = ("0"|"1"|"..."|"9"|"a"|"b"|"..."|"f"|"A"|"B"|"..."|"F"|"_" ). }
  +
</ebnf>
  +
  +
==Digit_sequence==
  +
<ebnf> "Digit_sequence" {
  +
Digit_sequence = Digit {Digit}.
  +
}
  +
</ebnf>
  +
  +
==Binary operator==
 
</div>
 
</div>
  +
Following operators can be redefined in your own class:
[[Image:SyntaxDiagramOf_Instruction.png|Instruction]]
 
  +
  +
<ebnf> "Binary operator" {
  +
Binary_operator = (("+"|"-"|"*"|"/"|"//"|"\\")|
  +
("<"|">"|"<="|">=")|
  +
("and"|"or"|"xor")|
  +
("and then"|"or else"|"implies")).}</ebnf>
   
   
 
<div id="InfixOperator">
 
<div id="InfixOperator">
  +
 
==Infix operator==
 
==Infix operator==
 
</div>
 
</div>
  +
<ebnf> "Infix operator" {
[[Image:SyntaxDiagramOf_Infix_operator.png|Infix_operator]]
 
  +
Infix_operator = (Binary_operator|Free_operator).}</ebnf>
  +
  +
'''Related items''': [[#BinaryOperator|Binary_operator]], [[#FreeOperator|Free_operator]].
   
   
 
<div id="PrefixOperator">
 
<div id="PrefixOperator">
  +
 
==Prefix operator==
 
==Prefix operator==
 
</div>
 
</div>
  +
<ebnf> "Prefix operator" {
[[Image:SyntaxDiagramOf_Prefix_operator.png|Prefix_operator]]
 
  +
Prefix_operator = (Unary_operator|Free_operator).}</ebnf>
  +
  +
'''Related items''': [[#UnaryOperator|Unary_operator]], [[#FreeOperator|Free_operator]].
  +
   
  +
<div id="UnaryOperator">
   
<div id="Unary">
+
==Unary operator==
==Unary==
 
 
</div>
 
</div>
  +
[[Image:SyntaxDiagramOf_Unary.png|Unary]]
 
  +
<ebnf> "Unary operator" {
  +
Unary_operator = ("+"|"-"|"not").}</ebnf>
  +
  +
  +
  +
<div id="FreeOperator">
  +
  +
==Free operator==
  +
<ebnf>
  +
"Free_Operator" { Free_Operator = ( "+" | "-" | "*" | "/" | "\" | "=" |
  +
"<" | ">" | "@" | "#" | "|" |"&" | "~") { Free_Operator }.}
  +
</ebnf>
  +
  +
==Writable==
  +
</div>
  +
What we call ''Writable'' here is what can be for example on
  +
the left-hand-side of the <TT>:=</TT> assignment operator.
  +
You have only 3 choices:
  +
* the name of one local variable of the enclosing [[Glossary#Method|method]],
  +
* the <TT>Result</TT> variable used to prepare the return value of the enclosing [[Glossary#Function|function]],
  +
* the name of one writable [[Glossary#attribute|attribute]] of [[Current]].
  +
  +
<div id="FeatureName">
  +
==Feature name==
  +
</div>
  +
[[Image:SyntaxDiagramOf_Feature_name.png|Feature_name]]
  +
  +
'''Related items''': [[#InfixOperator|Infix_operator]], [[#PrefixOperator|Prefix_operator]].
   
 
<div id="Compound">
 
<div id="Compound">
Line 167: Line 320:
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Compound.png|Compound]]
 
[[Image:SyntaxDiagramOf_Compound.png|Compound]]
  +
  +
'''Related items''': [[#Instruction|Instruction]].
  +
  +
<div id="Instruction">
  +
  +
==Instruction==
  +
</div>
  +
[[Image:SyntaxDiagramOf_Instruction.png|Instruction]]
  +
  +
'''Related items''':
  +
[[#Assignment|Assignment]],
  +
[[#Call|Call]],
  +
[[#Check|Check]],
  +
[[#Create_instruction|Create_instruction]],
  +
[[#Debug|Debug]],
  +
[[#IfThenElse|If_then_else]],
  +
[[#Inspect|Inspect]],
  +
[[#Loop|Loop]],
  +
[[#Retry|Retry]].
   
 
<div id="Assignment">
 
<div id="Assignment">
==Assignment==
+
===Assignment===
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Assignment.png|Assignment]]
 
[[Image:SyntaxDiagramOf_Assignment.png|Assignment]]
   
  +
'''Related items''': [[#Expression|Expression]], [[#Writable|Writable]].
<div id="WhenPart">
 
  +
==When part==
 
  +
<div id="Call">
  +
===Procedure call or function call===
 
</div>
 
</div>
[[Image:SyntaxDiagramOf_When_part.png|When_part]]
+
[[Image:SyntaxDiagramOf_Call.png|Call]]
   
  +
'''Related items''': [[#Expression|Expression]], [[#UnqualifiedCall|Unqualified_call]].
<div id="ElsePart">
 
  +
==Else part==
 
  +
<div id="Loop">
  +
===Loop: the only construct for iterative computation===
 
</div>
 
</div>
[[Image:SyntaxDiagramOf_Else_part.png|Else_part]]
+
[[Image:SyntaxDiagramOf_Loop.png|Loop]]
   
  +
'''Related items''':
<div id="FormalGenericList">
 
  +
[[#Assertion|Assertion]],
==Formal generic list==
 
  +
[[#Compound|Compound]],
  +
[[#Expression|Expression]].
  +
  +
<div id="IfThenElse">
  +
===If then else statement===
 
</div>
 
</div>
[[Image:SyntaxDiagramOf_Formal_generic_list.png|Formal_generic_list]]
+
[[Image:SyntaxDiagramOf_If_then_else.png|If_then_else]]
   
  +
'''Related items''':
<div id="FeatureName">
 
  +
[[#Assertion|Assertion]],
==Feature name==
 
  +
[[#Compound|Compound]],
  +
[[#Expression|Expression]].
  +
  +
<div id="Inspect">
  +
  +
===Inspect: the multi-branch selection statement===
 
</div>
 
</div>
[[Image:SyntaxDiagramOf_Feature_name.png|Feature_name]]
+
[[Image:SyntaxDiagramOf_Inspect.png|Inspect]]
   
  +
The order in which the <TT>when</TT> branches are written does not influence
<div id="RoutineBody">
 
  +
the effect of an <TT>inspect</TT> instruction.
==Routine body==
 
  +
  +
Also note that the ''Expression'' can only be of type
  +
<TT>INTEGER</TT>, <TT>CHARACTER</TT> or <TT>STRING</TT>.
  +
All used ''Constant''s 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 <TT>when</TT> parts (only one
  +
''Compound'' is ever selected).
  +
  +
By writing no <TT>else</TT> part at all (no keyword <TT>else</TT> 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|Expression]],
  +
[[#Compound|Compound]].
  +
  +
<div id="CreateInstruction">
  +
  +
===Create instruction===
  +
</div><ebnf> "Create_Instruction" {
  +
Create_Instruction = create ["{"Type"}"] writable ["." Unqualified_call].
  +
}
  +
</ebnf>
  +
  +
See also the [[#CreateExpression|Create_expression]] variant form.
  +
  +
'''Related items''': [[#Type|Type]], [[#UnqualifiedCall|Unqualified_call]], [[#Writable|Writable]].
  +
  +
<div id="Check">
  +
  +
===Check list===
 
</div>
 
</div>
  +
A <TT>check</TT> instruction helps express a property that you believe will be satisfied
[[Image:SyntaxDiagramOf_Routine_body.png|Routine_body]]
 
  +
whenever system execution reaches this instruction.
   
<div id="Call">
+
<ebnf> "Check" {
  +
Check = "check" Assertion "end".
==Call==
 
  +
}
  +
</ebnf>
  +
  +
'''Related items''': [[#Assertion|Assertion]].
  +
  +
<div id="Debug">
  +
  +
===Debug only compound===
 
</div>
 
</div>
  +
The <TT>Debug</TT> instruction serves to request the conditional execution of a certain
[[Image:SyntaxDiagramOf_Call.png|Call]]
 
  +
sequence of [[#Instruction|Instructions]], depending on a compilation option.
   
  +
[[Image:SyntaxDiagramOf_Debug.png|Debug]]
<div id="Loop">
 
  +
==Loop==
 
  +
'''Related items''':
  +
[[#Compound|Compound]],
  +
[[#Instruction|Instruction]].
  +
  +
<div id="Retry">
  +
===Retry for exceptions===
 
</div>
 
</div>
  +
The <TT>retry</TT> instruction is only for exceptions purpose and
[[Image:SyntaxDiagramOf_Loop.png|Loop]]
 
  +
the <TT>retry</TT> statement is valid only when used inside the rescue clause
  +
of some enclosing [[Glossary#Routine|routine]].
  +
The form of this instruction is just:
  +
  +
<ebnf> "Retry" {Retry = "retry".}</ebnf>
  +
  +
  +
The effect of a the <TT>retry</TT> instruction is to restart ''nearly from scratch''
  +
the execution of the enclosing [[Glossary#Routine|routine]].
  +
Actually, even the require assertion of the routine is re-checked.
  +
Only local variables (including <TT>Result</TT>) are not reset to the default value.
   
 
<div id="Expression">
 
<div id="Expression">
  +
 
==Expression==
 
==Expression==
 
</div>
 
</div>
  +
 
[[Image:SyntaxDiagramOf_Expression.png|Expression]]
 
[[Image:SyntaxDiagramOf_Expression.png|Expression]]
   
  +
'''Related items''':
<div id="ManifestString">
 
  +
[[#BinaryOperator|Binary_operator]],
==Manifest string==
 
  +
[[#Call|Call]],
  +
[[#Current|Current]],
  +
[[#ManifestNotation|Manifest_notation]],
  +
[[#Result|Result]],
  +
[[#Type|Type]],
  +
[[#UnaryOperator|Unary_operator]],
  +
[[#Writable|Writable]].
  +
  +
<div id="Current">
  +
===Current is an expression===
 
</div>
 
</div>
  +
And this ''Expression'' denotes the [[Current|<TT>Current</TT>]] object.
[[Image:SyntaxDiagramOf_Manifest_string.png|Manifest_string]]
 
  +
The notation is simply:
  +
  +
<ebnf> "Current" { Current = "current". } </ebnf>
  +
  +
  +
<div id="Result">
  +
  +
===The Result variable===
  +
</div>
  +
The <TT>Result</TT> variable is valid only inside the definition of some
  +
[[Glossary#Function|function]]. The notation is simply:
  +
  +
<ebnf> "Result" { Result = "result". }</ebnf>
  +
  +
  +
The purpose of the <TT>Result</TT> variable is to prepare the result of the
  +
enclosing function.
  +
Actually, the <TT>Result</TT> variable behave like an ordinary local variable.
  +
Like a local variable, the <TT>Result</TT> variable is automatically initialized
  +
with the default value of the corresponding type.
  +
Using the <TT>Result</TT> variable does not makes you returns from the enclosing
  +
function: it is just like a local variable.
  +
  +
  +
<div id="ManifestNotation">
  +
  +
===Manifest notation===
  +
</div>
  +
Manifest notation includes:
  +
* <TT>True</TT> and <TT>False</TT> for <TT>BOOLEAN</TT>,
  +
* <TT>'A'</TT>, <TT>'B'</TT>, <TT>'C'</TT>, ... for <TT>CHARACTER</TT>
  +
* <TT>1</TT>, <TT>2</TT>, <TT>3</TT>, ... for <TT>INTEGER</TT>
  +
* ...
  +
  +
See the file <TT>SmartEiffel/tutorial/manifest_notation.e</TT> to have a
  +
detailed explaination plus examples about all available notations for
  +
constants of types:
  +
<TT>BOOLEAN</TT>,
  +
<TT>CHARACTER</TT>,
  +
<TT>INTEGER</TT>,
  +
<TT>REAL</TT>,
  +
<TT>STRING</TT>
  +
and
  +
<TT>UNICODE_STRING</TT>.
  +
  +
Furthermore, the file ,
  +
<TT>SmartEiffel/tutorial/manifest_notation.e</TT>
  +
also explain how to create explicitely objects of types
  +
<TT>ARRAY</TT>,
  +
<TT>FAST_ARRAY</TT>,
  +
<TT>LINKED_LIST</TT>,
  +
<TT>DICTIONARY</TT>,
  +
<TT>SET</TT>,
  +
etc., ...
  +
  +
  +
<div id="ManifestString">
  +
  +
===Manifest string===
  +
<ebnf> "Manifest string" { Manifest_string = '"' string '"' . } </ebnf>
  +
  +
===Create expression===
  +
<ebnf> "Create expression" {
  +
Create_expression = create "{" type "}" [ "." Unqualified_call ].
  +
}
  +
</ebnf>
  +
  +
See also the [[#CreateInstruction|Create_instruction]] variant form.
  +
  +
'''Related items''': [[#Type|Type]], [[#UnqualifiedCall|Unqualified_call]].
   
 
<div id="UnqualifiedCall">
 
<div id="UnqualifiedCall">
  +
 
==Unqualified call==
 
==Unqualified call==
 
</div>
 
</div>
 
[[Image:SyntaxDiagramOf_Unqualified_call.png|Unqualified_call]]
 
[[Image:SyntaxDiagramOf_Unqualified_call.png|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
  +
[[Glossary#Routine|routine]] name.
  +
  +
The ''Identifier_2'' used together with the <TT>$</TT> 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 <TT>$</TT> facility is not supposed to be used in your every day life, but for some
  +
external interface facility.
  +
  +
'''Related items''': [[#Expression|Expression]].
  +
  +
<div id="Assertion">
  +
==Assertion==
  +
</div>
  +
[[Image:SyntaxDiagramOf_Assertion.png|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 <TT>_</TT> underscore
  +
character.
  +
  +
The ''Expression'' must be of type <TT>BOOLEAN</TT>.
  +
When the ''Expression'' is replaced by a ''Comment'' (which is bad news) this
  +
''Comment'' is considered equivalent to <TT>True</TT>.
  +
Finally, the semicolon used to separate the next ''Assertion''
  +
can be considered as the <TT>and</TT> operator.
  +
  +
'''Related items''': [[#Comment|Comment]], [[#Expression|Expression]].

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.