Borland Turbo Pascal is definitely the most successful and popular Pascal compiler ever. Comfortable Integrated Development Environment (IDE), elegant syntax, fast compilation and effective generated code are some of the strongest points of Turbo Pascal – a powerful programming tool which has contributed to the popularity of Pascal programming language.
Turbo Pascal was the programming tool of choice for many years. The original Pascal syntax was upgraded with objects and some other constructs which enabled programmers to use Turbo Pascal for games, scientific programming, commercial software, and any other task possible with computers.
Pascal was originally developed by a Swiss computer scientist Niklaus Wirth in late 1960s. He named the language after French philosopher and mathematician Blaise Pascal. In addition to the programming language, the name Pascal has been given also to the SI unit for pressure and Pascal’s law (the principle of transmission of fluid-pressure). Blaise Pascal lived in 17th century and contributed to mathematics (Pascal’s triangle showing binomial coefficients, mathematical theory of probabilities), hydrodynamics and hydrostatics (the principles of hydraulic fluids, he invented hydraulic press and the syringe), he also invented the mechanical calculator and was supporter of the scientific method. Therefore, the Pascal language is always written with its first letter in uppercase.
Initially the purpose of Pascal programming language was to teach structured programming. It was and still is used in many schools as the first high-level programming language. Wirth based Pascal on Algol programming language which was developed in 1950s and was also used to describe algorithms in the literature. Wirth tried to create a language that would be easy to compile and would generate efficient code. He used the principle of structured programming and added support for records, enumerations, subranges, dynamically allocated variables with associated pointers, and sets. Wirth later also developed programming languages Modula 2 and Oberon. Pascal uses reserverd words like
if, then, else, while, for, until and many others for control statements which makes it easy to read and understand. Therefore, Pascal programming language is suitable also to describe algorithms with very little additional comments.
Many Pascal compilers for many different platforms were developed in the 1970s like UCSD Pascal, IP Pascal and Lisa Pascal to name only a few of them. In 1980 Anders Hejlsberg developed Blue Label Pascal which was offered for the PC platform under different names. This compiler was later licensed by a software company Borland which added user interface and editor, changed the name to Turbo Pascal and offered it for a competitive price. Fast compiler (it was written in assembly language), integrated development environment which enabled fast edit-compile-run cycles and low price contributed to the popularity of Turbo Pascal. Borland later offered this compiler also as part of the high-end Borland Pascal package which included also additional libraries and other tools. The last released version was Borland Pascal 7.
I am a big fan of Pascal. Pascal programming language is easy to write and easy to read. I was impressed by the compilation speed of Borland Pascal and was wondering how it works. On the other hand I was interested in compiler theory so I started studying compiler construction books. At some point I decided to create a compatible compiler – Turbo Pascal compiler written in Turbo Pascal. The goal was to create a compiler that would use the same algorithms and data structures as the original compiler. The compiler would then compile programs with Borland syntax and would generate the same code. I was not interested in the IDE so I focused on command-line compiler. After some time I managed to create a complete compiler that reveals Turbo Pascal internals and shows all the beauty of the legendary Borland compiler. I really enjoyed working on this compiler. I must admit that Anders Hejlsberg and Borland have significantly contributed to my passion for Pascal.
I decided to reveal the secrets of the compiler. On this website you will find Turbo Pascal internals – most important functions of the compiler described in details together with the source code. The beauty of Pascal programming language is that it is easy to read and needs little comments. All the constant, variables, procedures and functions have meaningful names so the algorithms are easy to read and understand. Of course, this is not the original source code of the compiler since it was not written in Pascal, but the code of a compatible compiler written in Turbo Pascal. You will be able to see the internal functions, data structures, algorithms, tips and tricks used by the compiler. Even if Pascal is not your language of choice you can easily understand the algorithms and approaches used by Borland software engineers in early 1990s.
Every compiler is a symphony of data structures and algorithms and Turbo Pascal is no exception. If you were using Turbo Pascal some time ago or you are simply curious how the compiler works, then you will find all the answers here. And if you are making your own compiler using some conventional compiler tools you can still check compiler internals – what algorithms were used some time ago to make the most popular Pascal compiler ever.