ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

Turbo Pascal Compiler Design

Updated on May 15, 2011

Turbo Pascal is one of the legendary Borland Products that hit the market in 1983. It offered comfortable integrated development environment (IDE) and fast Pascal compiler for only $49.95. This resulted in a competitive product for rapid application development. Turbo Pascal was used to develop business applications, games, hobby projects and learning programming skills. Pascal programming language is still used to teach high-level structured programming in many schools.

One of the main characteristics of Turbo Pascal compiler is compilation speed. It is achieved by using few simple tricks. Turbo Pascal is one-pass compiler. It scans the source code, generates tokens which are processed by the parser which in turn generate intermediate code. This intermediate code is optimized and then the target code is generated.

Scanner loads source file, extracts lines and scans them for tokens. Token is the smallest element of the computer language. It can be an identifier, number, symbol or anything else that constitutes Pascal language. Scanner also processes compiler directives and skips comments.

A very important part of the compiler are symbol tables. Turbo Pascal uses hashing to speed up searching in symbol tables. For each identifier Turbo Pascal calculates hash value which determines in which linked list of identifiers it should be stored. The same applies for searching. Because only one list needs to be examined the search is very fast.

Parser generates low-level intermediate code which contains target instructions, reference data, instructions for labels and jumps and few instructions for the optimization purposes. A very important property of intermediate code used by Turbo Pascal is the possibility to use subroutines. This allows the compiler to generate code piece by piece from any part of expression or statement. Later the compiler joins intermediate code subroutines to create the final code. Finally, the linker links all modules, resolves references and generates executable file.

If you are interested in other details of this compiler you can examine the source code at Turbo Pascal website. Here you can get all the function and procedures described together with the source code.

Turbo Pascal internals are interesting reading for those who have used this compiler in the past and for thos who would like to make their own compiler and need some ideas on compiler design.


Submit a Comment

  • hotwebideas profile image

    Bruce Chamoff 6 years ago from New York

    Wow! I have not programmed with Pascal since 1996! Great post. Thanks, igorfuna.