Modula-2 + Smalltalk OO
A most versatile combination
Objective Modula-2 is a reflective, object oriented programming language with dynamic message dispatch (late binding) and both static and dynamic typing. Its object system is based on the object model of Smalltalk and it uses the runtime library of Objective-C to support the Cocoa and GNUstep APIs natively.
The design is an example how native support for Cocoa (Mac OS X), Cocoa Touch (iPhone) and GNUstep (BSD/Linux) can be added to static imperative programming languages without implementing an Objective-C bridge.
Objective Modula-2 in Brief
Base Language
Objective Modula-2 defines a set of language extensions to add native support for Cocoa, Cocoa Touch and GNUstep to any existing Modula-2 dialect without conflicts or inconsistencies.
However, the Objective Modula-2 reference implementation is based on the Modula-2 R10 dialect, a modern revision of Niklaus Wirth's fourth edition of Programming in Modula-2. The following is a brief summary of the changes relative to Wirth's language report:
Removed Features
- No local modules
- No variant records
- No
EXPORT
statement - No
WITH
DO
statement - No synonyms (
~
,&
,<>
) - No octal number literals
- No type conversion functions
- No anonymous types except for one-dimensional arrays
Replacement Features
- Radix 2 replaces radix 8 in binary literals
- Radix 16 replaces radix 8 in character code literals
- Extensible record types replace variant records
- Pragma delimiters
<*
and*>
replace(*$
and*)
- A type conversion operator
::
replaces conversion functions - Increment
++
and decrement--
statements replaceINC
andDEC
Base Language Extensions
- Atomic intrinsics
- Single-line
//
comments - Language defined pragmas
- Structured value constructors
- Extensible enumeration and record types
- Import qualifiers for import-all and re-export
- Built-in type
UNICHAR
for unicode characters - Immutable
CONST
function parameters and pointer target types - String literals may be concatenated using the
+
operator - Escape sequences
\0
,\n
,\r
,\t
,\\
,\'
,\"
in string literals - Abstract data types may define bindings to operators and built-in functions
- Typesafe foreign function interface to C, incl. typesafe variadic functions
Revised Semantics
- Array indices must always start at zero
- Variables are always exported immutable
- Strict name equivalence instead of lose name equivalence
CHAR
literals are assignment compatible withARRAY
OF
CHAR
- Named elements of sets and enumerations must always be qualified
Object Oriented Language Extensions to Support Cocoa/GNUstep
CLASS
declaration syntax for Objective-C compatible classesMETHOD
declaration syntax for Objective-C compatible methodsMETHOD
declaration semantics cover category functionalityPROTOCOL
MODULE
for Objective-C compatible protocols- Method invocation syntax as in Objective-C and Smalltalk
CRITICAL
statement for Objective-C compatible critical sectionsTRY
statement for Objective-C compatibleNSException
handlingOBJECT
,SUPER
,YES
,NO
,BYREF
,BYCOPY
,INOUT
,OUT
- Pragmas
FRAMEWORK
,IBAction
andIBOutlet
Objective Modula-2 Sample Code
Apple's Currency Converter in Objective Modula-2
The following sample files are Objective Modula-2 versions of the Currency Converter sample source files in Objective-C from Apple's Cocoa tutorial
Objective Modula-2 Papers
Language Documentation
- An Overview of Objective Modula-2 (PDF document)
- EBNF Grammar of Objective Modula-2 (PDF document)
- Modula-2 R10 Language Description (PDF document)
Older Discussion Papers
The documents below are OUTDATED, they are provided as historical background information
- Module Matrix, April 2009 (PDF document)
obsoleted in July 2009 by class-is-a-record based syntax - Language Extensions, April 2009 (PDF document)
obsoleted in July 2009 by class-is-a-record based syntax - EBNF for Lexical Analysis, April 2009 (PDF document)
obsoleted in July 2009 by class-is-a-record based syntax - EBNF for Syntax Analysis, April 2009 (PDF document)
obsoleted in July 2009 by class-is-a-record based syntax - Objective Modula-2 Paper of 2006
superseded by Language Overview documents - Compilation units, 2006
superseded by EBNF Grammar documents - Literals, 2006
superseded by EBNF Grammar documents - Wrapper Classes, 2006
concept discussed not presently pursued
Credits
Many thanks to the participants of the Objective Modula-2 language design discussion group for providing invaluable insights and suggestions, in particular (in alphabetical order) Brad Cox, Andreas Fischlin and Rick Sutcliffe.
Objective Modula-2 Compiler
The Objective Modula-2 compiler is a cross-platform object oriented Modula-2 compiler with native support for Cocoa (Mac OS X), Cocoa Touch (iPhone) and GNUstep (*nix).
Experimental translators for translating early drafts of Objective Modula-2 to Objective-C have been under development since 2006. These translators were single pass pre-processors that produced output by expanding text-templates using a general purpose template engine. They were not intended for software development but for testing ideas and concepts for the emerging language extensions for Cocoa and GNUstep support.
As the language definition has matured, a new compiler, in part derived from an earlier translator, is being developed with the aim to produce a reference implementation for use by the general public. This compiler is written by hand in the C language in order to maximise portability. Once completed, the compiler will consist of a recursive descent parser that builds an abstract syntax tree, and two code generators, one for Objective-C source to be post-compiled by an Objective-C compiler, the other for LLVM IR assembly to be post-processed by LLVM.
Source code for the compiler is being made available under an amended BSD license. However, source files which have an impact on the syntax are currently released under a peer review license. These files will be relicensed under the amended BSD license when the grammar has been finalised and a working front end for the finalised grammar has been completed.
Aliases and build parameters
Filenames and file extensions
Memory management and key value storage
Tables of reserved words, pragmas, built-in identifiers and tokens
- objm2_reserved_word_table.h
- objm2_pragma_ident_table.h
- objm2_builtin_ident_table.h
- objm2_token_table.h
- objm2_production_table.h
Lexical analysis
- objm2_reserved_words.h
- objm2_reserved_words.c
- objm2_tokens.h
- objm2_tokens.c
- objm2_lexer.h
- objm2_lexer.c
Syntax analysis
- objm2_productions.h
- objm2_productions.c
- objm2_first_follow.h
- objm2_tokenset.h
- objm2_tokenset.c
- objm2_parser.h
- objm2_parser.c currently being revised
Code generation
Driver program
Utilities
Utility to calculate hashes for the symbol table
Utility to generate FIRST and FOLLOW set initialisers for the parser
Makefile
Statistics
Statistics for published source files
Modula-2 Resources
Articles
Online Books
- N. Wirth, Programming in Modula-2, 4th Edition
- G. Dodrill, F. Schoonjans, Modula-2 Online Tutorial
- R. J. Sutcliffe, Modula-2: Abstractions for Data and Programming Structures
Modula-2 Grammars
- PIM Modula-2, PIM3 standard, original (ANTLR v3 source file)
- PIM Modula-2, PIM3 standard, LL(1) version (ANTLR v3 source file)
- PIM Modula-2, PIM4 standard, original (ANTLR v3 source file)
- PIM Modula-2, PIM4 standard, LL(1) version (ANTLR v3 source file)
- ISO Modula-2, ISO/IEC IS 10514 base standard (ANTLR v3 source file)
- R10 Modula-2, 2010 revision of PIM4, original, LL(1) (ANTLR v3 source file)
Modula-2 Compilers
- List of Modula-2 compilers at Modula2.net
- List of Modula-2 Compilers for Macintosh Mac OS X
- List of Free Modula-2 compilers at TheFreeCountry.com
Modula-2 IDE support
- Modula-2 IDE for Eclipse: Modulipse
- Modula-2 syntax colouring for Xcode 3 (Modula2.xclangspec)
Online Discussion
- Usenet Modula-2 discussion group compl.lang.modula2
- IRC #modula-2 channel on Freenode via webchat | using IRC client
The Smalltalk Webring
The Modula-2 Webring
Web sites and web pages related to the Modula-2 programming language.
List all sites | Previous site | Next site | Random site | Join this webring