x
Loading
 Loading
Hello, Guest | Login | Register

Compilers: The Front End

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.

Compile fig1
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:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace