Repository navigation
Expand file tree
/
Copy pathdemo.sysml
More file actions
144 lines (112 loc) · 5.36 KB
/
Copy pathdemo.sysml
File metadata and controls
144 lines (112 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// =============================================================================
// Semantic Layer Feature Demo
// Demonstrates runtime operators, feature chains, and validation
// =============================================================================
package SemanticLayerDemo {
// =========================================================================
// Track 1: Runtime Operators
// =========================================================================
// Equality operators
attribute intEquality = 42 == 42; // true
attribute intInequality = 42 != 43; // true
attribute realEquality = 3.14 == 3.14; // true
attribute nullEquality = null == null; // true
attribute crossKindCheck = 42 == null; // false
// Logical operators with short-circuit evaluation
attribute andTrue = (5 > 3) & (10 < 20); // true
attribute andFalse = (5 < 3) & (10 < 20); // false
attribute orTrue = (5 > 3) | (10 > 20); // true
attribute orFalse = (5 < 3) | (10 > 20); // false
attribute notTrue = not (5 < 3); // true
attribute notFalse = not (5 > 3); // false
attribute doubleNot = not (not true); // true
// Arithmetic negation
attribute negInt = -42; // -42
attribute negReal = -3.14; // -3.14
attribute doubleNeg = -(-5); // 5
attribute negExpr = -(3 + 2); // -5
// Qualified name lookup - multi-part names
package MathConstants {
attribute pi = 3.14159;
attribute e = 2.71828;
package Derived {
attribute twoPi = 6.28318;
}
}
attribute usePi = MathConstants::pi; // 3.14159
attribute useE = MathConstants::e; // 2.71828
attribute nestedLookup = MathConstants::Derived::twoPi; // 6.28318
// Combined operators - realistic expressions
attribute expr1 = (42 == 42) & (100 != 99); // true
attribute expr2 = MathConstants::pi > 3; // true
attribute expr3 = -(MathConstants::e) < 0; // true
attribute expr4 = (10 > 5) | (3 == 2); // true
attribute expr5 = not ((5 < 3) & (10 > 20)); // true
// =========================================================================
// Track 2: Feature Chain Resolution
// =========================================================================
// Simple feature chains - member access
part def Container {
attribute value = 0;
attribute name = "default";
}
part myContainer : Container;
// Simple chain: object.member
attribute simpleValue = myContainer.value; // 0
attribute simpleName = myContainer.name; // "default"
// Nested chains
part def Nested {
part inner : Container;
attribute id = 0;
}
part myNested : Nested;
attribute nestedValue = myNested.inner.value; // 0
attribute nestedId = myNested.id; // 0
// =========================================================================
// Track 3: Semantic Validation
// =========================================================================
// Typing conformance - valid specialization
attribute def SpeedType;
part def Vehicle {
attribute speed : SpeedType;
}
part def Car specializes Vehicle {
// Valid: Car.speed inherits Vehicle.speed type
}
// Valid subsetting - Car specializes Vehicle
part allVehicles : Vehicle[*];
part myCar : Car subsets allVehicles; // OK: Car conforms to Vehicle
// =========================================================================
// Integration Example
// =========================================================================
package Integration {
part def Sensor {
attribute reading = 0.0;
attribute threshold = 100.0;
}
part tempSensor : Sensor;
part pressureSensor : Sensor;
// Feature chains to access nested values
attribute tempValue = tempSensor.reading; // 0.0
attribute tempLimit = tempSensor.threshold; // 100.0
attribute pressureValue = pressureSensor.reading; // 0.0
attribute pressureLimit = pressureSensor.threshold; // 100.0
// Operators on chain results
attribute isHighTemp = tempValue > 90.0; // false
attribute isNormalPressure = pressureValue < 200.0; // true
// Combined logic
attribute systemOK = (not isHighTemp) & isNormalPressure; // true
}
// =========================================================================
// Edge Cases
// =========================================================================
// Negation of comparison results
attribute notEqual = not (42 == 43); // true
// Chained comparisons with negation
attribute complex1 = -(5) < 0; // true
attribute complex2 = -(-10) == 10; // true
// Multiple logical operators
attribute multiLogic = (true & false) | (true & true); // true
// Parenthesized expressions
attribute grouped = ((5 > 3) & (10 < 20)) | (1 == 2); // true
}