Jump to content

Annotated King Reference Manual/Expressions

From Wikibooks, open books for an open world

This page is work in progress.

Names

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

-

Indexed Components

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
indexed_component ::= sequence_component | map_component

sequence_component ::= prefix [expression]

map_component ::= prefix (expression)

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Slices

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
slice ::= prefix [discrete_range]

discrete_range ::= discrete_subtype_indication | range_specification

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Selected Components

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
selected_component ::= prefix . selector_name

selector_name ::= identifier | character_literal | operator_symbol

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Attributes

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

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 | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
aggregate ::= record_aggregate | map_aggregate | sequence_aggregate | set_aggregate

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Record Aggregates

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

-

Map Aggregates

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Sequence Aggregates

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

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 | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

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

Discussion

[edit | edit source]

Actually, others makes no sense for set aggregates. Sorry

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

Changed. (PP)

Expressions

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

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 | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

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 | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
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 | edit source]

-

Discussion

[edit | edit source]

-

Quantified Expressions

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
quantified_expression ::=
            for quantifier loop_parameter_specification => predicate
          | for quantifier iterator_specification => predicate

quantifier ::= all | some

predicate ::= boolean_expression

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Declare Expressions

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
declare_expression ::= 
          declare declare_declaration {declare_declaration}
          begin body_expression

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

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 | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
type_conversion ::= subtype_mark (expression)

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Qualified Expressions

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
qualified_expression ::= subtype_mark'(expression)

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Function calls

[edit | edit source]

Examples

[edit | edit source]

-

Syntax

[edit | edit source]
function_call ::= 
            function_name
          | function_prefix actual_parameter_part

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-