Annotated King Reference Manual/Expressions

This page is work in progress.

Names

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

-

Indexed Components

edit

Examples

edit

-

Syntax

edit
indexed_component ::= sequence_component | map_component

sequence_component ::= prefix [expression]

map_component ::= prefix (expression)

Rationale

edit

-

Discussion

edit

-

Slices

edit

Examples

edit

-

Syntax

edit
slice ::= prefix [discrete_range]

discrete_range ::= discrete_subtype_indication | range_specification

Rationale

edit

-

Discussion

edit

-

Selected Components

edit

Examples

edit

-

Syntax

edit
selected_component ::= prefix . selector_name

selector_name ::= identifier | character_literal | operator_symbol

Rationale

edit

-

Discussion

edit

-

Attributes

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

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)

Aggregates

edit

Examples

edit

-

Syntax

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

Rationale

edit

-

Discussion

edit

-

Record Aggregates

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

-

Map Aggregates

edit

Examples

edit

-

Syntax

edit
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

edit

Rationale

edit

-

Discussion

edit

-

Sequence Aggregates

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

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)

Set Aggregates

edit

Examples

edit

-

Syntax

edit
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

edit

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

Discussion

edit

Actually, others makes no sense for set aggregates. Sorry

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

Changed. (PP)

Expressions

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

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)

Operators

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

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)

Conditional Expressions

edit

Examples

edit

-

Syntax

edit
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

edit

-

Discussion

edit

-

Quantified Expressions

edit

Examples

edit

-

Syntax

edit
quantified_expression ::=
            for quantifier loop_parameter_specification => predicate
          | for quantifier iterator_specification => predicate

quantifier ::= all | some

predicate ::= boolean_expression

Rationale

edit

-

Discussion

edit

-

Declare Expressions

edit

Examples

edit

-

Syntax

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

Rationale

edit

-

Discussion

edit

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)

Type Conversions

edit

Examples

edit

-

Syntax

edit
type_conversion ::= subtype_mark (expression)

Rationale

edit

-

Discussion

edit

-

Qualified Expressions

edit

Examples

edit

-

Syntax

edit
qualified_expression ::= subtype_mark'(expression)

Rationale

edit

-

Discussion

edit

-

Function calls

edit

Examples

edit

-

Syntax

edit
function_call ::= 
            function_name
          | function_prefix actual_parameter_part

Rationale

edit

-

Discussion

edit

-