带注释的 King 参考手册/声明
外观
此页面正在建设中。
declarative_part ::= declarative_item {declarative_item} declarative_item ::= basic_declarative_item | body basic_declarative_item ::= basic_declaration | aspect_clause basic_declaration ::= null_declaration | type_declaration | subtype_declaration | object_declaration | named_value_declaration | subprogram_declaration | statement_procedure_declaration | expression_function_declaration | module_declaration | renaming_declaration | macro_declaration | macro_expansion defining_program_unit_name ::= [parent_unit_name.] defining_identifier
在 basic_declaration 中,defining_program_unit_name 只能是标识符。
对 parent_unit_name 的提及只能出现在库级别。它在这里提供,因为某些声明适用于库级别。
-
null;
null_declaration ::= null;
-
-
参见部分 类型.
subtype Month_Number is Integer range 1 .. 12;
subtype_declaration ::= subtype defining_identifier is subtype_indication [aspect_specification]; subtype_indication ::= subtype_mark [constraint] subtype_mark ::= subtype_name
constraint ::= scalar_constraint | composite_constraint scalar_constraint ::= range_constraint range_constraint ::= range range_specification range_specification ::= range_attribute_reference | simple_expression .. simple_expression range_attribute_reference ::= prefix'range_attribute_designator range_attribute_designator ::= range composite_constraint ::= discriminant_constraint discriminant_constraint ::= (discriminant_association {, discriminant_association}) discriminant_association ::= discriminant_selector_name => expression
-
-
Owner : State_Map is State_Map'(others => False);
object_declaration ::= defining_identifier : [constant] subtype_indication [is expression] [aspect_specification];
-
-
Thinking = 10.0;
Message = "Hello, World!";
named_value_declaration ::= defining_identifier = static_expression;
-
-
Set_Seed : procedure (State : out State; Seed : in Result <- Result'Last);
Random : function (State : in out State) return Result;
subprogram_declaration ::= subprogram_specification [aspect_specification]; subprogram_specification ::= procedure_specification | function_specification procedure_specification ::= defining_program_unit_name : procedure parameter_profile function_specification ::= defining_designator : function parameter_and_result_profile defining_designator ::= defining_program_unit_name | defining_operator_symbol operator_symbol ::= string_literal parameter_profile ::= [formal_part] parameter_and_result_profile ::= [formal_part] return subtype_mark formal_part ::= (parameter_specification {; parameter_specification}) parameter_specification ::= defining_identifier : parameter_mode subtype_mark [<- default_expression] parameter_mode ::= in | in out | out
-
-
Set_Seed : procedure (Seed : in Result <- 0) is (State <- Seed);
Nothing : procedure is (null);
statement_procedure_declaration ::= simple_statement_procedure | declare_statement_procedure simple_statement_procedure ::= procedure_specification [aspect_specification] is (simple_statement); declare_statement_procedure ::= procedure_specification [aspect_specification] is (declare declare_declaration {declare_declaration} begin simple_statement); declare_declaration ::= subtype_declaration | object_declaration | named_value_declaration
内部声明的对象只能是常量声明。
-
Has_Sticks : function (ID : in Philosopher_ID) return Boolean is (Owner (ID) );
expression_function_declaration ::= function_specification [aspect_specification] is (expression);
-
-
Bad_Random : module is
type State is hidden;
type Result is range 0 .. 2 ^ 16 - 1;
Set_Seed : procedure (State : out State; Seed : in Result <- Result'Last);
Random : function (State : in out State) return Result;
Bad_Random : end module;
module_declaration ::= module_specification; module_specification ::= defining_program_unit_name : module [aspect_specification] is {basic_declarative_item} [parent_unit_name.]identifier : end module
-
-
Main_Window : constant Window_ID renames King.GUI.Main_Window;
renaming_declaration ::= object_renaming_declaration | module_renaming_declaration | subprogram_renaming_declaration | macro_renaming_declaration object_renaming_declaration ::= defining_identifier : [constant] subtype_mark renames object_name [aspect_specification]; module_renaming_declaration ::= defining_program_unit_name : module renames module_name [aspect_specification]; subprogram_renaming_declaration ::= subprogram_specification renames callable_entity_name [aspect_specification]; macro_renaming_declaration ::= defining_program_unit_name : macro module renames macro_module_name [aspect_specification];
重命名对象的子类型必须与重命名对象的子类型相同。
重命名常量对象应包含保留字 constant,而变量对象则不应包含。
使用新的名称值来重命名命名值。使用新的子类型名称来重命名子类型。
-
Bounded_Lists : macro
type Element is hidden with <-;
"=" : function (Left : in Element; Right : in Element) return Boolean is <>;
Bounded_Lists : module is
type List (Max_Length : Position_Value) is hidden with Default_Initial_Condition => List.Is_Empty;
Length : function (List : in List) return Count_Value;
Is_Empty : function (List : in List) return Boolean is (List.Length = 0);
Is_Full : function (List : in List) return Boolean is (List.Length = List.Max_Length);
-- ...
Bounded_Lists : end module;
macro_declaration ::= macro_module_declaration macro_module_declaration ::= defining_program_unit_name : macro_formal_part module_specification; macro_formal_part ::= macro macro_formal_parameter_declaration {macro_formal_parameter_declaration} macro_formal_parameter_declaration ::= formal_object_declaration | formal_type_declaration | formal_subprogram_declaration formal_object_declaration ::= defining_identifier : constant subtype_mark [<- default_expression] [aspect_specification]; formal_type_declaration ::= formal_complete_type_declaration formal_complete_type_declaration ::= type defining_identifier[discriminant_part] is formal_type_definition [or use default_subtype_mark] [aspect_specification]; formal_type_definition ::= formal_hidden_type_definition | formal_map_type_definition | formal_sequence_type_definition | formal_set_type_definition | formal_discrete_type_definition | formal_signed_integer_type_definition | formal_floating_point_definition | formal_ordinary_fixed_point_definition | formal_any_numeric_definition formal_hidden_type_definition ::= hidden [(<>)] [with <-] formal_map_type_definition ::= map_type_definition formal_sequence_type_definition ::= sequence_type_definition formal_set_type_definition ::= set_type_definition formal_discrete_type_definition ::= [range] (<>) formal_signed_integer_type_definition ::= range <> formal_floating_point_definition ::= digits <> formal_ordinary_fixed_point_definition ::= delta <> formal_any_numeric_definition ::= delta digits [range] <> formal_subprogram_declaration ::= formal_concrete_subprogram_declaration formal_concrete_subprogram_declaration ::= subprogram_specification [is subprogram_default][aspect_specification]; | statement_procedure_declaration | expression_function_declaration subprogram_default ::= default_name | <>
-
-
Wrap : module is new King.Algorithms.Wrapping (Element => Philosopher_ID);
macro_expansion ::= defining_program_unit_name : module is new macro_module_name [macro_actual_part] [aspect_specification]; macro_actual_part ::= (macro_association {, macro_association}) macro_association ::= macro_formal_parameter_selector_name => explicit_macro_actual_parameter explicit_macro_actual_parameter ::= expression | subprogram_name | subtype_mark
-
-