Code generator

from Wikipedia, the free encyclopedia

A code generator is a computer program for software development . It translates models created in UML , XML , structure diagrams , decision tables or another formal language into a programming language ( C , C ++ , assembler , ...) of the selected target platform. It creates source code (code generation), which is then combined with other program parts to form a program.

The product of a code generator is (albeit rarely) called a generator.

In compiler construction , the code generator is the part of a compiler that generates machine code during the compilation process.

Model-driven code generators

A software generator or code generator is a piece of software that generates source code for more complex software using a description language adapted to the problem . This description can be a graphical or textual model. It is therefore an aid to make the software development process more effective. One example are generators that generate complete class hierarchies from the UML description language in the desired object-oriented target language (e.g. C ++, Java ). In this case, the source code generated from the code generator serves as an interface for a user, whereas the diagram defines a metamodel .

Model-driven code generation from UML was already described in 2004 for embedded systems . The generation of code frames has been considered state of the art since at least 2012. Classes with attributes and functions are generated here. The handling of round-trip engineering remains open , because code bodies and visualization are mixed up.

Automated code generators

Simple variants work on the basis of the source files and replace so-called macro calls with ready-made text modules. The preprocessor is an example of this. Other variants generate completely new source code by processing meta information. Meta information describes the code generation process as well as properties of the program code to be created on a higher level (see also model-driven architecture ) and is either in separate files (such as with the parser generator ) or in the form of comments (also: attributes, annotations) within the existing program code in front. In contrast to manually controlled code generators, the generated code is generated automatically before or during the compilation process. The programming languages C # and Java offer their own language constructs (so-called annotations ).


Examples of code generation are:

  • The generation of source text from a diagram, a model, for example a program flow chart, a structure diagram or a UML model , or from other descriptions stored in metadata in order to reduce costs and time or to increase the quality of software development, universal application and CASE
  • Assemblers , which generate machine code from assembly code
  • Compilers that generate assembler code, machine code or byte code from code in a high-level language
  • The recovery of a source text from the translated program using reverse engineering
  • The automatic generation from existing code or existing program parts , for example the creation of an IDL interface from a Java interface
  • The generation of the implementation of an abstract description for example with Application Server - frameworks like J2EE
  • The automatic generation of new source texts from comments and annotations ( metadata ) in existing source texts, for example in Java using XDoclet or annotations
  • In the area of embedded systems (e.g. vehicle control units) the automatic generation of serial codes with a code generator


See also


  • Krzysztof Czarnecki and Ulrich W. Eisenecker: Generative Programming: Methods, Tools, and Applications . Addison-Wesley, 2000.
  • Thomas Stahl, Markus Völter, Sven Efftinge: Model-driven software development. Techniques, engineering, management . 2nd Edition. Dpunkt Verlag, 2007, ISBN 978-3-89864-448-8 .
  • Georg Pietrek, Jens Trompeter (Ed.), Model-Driven Software Development. MDA and MDSD in Practice , Developer Press, hardcover, ISBN 978-3939084112 .

Web links

Wiktionary: Generator  - explanations of meanings, word origins, synonyms, translations

Individual evidence

  1. ^ Daniel Witsch, Birgit Vogel-Heuser: Automatic code generation from the UML for the IEC 61131-3 . In: Embedded Systems . Springer Berlin Heidelberg, Berlin, Heidelberg 2004, ISBN 978-3-540-23424-1 , pp. 9-18 , doi : 10.1007 / 978-3-642-18594-6_2 ( [accessed August 16, 2019]).
  2. Bernhard Rumpe: Agile modeling with UML (= ). Springer Berlin Heidelberg, Berlin, Heidelberg 2012, ISBN 978-3-642-22429-4 , doi : 10.1007 / 978-3-642-22430-0 ( [accessed on August 16, 2019]).