How does source code become a program?
Source code is the actual text used to write the instructions for a computer program, and this text is then translated into something meaningful the computer can understand. But how does this translation process occur?
This tutorial focuses on:
- Parsing source code
- Compiling source code
- Interpreting source code
- Which languages go through which processes and why
Parsing source code
To 'parse' means to break up into smaller parts. Before source code can be converted into meaningful data for the computer, it has to be parsed. Once this happens, source code is ready for the next step which is compilation.
Compiling source code
Compiling source code refers to turning it into an actual program.
When source code is compiled, it is turned into an actual program (machine code) through a series of steps:
Source code is turned into object code by a compiler
Object code is the machine code that is actually executed by the computer. A compiler turns source code into object code, but it is not yet ready to become a program. Before object code can become a program, it has to pass through a linker.
Object code is passed through a linker
A linker is a program that combines various modules and object code files into an executable program. Once the data is passed through a linker, an executable program comes into existence.
NOTE: Machine code is platform specific. So for example, a program that is compiled on Windows will not work on Linux.
Interpreting source code
Interpreting source code refers to turning it into an intermediate form which is executed by a program called an interpreter instead of turning source code directly into machine code like a compiler does.
An interpreter interprets the source code into something that the computer can understand.
Which languages go through which process and why
While code written in any programming language must be parsed, some code is compiled, and some code is interpreted.
Code written in languages used for software development such as C, C++, C#, and Delphi is compiled. These languages are designed to create executable programs, so code written in them needs to be compiled.
It is actually possible to either compile or interpret code written in some high level languages if the circumstances require it. For example, an interpreter is sometimes used during the development stage of a program because the process of compiling a program (if it is a large program) can be time consuming.