This demo showcases all semantic layer features implemented in the OpenSysML SysML v2 compiler.
Equality operators (==, !=):
- Deep equality for all value kinds (const, string, null, instance, sequence, set)
- Cross-kind comparison returns false (not error)
Logical operators (&, |, not):
- Short-circuit evaluation for
&(and) and|(or) - Boolean negation with
not
Arithmetic negation (-):
- Unary minus for numeric values (int and real)
- Delegates to semantics layer for type-correct evaluation
Qualified name lookup:
- Multi-part names:
A::B::C - Nested namespace resolution
- Inheritance-aware member lookup
Member access chains:
- Simple chains:
object.member - Nested chains:
object.member.submember - Type-aware resolution following relationships
Feature chains in relationships:
- Subsetting with chains
- Redefinition with chains
- Symbol storage in AST for downstream passes
Typing conformance:
- Validates subsetting relationships respect type hierarchies
- Uses
model.Conforms()for inheritance checking
Redefinition validation:
- Inheritance check: member must be inherited
- Type conformance: redefined type must conform to original
- Multiplicity bounds:
lower >= original.lower,upper <= original.upper
# Start the REPL and load the demo
go run ./cmd/sysml
%load examples/semantic-layer/demo.sysml
# Evaluate specific attributes
%eval equalityDemo.intEquality
%eval logicalDemo.andTrue
%eval negationDemo.negInt
%eval qualifiedDemo.usePi
%eval chainDemo.simpleValue%eval equalityDemo.intEquality
= true
%eval logicalDemo.andTrue
= true
%eval negationDemo.negInt
= -42
%eval qualifiedDemo.usePi
= 3.14159
%eval chainDemo.simpleValue
= 42
%eval chainDemo.nestedValue
= 100
The demo is organized into sections mirroring the implementation tracks:
-
Runtime Operators (lines 8-64)
- Equality, logical, negation, qualified names
- Combined operator expressions
-
Feature Chain Resolution (lines 66-130)
- Simple and nested chains
- Chains in relationships
- Redefinition with chains
-
Semantic Validation (lines 132-175)
- Typing conformance examples
- Redefinition validation
- Valid constraint scenarios
-
Integration Example (lines 177-214)
- Realistic vehicle monitoring system
- Combines all features in one scenario
- Feature chains + operators + validation
-
Edge Cases (lines 216-232)
- Complex operator combinations
- Negation of comparisons
- Parenthesized expressions
All operators follow SysML v2 syntax:
- Logical AND:
&(not&&) - Logical OR:
|(not||) - Logical NOT:
not(not!) - Equality:
==and!= - Negation:
-(unary minus)
Feature chains use dot notation:
part myNested : Nested {
part inner : Container {
attribute value = 100;
}
}
attribute result = myNested.inner.value; // 100
Resolution:
- Extracts operand symbol (
myNested) - Follows typing relationships to get type (
Nested) - Walks chain members using
model.LookupMember(inheritance-aware) - Stores intermediate symbols in AST (
part.Sym)
Typing conformance validates subsetting:
part def Car specializes Vehicle { ... }
attribute myCar : Car subsets allVehicles : Vehicle[*]; // Valid
Redefinition validation checks:
part def ElectricEngine specializes Engine {
attribute redefines power[200..400]; // Valid if [200..400] ⊆ Engine.power bounds
}
The demo file is validated during test runs:
# Parse validation
go test ./internal/syntax/parser/
# Resolution validation
go test ./internal/semantic/resolve/
# Runtime evaluation
go test ./internal/exec/runtime/
# Semantic validation
go test ./internal/check/passes/All tests should pass with this demo loaded.
- Architecture - the pipeline this demo exercises
- Spec compliance - semantic rule to implementation to test
- PR #11 - Pull request with all changes
To extend this demo:
- Add new feature demonstrations in their respective sections
- Ensure new examples parse cleanly in REPL
- Add explanatory comments showing expected results
- Update this README with new feature descriptions