Pascal is one of programming languages that is not considered as mainstream. However, 25 years ago things were different. The reason for this was Borland which created a now legendary product Turbo Pascal. It was built on the core of Pascal compiler developed by Anders Hejlsberg. Borland added comfortable editor with simple IDE and offered the product for competitive price. The success was inevitable. Borland Pascal was used as primary development tool on the PC platform for more than 10 years.
The first Turbo Pascal compiler was released in 1983. Borland took the compiler written by Anders Hejlsberg and packed it with an advanced integrated development environment. This approach was considered very advanced and was well accepted among developers. IDE provided an elegant way to develop programs because all the phases (writing, compiling and debugging) were done inside IDE. No command-line commands or external editors.
One of the strengths of this product was powerful IDE where you could edit, compile and run the program. Another strength was the compiler itself: support for extended Pascal syntax, fast compilation and effective generated code. Turbo Pascal was popular because you could do almost anything with it - from business applications to games. There are still many libraries for every possible topic that were written for this popular Pascal compiler.
The compiler was very fast. It implemented some tricks to quickly compile huge programs. This property additionally contributed to the popularity of Turbo Pascal compiler and Pascal programming language in general. Pascal programming language is not so popular as it once was. It is still used in the Delphi development package, but the developers have oriented themselves to other languages, mainly to C.
Today Pascal compilers are rarely used. They were replaced by modern RAD tools like Delphi that still use Pascal programming language and also other languages where C is probably the most commonly used language these days.
Many older programmers still like Pascal because its simplicity and easy understanding of what the code does. Even if there are little or no comments it is possible to quickly understand the program because it looks like English text. Pascal was initially designed to teach structured programming and because of this it is still used in many schools as the first high-level programming language.
However, Turbo Pascal compiler contains many brilliant algorithms and approaches that can be used in many other projects including constructing a new compiler. Fortunately all the secrets of this legendary Pascal compiler are now revealed and you can take a look at Turbo Pascal internals and examine the source code of the compiler.
At Turbo Pascal website you can find the source code of all important parts of the compiler: scanner, parser, expression processing, linker and other elements of the compiler. This is a Turbo Pascal compiler written in Turbo Pascal. Of course, this is not the original source code but a compatible compiler that behaves exactly as the original Borland Turbo Pascal 7.0 command line compiler. It compiles Turbo Pascal source code and generates exactly the same binary files as the original compiler. It also uses the same algorithms as those implemented in TPC.EXE command line compiler that is part of the Borland Pascal package.
Now you have the possibility to take a look at the algorithms and data structures used by this legendary Borland compiler. At the Turbo Pascal website you have source code of a Turbo Pascal compatible compiler. This is a compiler written in Turbo Pascal that behaves exactly as the original command line compiler. Here are revealed all compiler internals. You can check what algorithms have contributed to fast compilation and how a unit is constructed.
If you are interested how a compiler is constructed or you would like to make you own then this source code will answer many questions. A source code of a working compiler is the best book on compiler design. Even if Pascal is not your target language you can benefit from examining the Turbo Pascal source code. Pascal is very easy to read because most keywords are common English words and the program reads almost as plain English text. In addition to this all constants, variables, functions and procedures have meaningful names that clearly show what they do or what they are used for.
If you have used Borland Pascal years ago then you should definitely check what made this compiler so successful. And if you are constructing your own compiler then you will definitely get some practical ideas on implementing particular compiler modules. Turbo Pascal will remain as the most successful implementation of a Pascal compiler.
Examining the compiler source code can be very useful if you are making your own compiler. If you know what hash function is or how parser works that you can examine how Borland (and previously Anders Hejlsberg) solved these problems. It can also be very entertaining if you once used this compiler and were wondering how it works.
Every compiler uses many more or less sophisticated algorithms. And the design of data structures and symbol tables also plays an important role in compiler construction. There are many excellent books on compiler design and implementation. But the best book is the compiler itself. Borland Pascal is still considered as the most successful Pascal compiler. One of the reasons for this title lies in the compiler itself. All the secrets are revealed and learning from them can be very useful and entertaining.
Turbo Pascal source code is not just a compiler. It is a collection of proven design - effective algorithms and practical data structures. At TurboPascal.org you can get all the secrets for free.
No comments:
Post a Comment