Annotated King Reference Manual/Statements
This page is work in progress.
Simple and Compound Statements
editSyntax
editsequence_of_statements ::= statement {statement} statement ::= simple_statement | compound_statement simple_statement ::= null_statement | assignment_statement | exit_statement | procedure_call_statement | wait_statement | return_statement | end_statement compound_statement ::= if_statement | case_statement | loop_statement | declare_statement | task_declare_statement | select_statement null_statement ::= null; statement_identifier ::= direct_name
Rationale
edit-
Discussion
edit-
Assignment Statements
editExamples
editState.Seed <- Seed + 1;
Syntax
editassignment_statement ::= variable_name <- expression;
Rationale
edit-
Discussion
edit-
If Statements
editExamples
editif Success then
Stick (ID) <- True;
Stick (Wrap.Next (ID) ) <- True;
Owner (ID) <- True;
end if;
Syntax
editif_statement ::= simple_if_statement | extended_if_statement
simple_if_statement ::= if condition then sequence_of_statements [else sequence_of_statements] end if; extended_if_statement ::= if condition then sequence_of_statements else_if condition then sequence_of_statements {else_if condition then sequence_of_statements} else sequence_of_statements end if; condition ::= boolean_expression
Rationale
edit-
Discussion
edit-
Case Statements
editExamples
edit-
Syntax
editcase_statement ::= normal_case_statement | exception_handling_case_statement
normal_case_statement ::= case selecting_expression is normal_case_statement_alternative {normal_case_statement_alternative} end case; normal_case_statement_alternative ::= when discrete_choice_list => sequence_of_statements
exception_handling_case_statement ::= case exception_identifier is exception_handling_case_statement_alternative {exception_handling_case_statement_alternative} end case; exception_handling_case_statement_alternative ::= when exception_occurrence_list => sequence_of_statements
Rationale
edit- Normal case statements may appear in any sequence of statements. Exception-handling case statements may only appear in an exception handler.
The exception_identifier must be the identifier following when of the enclosing exception handler.
Discussion
edit-
Loop Statements
editExamples
editGet_Line : loop
exit Get_Line when King.IO.Text.End_Of_Line;
Value <- Value & King.IO.Text.Next'As_Universal;
Get_Line : end loop;
Syntax
editloop_statement ::= loop_statement_identifier : [iteration_scheme] loop sequence_of_statements loop_identifier : end loop; iteration_scheme ::= for loop_parameter_specification | for loop_parameter_specification_no_reverse task | for iterator_specification [task] loop_parameter_specification ::= defining_identifier in [reverse] discrete_subtype_definition [iterator_filter] loop_parameter_specification_no_reverse ::= defining_identifier in discrete_subtype_definition [iterator_filter] discrete_subtype_definition ::= discrete_subtype_indication | range_specification iterator_specification ::= defining_identifier of iterable_name [iterator_filter] iterator_filter ::= when condition
Rationale
edit-
Discussion
edit-
Declare Statements
editExamples
edit-
Syntax
editdeclare_statement ::= declare_statement_identifier: declare declarative_part declare_identifier : begin sequence_of_statements declare_identifier : when identifier => sequence_of_statements declare_identifier : end declare;
Rationale
edit-
Discussion
edit-
Task Declare Statements
editExamples
edit-
Syntax
edittask_declare_statement ::= task_declare_statement_identifier : task declare declarative_part task_declare_identifier : begin sequence_of_statements task_declare_identifier : and sequence_of_statements {task_declare_identifier : and sequence_of_statements} task_declare_identifier : end task declare;
Rationale
edit-
Discussion
edit-
Exit Statements
editExamples
editexit Get_Line when King.IO.Text.End_Of_Line;
Syntax
editexit_statement ::= exit loop_name [when condition];
Rationale
edit-
Discussion
edit-
Wait statements
editExamples
editwait of 1.0;
Syntax
editwait_statement ::= wait wait_mode wait_expression; wait_mode ::= for | of
Rationale
editThe wait of statement is for a relative amount of time, and blocks the task for the number of seconds given. It can be read as, "Perform a wait of this many seconds." The wait for statement takes a Duration value and blocks the task until that time arrives, unless it is in the past. It can be read as, "Wait for this time to arrive." The duration is the number of seconds since the epoch, which is not defined, but meaningful values can be constructed using the standard library.
Discussion
edit-
Select Statements
editExamples
edit-
Syntax
editselect_statement ::= select_statement_identifier : select blocking_call [sequence_of_statements] {select_identifier : or blocking_call [sequence_of_statements]} select_identifier : or wait_statement [sequence_of_statements] select_identifier : end select; blocking_call ::= assignment_statement | procedure_call_statement
Rationale
editA blocking call would be a call to any subprogram of a passive task.
Discussion
edit-
Procedure Call Statement
editExamples
editMessage_Queue.Put (Item => ID'Image & " waiting for podium");
King.IO.Text.Put_Line (Line => Message);
Syntax
editprocedure_call_statement ::= procedure_prefix [actual_parameter_part]; actual_parameter_part ::= (parameter_association {, parameter_association}) parameter_association ::= formal_parameter_selector_name => explicit_actual_parameter explicit_actual_parameter ::= expression | variable_name
Rationale
edit-
Discussion
edit-
Return Statement
editExamples
editreturn State.Seed;
Syntax
editreturn_statement ::= return [expression] [when condition];
Rationale
edit-
Discussion
edit-
End Statement
editExamples
editend Task_Name;
Syntax
editend_statement ::= end task_name;
Rationale
edit-
Discussion
edit-