The SCCD (Statecharts + Class Diagrams) compiler and runtime.

Simon Van Mierlo d04f09d6e8 Merge branch 'master' of 2 years ago
doc 46113778d9 associate_instance and disassociate_instance now fixed 4 years ago
examples 37525b9675 private ports now work in both directions; added a bouncing balls example where the SCCD model does not contain UI code (completely external) 2 years ago
src d04f09d6e8 Merge branch 'master' of 2 years ago
test 8f66390cbb Fix tests for Py3 as well 3 years ago
textualnotations 068c424a35 Fix indentations. 3 years ago
.gitignore d779aff8e8 Ignore PyCharm project files. 3 years ago
LICENSE 04ec602b01 initial commit (from svn repo) 5 years ago 19a6463d6f changed javascript dependencies in readme 5 years ago 04ec602b01 initial commit (from svn repo) 5 years ago
schema.xml 04ec602b01 initial commit (from svn repo) 5 years ago

Statecharts and Class Diagram Compiler


Within the src directory, execute python install --user.

Compiling SCCDXML Files

To compile a conforming SCCDXML file, the provided Python compiler can be used:

$python -m sccd.compiler.sccdc --help
usage: python -m sccd.compiler.sccdc [-h] [-o OUTPUT] [-v VERBOSE]
                                     [-p PLATFORM] [-l LANGUAGE]

positional arguments:
  input                 The path to the XML file to be compiled.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        The path to the generated code. Defaults to the same
                        name as the input file but with matching extension.
  -v VERBOSE, --verbose VERBOSE
                        2 = all output; 1 = only warnings and errors; 0 = only
                        errors; -1 = no output. Defaults to 2.
  -p PLATFORM, --platform PLATFORM
                        Let the compiled code run on top of threads, gameloop
                        or eventloop. The default is eventloop.
  -l LANGUAGE, --language LANGUAGE
                        Target language, either "javascript" or "python".
                        Defaults to the latter.

The Threads Platform

The Threads platform is the most basic platform. It runs the SCCD model on the main thread when is called (meaning that the program will block on this call). If input needs to be provided to the SCCD model or the output of the SCCD model needs to be processed while it's running, a separate thread should be started. For example, the code below shows how input/output works for a compiled SCCD model target_py/ which was compiled for the threads platform and has two ports ("input" and "output"):

import as target
from sccd.runtime.statecharts_core import Event
import threading

if __name__ == '__main__':
    controller = target.Controller()
    def raw_inputter():
        while 1:
            controller.addInput(Event(raw_input(), "input", []))
    input_thread = threading.Thread(target=raw_inputter)
    input_thread.daemon = True
    output_listener = controller.addOutputListener(["output"])
    def outputter():
        while 1:
            print output_listener.fetch(-1)
    output_thread = threading.Thread(target=outputter)
    output_thread.daemon = True

The Eventloop Platform

The Eventloop platform works only in combination with a UI system that allows for scheduling events. Default implementations are provided for the Tkinter UI library on Python, and the default scheduler found in Javascript (through the setTimeout function).

In Python:

import Tkinter as tk
import as target
from sccd.runtime.libs.ui import ui
from sccd.runtime.statecharts_core import Event
from sccd.runtime.tkinter_eventloop import *

if __name__ == '__main__':
	ui.window = tk.Tk()
	controller = target.Controller(TkEventLoop(ui.window))

In Javascript:

<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src="target_js/target.js"></script>
controller = new Target.Controller(new JsEventLoop());

The Gameloop Platform

The Gameloop platform works in combination with a game engine, which calls the update function of the controller at regular intervals.


A number of examples can be found in the examples folder, demonstrating the syntax and capabilities of SCCD. They can be compiled by executing make clean all inside the examples folder. Each example has an associated runner file, with which the example can be executed.


A number of tests are provided which make sure the compiler and runtime implement the correct behaviour. They can be compiled by executing make clean all inside the tests folder. Tests are compiled for both Python and Javascript.

The generated Python test cases (in the tests/target_py folder) can be run by executing inside the tests folder.

The generated Javascript test cases (in the tests/target_js folder) can be run by executing run_tests.html inside the tests folder.