next up previous contents
Next: Types Up: The MPD Programming Language Previous: Contents   Contents

Overview

MPD is a syntactic variant of a language called SR developed at the University of Arizona since 1979. It is an imperative language (like Pascal or C) with rich support for concurrent programming.

An ordinary (non-distributed) MPD program consists of resources and globals. A resource is similar to a Java class: It declares a pattern for a class of objects, each is of which is created dynamically. A resource exports operations, types, constants etc.; its body contains variables, procedures, and processes that implement the operations and/or perform background tasks. A global is a collection of variables and operations that are shared by all resources (and other globals).

Every MPD program contains at least one resource. The simplest MPD program consists of a single resource. One resource in every program is treated as the ``main'' resource. The main resource can have any name the programmer chooses; it does not have to be named ``main''. The main resource is typically the last one that is compiled and must be the last one linked. It may not be imported by any other resource nor have any parameters. We will return to resources in section 11. For the moment we just give a simple example program from the MPD distribution below. It serves to illustrate command-line arguments, intermixed declarations and statements, dynamic arrays, and simple for loops.

# iterative program to sum elements of an array
          # store in a file such as "sum.mpd"
          # compile by executing "mpd sum.mpd"
          # run by executing "a.out size"

resource sum()
  # declare and read first command-line argument
  int size; getarg(1,size);

  # declare and initialize array a
  int a[1:size];         # same as int a[size]
  for [i = 1 to size] {
    a[i] = i;
  }

  # calculate then print a[1] + ... + a[size]
  int total = 0;
  for [i = 1 to size] {
    total = total + a[i];   # same as total += a[i]
  }
  write("the sum of 1 ...", size, "is", total);

end


next up previous contents
Next: Types Up: The MPD Programming Language Previous: Contents   Contents
David Sands 2003-09-05