Component Pascal

from Wikipedia, the free encyclopedia
Component Pascal
Paradigms : imperative , modular , object-oriented , component-oriented
Publishing year: 1990
Developer: Niklaus Wirth /
Oberon microsystems
Current  version : 1.5   (2005, Release Candidate 1.6: 2007)
Typing : static and dynamic, strong
Important implementations : BlackBox Component Builder , Gardens Point Component Pascal
Influenced by: Modula-2 / Oberon
Operating system : Windows , runtime systems .NET and JVM
License : free
Oberon microsystems

Component Pascal is an imperative , modular , object and component-oriented programming language that has been free since 2004 and has been developed since 1990 for the component-based development system BlackBox Component Builder developed by Oberon microsystems . In the meantime there are also versions under the name Gardens Point Component Pascal that can run under .NET and under the Java Virtual Machine .

Component Pascal was developed from the Oberon programming language and was still operating under the name Oberon / L when it was published in 1994. The associated framework was called Oberon / F. With release 1.3 (which was released around the turn of the year 1996/1997) the language Oberon / L Component Pascal and the framework Oberon / F became the BlackBox Component Builder.

properties

Component Pascal has a very short and simple language description with a fully structured syntax . It allows static types and objects as well as dynamic types and dynamic binding . It is a very strongly typed and type-safe programming language as long as the SYSTEM module is not explicitly imported, which is usually only intended for system programming , and is therefore easily portable . Inheritance is anchored in the programming language, but not multiple inheritance in order to avoid additional burden for the compilers and to make the language semantics as clear as possible and to avoid the Diamond problem .

Component Pascal also supports automatic garbage collection and dynamic loading and removal of modules or components at runtime , even while instances already exist and are to be used.

In addition, Component Pascal allows assertions , generic programming and the overwriting of data types and thus also methods (so-called type-bound procedures ). In the interests of simplicity and better traceability of the source code, however, it is not possible to overload operators or methods.

The programming language Component Pascal and the development and runtime system BlackBox Component Builder have been open source since 2005 .

Areas of application

Component Pascal is characterized by its low hardware requirements , high stability , simplicity and speed, both in terms of runtime and software development . It is mainly used for scientific and technical applications, in teaching and research , but also for commercial applications.

Programs

Hello World

The Hello World program in Component Pascal 1. Example

The ( parameterless ) command output is defined in the HalloWelt module . The asterisk (*) after the procedure name defines the export of the procedure output , so that it can be referenced outside the module with the syntax HalloWelt.Output . The following source code is a simple program that displays the message Hello World! followed by a line break prints:

 MODULE HalloWelt;

 IMPORT Out;

 PROCEDURE Output*;
 BEGIN
    Out.Open;
    Out.String ("Hallo Welt!");
    Out.Ln;
 END Output;

 END HalloWelt.

The Hello World program in Component Pascal 2nd example

In the module HalloWelt2 define a variable that will later be displayed in a dialog box. The asterisk (*) after the procedure name defines the export of the procedure output , so that it can be referenced outside the module with the syntax HalloWelt.Output . The following source code is a simple program that displays the message Hello World! in a dialog box that opens via "IMPORT Dialog;" was imported. In the dialog box are u. a. all variables marked with an * are output. With "VAR output *: ARRAY 50 OF CHAR" it is specified that a variable "output" is to be created which 1. is visible in the dialog ( ) and 2. consists of a sequence of 50 characters (ARRAY 50 OF CHAR) the line "Dialog.UpdateString (output);" is ordered that the content of the variable "output" is assigned to the dialog box and is displayed immediately: VAR*

  MODULE HalloWelt2;

  IMPORT Dialog;

  VAR ausgabe*: ARRAY 50 OF CHAR;

  PROCEDURE Output*;
  BEGIN
    ausgabe:= "Hallo Welt!" ;
    Dialog.UpdateString(ausgabe);
  END Output;

 END HalloWelt2.

computer

