Over time, this column has discussed many programming topics and techniques. However, one subject we have never fully addressed is what actually happens at “compile time.” How does a compiler take the program you write and translate it into something that a machine can understand and execute?
Over time, this column has discussed many programming topics and techniques. However, one subject we have never fully addressed is what actually happens at “compile time.” How does a compiler take the program you write and translate it into something that a machine can understand and execute?
As it turns out, many of the concepts and methods found in any compiler can be applied to other applications. A compiler is just an application that translates something (your code) written in one language to its equivalent in another. Just as the GNU Compiler Collection’s C compiler (gcc) translates C code into machine-readable code, you can think of a Web browser as a compiler that translates HTML into a human-readable page.
All compilers, independent of input and output format, work similarly. Figure One shows a diagram of the seven steps a compiler performs.
Figure One: The compilation process
STEP ONE: Lexical analysis translates a stream of characters (the source code) into a stream of tokens. A token is a sequence of characters that represents a single building block of a programming language — a variable, a keyword, or even just a semicolon (a very important part of C and other languages).
STEP TWO: Syntax analysis determines if the source code (now represented by…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: