The IEC 61131-3 Structured Text to XML Compiler

by Volker Birk

This is a compiler being used for automated software development. I.e. it was used in a project to generate HMI code out of the IEC source code of a 300 kLOC controlling program for a production machine.

The IEC 61131-3 ST Compiler together with the YML toolchain were successfully used for that purpose already. Both tools are Free Software. Please feel free to use them in your projects yourself. If you need support, ask pibit AG. The toolchains are fully commercially supported. So it's not only possible to generate ST code out of UML with those tools for you, the reverse is also possible: generating code out of your PLC program for connected systems.

This compiler parses an IEC Structured Text source and compiles out an XML representation of the syntax tree of the source. As tag names mainly the defined names in the IEC 61131-3 grammar are used, replacing the underscore _ characters in the names of the non-terminal symbols with a minus sign -.

IEC Structured Text to XML Compiler is written in Python using the pyPEG library (which is included). It requires Python version 2.5 or later and the lxml Python library to run.


To use it, enter iec2xml followed by the filename of your IEC ST source into a shell:

% iec2xml -Po sample.xml sample.EXP

Command line syntax

The IEC Structured Text to XML compiler has the following options:

-h, --help

Show a help message and exit.

-o FILE, --output=FILE

Don't output to stdout, instead place output in file FILE.

-p, --parse-only

Parse only, then output pyAST as text to stdout. The pyAST is the Abstract Syntax Tree of the parsed script as Python data structure.

-P, --pretty

Pretty print output adding whitespace (available with lxml installed only)


Show version information of the implementation.

The YML tool chain

The YML tool chain can be used to process the output of the IEC Structured Text to XML compiler.

XML Renicing Tool

Sometimes, you may want to have more human readable output with iec2xml. So an XML renicing tool can be helpful.

The XMLStarlet command line tool may be of interest.

Have a look on its fo command.

Windows tool chain

See also the tips for a Windows tool chain for YML.