Sample Implementations

To create Modula-3 programs:

· Select the directory where you want your files to reside.

· Create a sub-directory named src.

· Switch to the src sub-directory and type the programs below.

· Run the Modula-3 make program by typing m3build.

File Main.m3

(* Line numbers in comments, used in explanation underneath the make file: Line 1*)
MODULE Main;      				(*Line 2*)
IMPORT IO;        				(*Line 3*)
VAR name: TEXT;   				(*Line 4*)
BEGIN                               		(*Line 5*)
  IO.Put("Enter your name: ");      		(*Line 6*)
  name := IO.GetLine();                 	(*Line 7*)
  IO.Put("Your name is: " & name & "\n"); 	(*Line 8*)
END Main.         				(*Line 9*)
 

File Main.m3 explanation

Line 1. Comment lines go within "(* *)"(C/C++)

Line 2. This file contains the Main MODULE.

Line 3. Tells the compiler to include routines from a library called IO. In Modula-3 libraries are

known as Interfaces. From here on this name will be used instead of library.

Line 4. Declaration of variable name of type TEXT. (Pascal)

Line 5. Since this program is made of more than one statement it is necessary to have a block

marked with BEGIN/END. (Pascal)
Line 6. Call to output function of interface IO.
Line 7. Populate variable name by using input function of IO interface.
Line 8. Output some literal text and the value of the variable name.
Line 9. End of module Main.