-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrepl-behavioral-demo.sysml
More file actions
161 lines (138 loc) · 4.28 KB
/
Copy pathrepl-behavioral-demo.sysml
File metadata and controls
161 lines (138 loc) · 4.28 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// REPL Behavioral Commands Demo
//
// This file demonstrates the new REPL commands for evaluating
// behavioral elements: calculations, constraints, and requirements.
//
// Try these commands in the REPL:
// %load examples/repl-behavioral-demo.sysml
// %calc distance 3 4
// %calc volume 2 3 5
// %calc factorial 5
// %constraint PositiveArea
// %constraint ValidSpeed
// %constraint InvalidSpeed
// %requirement SafetyReq
// %requirement PerformanceReq
// %requirement ViolatedReq
// ============================================================================
// CALCULATIONS
// ============================================================================
// Calculate distance using Pythagorean theorem
calc distance {
in x;
in y;
x * x + y * y // simplified: should use sqrt
}
// Calculate volume of a box
calc volume {
in length;
in width;
in height;
length * width * height
}
// Calculate factorial (iterative approximation using product)
calc factorial {
in n;
n * (n - 1) // simplified: just n * (n-1) for demo
}
// Convert temperature from Celsius to Fahrenheit
calc celsiusToFahrenheit {
in celsius;
celsius * 9 / 5 + 32
}
// Calculate area of rectangle
calc rectangleArea {
in length;
in width;
length * width
}
// ============================================================================
// CONSTRAINTS
// ============================================================================
// Constraint: area must be positive
constraint PositiveArea {
10 * 5 > 0
}
// Constraint: speed must be within valid range
constraint ValidSpeed {
65 >= 0 and 65 <= 120
}
// Constraint: this will fail - invalid speed
constraint InvalidSpeed {
150 <= 120
}
// Constraint: both dimensions positive
constraint AssumePositive {
10 > 0 and 5 > 0
}
// Constraint: negated assertion
constraint NotNegative {
not (50 < 0)
}
// ============================================================================
// REQUIREMENTS
// ============================================================================
// Safety requirement: braking distance must be adequate
requirement SafetyReq {
// Assume reasonable speed
assume constraint { 65 > 0 }
assume constraint { 65 < 200 }
// Require adequate braking distance
require constraint { 100 > 50 }
}
// Performance requirement: acceleration must meet target
requirement PerformanceReq {
// Assume valid conditions
assume constraint { 100 > 0 }
// Require performance threshold
require constraint { 95 >= 90 }
}
// This requirement will fail
requirement ViolatedReq {
// Assumptions pass
assume constraint { 50 > 0 }
// But requirement fails
require constraint { 30 > 100 }
}
// Complex requirement with multiple conditions
requirement ComplexReq {
assume constraint { 100 >= 0 }
assume constraint { 100 <= 200 }
require constraint { 150 > 100 }
require constraint { 150 < 200 }
}
// ============================================================================
// USAGE EXAMPLES
// ============================================================================
// To test these in the REPL:
//
// 1. Start the REPL:
// $ sysml repl
//
// 2. Load this file:
// %load examples/repl-behavioral-demo.sysml
//
// 3. Invoke calculations:
// %calc distance 3 4 // Returns: 25 (3² + 4²)
// %calc volume 2 3 5 // Returns: 30
// %calc factorial 5 // Returns: 20 (simplified)
// %calc celsiusToFahrenheit 100 // Returns: 212
// %calc rectangleArea 10 5 // Returns: 50
//
// 4. Evaluate constraints:
// %constraint PositiveArea // ✓ passed
// %constraint ValidSpeed // ✓ passed
// %constraint InvalidSpeed // ✗ failed (expected)
// %constraint AssumePositive // ✓ passed
// %constraint NotNegative // ✓ passed
//
// 5. Evaluate requirements:
// %requirement SafetyReq // ✓ satisfied
// %requirement PerformanceReq // ✓ satisfied
// %requirement ViolatedReq // ✗ failed (expected)
// %requirement ComplexReq // ✓ satisfied
//
// Note: Arguments are parsed as literal expressions. You can use:
// - Integer literals: 10, -5, 100
// - Arithmetic: 3 + 4, 10 * 2
// - Parentheses: (5 + 3) * 2