Further syntax documentation
SCCharts Statemachine
Each SCChart starts with the keyword scchart followed by an ID. A ID can be any alpha-numerical combination, but must start with an alphabetical character or an underscore (a single underscore is prohibited). However, underscores are used to identify auto-generated constructs, so the modeler should not use them as prefix.
Simple States
One of the basic constructs of SCCharts is a simple state. A simple state does not have any inner behavior and can be connected via transitions to other states.
Initial State
To tell the program where to start, a state can be marked as initial. Exactly one state (per concurrent region, see concurrency) must be marked as initial.
Transitions
Transitions connect states. There are different kinds of Transitions, but we will restrict ourselves to the two basic types for now. (See below for more complex transitions.)
They can be guarded by a trigger that determines when this transition is enabled and they can have one or more effects that are executed whenever this transition becomes active.
The exact syntax is as follows:
[immediate] [if condition] [do effect [; effect]*] (go | abort | join) to targetstate
Delayed Transitions
A delayed transition cannot trigger in the instance the parent state is entered. If a state is entered, they become active in the next tick. You can see this in the Simple example. Just write go to.
Immediate transitions are checked as soon as their parent state is entered. Hence, the state can be entered and left within the same tick. Use the keyword immediate to create an immediate transition
Explicit Delay Behavior
Transitions can be marked as delayed or auto explicitly. At the moment this is identical as not being immediate. However, in the upcoming 1.1 update, this will play a bigger role, when code generators can decide themselves if a transition has to be delayed or not.
Final State
A state can also be marked as final. A final state marks the end of a thread. If a final state is reached on root level, the program terminates.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Simple {
initial state A
go to B
state B
go to C
state C
immediate go to A
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Simple {
initial state A
auto go to B
state B
delayed go to C
final state C
} |
Image RemovedImage RemovedIf you add brackets to a Declarations & Variables
Each scope (for now just the SCChart) can have a list of declarations. The SCChart code on the right gives an example. A declaration starts with the type, followed by a list of variable identifier. Each variables can be initialized with a specific value.
Types
The following native types are supported: bool, int, float, string, host, and signal (see below)
Additionally, you can mark a declaration as extern and give it a string that will be used in the serialization of the final code, e.g., the name of a host type. You can then add variables as before.
Please note that most code generators will translate the semantical type float into a high-precision floating point host type (e.g. double in java).
Arrays
|
scchart Transitions {
input bool A, B
output int X, Y
initial state A
immediate if A do X++ go to B
state B
if A && B do X++; Y = X * 2 go to A
} |
Image Added
Image Added
Image Added
Declarations & Variables
Each scope (for now just the SCChart) can have a list of declarations. The SCChart code on the right gives an example. A declaration starts with the type, followed by a list of variable identifier. Each variables can be initialized with a specific value.
Types
The following native types are supported: bool, int, float, string, host, and signal (see below)
Additionally, you can mark a declaration as extern and give it a string that will be used in the serialization of the final code, e.g., the name of a host type. You can then add variables as before.
Please note that most code generators will translate the semantical type float into a high-precision floating point host type (e.g. double in java).
Arrays
If you add brackets to a variable and specify cardinalities, you declare an array.
Constants
Declarations can be marked as constant, meaning that each occurrence is then replaced by the initialization because the variable is not allowed to be changed.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Variables {
input bool second
output bool beep
int i, j, k
int arr[10]
bool alarm = false
const bool ON = 1
extern "rObj" rail
initial state A
go to B
state B
} |
Vectors
You can assign a whole vector to an array at once.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart tuples {
output int arr[5] = {1, 2, 3, 4, 5}
initial state init {
entry do arr = {6, 7, 8, 9, 10}
}
} |
To assign only certain values of an array, you can also use the ignore value placeholder. Consult the expression manual for further information.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart tuples {
const int A = 1
output int arr[3][2] = {{A,0}, {2,0}, {3,0}}
initial state init
do arr = {{arr[0] + 1, _}, _, {arr[2] + 1, _}} go to init
} |
This would, for example, result in c code assignments as displayed on the right.
Code Block |
---|
language | cpp |
---|
linenumbers | true |
---|
|
void logic(TickData* d) {
d->_g0 = d->_GO;
if (d->_g0) {
d->arr[0][0] = 1;
d->arr[0][1] = 0;
d->arr[1][0] = 2;
d->arr[1][1] = 0;
d->arr[2][0] = 3;
d->arr[2][1] = 0;
}
d->_g2 = d->_pg1;
if (d->_g2) {
d->arr[0][0] = d->arr[0] + 1;
d->arr[2][0] = d->arr[2] + 1;
}
d->_g1 = d->_g0 || d->_g2;
} |
You can simply use JavaDoc-style comments to comment you SCChart. The comments will appear in the synthesized diagram as comment boxes. You can toggle these boxes in your sidebar.
Additionally, for documentation reason, you can annotate different elements to give them a user-defined style. E.g. colorize a state or comment box for visual effect. Use html-like color codes for different colors. Please read more on annotations in the section belowSignals
Signals, as known from languages such as Esterel, are set to absent at the beginning of the tick. They can then be set to present during the current tick. Pure signals just know their activity state, whereas valued signals - in addition to their state also carry a value, which is persistent across ticks. If valued signals are emitted multiple times in the same tick, they require a combine function to merge the emitted values.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
/**
* Getting there!
*/
scchart Root {
/** Test */
input bool second
output bool speaker
/**
* Main region!
*/
region main:
/**
* The initial state
* This is entered as soon as the program starts.
*/
@foreground f0f024
@background ffffcc
@backgroundTarget fff9ba
initial state Superstate {
initial state R1
}
/** Transition */
/** Transition 2 */
join to Sscchart Singals {
signal x
signal int y = 0 combine +
region {
initial state A
do x; y(3) go to B
final state B
}
region {
initial state A
if x do y(4) go to B
final state B
}
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart superstates {
input bool F
initial state init {
initial state init
if F go to done
final state done
}
join to done
You can simply use JavaDoc-style comments to comment you SCChart. The comments will appear in the synthesized diagram as comment boxes. You can toggle these boxes in your sidebar.
Additionally, for documentation reason, you can annotate different elements to give them a user-defined style. E.g. colorize a state or comment box for visual effect. Please use a double @@ inside comments (to allow java doc etc). Use html-like color codes for different colors. Please read more on annotations in the section below.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
/**
* Getting there!
*/
scchart Root {
/** Test */
input bool second
output bool speaker
/**
* Main region!
*/
region main:
/**
* The finalinitial state!
* @@foreground f00
* @@background a00This is entered as soon as the program starts.
*/
@foreground f0f024
final state@background S
} |
Image Removed
Hierarchy & Concurrency
Superstates
Superstates model hierarchy. Each nested superstate creates a new scope. The syntax is easy: just start a new scope via curly brackets after your initial state declaration.
A superstate can be exited by any transition preemption type. However, especially the termination (or join) is of interest as it is taken as soon as the superstate finishes (meaning a final state is reached.)
Regions
Regions model concurrency. They follow the initialize-update-read protocol if scheduling between different regions becomes necessary.
A termination transition is taken if all regions of the superstate have reached a final state.
ffffcc
@backgroundTarget fff9ba
initial state Superstate {
initial state R1
}
/** Transition */
/** Transition 2 */
join to S
/**
* The final state!
* @@foreground f00
* @@background a00
*/
final state |
donecodeImage Added
languageHierarchy & Concurrency
sct | linenumbers | true |
scchart concurrencies {
input bool E, F
initial state EF {
region handleF {
initial state init
if F go to done
final state done
}
region handleE {
Superstates
Superstates model hierarchy. Each nested superstate creates a new scope. The syntax is easy: just start a new scope via curly brackets after your initial state declaration.
A superstate can be exited by any transition preemption type. However, especially the termination (or join) is of interest as it is taken as soon as the superstate finishes (meaning a final state is reached.)
Regions
Regions model concurrency. They follow the initialize-update-read protocol if scheduling between different regions becomes necessary.
A termination transition is taken if all regions of the superstate have reached a final state.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart superstates {
input bool F
initial state init {
initial state init
if EF go to done
final state done
}
}
join to done
final state done
} |
Image Removed
Image Removed
For Regions
You can automatically duplicate regions and access a region counter variable.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart |
IIIRO
input int IR
output bool OIIOentrydoO=false
handleF {
initial state init
|
II{
regionmainfori:1to3{initialstateIWaitifI==iIDone IDone do O =trueDone Done }
if R go to IIO
}This is also possible for a complete arrayImage Added
Image Added
Actions
Action in SCCharts are defined at the beginning of a state after the declarations.
Entry Action
An entry action is executed immediately when its state is entered. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
During Action
A during action is executed in each tick its state is active except when the state is entered. If an immediate during is used the action is also executed in the tick the state is entered. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
Exit Action
An entry action is executed when its state is left. Exit actions are considered inner behavior and are consequently suppressed if the state is strongly aborted. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Actions {
input bool trigger
output int effect
initial state A
go to B
state B {
entry do effect = 0
entry if trigger do effect++
during if trigger do effect++
immediate during if trigger do effect++
exit if trigger do effect *= 10
initial state B1
if trigger go to B2
state B2
}
} |
Image Removed
User Label
Transitions and actions in the diagram can be replaced by user defined labels.
Displaying these label can be controlled by the 'User Labels' synthesis option.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart UserLabels {
output int O
initial state A {
entry do O = 1 label "Initialize O"
during do O++ label "Increment O"
exit do O = 0 label "Reset O"
} do print("Hello World") go to B label "Say Hello"
final state B
} |
Image Removed
Suspend
Suspend suppresses the inner behavior of a state, if is trigger is evaluated to true. If the immediate modifier is present the suspension can already be enabled in the tick the state is entered, otherwise the trigger is only checked in subsequent ticks. The weak modifier allows instantaneous inner behavior of a suspended state but the reached state is not memorized.
Note |
---|
Weak suspend is not fully supported in 1.0 and may not be transformed or visualized (during simulation) correctly. |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Suspension {
input bool S1, S2, S3, S4
output int O = 0
suspend if S1
immediate suspend if S2
weak suspend if S3
immediate weak suspend if S3
initial state A
do O++ go to A
} |
Image Removed
In Core SCCharts only simple transitions that originate from simple states and terminations for superstates are legit. However, there are more complex transition types if taking Extended SCCharts into account.
Abort
SCCharts knows two types of preemption: weak and strong aborts.
Semantically, a weak abort allows the behavior of the aborting superstate in the current tick to proceed before preemption, whereas strong aborts terminate the superstate immediately. In the diagram, strong aborts are depicted with a red circle decorator.
Count Delay
In a count delay transition, the transiton trigger has to become true multiple times before firing.
Shallow History
If a superstate is entered via a shallow history transition, the superstate continues its execution at the point it was left excluding deeper hierarchies.
Deep History
With deep history transitions, the execution also recognizes deeper nesting levels, when re-entering the superstate.
Deferred
If a deferred transition is taken in the current tick, the target state will be entered in the next tick.
Note |
---|
History and deferred transitions are not fully supported in 1.0 and may result in unexpected behavior when combined. They may not be visualized correctly during simulation. |
Signals
Signals, as known from languages such as Esterel, are set to absent at the beginning of the tick. They can then be set to present during the current tick. Pure signals just know their activity state, whereas valued signals - in addition to their state also carry a value, which is persistent across ticks.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Aborts {
input bool I, S, W, Imm
output int F = 0
initial state A {
initial state A0
immediate if I && Imm go to A1
if I go to A2
final state A1
final state A2
}
immediate if S && Imm do F = 1 abort to F1
if S do F = 2 abort to F2
immediate if W && Imm do F = 3 go to F3
if W do F = 5 go to F4
do F = 5 join to F5
final state F1
final state F2
final state F3
final state F4
final state F5
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart ComplexTransitions {
input bool CD, SH, DH, D
output int F, F2
initial state A {
entry do F = 0
during do F++
initial state AA {
entry do F2 = 0
during do F2++
}
}
if 3 CD go to Wait
state Wait
if SH go to A shallow history
if DH go to A history
if D go to A deferred
go to A
} |
Image Removed
Image Removed
References
We will use the beep.sctx as example for referenced SCCharts.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Beep {
input bool second
output bool beep = false
initial state A
if second do beep = true go to B
state B
if second do beep = false go to A
} |
If you want to use another SCChart inside your model, you must first include it with an import statement. For example, if you want to include beep into the comment example "root" from above, you can add import "beep" and include a state that references beep.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "beep"
/**
* Getting there!
*/
scchart Root {
/** Test */
input bool second
output bool speaker
/**
* Main region!
*/
region main:
/**
* The initial state
* This is entered as soon as the program starts.
* @@foreground f0f024
* @@background ffffcc
* @@backgroundTarget fff9ba
*/
initial state R is Beep(second to second, speaker to beep)
/** Transition */
/** Transition 2 */
join to S
/**
* The final state!
* @@foreground f0f0240
* @@background ffc
*/
final state S
} |
The keyword is indicates that R is a reference. When you are referencing, you have to bind the interface of the referenced SCChart model to variables of the actual on. You must do this in the parentheses after the referenced state. In the example second is bound to second, and the local speaker boolean is bound to the beep from beep's interface. You can read more about variable bindings in the next paragraph. Also, the content assist will help you with your bindings and inform you about missing bindings.
Details about Bindings
There are three different kinds of bindings: explicit bindings, order bindings, and implicit bindings. In the example we used explicit bindings, which are the safest way of bindings.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
initial state R is Beep(second to second, speaker to beep) |
They state explicitly which local variable gets bound to which remote. The content assist will help you with errors.
If you know the order of the variables (and/or listen to the content assist), you can also use order bindings and simply state the list of local variables.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
initial state R is Beep(second, speaker) |
They will be bound to the interface in the order of declaration in the remote SCChart. However, be aware of the fact that the bindings will change, when the declarations of the referenced SCChart change.
In the example, the names of the local and referenced second variables are identical. Hence, you can also omit the binding completely.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
initial state R is Beep(speaker to beep) |
SCCharts will then bind the variable implicitly. However, we also consider this kind of binding unsafe and the editor will warn you about any implicit bindings. They can be handy though when dealing with large interfaces.
Continuation
As any state, referenced states are allowed to own transitions. However, if you are using terminations, you must make sure that the referenced SCChart terminates. Otherwise, the transition will never trigger. The content assist will help you with this issue.
Legacy
Info |
---|
You do not need to activate the Xtext nature as in previous versions of SCCharts. In fact, we recommend to deactivate the Xtext nature for SCCharts projects. |
Image Removed
Image Removed
Example warnings from the content assist:
Image Removed
Image Removed
Image Removed
Inheritance
SCCharts support inheritance, similar to the concept of references.
Each root state can extend multiple base states (since the name super states is already used) by listing them after the extends keyword.
Such an state will inherit all declarations, action and regions of the base states. If conflicts arise or a state has a cyclic inheritance hierarchy, a warning will be displayed. If a state is contained multiple times in the inheritance hierarchy its content will inherited only once.
Declarations can have the private keyword to prevent extending SCCharts from accessing these variables.
Root-level regions of base states can be overriden with the override keyword and consequently replace the behavior by the new definition. Anonymous regions (defined without an ID) cannot be overridden.
Regions can also be references similar to states by using the is keyword. If the reference should refer to the implementation in the base state, the super keyword must be used.Actions
Action in SCCharts are defined at the beginning of a state after the declarations.
Entry Action
An entry action is executed immediately when its state is entered. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
During Action
A during action is executed in each tick its state is active except when the state is entered. If an immediate during is used the action is also executed in the tick the state is entered. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
Exit Action
An entry action is executed when its state is left. Exit actions are considered inner behavior and are consequently suppressed if the state is strongly aborted. If the optional trigger is specified the effect(s) will only be executed if the trigger condition is true.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Actions {
input bool trigger
output int effect
initial state A
go to B
state B {
entry do effect = 0
entry if trigger do effect++
during if trigger do effect++
immediate during if trigger do effect++
exit if trigger do effect *= 10
initial state B1
if trigger go to B2
state B2
}
} |
Image Added
User Label
Transitions and actions in the diagram can be replaced by user defined labels.
Displaying these label can be controlled by the 'User Labels' synthesis option.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart UserLabels {
output int O
initial state A {
entry do O = 1 label "Initialize O"
during do O++ label "Increment O"
exit do O = 0 label "Reset O"
} do print("Hello World") go to B label "Say Hello"
final state B
} |
Image Added
Suspend
Suspend suppresses the inner behavior of a state, if is trigger is evaluated to true. If the immediate modifier is present the suspension can already be enabled in the tick the state is entered, otherwise the trigger is only checked in subsequent ticks. The weak modifier allows instantaneous inner behavior of a suspended state but the reached state is not memorized.
Note |
---|
Weak suspend is not fully supported in 1.0 and may not be transformed or visualized (during simulation) correctly. |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Suspension {
input bool S1, S2, S3, S4
output int O = 0
suspend if S1
immediate suspend if S2
weak suspend if S3
immediate weak suspend if S3
initial state A
do O++ go to A
} |
Image Added
In Core SCCharts only simple transitions that originate from simple states and terminations for superstates are legit. However, there are more complex transition types if taking Extended SCCharts into account.
Abort
SCCharts knows two types of preemption: weak and strong aborts.
Semantically, a weak abort allows the behavior of the aborting superstate in the current tick to proceed before preemption, whereas strong aborts terminate the superstate immediately. In the diagram, strong aborts are depicted with a red circle decorator.
Count Delay
In a count delay transition, the transition trigger has to become true multiple times before firing.
Shallow History
If a superstate is entered via a shallow history transition, the superstate continues its execution in the state that was active when the superstate was left. The last active state is re-entered that means entry actions will be executed again. If this state is a superstate too, shallow history will not restore the last active state in deeper hierarchy levels.
Deep History
With deep history transitions, the execution also recognizes deeper nesting levels, when re-entering the superstate.
Deferred
If a deferred transition is taken, it preempts all immediate behavior in the target state, this includes entry actions.
Note |
---|
History and deferred transitions are not fully supported in 1.0 and may result in unexpected behavior when combined. They may not be visualized correctly during simulation. |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Aborts {
input bool I, S, W, Imm
output int F = 0
initial state A {
initial state A0
immediate if I && Imm go to A1
if I go to A2
final state A1
final state A2
}
immediate if S && Imm do F = 1 abort to F1
if S do F = 2 abort to F2
immediate if W && Imm do F = 3 go to F3
if W do F = 5 go to F4
do F = 5 join to F5
final state F1
final state F2
final state F3
final state F4
final state F5
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart MotorWithButton
extends ButtonBehavior, MotorBehavior { ComplexTransitions {
input bool CD, SH, DH, D
output int F, F2
initial state A {
initial state Init
immediate do F = 0 go to Count
override regionstate HandleMotorCount {
suspend if !buttonPressed
during do F++
region is super.HandleMotor
}
}
scchart MotorBehavior {
outputinitial intstate motorRotationInit
const int motorRotationMax = 16
entryimmediate do motorRotationF2 = 0 go to Count2
region HandleMotor {
initial state IncrementCount2 {
during do motorRotationF2++
}
}
}
if motorRotation == motorRotationMax3 CD go to Wait
state Wait
if doSH motorRotationgo =to 0
A shallow history
if DH abortgo to A Incrementhistory
}
}
scchart ButtonBehavior {
input float buttonPositionif D go to A deferred
go bool buttonPressed = false
private const float threshold = 0.5
region HandleButton {
initial state Released
if buttonPosition < threshold
do buttonPressed = true
go to Pressed
state Pressed
if buttonPosition >= threshold
do buttonPressed = false
go to Released
}
} |
Image Removed
Image Removed
Dataflow
You can convert a region into a dataflow region by replacing the region keyword with the keyword dataflow. Within a dataflow scope, you can simply write down your equations.
On the right you see several examples and their synthesized diagrams.
Equations (df#0007)
You can use all expressions in the kexpressions language. This includes standard operations such as arithmetics and binary/logical logic. A full set of operations can be found at the end of this page (in the future).
References (df#0461)
Just as before, you can declare references to other SCCharts. As before, use the ref keyword in your declaration section. Each variable represents an instance. Inputs and outputs are separated by a dot (.). Same wires are merged automatically in the diagram.
Of course you can model loops in your wiring. However, depending on the consecutive compilation/scheduling the program may or may not be executable/schedulable.
Tuples (df#0603)
You can use the aforementioned tuple syntax to assign all/some inputs at once. Hence, it is possible to construct complex models with only a few lines of code.
Skins (df#1000, df#1100)
You can use customized skins instead of the standard referenced SCCharts actor diagram. Since we are using Klighd, you have to specify your actor in Klighd's Graph Syntax (.kgt). Once you have created a custom .kgt, you can add it to an SCChart with the @figure
annotation. The annotation combined with a skinpath relative to the calling model points to the target .kgt.
For example: Imaging df#0007 is annotated with @figure "and2AN.kgt". Now df#1000 can set a skinpath pragma. Together they point to the .kgt that should be used as actor diagram. In this case, we get an and
with a negated input.
Even if df#0007 was not annotated, you can archive the same result if you annotate the ref
declaration in df#1000.:
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
@figure "and2AN.kgt"
ref df#0008 A, A2 |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart df#0007 {
input bool in1, in2
output bool out
dataflow:
out = in1 + in2
}to A
} |
Image Added
Image Added
References
We will use the beep.sctx as example for referenced SCCharts.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart Beep {
input bool second
output bool beep = false
initial state A
if second do beep = true go to B
state B
if second do beep = false go to A
} |
If you want to use another SCChart inside your model, you must first include it with an import statement. For example, if you want to include beep into the comment example "root" from above, you can add import "beep" and include a state that references beep.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "beep"
/**
* Getting there!
*/
scchart Root {
/** Test */
input bool second
output bool speaker
/**
* Main region!
*/
region main:
/**
* The initial state
* This is entered as soon as the program starts.
* @@foreground f0f024
* @@background ffffcc
* @@backgroundTarget fff9ba
*/
initial state R is Beep(second to second, speaker to beep)
/** Transition */
/** Transition 2 */
join to S
/**
* The final state!
* @@foreground f0f0240
* @@background ffc
*/
final state S
} |
The keyword is indicates that R is a reference. When you are referencing, you have to bind the interface of the referenced SCChart model to variables of the actual on. You must do this in the parentheses after the referenced state. In the example second is bound to second, and the local speaker boolean is bound to the beep from beep's interface. You can read more about variable bindings in the next paragraph. Also, the content assist will help you with your bindings and inform you about missing bindings.
Details about Bindings
There are three different kinds of bindings: explicit bindings, order bindings, and implicit bindings. In the example we used explicit bindings, which are the safest way of bindings.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0002"
scchart df#0461 {
output int O, O2, O3, O4
ref df#0002 A, A2, A3, A4
dataflow:
O = A.O || A2.O || A3.O
O2 = A.O || A2.O || A3.O
O3 = A.O || A2.O || A3.O
O4 = A.O || A2.O || A3.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0000"
scchart df#0521 {
input bool I
output int O
ref df#0000 A
dataflow:
A.I = I + A.O
O = A.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0006"
scchart df#0603 {
input int I, I2
output int O
ref df#0006 A, A2
dataflow:
A = {0, 1, _, I}
A2 = {0, A.O, I + 1, I - 1}
A.I3 = 100
O = A2.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0007"
#skinpath "skin"
scchart df#1000 {
input int I, I2
output int O
ref df#0007 A, A2
dataflow:
A = {true, false}
A2 = {true, A.out}
O = A2.out
} |
Image Removed
Image Removed
Image Removed
Image Removed
Image Removed
Hostcode
There are several ways to add hostcode to your models.
External References (hostcode#10)
You can declare a new object as external reference like before with (internal) references. Use the keyword extern to mark it as extern. Then use a string
to set the name of the function and an object which you will use to reference this hostcode snippet. As it is handled as a call, you can add parameters and they will be recognized by the dependency analysis.
Additionally, you can annotate your code snippets with the name of the code generator (e.g. C, Java) to tell the code generation which one should be used when. See the example on the right for more details.
Function Calls
While an External Reference is the preferred way to declare a hostcode call, you can call any function without declaring it first. However, due to grammar limitations and platform-dependency this older features is considered deprecated. You should really use external references.
Nevertheless, you can still use this feature by using the extern keyword directly inside the expression (e.g. r = extern gettimeofday()) without declaring the call beforehand.
The dependency analysis will consider parameters.
Legacy Hostcode (hostcode#30)
You can simply place the host code in accent grave (`) quotes. The code is put as it is into the final code. There is no further processing and also no parameter list. You can of course put the parameters inside the host code quotes, but they will be copied as they are.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart hostcode#10 {
output float r
extern @C "rand",
@Java "Math.random" rand
entry do rand(0)
initial state init
do r = rand() go to init
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart hostcode#30 {
entry do `srand();`
initial state init
} |
Image Removed
Image Removed
Annotations
The textual SCCharts language supports several annotations to influence the visual representation of the model.
Annotation are processed in sequential order.
Pattern | Usage | Description | Example |
---|
No Format |
---|
| @diagram[<key>] <value> |
| Location: | scchart |
---|
<key> | The name of the synthesis option. The given name is evaluated case-insensitive and whitespace-ignoring. The options are searched for the first matching prefix. |
---|
<value> | The value type depends on the option type: CheckBox: true or false Choice: Name of choice item Slider: Float value |
---|
| Sets the synthesis option identified by <key> to the given value.
The available synthesis options for a diagram are displayed in the sidebar of the diagram view.
The values from the sidebar will be ignored if a corresponding annotation is present.
Expand |
---|
|
initiallycollapseregions | Collapses all regions. Very helpful for lager models, since it fastens initial diagram rendering. |
Code Block |
---|
| @diagram[paper] true
scchart Testing {
initial state A
--> B;
final state B;
} |
| No Format |
---|
| @layout[<key>] <value> |
| Location: | scchart, state, region, transition |
---|
<key> | The ID of the layout option. The options are searched for the first matching postfix. |
---|
<value> | The value type depends on the option type. The value is parsed case-sensitive. |
---|
| Sets the layout property identified by <key> to the given value on the annotated element. The available layout options are documented here. Layout options will only affect the annotated element and no underlying hierarchy levels. If a layout direction is specified with this annotation it overrides the layout direction set by HV-/VH-Layout in any parent element for this element. Special case: If the direction is set on the scchart element (top level) it overrides the default alternating layout. The layout option is identified by matching a postfix. Hence the key direction matches both org.eclipse.elk.direction and org.eclipse.elk.layered.priority.direction . If none or multiple options match a warning is displayed. Expand |
---|
| elk.direction | Layout direction | elk. priority | Influences the order of regions |
|
| Code Block |
---|
|
scchart Testing {
@layout[algorithm] org.eclipse.elk.graphviz.circo
region:
initial final state A
--> B;
state B
--> C;
state C
--> A;
} |
Code Block |
---|
|
scchart Testing {
@layout[elk.direction] UP
region "up":
initial state A
--> B;
final state B;
@layout[elk.direction] LEFT
region "left":
initial state A
--> B;
final state B;
} |
No Format |
---|
| @HVLayout
@VHLayout |
| Location: | scchart, state, region |
---|
| Defines the order of the alternating layout directions. The annotation can be mixed and nested in the SCChart and will only affect succeeding hierarchy levels. The default is an implicit HVLayout starting at the top level state. | Code Block |
---|
| @VHLayout
scchart Testing {
initial state A
go to B;
final state B;
} |
|
No Format |
---|
| @collapse
@expand |
| | The annotated region will be initially collapse or expanded. | Code Block |
---|
| scchart Testing {
@collapse
region {
initial state A
go to B;
final state B;
}
} |
|
| Location: | scchart, state, region, transition |
---|
| The annotated element will be excluded from the diagram. Transitions with a hidden source or target state will be hidden as well. | Code Block |
---|
| scchart Testing {
initial state A
go to B;
@hide
final state B;
} |
|
Pragmas
Pragmas are annotations that are valid for the whole file in contrast to annotations that are valid for semantic model elements. They are placed in front of an .sctx.
Pragma | Effect |
---|
#KiCoEnv {<json>} | Configures the compiler environment. |
#hostcode | Allows hostcode additions that are placed at the beginning of the generated code file. The exact handling may depend on the used code generator.initial state R is Beep(second to second, speaker to beep) |
They state explicitly which local variable gets bound to which remote. The content assist will help you with errors.
If you know the order of the variables (and/or listen to the content assist), you can also use order bindings and simply state the list of local variables.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
initial state R is Beep(second, speaker) |
They will be bound to the interface in the order of declaration in the remote SCChart. However, be aware of the fact that the bindings will change, when the declarations of the referenced SCChart change.
In the example, the names of the local and referenced second variables are identical. Hence, you can also omit the binding completely.
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
initial state R is Beep(speaker to beep) |
SCCharts will then bind the variable implicitly. However, we also consider this kind of binding unsafe and the editor will warn you about any implicit bindings. They can be handy though when dealing with large interfaces.
Continuation
As any state, referenced states are allowed to own transitions. However, if you are using terminations, you must make sure that the referenced SCChart terminates. Otherwise, the transition will never trigger. The content assist will help you with this issue.
Legacy
Info |
---|
You do not need to activate the Xtext nature as in previous versions of SCCharts. In fact, we recommend to deactivate the Xtext nature for SCCharts projects. |
Image Added
Image Added
Example warnings from the content assist:
Image Added
Image Added
Image Added
Dataflow
You can convert a region into a dataflow region by replacing the region keyword with the keyword dataflow. Within a dataflow scope, you can simply write down your equations.
On the right you see several examples and their synthesized diagrams.
Equations (df#0007)
You can use all expressions in the kexpressions language. This includes standard operations such as arithmetics and binary/logical logic. A full set of operations can be found at the end of this page (in the future).
References (df#0461)
Just as before, you can declare references to other SCCharts. As before, use the ref keyword in your declaration section. Each variable represents an instance. Inputs and outputs are separated by a dot (.). Same wires are merged automatically in the diagram.
Of course you can model loops in your wiring. However, depending on the consecutive compilation/scheduling the program may or may not be executable/schedulable.
Tuples (df#0603)
You can use the aforementioned tuple syntax to assign all/some inputs at once. Hence, it is possible to construct complex models with only a few lines of code.
Skins (df#1000, df#1100)
You can use customized skins instead of the standard referenced SCCharts actor diagram. Since we are using Klighd, you have to specify your actor in Klighd's Graph Syntax (.kgt). Once you have created a custom .kgt, you can add it to an SCChart with the @figure
annotation. The annotation combined with a skinpath relative to the calling model points to the target .kgt.
For example: Imaging df#0007 is annotated with @figure "and2AN.kgt". Now df#1000 can set a skinpath pragma. Together they point to the .kgt that should be used as actor diagram. In this case, we get an and
with a negated input.
Even if df#0007 was not annotated, you can archive the same result if you annotate the ref
declaration in df#1000.:
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
@figure "and2AN.kgt"
ref df#0008 A, A2 |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart df#0007 {
input bool in1, in2
output bool out
dataflow:
out = in1 + in2
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0002"
scchart df#0461 {
output int O, O2, O3, O4
ref df#0002 A, A2, A3, A4
dataflow:
O = A.O || A2.O || A3.O
O2 = A.O || A2.O || A3.O
O3 = A.O || A2.O || A3.O
O4 = A.O || A2.O || A3.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0000"
scchart df#0521 {
input bool I
output int O
ref df#0000 A
dataflow:
A.I = I + A.O
O = A.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0006"
scchart df#0603 {
input int I, I2
output int O
ref df#0006 A, A2
dataflow:
A = {0, 1, _, I}
A2 = {0, A.O, I + 1, I - 1}
A.I3 = 100
O = A2.O
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
import "DF-0007"
#skinpath "skin"
scchart df#1000 {
input int I, I2
output int O
ref df#0007 A, A2
dataflow:
A = {true, false}
A2 = {true, A.out}
O = A2.out
} |
Image Added
Image Added
Image Added
Image Added
Image Added
Hostcode
There are several ways to add hostcode to your models.
External References (hostcode#10)
You can declare a new object as external reference like before with (internal) references. Use the keyword extern to mark it as extern. Then use a string
to set the name of the function and an object which you will use to reference this hostcode snippet. As it is handled as a call, you can add parameters and they will be recognized by the dependency analysis.
Additionally, you can annotate your code snippets with the name of the code generator (e.g. C, Java) to tell the code generation which one should be used when. See the example on the right for more details.
Function Calls
While an External Reference is the preferred way to declare a hostcode call, you can call any function without declaring it first. However, due to grammar limitations and platform-dependency this older features is considered deprecated. You should really use external references.
Nevertheless, you can still use this feature by using the extern keyword directly inside the expression (e.g. r = extern gettimeofday()) without declaring the call beforehand.
The dependency analysis will consider parameters.
Legacy Hostcode (hostcode#30)
You can simply place the host code in accent grave (`) quotes. The code is put as it is into the final code. There is no further processing and also no parameter list. You can of course put the parameters inside the host code quotes, but they will be copied as they are.
Host Types (hostcode#40)
You can create variables of non-built-in types by using host declarations. The type is given as a string that will be used in code generation.
Info |
---|
|
There are pragmas that allow to include host code snippets, such as includes and imports, in the generated code (#hostcode). As well as ways to include header files or libraries in the simulation process to enable linking and execution of the SCCharts program (#resource). See: Annotations and Pragmas Due to the introduction of object-orientation in SCCharts, there is also support for host classes and structs. See: Object Orientation |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart hostcode#10 {
output float r
extern @C "rand",
@Java "Math.random" rand
entry do rand(0)
initial state init
do r = rand() go to init
} |
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart hostcode#30 {
entry do `srand();`
initial state init
}
|
Code Block |
---|
language | sct |
---|
linenumbers | true |
---|
|
scchart hostcode#40 {
host "int64" number
initial state init
} |
Image Added
Image Added
Quick Overview
Here you can see an SCCharts graphical notation overview.