Compilation in Pascal programming
When you write a program, it is necessary to test code fragments for syntactic correctness, content errors and conformance with the intent of the programmer.
During the compilation the environment of FreePascal program asks you to save the file with the source code on the disk. After this operation, the instructions contained in the source code will be converted to a stand-alone computer program.
The Pascal source code files have the extension .pas, such as: program.pas. After compiling in DOS / WINDOWS we get an output file that is independent program with the extension .exe, eg program.exe. Application can be run directly from the command line by typing its name.
Running a compiled program
As you can see, FreePascal compiler on Windows for the directory in which it creates programs, takes the default C: \ FPC \ 2.2.4 \ bin \ i386-win32. From here we can start compiling the binary.
When you start reading the compilation and analysis of the following source code for compliance with the rules of Pascal. The source code is tested to verify lexical compliance. The characters in the input stream are grouped into lexical symbols, called tokens (tokens are the basic components of the language of the source code for example: keywords, operators). Lexical analysis can be referred to as linear or scan analysis.
The next step is controlling the correctness of parsing lexical alignment and compliance with the rules of the programming language. The information gathered at this stage are then used in the process of generating the intermediate code. Parsing is also called hierarchical or syntactic analysis. The next step is the semantic analysis, with the task of testing for semantic compliance of tokens (the basic units of language) with the rules of the programming language. Such semantic compliance is a compliance of data types or control of correctness declaring of used objects.
Information gathered during the semantic analysis will be used to generate intermediate code.
The next step is to construct – based on previously collected information – of intermediate code, optimization and generating the object code. That’s how compilation in Pascal programming looks like.