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