Ruud's Commodore Site: Pascal86 Home Email

Pascal86




What is it

Pascal86 is a Pascal version that is a written in Turbo Pascal 7. It is called Pascal86 because it should run on a 8086/8088 PC in the first place. The ultimate goal is that it should be able to compile itself and therefore should be able to run on another computer. But I have some doubts: Pascal86 compiled by TP7 generates an executable of 131 KB big. I wonder how to run that on a Commodore 64. But I would be glad if that worked at least for the PC itself.


History

Preferring Pascal above C, I decided to write a Pascal86 for my C64. Yes, there are various compilers available like Oxford Pascal and the Data-Becker version but I wanted one with the capabilities Borland's Turbo Pascal and written in Borland's Turbo Pascal 7.0 (TP7).

The first idea was to write one in ML but then the idea changed into writing it in Pascal with the idea that, in the end, it should be capable of compiling itself. The main idea was that it should generate a binary in the end and should be able to do it for the various Commodores: C64, PET, CBM, Plus/4 etc., etc. I even had some Z80 machines in mind. This meant that I had to reserve program lines for every type of machine for every component and that was a bit too much.
Then I got the great idea of not generating binaries but macros only! Macros can be completely independent of the used machine and/or processor. The only thing I had to do was to tell the assembler what file to use when translating the macros into ML. From this rose the idea that I also wanted it to run on a PC.

At this moment I'm writing the macro files for the 8088. I started with writing them for the C64 but testing the resulting executable was much simpler for the PC version. Still lot of work to do.....


The program itself

I didn't start completely from scratch. I collected various compilers and looked how they worked. Most worked the same: first a list with key words was created and when the parser ran into a word that belonged to that list, then the procedure that handled that keyword was started. So I did roughly the same. The compiler that had IMHO the most impact was Pascal P4 by Niklaus Wirth.


Writing and testing the compiler

I developed the program while testing it in the same time. The simplest program IMHO will look like this:
begin
end.
My compiler knows what first keywords it can expect and "begin" is one of then. So it runs the procedure connected to "begin" and runs it. Here the compiler is told what keywords it can expect now and how to handle them. At the end of the procedure it expects to run into the keyword "end" and nothing else. And in this case it expects this "end" to be followed by a dot, not a semicolon.
So I started with a very simple compiler that was able to handle this very simple program. Then I started to add valid lines, looked where it went wrong, and added the needed code so my compiler could handle them.





Having questions or comment? You want more information?
You can email me here.