25장 KerML의 구조와 표기법
3장부터 24장까지 장마다 “KerML에서 보면” 절에서 KerML을 한 조각씩 보았습니다. 그 조각들은 SysML의 종류를 따라 놓였기 때문에, KerML이 그 자체로 어떤 모양의 언어인지는 아직 한눈에 들어오지 않습니다. 이 장은 흩어진 조각을 KerML의 순서대로 다시 모읍니다. KerML로 모델을 작성할 일이 없는 독자에게도 이 정리는 쓸모가 있습니다. 명세와 표준 library는 KerML의 용어와 표기법으로 적혀 있고, SysML의 종류가 스무 가지를 넘는데도 규칙이 한결같은 까닭이 KerML의 구조에 있기 때문입니다.
세 계층과 metaclass
KerML의 abstract syntax는 세 계층에 걸쳐 정의됩니다. 아래 그림은 Root와 Core의 metaclass가 서로 어떻게 특수화하는지를 보여 줍니다.
flowchart BT
relationship["`**Relationship**`"] --> element["`**Element**`"]
annotating["`**AnnotatingElement**`"] --> element
namespace["`**Namespace**`"] --> element
type["`**Type**`"] --> namespace
classifier["`**Classifier**`"] --> type
feature["`**Feature**`"] --> type
subgraph root["Root"]
element
relationship
annotating
namespace
end
subgraph core["Core"]
type
classifier
feature
end
| 계층 | 정하는 것 | 의미론 |
|---|---|---|
| Root | element와 relationship, annotation, namespace와 import | 없습니다. 모델을 조직하는 구조만 정합니다. |
| Core | type, classifier, feature와 그 사이의 relationship | 수리 논리로 정의합니다. |
| Kernel | data type, class, association, behavior, function, expression, metadata, package | Kernel Semantic Library가 정의합니다. |
Kernel에서 대상을 모델링하는 metaclass는 모두 Classifier나 Feature를 특수화한 것입니다. 그래서 Core의 규칙은 Kernel의 모든 종류에 적용되고, Kernel을 특수화한 SysML의 모든 종류에도 적용됩니다. 5장과 6장의 내용이 종류를 가리지 않았던 것은 그것이 Core의 내용이었기 때문입니다.
Root: 모델의 뼈대
Root는 3장에서 다룬 내용 그대로입니다. 모델은 element로 이루어지고, element 사이의 관계도 relationship이라는 element입니다.
| 개념 | 키워드 | 내용 |
|---|---|---|
| dependency | dependency | 의미론 없이 의존만 나타내는 relationship입니다. |
| comment, documentation | comment, doc | 사람이 읽는 설명입니다. |
| textual representation | rep, language | element를 다른 언어의 텍스트로 나타낸 것입니다. |
| namespace | namespace | member에 이름을 주는 element입니다. |
| membership | alias, 가시성 키워드 | namespace와 member를 잇는 relationship입니다. |
| import | import | 다른 namespace의 member를 가져오는 relationship입니다. |
Root에는 type이 없으므로 Root만으로는 대상을 모델링할 수 없습니다. Root가 정하는 것은 소유와 이름이라는, 어떤 모델에나 필요한 구조입니다.
Core: type, classifier, feature
type은 대상을 분류하는 namespace입니다. type은 두 가지로 나뉩니다.
| classifier | feature | |
|---|---|---|
| 분류하는 것 | 대상 | 대상과 대상 사이의 관계 |
| instance | 대상 하나 | 한 대상에서 다른 대상으로 가는 쌍 |
| 선언 | classifier C; | feature f : C; |
feature가 type이라는 것은 feature도 무언가를 분류한다는 뜻입니다. Drone의 feature battery는 드론과 배터리의 쌍을 분류합니다. 쌍의 앞자리에 올 수 있는 대상을 정하는 것이 featuring type이고, 뒷자리에 올 수 있는 대상을 정하는 것이 feature의 type입니다. feature도 type이므로 feature 안에 feature를 선언할 수 있고, feature끼리 특수화할 수 있습니다. 8장에서 usage 안에 usage를 중첩하고 5장에서 usage가 usage를 subset한 것이 이 성질입니다.
Core의 relationship은 다음과 같습니다. 앞의 여섯은 이미 보았습니다.
| relationship | KerML 표기 | 뜻 | 본 곳 |
|---|---|---|---|
| subclassification | specializes, :> | classifier의 instance는 일반 classifier의 instance입니다. | 5장 |
| feature typing | typed by, : | feature의 value는 그 type의 instance입니다. | 4장 |
| subsetting | subsets, :> | feature의 value는 다른 feature의 value 가운데 일부입니다. | 5장 |
| redefinition | redefines, :>> | 물려받은 feature를 대신합니다. | 5장 |
| reference subsetting, cross subsetting | references, ::>, crosses, => | connector의 end가 쓰는 subsetting입니다. | 9장 |
| conjugation | conjugates, ~ | in과 out을 뒤집어 물려받습니다. | 10장 |
| disjoining | disjoint from | 두 type은 instance를 함께 갖지 않습니다. | 이 장 |
| unioning, intersecting, differencing | unions, intersects, differences | type의 extent를 다른 type의 합집합, 교집합, 차집합으로 정합니다. | 이 장 |
| feature chaining | chains | feature의 value를 다른 feature를 차례로 따라간 결과로 정합니다. | 6장 |
| feature inverting | inverse of | 두 feature가 서로 반대 방향의 관계입니다. | 이 장 |
| type featuring | featured by | feature의 featuring type을 정합니다. | 이 장 |
SysML 표기법에 없는 relationship
표의 아래쪽 다섯은 SysML 표기법에 대응하는 키워드가 없습니다. 이 가운데 feature chaining은 SysML에서 점으로 잇는 표기로 쓰고, 나머지 넷은 SysML 모델에서 직접 쓸 수 없습니다. 표준 library는 이 관계를 써서 SysML 종류의 뜻을 정합니다.
disjoining은 두 type이 instance를 함께 갖지 않는다고 선언합니다. 7장에서 data value와 occurrence가 겹치지 않는다고 한 것은 library의 Occurrence가 DataValue와 disjoint하다고 선언했기 때문입니다.
classifier Mineral;
classifier Animal disjoint from Mineral;
unioning, intersecting, differencing은 type의 extent를 다른 type의 extent로 정합니다.
classifier Adult;
classifier Child;
classifier Person unions Adult, Child {
feature parents : Person[2];
feature children : Person[*] inverse of parents;
feature grandparents : Person[*] chains parents.parents;
}
Person의 instance는 Adult의 instance이거나 Child의 instance입니다. children은 parents의 inverse이므로, 어떤 사람이 다른 사람의 parents에 들어 있으면 뒤의 사람은 앞 사람의 children에 들어 있습니다. grandparents의 value는 parents를 두 번 따라간 결과입니다. 6장에서 식에 쓴 a.b.c는 이름을 주지 않고 그 자리에서 만든 feature chain입니다.
type의 조건은 기본으로 필요조건입니다. feature wheels[4]를 가진 type Car는 “car이면 바퀴가 넷“이라고만 말합니다. 키워드 all을 붙이면 조건이 충분조건도 되어, 바퀴가 넷인 것은 모두 그 type의 instance가 됩니다.
type Vehicle specializes Base::Anything;
type all FourWheeled specializes Vehicle {
feature wheels[4];
}
featuring type과 member
feature를 type의 본문에 선언하면 두 가지가 한꺼번에 정해집니다. 그 type이 feature를 소유하고, 그 type이 feature의 featuring type이 됩니다. 이 두 가지를 묶은 relationship이 feature membership입니다. KerML은 둘을 따로 정하는 표기도 제공합니다.
classifier A;
classifier B {
feature f;
member feature g featured by A;
}
f는 B가 소유하고 featuring type도 B입니다. g는 B가 소유하지만 featuring type은 A입니다. 11장의 variant가 variation의 본문에 적혀 있으면서 variation의 feature가 아니었던 것이 member의 예입니다.
type의 본문 밖에 선언한 feature는 featuring type을 따로 정하지 않으면 Base::Anything을 featuring type으로 갖는 것으로 봅니다. SysML에서 package에 직접 선언한 usage가 이 경우입니다.
Kernel: classifier와 feature의 짝
Kernel은 classifier를 instance의 성격에 따라 나누고, 그 classifier를 type으로 갖는 feature에도 이름을 붙였습니다. 그래서 Kernel의 개념은 대부분 짝을 이룹니다.
| classifier | 키워드 | instance | 그 classifier를 type으로 갖는 feature | 키워드 |
|---|---|---|---|---|
| data type | datatype | data value | feature | |
| class | class | occurrence | feature | |
| structure | struct | object | feature | |
| association | assoc | link | connector | connector |
| association structure | assoc struct | link object | connector | connector |
| behavior | behavior | performance | step | step |
| function | function | evaluation | expression | expr |
| predicate | predicate | 결과가 Boolean인 evaluation | boolean expression, invariant | bool, inv |
| interaction | interaction | transfer | flow | flow |
| metaclass | metaclass | metaobject | metadata feature | metadata |
표의 classifier는 서로 특수화합니다. structure와 behavior는 class이고, function은 behavior이며, predicate는 function입니다. association structure는 association이면서 structure이고, interaction은 association이면서 behavior입니다. connector 가운데 뜻이 정해진 것으로 binding connector(binding)와 succession(succession)이 있습니다.
Kernel에는 짝에 들지 않는 것도 있습니다.
| 개념 | 내용 | 본 곳 |
|---|---|---|
| expression의 표기 | 연산자, 호출, feature 참조, 리터럴 | 12장 |
| feature value | =, :=, default | 6장 |
| multiplicity range | [1..*] | 6장 |
| package | package, library package, filter | 24장 |
SysML은 이 표의 짝마다 definition과 usage를 하나씩 대응시켰습니다. 어느 것이 어느 것에 대응하는지는 27장에서 정리합니다.
선언의 모양
KerML의 선언은 종류와 관계없이 같은 순서로 적습니다.
| 순서 | 부분 | 예 |
|---|---|---|
| 1 | 가시성 | private |
| 2 | 앞에 붙는 성질 | abstract, in, composite |
| 3 | 종류 키워드 | struct, feature, connector |
| 4 | short name과 name | <'B-1'> Battery |
| 5 | multiplicity | [4..8]. feature에서는 : Rotor[4..8]처럼 type 뒤에 적어도 됩니다. |
| 6 | specialization | : Rotor, subsets parts, specializes Device |
| 7 | 그 밖의 relationship | disjoint from …, chains …, featured by … |
| 8 | feature value | = 6 |
| 9 | 본문 | { … } 또는 ; |
feature 앞에 붙는 성질은 다음 순서로 적습니다.
| 순서 | 키워드 | 뜻 |
|---|---|---|
| 1 | in, out, inout | direction |
| 2 | derived | 다른 것에서 계산되는 feature |
| 3 | abstract | value가 반드시 더 구체적인 feature의 value여야 하는 feature |
| 4 | composite 또는 portion | value가 전체에 딸린 부분, 같은 대상의 일부 |
| 5 | var 또는 const | 시간에 따라 달라질 수 있음, 달라지지 않음 |
end feature는 이 대신 end를 적고, 그 앞에 const만 둘 수 있습니다.
relationship은 선언의 일부로 적을 수도 있고 독립된 선언으로 적을 수도 있습니다. 다음 두 줄은 같은 relationship을 만듭니다. 독립된 선언은 양쪽 element를 고칠 수 없는 자리에서 relationship을 더하거나, relationship에 이름과 설명을 붙일 때 씁니다.
classifier Aircraft specializes Vehicle;
classifier Airship;
specialization airshipIsVehicle subtype Airship specializes Vehicle;
SysML 표기와 KerML 표기
같은 내용을 두 표기법으로 적을 때 달라지는 키워드를 모으면 다음과 같습니다.
| SysML | KerML |
|---|---|
attribute def | datatype |
occurrence def | class |
item def, part def, port def | struct |
connection def, interface def | assoc struct |
action def, state def | behavior |
calc def | function |
constraint def, requirement def | predicate |
metadata def | metaclass |
attribute, item, part, port | feature |
connect a to b; | connector a to b; |
bind a = b; | binding a = b; |
first a then b; | succession a then b; |
action, state | step |
calc | expr |
constraint, assert constraint | bool, inv |
ref | 적지 않습니다. referential이 기본입니다. |
| 적지 않습니다. composite가 기본입니다. | composite |
constant | const |
timeslice, snapshot | portion |
기호는 두 표기법이 같습니다. :, :>, :>>, ::>, =>, ~, =, :=, ::, .은 어느 쪽에서나 같은 뜻입니다.
두 표기법은 기본값이 반대인 곳이 두 군데 있습니다. KerML의 feature는 적지 않으면 referential이고 시간에 따라 달라지지 않으며, SysML의 usage는 종류에 따라 composite이고 달라질 수 있는 것이 기본입니다. 6장에서 본 이 차이는 KerML로 적은 library를 읽을 때 틀리기 쉬운 곳입니다.
KerML을 직접 쓰는 경우
SysML 사용자가 KerML 표기법으로 모델을 작성하는 일은 드뭅니다. KerML을 읽고 쓸 일이 생기는 경우는 다음과 같습니다.
| 경우 | 하는 일 |
|---|---|
| 명세와 표준 library를 읽을 때 | Kernel Semantic Library는 KerML로 적혀 있고, SysML 명세는 종류의 뜻을 KerML로 풀어 설명합니다. |
| 도구를 만들 때 | 구문 분석기와 저장 형식은 KerML의 abstract syntax를 따릅니다. |
| SysML이 아닌 언어를 KerML 위에 만들 때 | 27장에서 볼 SysML의 방식대로 KerML을 확장합니다. |
| SysML 표기법에 없는 relationship이 필요할 때 | disjoining이나 feature inverting을 쓰는 library를 KerML로 적습니다. |
KerML로 적은 element는 SysML 모델에서 그대로 쓸 수 있습니다. KerML의 data type은 attribute usage의 type이 되고, structure는 item usage와 part usage의 type이 되며, function은 expression 안에서 호출할 수 있습니다. ScalarValues::Real과 NumericalFunctions::sum을 써 온 것이 그 예입니다.
명세에서 찾아보기
| 주제 | 조항 |
|---|---|
| KerML의 구성 | KerML 6, 7.1 |
| Root | KerML 7.2, 8.3.2 |
| Core | KerML 7.3, 8.3.3 |
| disjoining, unioning, intersecting, differencing | KerML 7.3.2.5, 7.3.2.7 |
| feature chaining, feature inverting, type featuring | KerML 7.3.4.6 ~ 7.3.4.8 |
| Kernel | KerML 7.4, 8.3.4 |
| KerML 텍스트 표기법 | KerML 8.2 |
| 예약어 | KerML 8.2.2.6, SysML 8.2.2.1.2 |