跳轉到內容

註釋國王參考手冊/表示式

來自華夏公益教科書,開放書籍,開放世界

此頁面正在建設中。

-

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

-

-

索引元件

[編輯 | 編輯原始碼]

-

indexed_component ::= sequence_component | map_component

sequence_component ::= prefix [expression]

map_component ::= prefix (expression)

-

-

-

slice ::= prefix [discrete_range]

discrete_range ::= discrete_subtype_indication | range_specification

-

-

選定元件

[編輯 | 編輯原始碼]

-

selected_component ::= prefix . selector_name

selector_name ::= identifier | character_literal | operator_symbol

-

-

-

attribute_reference ::= prefix'attribute_designator

attribute_designator ::= identifier [actual_parameter_part] | delta | digits

range_attribute_reference ::= prefix'range_attribute_designator

range_attribute_designator ::= range

-

屬性函式可以有多個引數,這些引數不必是靜態的。例如,對數值型別使用‘Image’屬性函式,幷包含寬度、基數等引數。

-> 我也想知道關於 Ada 的情況。我想屬性函式只是透過識別符號作為函式名進行解引用,然後應用函式簽名。(PP)

它可能應該為

識別符號 [實際引數部分]

已更改。(PP)

-

aggregate ::= record_aggregate | map_aggregate | sequence_aggregate | set_aggregate

-

-

記錄聚合

[編輯 | 編輯原始碼]

-

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

-

-

對映聚合

[編輯 | 編輯原始碼]

-

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

-

-

序列聚合

[編輯 | 編輯原始碼]

-

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 => <>

-

others 只能用於有界序列。我不記得它是否屬於離散選擇列表,但它應該允許在有界序列的命名關聯中使用。

-> 我不明白如何定義一個有界序列。有什麼例子嗎? (PP)

我決定消除有界序列

允許單個值的聚合ː S'[7]

named_sequence_aggregate 似乎有兩個相同的選項 (JC)

已更改。(PP)

集合聚合

[編輯 | 編輯原始碼]

-

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

all 只有在宇宙型別為離散且有限時才允許。

實際上,others 對集合聚合沒有意義。抱歉

允許單個值的聚合ː S'̪7ˈ(JC)

已更改。(PP)

表示式

[編輯 | 編輯原始碼]

-

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)

-

請記住,King 允許一元運算子在不使用括號的情況下緊隨二元運算子ː 10.0 ^ -9。我認為這些規則不允許這樣做。

-> 已更改。 (PP)

似乎 A * -B 仍然不行 (JC)

分解

因子 乘法運算子 因子

因子 -> 主項 -> A

乘法運算子 -> *

因子 -> 一元加法運算子 主項 -> -B

正確嗎? (PP)

運算子

[編輯 | 編輯原始碼]

-

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

-

一元運算子,包括 not,具有最高優先順序,以允許一元運算子在不使用括號的情況下緊隨二元運算子。不要忘記 "\" 一元運算子。

-> 已更改。 (PP)

所有一元運算子都具有最高優先順序。你需要類似於

二元加法運算子

乘法運算子

指數運算子 ::= ^

最高優先順序運算子

所有一元運算子都是最高優先順序運算子的一部分 (JC)

條件表示式

[編輯 | 編輯原始碼]

-

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

-

-

量化表示式

[編輯 | 編輯原始碼]

-

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

quantifier ::= all | some

predicate ::= boolean_expression

-

-

宣告表示式

[編輯 | 編輯原始碼]

-

declare_expression ::= 
          declare declare_declaration {declare_declaration}
          begin body_expression

-

宣告表示式的宣告僅限於常量和子型別。據我回憶,你已經在其他地方處理了這個問題。

添加註釋。(PP)

不包括子型別 (JC)

已更改。(PP)

型別轉換

[編輯 | 編輯原始碼]

-

type_conversion ::= subtype_mark (expression)

-

-

限定表示式

[編輯 | 編輯原始碼]

-

qualified_expression ::= subtype_mark'(expression)

-

-

函式呼叫

[編輯 | 編輯原始碼]

-

function_call ::= 
            function_name
          | function_prefix actual_parameter_part

-

-

華夏公益教科書