I wonder what is compiling, what happens when you compile? I mean yes you press compile or type in in the console but what does it actually do in the "background"?
A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.
Compile refers to the act of converting programs written in high level programming language, which is understandable and written by humans, into a low level binary language understood only by the computer.
First, the compiler "lexes" the source. This means that it transforms the source into a sequence of "tokens." Tokens are sequences of letters, numbers and symbols that have meaning to the compiler.
Next, the compiler "parses" the sequence of tokens from step one. This means that the compiler checks to ensure that the source conforms to rules (the grammar) of the programming language.
Next, the compiler performs syntactic analysis to create a representation of the source to determine the semantical meaning of the source. This is the step where the compiler will build a syntax tree.
Finally, the compiler will generate output that captures the semantic meaning of the source in the target representation (be it machine code, an intermediate language such as Microsoft's CIL, or another programming language).
For the brief details see Wikipedia. For the gory details see the dragon book (every student of computer science should study this book).
See this
Basically, magic elves and fairies turn human readable code into machine code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With