Modula 2 - Quick Reference

Comments
  • The Gardens Point Modula (GPM) compilers were an ongoing research focus of the Programming Languages and Systems Group in the Faculty of Information Technology at the Queensland University of Technology in Brisbane. The following material was adapted to our needs. Click here for some useful information and download.

  • The Program Development Cycle

    The Program Development Cycle for an application program written in Modula-2 is summarized below :

    1.  Use a text editor to create or modify the source modules. Source modules can be organised in a variety of ways. It is assumed the normal convention of writing separate definition and implementation modules is used in the development cycle.

        For example : pico filename
        (Remark: In our tutorial classes we are using pico editor, but you can use any available editor).

    2.  Use gpm to compile each of the modules of the program. If compilation errors are encountered in a module, you must go back to Step 1 and correct the errors before continuing. For each definition module (.def), gpm creates a symbol file (.syx). For each implementation module (.mod), gpm creates a reference file (.rfx) and an object file (.o). Optional listings (.lst) can also be created during compilation.

         Source modules are compiled with the comand gpm. Its command line syntax is

         gpm  [-options]  filename (To check all options type man gpm).

    3.  Use build to create a single executable file.

         The command line syntax for the load-builder is

         build  [-options]  basename (To check all options type man build).

         The program can now be executed with the command basename, where basename is the name of the base (main) module (with the name moved to lower case).The executable file has no extension.

    4.  Debug your program if logical or run-time errors are encountered when the program is executed. It will be necessary to return to step 1 to correct one or more source modules.



    Some Examples.
    a) The minimum Modula-2 program
    MODULE SmallestModule2Program;
    BEGIN
    END SmallestModule2Program.

    b) Inserting comments in your programs.

    (* This is a comment that is prior to the start of the program itself. *)
    MODULE ModComs;
    FROM InOut IMPORT WriteLn, WriteString;

                       (* This is a block
                            of comments that
                            illustrate one way
                            to format some of
                            your comments.    *)

    BEGIN  (* This is the beginning of the main program *)
       WriteString("This is a comments demo program.");
       WriteLn;
    (* WriteString("This will not be output.");
       WriteString("Nor will this."); *)
    END ModComs.  (* This is the end of the main program *)
    (* This is a comment after the end of the program *)


    c) Your first program.
    MODULE hello;
            FROM InOut IMPORT WriteString, WriteLn;
            CONST str = "Hello World !!!!";
    BEGIN
            WriteString(str);WriteLn;
    END hello.