Syntax Basics
OSC2 uses indentation-based syntax (similar to Python) to organize code blocks. Files use the .osc extension.
Comments
Use # for single-line comments:
# This is a comment
scenario my_scenario:
# Indented comment
do serial:
car.drive()
File Structure
An OSC2 file consists of import declarations and top-level definitions:
# Imports (optional)
import osc.standard
# Top-level definitions: types, enums, structs, actors, scenarios, etc.
type my_type is ...
scenario my_scenario:
...
Imports
Use the import statement to reference other files:
import "path/to/file.osc" # File path import
import osc.standard # Standard library import
Keywords
OSC2 reserved keywords:
scenario actor action struct type enum do serial parallel one_of event keep extend inherits def import with is it var global cover call wait on until emit if default fall rise elapsed every sample hard only remove_default undefined as in and or not range list of record external SI unit bool int uint float string
Identifiers
Identifiers are case-sensitive and support Unicode characters. Use pipe symbols to include spaces:
my_variable: int
|my variable|: string
Scenario Structure
Scenarios are declared with the scenario keyword, using do to define behavior:
scenario my_scenario:
ego: vehicle
do serial:
ego.drive(duration: 10s)
Behavior Composition
- `serial — Sequential execution (next starts after previous ends)
parallel— Concurrent execution (all start at the same time)one_of— Selective execution (randomly picks one branch)
do serial:
phase1: parallel(duration: 5s):
car1.drive()
car2.drive()
phase2: serial:
car1.drive(speed: 30kph)
car2.drive(speed: 50kph)
Modifiers
Use with to add parameters and constraints to behaviors:
car.drive() with:
speed(60kph)
lane(1)
keep(speed < 80kph)
Literals
42 # Integer
3.14159 # Float
true # Boolean
"hello" # String
10m # Physical quantity (10 meters)
50kph # Physical quantity (50 km/h)
[1..10] # Range
Complete Example
import osc.standard
scenario highway_drive:
ego: vehicle
do serial:
approach: parallel(duration: 10s):
ego.drive with:
speed(60kph)
lane(1)
cruise: parallel(duration: 30s):
ego.drive with:
speed(80kph)
lane(1)