Faculty of Information Technology Programming Languages and Systems
Skip to Content
QUT Home FIT Home PLAS Home Projects People Wiki Contacts
 
     

Imperative Mini Component Pascal (IMCP)

   

IMCP

Imperative Mini Component Pascal (IMCP) is an imperative extension of FMCP. Unlike FMCP, it is a 'pure' subset of Component Pascal in that every valid IMCP program should also be a valid Component Pascal program.

Language features

Overview

The constructs supported by IMCP are considerably richer than those supported by FMCP. IMCP supports:

  • Record type declarations;
  • Pointer type declarations;
  • Local and global variable declarations;
  • INTEGER and BOOLEAN primitive types;
  • NIL;
  • Function and procedure methods bound to pointer types;
  • NEW(...) pointer type instantiations;
  • Assignment;
  • WHILE loops;
  • IF statements; and
  • WITH type casts.
As in FMCP, however, a number of Component Pascal language features have been simplified.

Record value and pointer types

One of the key features of Component Pascal is the distinction between record value (i.e. stack) types and record pointer (i.e. heap) types, and the implicit dereferencing of such record pointer types. The formalisation of IMCP also attempts to capture this distinction. The syntax for type declarations in IMCP makes an important simplification, however. Component Pascal allows the declaration of pointers to `anonymous' record types -- for example:

P = POINTER TO EXTENSIBLE RECORD (ANYREC)
  f: INTEGER;
END;

IMCP does not allow such declarations as it would introduce unnecessary complexities in the record field lookup function and other auxiliary definitions. It should also be noted that IMCP, like Component Pascal, is a type-safe language and thus pointer declarations can only point to record types; declarations like the following are not permitted:

R = EXTENSIBLE RECORD (ANYREC) END;
P = POINTER TO R;
S = POINTER TO P; (* cannot declare a pointer to a pointer *)

Since IMCP supports local variable declarations and assignment, the need for FMCP's "NEW R(...)" construct is removed. Like in Component Pascal, new instances of record value types must be created by first declaring a local variable, then manually initialising its fields using field assignment statements.

Methods

Like FMCP, IMCP simplifies the Component Pascal requirements for method receiver types. However, in IMCP the requirement is that method receiver types must be pointer types.

Another Component Pascal convention that is modelled in IMCP is the distinction between function methods (i.e. methods that return a result) and 'proper procedures' (i.e. methods that return no result). Instead of modelling this distinction by introducing an explicit VOID type (and perhaps some shorthand that would allow it to be omitted in order to preserve compatibility with Component Pascal), we have decided to make the return type and return expression optional syntactic elements, denoted in the abstract syntax through the use of square brackets [ ].

Method bodies consist of a series of statements. Note that RETURN is not present in the syntactic category of statements. Instead, RETURN is explicitly included in the syntax for method bodies. Methods always conclude with a RETURN; this may or may not include a return expression, depending on whether the method is a function or procedure. We decided to make the RETURN statement the compulsory final statement in a method as this simplifies the task of defining operational semantics.

Another simplification is that unlike Component Pascal, IMCP does not allow covariant return types in overriding methods. The return expression, however, can be a subtype of the declared return expression.

Expressions and statements

Expressions are factored out into two syntactic categories; expressions and left expressions (i.e. those expressions that can occur on the left hand side of an assignment statement). Otherwise, they are similar to expressions in FMCP. The statements supported by IMCP are as follows. NEW() instantiates a variable of pointer type. Method calls can act as statements, providing that they are calls to proper procedures. Assignment can be performed on variables or record fields. The only forms of looping and conditionals supported are WHILE and IF.

The casting semantics merit some discussion. In Component Pascal, casting is achieved through the WITH statement. A WITH statement of the form:

WITH x:P DO
  (* ... statements ... *)
ELSE
  (* ... statements ... *)
END;

states that if the variable x has dynamic type P, then execute the first set of statements; otherwise, execute the second set of statements. Again, in this case IMCP makes a simplification. In Component Pascal, the variable in a cast must by a VAR record type or a pointer type, whereas in IMCP, the variable in a cast must be a pointer type as VAR types are not supported.

PLAS
Projects
  ActiveSheets
  Bioinformatics
  ConcernMaps
  ELP
  ELP.NET
  G2 Cluster Computing
  Generics
    Mini Component Pascal
      Background
      FMCP
      IMCP
      Metavariables etc
        Abstract syntax
        Type rules
        Auxiliary definitions
      Example program
      IMCPI
      IMCPG
      Cardelli type inferencer
      Online compilers
  Gardens Point Component Pascal
  Gardens Point Flow
  Gardens Point Modula
  Gardens Point Service Language
  Language Processing Tools
  Mentok
  Metaphor
  Mobilizer
  RikWik
  Ruby.NET
People
Wiki
Contacts