DEV Community

Cover image for ISO Pascal is love
Matheus
Matheus

Posted on

ISO Pascal is love

I finished the ISO Pascal book, and I found the language very interesting. I'm in love with this language!

Unlike other Pascal implementations, ISO Pascal is minimalist. The language features thirty-five keywords, thirteen built-in procedures, and seventeen built-in functions. The language is proposed for teaching structured programming, but may do very well for other tasks. At first glance, the language may seem unusable or uneasy. However, once mastered, there's no going back! The language is excellent!

The following is a program I wrote. The program reads from a file, constructs a circular linked list from the contents, and prints the contents.

program Index(Input, Output, Pipe);

const
        MaxArg = 1000;
        MaxStr = 1000;
        EndOfStr = Chr(0);
type
        PStrbuf = ^Strbuf;
        Strbuf = record
                Length: Integer;
                Buffer: Array[1..MaxStr] of Char;
                Next: PStrbuf;
                Prev: PStrbuf;
        end;
var
        BufArg: PStrbuf;
        Pipe: Text;

procedure Print(Str: PStrbuf);
var
        I: Integer;
begin
        I := 1;
        while Str^.Buffer[I] <> EndOfStr do
        begin
                Write(Str^.Buffer[I]);
                I := I + 1;
        end;
        Writeln
end;

procedure AllocStr(Str: PStrbuf; var Overflow: Boolean); { The var declaration here means to pass by reference. }
var
        I: Integer;
        C: Char;
begin
        Str^.Length := 0;
        I := 1;
        while (not Overflow) and (not Eoln(Pipe)) do
                if I < MaxStr then
                begin
                        Read(Pipe, C);
                        Str^.Buffer[I] := C;
                        Str^.Length := I;
                        I := I + 1;
                end
                else
                        Overflow := True;
        if not Overflow then
                Str^.Buffer[I] := EndOfStr
end;

procedure AllocArg(Last: PStrbuf; Str: PStrbuf);
begin
        Last^.Next := Str;
        BufArg^.Prev := Str;
        Str^.Next := BufArg;
        Str^.Prev := Last
end;

procedure Main;
var
        BufPtr: PStrbuf;
        Str: PStrbuf;
        Overflow: Boolean;
begin
        Reset(Pipe);
        New(BufArg);
        BufArg^.Next := BufArg;
        BufArg^.Prev := BufArg;
        BufArg^.Length := 0;
        BufArg^.Buffer[1] := EndOfStr;
        Overflow := False;
        while (not Overflow) and (not Eof(Pipe)) do
        begin
                New(Str);
                AllocStr(Str, Overflow);
                AllocArg(BufArg^.Prev, Str);
                if Overflow then
                begin
                        Writeln('Overflow!');
                end
                else
                        Get(Pipe);
        end;
        if not Overflow then
        begin
                BufPtr := BufArg^.Next;
                while BufPtr <> BufArg do
                begin
                        Print(BufPtr);
                        BufPtr := BufPtr^.Next;
                end
        end
end;

begin
        Main
end.
Enter fullscreen mode Exit fullscreen mode

The language is very different from C. Such a small language, yet so much can be done. Really cool, and, at the same time, odd. It doesn't have return. It doesn't have break. It doesn't have continue. It doesn't have a sizeof operator. It doesn't have an address-of operator. Even then, it does excellently!

Top comments (0)