Turbo Pascal Compiler Source Code
Turbo Pascal combines the simplicity of Object Pascal language with the power and efficiency of C++. Simple intuitive syntax, efficient generated code and easy development contributed to the popularity of Borland Turbo Pascal and Pascal programming language in general. While Pascal programming laguage was designed and used to teach structured programmning, Turbo Pascal went far beyond teaching. Borland advertised it as the fastest way to learn object-oriented programming. And they were right. Turbo Pascal became the most popular Pascal compiler ever.
If you are interested in the secrets of this legendary compiler or you would like to make your own compiler then you came to the right place. Get the complete source code of the Turbo Pascal compiler written in Turbo Pascal:
Every compiler is a combination of many sophisticated algorithms and complex data structures. With right approach you can achieve fast compilation and optimized code. If you have ever tried to write a compiler then you know what right algorithms and data structures mean. There are many excellent books on compiler construction. However, Turbo Pascal compiler source code is the best book on compiler design. Why starting from scratch when you can have the source code of a working compiler? And not just any compiler - Turbo Pascal is famous for compilation speed. Interested in the secrets of the legendary compiler?
Below you can find few code snippets from the Turbo Pascal compiler.
Procedure TExpression.ProcessExpression; Var RightSimpleExpression: TExpression; Operation: TCalcOperation; begin ProcessSimpleExpression; Case Token of Token_Equal: Operation := Calc_IsEqual; Token_NotEqual: Operation := Calc_IsNotEqual; Token_Greater: Operation := Calc_IsGreater; Token_Lower: Operation := Calc_IsLower; Token_GreaterOrEqual: Operation := Calc_IsGreaterOrEqual; Token_LowerOrEqual: Operation := Calc_IsLowerOrEqual; Token_IN: Operation := Calc_IN; else begin Exit; end; end; GetNextToken; RightSimpleExpression.ProcessSimpleExpression; If Operation = Calc_IN then GenerateCodeForOperator_IN (Self, RightSimpleExpression) else CalculateOperation (Operation, Self, RightSimpleExpression); end;
Procedure ProcessDeclarations; begin Repeat StatementCompilerSwitches := ModuleCompilerSwitches; Case Token of Token_CONST: ProcessConstantDeclarations; Token_TYPE: ProcessTypeDeclarations; Token_VAR: ProcessVariableDeclarations; Token_PROCEDURE: ProcessProcedureDeclaration; Token_FUNCTION: ProcessProcedureDeclaration; else If SourceType <> stUnitInterface then Case Token of Token_LABEL: ProcessLabelDeclarations; Token_CONSTRUCTOR: ProcessProcedureDeclaration; Token_DESTRUCTOR: ProcessProcedureDeclaration; else Exit; end else Exit; end; until False; end;
Before you decide if this is what you are looking for you can
check the code on the Turbo Pascal Compiler Internals website.
Turbo Pascal Compiler
The best book on compiler design