The addition calculator program in Component Pascal 1st example

 MODULE Kurs10Rechner;
 IMPORT Dialog;

 VAR zahl1*, zahl2*, ergebnis*, rest* : INTEGER;

   PROCEDURE add* ;
   BEGIN
      ergebnis := (zahl1 + zahl2);
      Dialog.UpdateInt(ergebnis);
   END add;

 END Kurs10Rechner.

Examples of implementing inheritance

The implementation of inheritable structures in Component Pascal has been simplified somewhat compared to its predecessor, Oberon , and has been structured even more clearly and securely. The comments between (*and *)are used for explanation and are ignored by the compiler. Examples:

 MODULE Vererbung1;

 TYPE (* Typendefinitionen *)

    GraphischesObjekt* = POINTER TO ABSTRACT RECORD farbe*: INTEGER; END;
    Punkt* = POINTER TO RECORD (GraphischesObjekt) x*, y*: INTEGER; END;
    Linie* = POINTER TO RECORD (GraphischesObjekt) xStart*, yStart*, xEnde*, yEnde*: INTEGER; END;

 VAR (* Variablendefinitionen *)

    punkt1: Punkt;
    linie1: Linie;

 PROCEDURE (g: GraphischesObjekt) Zeichne* (), NEW, EXTENSIBLE;
 BEGIN
    (* Leere, erweiterbare Methode *)
 END Zeichne;

 PROCEDURE (punkt: Punkt) Zeichne* ();
 BEGIN
    (* ... *)
 END Zeichne;

 PROCEDURE (linie: Linie) Zeichne* ();
 BEGIN
    (* ... *)
 END Zeichne;

 BEGIN

    NEW (punkt1);
    punkt1.farbe := 0FFH; (* Objektfarbe wird auf 0FF ("H" für hexadezimal) gesetzt *)
    punkt1.x := 1;
    punkt1.y := 1;
    punkt1.Zeichne ();

    NEW (linie1);
    linie1.farbe := 07FH; (* Objektfarbe wird auf 07F ("H" für hexadezimal) gesetzt *)
    linie1.xStart := 1;
    linie1.yStart := 1;
    linie1.xEnde  := 2;
    linie1.yEnde  := 2;
    linie1.Zeichne ();

 END Vererbung1.

Attributes that only have read access can be changed using type-specific procedures (methods). The export of corresponding identifiers, which can only be read outside of the object's own modules, is not indicated by *, but by -. Example:

 MODULE Vererbung2;

 TYPE

    Objekt* = POINTER TO RECORD x-: INTEGER; END; (* Kommentar: außerhalb des Moduls "Vererbung2" ist kein direkter Schreibzugriff auf das Attribut "x" möglich *)

 PROCEDURE (objekt: Objekt) setzeX* (wert: INTEGER), NEW; (* Kommentar: für den indirekten Schreibzugriff auf das Attribut "x" *)
 BEGIN
    objekt.x := wert;
 END setzeX;

 END Vererbung2.
 MODULE AnderesModul;

 IMPORT Vererbung2;

 VAR

    objekt1: Vererbung2.Objekt;
    int: INTEGER;

 BEGIN

    NEW (objekt1);
    objekt1.setzeX (1); (* Kommentar: die Anweisung "objekt1.x := 1" ist außerhalb des Moduls "Vererbung2" nicht möglich *)
    int := objekt1.x;  (* Kommentar: direkter Lesezugriff auf das Attribut ""x ist möglich *)

 END AnderesModul.

literature

  • Karlheinz Hug: modules, classes, contracts. A textbook on component-oriented software construction with Component Pascal . Vieweg Publishing Company, 2001
  • J. Stanley Warford: Computing Fundamentals - The Theory and Practice of Software Design with BlackBox Component Builder . Vieweg, 2002
  • Markus Bautsch: Cycles of Software Crises . In: ENISA Quarterly on Secure Software (PDF; 2 MB)

Web links