Annotated King Reference Manual/Expressions
This page is work in progress.
Names
editExamples
edit-
Syntax
editname ::= 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
editExamples
edit-
Syntax
editindexed_component ::= sequence_component | map_component sequence_component ::= prefix [expression] map_component ::= prefix (expression)
Rationale
edit-
Discussion
edit-
Slices
editExamples
edit-
Syntax
editslice ::= prefix [discrete_range] discrete_range ::= discrete_subtype_indication | range_specification
Rationale
edit-
Discussion
edit-
Selected Components
editExamples
edit-
Syntax
editselected_component ::= prefix . selector_name selector_name ::= identifier | character_literal | operator_symbol
Rationale
edit-
Discussion
edit-
Attributes
editExamples
edit-
Syntax
editattribute_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
editAttribute 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
editExamples
edit-
Syntax
editaggregate ::= record_aggregate | map_aggregate | sequence_aggregate | set_aggregate
Rationale
edit-
Discussion
edit-
Record Aggregates
editExamples
edit-
Syntax
editrecord_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
editExamples
edit-
Syntax
editmap_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
editRationale
edit-
Discussion
edit-
Sequence Aggregates
editExamples
edit-
Syntax
editsequence_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
editothers 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
editExamples
edit-
Syntax
editset_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
editall is only allowed if the universe type is discrete and finite.
Discussion
editActually, others makes no sense for set aggregates. Sorry
Aggregates with a single value are allowedː S'̪7ˈ(JC)
Changed. (PP)
Expressions
editExamples
edit-
Syntax
editexpression ::= 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
editRemember 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
editExamples
edit-
Syntax
editlogical_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
editUnary 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
editExamples
edit-
Syntax
editconditional_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
editExamples
edit-
Syntax
editquantified_expression ::= for quantifier loop_parameter_specification => predicate | for quantifier iterator_specification => predicate quantifier ::= all | some predicate ::= boolean_expression
Rationale
edit-
Discussion
edit-
Declare Expressions
editExamples
edit-
Syntax
editdeclare_expression ::= declare declare_declaration {declare_declaration} begin body_expression
Rationale
edit-
Discussion
editThe 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
editExamples
edit-
Syntax
edittype_conversion ::= subtype_mark (expression)
Rationale
edit-
Discussion
edit-
Qualified Expressions
editExamples
edit-
Syntax
editqualified_expression ::= subtype_mark'(expression)
Rationale
edit-
Discussion
edit-
Function calls
editExamples
edit-
Syntax
editfunction_call ::= function_name | function_prefix actual_parameter_part
Rationale
edit-
Discussion
edit-