S T R U C T O R I Z E R - User Guide
Export > Source code

Code Export Preparations

First of all, if you want to use the code generators, you should make sure to have filled in the parser preferences appropriately. You can find them via the menu "Preferences => Parser ...":

Parser Preferences dialog with french keys

All of the words you filled in there will be filtered out and replaced by the respective target language keywords.

For example, if your diagram contains a FOR-loop and you are writing french diagrams, you may have something like this:

If you then do a "Pascal" export, the generated code will be:
for I:=1 to 10
    { do something }
but a "C" export will result in the code:
for (I=1; I<=10; I+=(1)) {
    // do something

As you can notice, the words "pour" and "à" have been eliminated or replaced with whatever the exported code requires. For being able to do this, the generators must be fed the necessary information about the syntax you are using in your diagrams.

Interactive Code Export


To export a diagram as code, go to the menu and select "File => Export => Code ..." and the name of the language you want to export to.

The currently supported programming or script languages are the following ones (where StruktTeX is not actually a programming language but an add-on to LaTeX providing embeddable NSD drawings):

  • Pascal / Delphi
  • Oberon
  • StrukTeX
  • Perl
  • ksh
  • bash
  • C
  • C#
  • C++
  • Java
  • PHP
  • Python
  • Basic

Export Configuration

In the Export Preferences you may select your most frequently used (favourite) target language in order to accelerate the export via key combination Ctrl+Shift+X:
File menu with new menu item for export to the favourite language

You should be aware, of course, that the generated program files will usually not immediately be compilable or executable in the target language but require some manual post-processing because the generators will have to do a lot of mere guesswork: Though Structorizer tries hard to derive static type information from assignments or implicit declarations, the types of many of the used variables will not be known such that the generators will hardly be able to produce complete declaration lists for languages that require strict declaration. You will have to check for wrong, missing or mis-placed declarations and must accomplish or correct them manually. Some algorithmic construct may not directly be translatable such that the generators must try their best to compose something closely equivalent.

Usually "TODO" comments inserted in the generated code will guide you through the manual post-processing work.

The Export Option "No conversion of the expression/instruction contents" allows you to perform a kind of raw export with mere control structure conversion and mostly suppressed translation of the element contents. It is recommended to use this option if you explicitly write target code in Structorizer elements. In this case Structorizer wouldn't know how to translate your code into any other language, though.

Export Option "Involve called subroutines" is to enrich the code for the selected diagram with the routine definitions for all subroutines referred to by contained CALL elements - if the corresponding diagrams are reachable via the Arranger. Unavailable subroutines the exported diagram depends on will be reported without aborting the export process (the definitions will simply be missing in the resulting file(s)). You may find hints for missing subroutines in advance in the Analyser Report List if Analyser Preference "Check for inappropriate subroutine CALLs and missing call targets" is enabled.

See also: Code generators

Batch Export

Structorizer may also be used in batch mode to generate a source file for a supported programming language or other textual export format (like StrukTeX) from NSD files. The command syntax is given below, where the underlined pseudo program name Structorizer is to be replaced by the respective batch or shell script name for the console environment:

  • structorizer.sh for Linux, UNIX, and the like;
  • Structorizer.bat for Windows.

The scripts can be found in the Structorizer installation directory; don't try with Structorizer.exe! The Java WebStart installation is not suited, either - you need the unzipped respective downloadable version.

Structorizer -x generator [-b] [-c] [-l] [-t] [-e encoding] [-] [-f] [-o output-file] source-file ...

The options mean:

-x (followed by a generator name ) must be the first option and selects the target language or generator class. Currently supported language or generator class names are (case-insensitive, synonyms separated by "|"):

  • PasGenerator | Pascal | Delphi
  • OberonGenerator | Oberon
  • TexGenerator | StrukTeX
  • PerlGenerator | Perl
  • KSHGenerator | ksh
  • BASHGenerator | bash
  • CGenerator | C
  • CSharpGenerator | C#
  • CPlusPlusGenerator | C++
  • JavaGenerator | Java
  • PHPGenerator | PHP
  • PythonGenerator | Python
  • BasGenerator | Basic

-b sets the opening block brace for the body of compound statements at the beginning of the next line (otherwise to the end of the same line).

-c will export simple instructions as comments.

-l will create line numbers and more ancient-style code on BASIC export.

-t will suppress most transformations of instruction and expression contents (intended for the case that the Structorizer elements already contain code complying with the target language syntax).

-e ("encoding", followed by a charset name) determines the output file character set (UTF-8 being the default).

-f forces overwriting an existing file with same name as the designated output file (see -o), otherwise a name modification by an added or incremented counter is made (e.g. output.cpp -> output.0.cpp).

-o (followed by a file path or name) specifies a specific output file name. I not given, the output file name will be derived from the first nsd file name by replacing the file name extension with the one associated to the target language, e.g. ".java". The taget-language-specific file name extension is ensured in either case. If several nsd files are given then without option -o the created file will be named after the first nsd file name, with option -o, however, the filename of the option will be used.

- (single minus sign) will direct the code to the standard output instead of to the default output file. If -o option is also given, then the result will be written both to standard output and to the specified output file.

nsd-file (one or many file paths/names) the Structorizer diagram files to be converted to the target source file.

Note that the parser preferences configured in interactive Structorizer mode will be valid here, whereas the export options configured in interactive mode are not valid here, only the command line options described above will be observed (for binary options the contrary of the described option effect being the default, e.g. without specifying -l option there won't be line numbers or other old-fashioned relics in BASIC output).

Export of Diagrams for Turtleizer

If you export diagrams that control Turtleizer, then the exported code won't work unless you find some more or less compatible source package for your target language. For Java and C++, however, you may easily get identical or equivalent Turtle support:

  • From release 3.27 on, the original Turtleizer package sources from Structorizer are available for separate download and may be integrated in the Java project you set up around your exported code. You may also need the diagrcontrol package (a required interface) if it is not included in the Turtleizer download. Both packages require Java 8 as platform. The exported Java file will automatically be prepared to work with this package.
  • For C++, there is a functionally equivalent VisualStudio project Turtleizer_CPP available on GitHub that can at least be used by console applications under Windows -- either as static library (after having updated the project file to your VisualStudio version) or simply by integrating the header and code files in your C++ project. Your exported C++ file will just have to include the "Turtleizer.h" header (provided the other project settings are suited, see the README.md file in the download for details).