StruktoLab uses a simple pseudocode syntax to define structograms. Two languages are supported: German (default) and English. Indentation (4 spaces) defines nesting.
// Task (any plain statement)
ergebnis = 1
// Input
eingabe("Zahl n")
// Output
ausgabe("Ergebnis")
// Task (any plain statement)
result = 1
// Input
input("number n")
// Output
output("result")
falls x > 0:
ausgabe("positiv")
sonst:
ausgabe("nicht positiv")
if x > 0:
output("positive")
else:
output("not positive")
[ratio, ratio]:falls x > 0 [0.7, 0.3]: β 70% for true, 30% for false.
unterscheide farbe:
fall "rot":
ausgabe("stopp")
fall "grΓΌn":
ausgabe("los")
sonst:
ausgabe("unbekannt")
switch color:
case "red":
output("stop")
case "green":
output("go")
else:
output("unknown")
unterscheide farbe [0.4, 0.3, 0.3]:
// Count loop (for)
wiederhole fΓΌr i = 1 bis 10:
ausgabe(i)
// Head loop (while)
wiederhole solange x > 0:
x = x - 1
// Foot loop (do-while)
wiederhole:
eingabe("Wert")
solange wert != 0
// Count loop (for)
repeat for i = 1 to 10:
output(i)
// Head loop (while)
repeat while x > 0:
x = x - 1
// Foot loop (do-while)
repeat:
input("value")
while value != 0
funktion factorial(n):
falls n <= 1:
ergebnis = 1
sonst:
ergebnis = n * factorial(n - 1)
function factorial(n):
if n <= 1:
result = 1
else:
result = n * factorial(n - 1)
versuche:
x = parse(eingabe)
fange Exception e:
ausgabe("Fehler")
try:
x = parse(input)
catch Exception e:
output("error")
Use \n in node text for manual line breaks within a single node. In the visual editor, press Shift+Enter while editing a node.
| Concept | German | English |
|---|---|---|
| If | falls | if |
| Else | sonst | else |
| Repeat | wiederhole | repeat |
| While | solange | while |
| For | fΓΌr | for |
| To (range) | bis | to |
| Switch | unterscheide | switch |
| Case | fall | case |
| Function | funktion | function |
| Try | versuche | try |
| Catch | fange | catch |
| Input | eingabe | input |
| Output | ausgabe | output |
| True label | Wahr | True |
| False label | Falsch | False |
| Default label | Sonst | Default |
<struktolab-editor>A full-featured visual structogram editor with toolbar, pseudocode sync, and import/export.
<!-- Load the script -->
<script src="struktolab-editor.js"></script>
<!-- Empty editor -->
<struktolab-editor font-size="14"></struktolab-editor>
<!-- With pseudocode -->
<struktolab-editor font-size="14" lang="en">
<script type="text/pseudocode">
input("number n")
result = 1
repeat for i = 1 to n:
result = result * i
output(result)
</script>
</struktolab-editor>
<!-- With JSON -->
<struktolab-editor font-size="14">
<script type="application/json">
{ "type": "TaskNode", "text": "x = 42" }
</script>
</struktolab-editor>
<!-- From external JSON file -->
<struktolab-editor src="my-diagram.json"></struktolab-editor>
| Attribute | Description | Default |
|---|---|---|
width | Fixed width in pixels (auto-sizes if omitted) | auto |
font-size | Font size in pixels | 14 |
lang | Pseudocode language: de or en | de |
src | URL to a JSON tree file | β |
const editor = document.querySelector('struktolab-editor');
// Get / set the tree object
editor.tree = { type: "TaskNode", text: "hello" };
console.log(editor.tree);
// Set from pseudocode string
editor.pseudocode = 'input("name")\noutput("Hello " + name)';
// Code generation
editor.toCode('python'); // β Python code
editor.toCode('java'); // β Java code
editor.toCode('javascript'); // β JavaScript code
// Save / Load JSON (clean, no internal IDs)
const json = editor.saveJSON();
editor.loadJSON(json);
// Export as image
const pngBlob = await editor.exportImage('png');
const svgBlob = await editor.exportImage('svg');
// Programmatic update (re-renders + emits change event)
editor.change({ type: "TaskNode", text: "updated" });
// Listen for changes
editor.addEventListener('change', (e) => {
console.log('Tree changed:', e.detail.tree);
});
<struktolab-renderer>A read-only SVG renderer for displaying structograms. Same attributes and tree format as the editor, but without editing capabilities.
<script src="struktolab-renderer.js"></script>
<struktolab-renderer font-size="14" lang="en">
<script type="text/pseudocode">
if x > 0:
output("positive")
else:
output("not positive")
</script>
</struktolab-renderer>
const renderer = document.querySelector('struktolab-renderer');
// Set tree or pseudocode
renderer.tree = { type: "TaskNode", text: "hello" };
renderer.pseudocode = 'output("hello")';
// Code generation
renderer.toCode('python');
The tree is a nested JSON structure. Each node has a type, optional text, and a followElement for the next sibling.
| Type | Properties |
|---|---|
TaskNode | text, followElement |
InputNode | text, followElement |
OutputNode | text, followElement |
BranchNode | text, trueChild, falseChild, columnWidths, followElement |
CaseNode | text, cases (array of InsertCase), defaultOn, defaultNode, columnWidths, followElement |
HeadLoopNode | text, child, followElement |
FootLoopNode | text, child, followElement |
CountLoopNode | text, child, followElement |
FunctionNode | text, parameters (array), child, followElement |
TryCatchNode | text, tryChild, catchChild, followElement |
{
"type": "BranchNode",
"text": "x > 0",
"columnWidths": [0.6, 0.4],
"trueChild": {
"type": "OutputNode",
"text": "positive"
},
"falseChild": {
"type": "OutputNode",
"text": "not positive"
},
"followElement": {
"type": "TaskNode",
"text": "done"
}
}
StruktoLab encodes the entire structogram state in the URL hash using pako (zlib compression). This makes diagrams shareable via a single link β no server required.
URLs from struktolab.openpatch.org are compatible and can be opened directly.
Format: #pako:<base64url-compressed-json>
The compressed JSON contains:
{
"origin": "https://example.com",
"version": 2,
"model": { /* tree JSON */ },
"settings": { "lang": "de", "fontSize": "14" }
}