Compilers: Translating Human Readable Code into Machine Language

compiler banner

Compilers are computer programs that translate high-level programming code into lower-level code like assembly language. The compiler is part of the computer translation hierarchy which ultimately translates human-readable code into machine-readable code.

Common compilers like GCC are the product of decades of a concerted effort from developers around the world (R). Compilers, and their close relative interpreters, are irreplaceable components of software development.

They provide a wide range of utility that analyzes, optimizes, and generates code on several levels. Anyone writing code should at least be aware that compilers exist and have a general idea of the role they place in software development. /rant.

Compiler Actions

computer compiler diagram
The compiler involves many steps that ultimately translates high-level code into low-level assembly code.

Compilers result in becoming key components in software development. One of the first compilers,  created by John Backus for the FORTRAN language, reportedly took 18-person years to complete (R). That’s a lot of development time. Needless to say, most commonly-used compilers like GCC are the product of years of optimizations to ensure they’re working efficiently. This is vital given the wide range of utility they provide:

  • Pre-Processing
  • Lexical Analysis
  • Parsing
  • Semantic Analysis
  • Intermediate Code Generation
  • Code Optimization
  • Code Generation

If there is an issue with the compiler, issues in any of the above steps could result, which can be notoriously difficult to identify.

The Bootstrapping Issue

Consider this question: if you wanted to code a compiler in C to compile C language, what language would you write the compiler in? This is comparable to the age-old question of whether the chicken-or-egg came first. In the context of language compilers, this problem is referred to as Bootstrapping (R).

In the past, one might have been required to first build a partial compiler in a lower-level language. For example, building a C compiler using assembly language. In modern practice, compilers are commonly able to be built for target platforms by using some standard library components first, and then iteratively building more complexity. For a detailed example of this process, check out the build instructions for the GCC Compiler.

Cross-Compilers

A cross compiler is a piece of computer software that generates executable files for a platform other than the one on which it is running. For example, the Java Virtual Machine (JVM) is an example of a cross-platform compilation. This software compiles Java code into an intermediate bytecode language that can be run on any machine with Java libraries installed.

Another example of cross-platform compilation would be popular game development software such as Unity3D and Unreal Engine that can be run on a Windows machine, yet generate executables for iOs, Android, Linux, and Windows. The tradeoff is usually efficient but, when considering the savings in development time, it’s often preferred.

GCC is another example of compilers that can be configured for cross-platform use. This open-source software first requires developers to compile a small piece of platform-specific code using the C-Standard library (or at least part of it.) This is an example of the bootstrapping problem with compilers, to some degree: how can one program a compiler, using said language, when that language doesn’t have a compiler?

In many cases, the answer is by creating a lightweight compiler using a lower-level language like assembly. GCC’s use of the C-Standard Library for initial cross-platform configuration helps avoid this issue.

History

Early computer programming, prior to the 1960s, was done almost entirely in assembly language. During the 1950s however, the concept of compilers was beginning to take form. In a now-historic document, PhD. candidate Corrado Bohm developed a computing language, translation method, and a machine that would mimic core features of future compilers.

In first compiler resembling modern feature sets, was developed by Alick Glennie in 1952 at the University of Manchester for a computer named Mark 1. At the time, this technology was referred to as an Autocoder, which would go on to be synonymous with term compiler.

The first commercially available compiler was developed at IBM under John Backus in 1957 and was used with the FORTRAN language. By the end of 1958, a compiler was created for the ALGOL 58 language, running on the now historic Z22 computer.

In 1960, the first demonstration of a cross-platform compiler was completed using the COBOL language. In these early days, compilers were more conceptual pursuits than practical commercial implementations. Due to memory restrictions—mostly; compiler-generated assembly code was rarely as efficient as that created by an experienced assembly language programmer.

Review

What is a Compiler?

Compilers are software that translates higher-level languages like C into lower-level languages like Assembly.

What’s the Difference Between a Compiler & Interpreter?

Interpreters translate programs one line at a time into machine code. Interpreters do not generate intermediate code which results in very inefficient use of memory. Interpreters continue executing programs until the first error is encountered whereas compilers will stop compilation if an error is found anywhere in the program.

What is a Cross Compiler?

Cross-compilation is creating executable code for a platform other than the one generating the code. For example, using a Windows machine to create an Android application.

When was the first commercial Compiler Created?

The first commercial compiler was created in 1958 for the ALGOL 58 machine by the FORTRAN team.

Zαck West
Full-Stack Software Engineer with 10+ years of experience. Expertise in developing distributed systems, implementing object-oriented models with a focus on semantic clarity, driving development with TDD, enhancing interfaces through thoughtful visual design, and developing deep learning agents.