Programmer's Wiki

Modula-2 is a strongly typed, imperative programming language that was developed in the late 1970s by Professor Niklaus Wirth at the Swiss Federal Institute of Technology in Zurich (ETHZ) as a system implementation language for a Macintosh like personal computer workstation project called Lilith. Modula-2 is based on Wirth's earlier languages Pascal and Modula. In response to several criticisms of Pascal, Wirth improved on the Pascal design in Modula-2, most notably:

  • no goto statement
  • no dangling else; IF always requires END, ELSE/ELSIF occur within an IF ... END block
  • fewer uses of blocks (BEGIN ... END)
  • and endless loop statement (LOOP ... EXIT ... END)
  • source text is case sensitive, reserved words are in all uppercase
  • a function/procedure type
  • clean separation of interface and implementation of a module within two files
  • data encapsulation via local modules and opaque types
  • I/O functions via library modules, not built-in
  • emulation of concurrency via built-in coroutines

Standards and Dialects[]

Wirth published the Modula-2 language specification under the title "Programming in Modula-2" for which three revised editions appeared in print by Springer Verlag. Each revision made minor changes to the language specification and the resulting "dialects" are commonly referred to as PIM, PIM2, PIM3 and PIM4. Most of the available Modula-2 compilers available in the 1980s followed either the PIM2 or the PIM3 standard.

Towards the end of the 1980s, an international standardisation committee was formed at the International Standards Organisation (ISO). The resulting Modula-2 ISO standard was ratified and published in 1993. Compilers developed since then usually follow the ISO standard or a subset thereof. The main differences between ISO and the PIM standards are:

  • no assumptions about the underlying hardware architecture, e.g. number of bits in a byte does not necessarily have to be 8 (as required in C)
  • various clarifications on semantics where PIM did not specify them
  • behaviour of DIV and MOD when used with negative arguments
  • string literals can be concatenated (using "+")
  • delimiters for compiler pragmas are "<*" and "*>"
  • structured value constructors
  • module finalisation
  • exception handling
  • type COMPLEX
  • a standardised library

Following the ratification of the base standard, the ISO working group produced two optional standard extensions, one for object oriented language extensions and another for generic language extensions.

Modula-2 Grammars[]

Current Modula-2 Compilers[]

There have been many Modula-2 compilers for microcomputers and personal computers in the 1980s, most of which have since disappeared or are for platforms which have since disappeared. Most web sites with information about Modula-2 list so many of these abandonware compilers that an unaware person in search for information will find it very difficult to find the compilers which are actually available for use on current computer platforms. The following list of Modula-2 compilers therefore shall not repeat this mistake and only list the compilers which are relevant in the 21st century. Operating systems such as CP/M, Atari TOS, the classic Amiga OS, the classic Macintosh OS and OS/2 are certainly still in use by some people but they are no longer relevant.

Current Open Source Modula-2 Compilers[]

  • GNU Modula-2, a Modula-2 front-end for GCC, PIM2/3/4 and ISO, still under development but functional
  • M2M, the original M-code Modula-2 compiler by ETHZ, PIM2, generates code for a virtual machine and is therefore portable and still functional
  • Objective Modula-2, PIM3 with language extensions for Cocoa/GNUstep, still under development, front-end functional

Current Commercial Modula-2 Compilers[]

  • Canterbury Modula-2, written in Java, generates Java source code
  • Gardens Point Modula-2, for Unix systems and .NET CLR
  • MOD51 Modula-2, targeting 8051 type embedded controllers
  • MOCKA Modula-2, PIM3, executable for Linux available free of charge
  • p1 Modula-2, ISO, for Macintosh, demo-version available free of charge
  • Waterloo Modula-2, PIM3, for VM/SP CMS (IBM Mainframe OS)
  • XDS Modula-2, ISO, executables for Linux and Windows available free of charge

Further reading[]