Annotated King Reference Manual/Statements
This page is work in progress.
Simple and Compound Statements
[edit | edit source]Syntax
[edit | edit source]sequence_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 | edit source]-
Discussion
[edit | edit source]-
Assignment Statements
[edit | edit source]Examples
[edit | edit source]State.Seed <- Seed + 1;
Syntax
[edit | edit source]assignment_statement ::= variable_name <- expression;
Rationale
[edit | edit source]-
Discussion
[edit | edit source]-
If Statements
[edit | edit source]Examples
[edit | edit source]if Success then
Stick (ID) <- True;
Stick (Wrap.Next (ID) ) <- True;
Owner (ID) <- True;
end if;
Syntax
[edit | edit source]if_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 | edit source]-
Discussion
[edit | edit source]-
Case Statements
[edit | edit source]Examples
[edit | edit source]-
Syntax
[edit | edit source]case_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 | edit source]- 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 | edit source]-
Loop Statements
[edit | edit source]Examples
[edit | edit source]Get_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
[edit | edit source]loop_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 | edit source]-
Discussion
[edit | edit source]-
Declare Statements
[edit | edit source]Examples
[edit | edit source]-
Syntax
[edit | edit source]declare_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 | edit source]-
Discussion
[edit | edit source]-
Task Declare Statements
[edit | edit source]Examples
[edit | edit source]-
Syntax
[edit | edit source]task_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 | edit source]-
Discussion
[edit | edit source]-
Exit Statements
[edit | edit source]Examples
[edit | edit source]exit Get_Line when King.IO.Text.End_Of_Line;
Syntax
[edit | edit source]exit_statement ::= exit loop_name [when condition];
Rationale
[edit | edit source]-
Discussion
[edit | edit source]-
Wait statements
[edit | edit source]Examples
[edit | edit source]wait of 1.0;
Syntax
[edit | edit source]wait_statement ::= wait wait_mode wait_expression; wait_mode ::= for | of
Rationale
[edit | edit source]The 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 | edit source]-
Select Statements
[edit | edit source]Examples
[edit | edit source]-
Syntax
[edit | edit source]select_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
[edit | edit source]A blocking call would be a call to any subprogram of a passive task.
Discussion
[edit | edit source]-
Procedure Call Statement
[edit | edit source]Examples
[edit | edit source]Message_Queue.Put (Item => ID'Image & " waiting for podium");
King.IO.Text.Put_Line (Line => Message);
Syntax
[edit | edit source]procedure_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 | edit source]-
Discussion
[edit | edit source]-
Return Statement
[edit | edit source]Examples
[edit | edit source]return State.Seed;
Syntax
[edit | edit source]return_statement ::= return [expression] [when condition];
Rationale
[edit | edit source]-
Discussion
[edit | edit source]-
End Statement
[edit | edit source]Examples
[edit | edit source]end Task_Name;
Syntax
[edit | edit source]end_statement ::= end task_name;
Rationale
[edit | edit source]-
Discussion
[edit | edit source]-