Annotated King Reference Manual/Expressions

This page is work in progress.

Examples
-

Syntax
name ::= direct_name | indexed_component    | slice | selected_component   | attribute_reference | type_conversion       | function_call | character_literal     | qualified_expression direct_name ::= identifier | operator_symbol prefix ::= name

Rationale
-

Discussion
-

Examples
-

Syntax
indexed_component ::= sequence_component | map_component sequence_component ::= prefix [expression] map_component ::= prefix (expression)

Rationale
-

Discussion
-

Examples
-

Syntax
slice ::= prefix [discrete_range] discrete_range ::= discrete_subtype_indication | range_specification

Rationale
-

Discussion
-

Examples
-

Syntax
selected_component ::= prefix . selector_name selector_name ::= identifier | character_literal | operator_symbol

Rationale
-

Discussion
-

Examples
-

Syntax
attribute_reference ::= prefix 'attribute_designator attribute_designator ::= identifier [actual_parameter_part] | delta | digits range_attribute_reference ::= prefix 'range_attribute_designator range_attribute_designator ::= range

Rationale
-

Discussion
Attribute functions can have multiple arguments, which need not be static. Consider 'Image for numeric types, with such parameters as Width, Base, ...

-> I was wondering also about Ada. I guess that attribute functions are deferencing just by the identifier as a function name and then the function signature applies. (PP)

It should probably be

identifier [actual_parameter_part]

Changed. (PP)

Examples
-

Syntax
aggregate ::= record_aggregate | map_aggregate | sequence_aggregate | set_aggregate

Rationale
-

Discussion
-

Examples
-

Syntax
record_aggregate ::= record_subtype_mark '(record_component_association_list) record_component_association_list ::= record_component_association {, record_component_association} | null record_component_association ::= component_choice_list => expression | component_choice_list => <> component_choice_list ::= component_selector_name {| component_selector_name} | others

Rationale
-

Discussion
-

Examples
-

Syntax
map_aggregate ::= map_subtype_mark '(null_map_aggregate | named_map_aggregate) null_map_aggregate ::= null named_map_aggregate ::= map_element_association_list map_element_association_list ::= map_element_association {, map_element_association} map_element_association ::= key_choice_list => expression | key_choice_list => <> | iterated_element_association key_choice_list ::= key_choice {| key_choice} key_choice ::= key_expression | discrete_range iterated_element_association ::= for loop_parameter_specification[ use key_expression] => expression | for iterator_specification[ use key_expression] => expression

Rationale
-

Discussion
-

Examples
-

Syntax
sequence_aggregate ::= sequence_subtype_mark '[ positional_sequence_aggregate [named_sequence_aggregate] | null_sequence_aggregate | named_sequence_aggregate ] positional_sequence_aggregate ::= expression {, expression} null_sequence_aggregate ::= null named_sequence_aggregate ::= sequence_component_association_list sequence_component_association_list ::= sequence_component_association {, sequence_component_association} sequence_component_association ::= discrete_choice_list => expression | discrete_choice_list => <>

Rationale
-

Discussion
others is only allowed for bounded sequences. I don't recall if it is part of discrete choice list, but it should be allowed in named associations for bounded sequences.

-> I can't figure out how to define a bounded sequence. Any example? (PP)

I've decided to eliminate bounded sequences

Aggregates of a single value are allowedː S'[7]

named_sequence_aggregate seems to have 2 choices that are the same (JC)

Changed. (PP)

Examples
-

Syntax
set_aggregate ::= set_subtype_mark '{ positional_set_aggregate | null_set_aggregate | all_set_aggregate } positional_set_aggregate ::= expression {, expression} null_set_aggregate ::= null all_set_aggregate ::= all

Rationale
all is only allowed if the universe type is discrete and finite.

Discussion
Actually, others makes no sense for set aggregates. Sorry

Aggregates with a single value are allowedː S'̪7ˈ(JC)

Changed. (PP)

Examples
-

Syntax
expression ::= relation {and relation} | relation {and then relation} | relation {or relation}  | relation {or else relation} | relation {xor relation} choice_expression ::= choice_relation {and choice_relation} | choice_relation {or choice_relation} | choice_relation {xor choice_relation} | choice_relation {and then choice_relation} | choice_relation {or else choice_relation} choice_relation ::= simple_expression [relational_operator simple_expression] relation ::= simple_expression [relational_operator simple_expression] | tested_simple_expression [not] in membership_choice_list membership_choice_list ::= membership_choice {| membership_choice} membership_choice ::= choice_simple_expression | range | subtype_mark simple_expression ::= term {binary_adding_operator term} term ::= factor {multiplying_operator factor} factor ::= [unary_adding_operator] primary [^ [unary_adding_operator] primary] | not primary | \ primary primary ::= numeric_literal | null | string_literal | aggregate | name | (expression) | (conditional_expression) | (quantified_expression) | (declare_expression)

Rationale
-

Discussion
Remember that King allows a unary operator to follow a binary operator without parenthesesː 10.0 ^ -9. I don't think these rules allow that.

-> Changed. (PP)

Seems that A * -B is still not OK (JC)

Decomposition:

factor multiplying_operator factor

factor -> primary -> A

multiplying_operator -> *

factor -> unary_adding_operator primary -> -B

Is it correct? (PP)

Examples
-

Syntax
logical_operator ::= and | or | xor relational_operator ::= = | /= | < | <= | > | >= binary_adding_operator ::= + | - | & unary_adding_operator ::= + | - multiplying_operator ::= * | / | mod | rem exponentiation_operator ::= ^ highest_precedence_operator ::= ^ | not | \ | unary_adding_operator

Rationale
-

Discussion
Unary operators, including not, have the highest precedence, to allow unary operators to follow binary operators without parentheses. Don't forget the "\" unary operator.

-> Changed. (PP)

All unary operators have highest precedence. You need something like

binary_adding_operator

multiplying_operator

exponentiation_operator ::= ^

highest_precedence_operator

with all the unary operators part of highest_precedence_operator (JC)

Examples
-

Syntax
conditional_expression ::= if_expression | case_expression if_expression ::= if condition then dependent_expression {else_if condition then dependent_expression} else dependent_expression condition ::= boolean_expression case_expression ::= case selecting_expression is case_expression_alternative {, case_expression_alternative} case_expression_alternative ::= when discrete_choice_list => dependent_expression

Rationale
-

Discussion
-

Examples
-

Syntax
quantified_expression ::= for quantifier loop_parameter_specification => predicate | for quantifier iterator_specification => predicate quantifier ::= all | some predicate ::= boolean_expression

Rationale
-

Discussion
-

Examples
-

Syntax
declare_expression ::= declare declare_declaration {declare_declaration} begin body_expression

Rationale
-

Discussion
The declarations of a declare expression are limited to constants and subtypes. You dealt with this already elsewhere IIRC.

Note added. (PP)

Does not include subtypes (JC)

Changed. (PP)

Examples
-

Syntax
type_conversion ::= subtype_mark (expression)

Rationale
-

Discussion
-

Examples
-

Syntax
qualified_expression ::= subtype_mark '(expression)

Rationale
-

Discussion
-

Examples
-

Syntax
function_call ::= function_name | function_prefix actual_parameter_part

Rationale
-

Discussion
-