Skip to content
Home

Compiler (computer program)

A compiler is software that translates source code from one programming language into another (often machine code or an intermediate form). This article explains its parts, history, types, and uses.

Overview

A compiler is a computer program that converts source code written in one programming language into code in another language. The original language is called the source language and the result is the target language. In many common situations the target is machine code that a processor can execute directly, or an intermediate form such as bytecode that runs on a virtual machine. For a concise introduction see general overview.

Image gallery

1 Image

Core parts and processing phases

Most compilers are organized into front-end and back-end stages and perform several distinct phases. These phases transform and check the program text progressively from raw characters to executable instructions:

  • Lexical analysis — groups characters into tokens such as identifiers, literals, and operators.
  • Syntax analysis (parsing) — builds a tree-like structure representing the program's grammar.
  • Semantic analysis — checks types, symbol use, and other language rules and annotates the tree with meaning.
  • Intermediate representation and optimization — converts the program into a form suitable for transformation and attempts to improve performance or size.
  • Code generation — emits target language text or machine instructions.
  • Linking and assembly — combines multiple compiled units and resolves references to create a final executable.

Specialized tools such as parser generators and compiler-compiler systems help build front ends for new languages.

History and development

Compilers emerged as programmers sought to write in higher-level languages instead of raw machine instructions. Early high-level languages and their compilers made it practical to express algorithms more clearly and to target different hardware through translated output. Over time the field added many techniques — from formal grammars and automatic parser construction to sophisticated optimization strategies — enabling compilers to produce highly efficient code and to support large, complex software systems. For background reading, consult historical summaries.

Types and notable distinctions

Compilers vary by their goals and outputs. Common distinctions include:

  • Ahead-of-time (AOT) compilers, which translate source to target before execution.
  • Just-in-time (JIT) compilers, which compile code at runtime to take advantage of actual execution conditions.
  • Cross-compilers, which produce executable code for a different machine or operating system than the one on which they run.
  • Transpilers, which translate between high-level languages rather than to machine code.
  • Decompilers, which attempt to recover readable source from compiled binaries.

Whether a tool is called a compiler or an interpreter depends on whether it produces an independent output program or executes the code directly; many modern systems mix both approaches (for example, compiling to bytecode and interpreting or JIT-compiling that bytecode).

Uses, examples, and importance

Compilers are central to software development. They enable portability by targeting different processors and operating systems, improve performance through optimization, support static error checking and analysis, and make new programming paradigms practical. Well-known compiled languages include systems-oriented languages and many general-purpose languages; compilers for them translate human-readable programs into efficient machine-level operations or portable bytecode. For practical tutorials and toolchains, see developer resources and implementations of cross-compilation for embedded systems at platform guides.

Beyond producing executables, modern compiler infrastructure often provides libraries and services used by integrated development environments (IDEs), static analyzers, and refactoring tools. This shared tooling amplifies productivity and helps maintain software quality at scale.

Terminology

A translator is a program that accepts as input a program formulated in a source language and translates it into a semantically equivalent program in a target language. Thus, in particular, it is required that the generated program produces the same results as the given program. The source language assembler is often regarded as an exception - its translator (into machine code) is called "assembler" and is generally not called "compiler". The translator's task covers a wide range of subtasks, from syntax analysis to target code generation. An important task is also to detect and report errors in the source program.

The word "compiler" is derived from the English "to compile" and means "compiler" in the true sense of the word. In the 1950s, the term was not yet firmly anchored in the computer world. Originally, compilers referred to a utility program that assembled an entire program from individual subroutines or formula evaluations in order to perform special tasks. (Today, this task is performed by the linker, which can, however, also be integrated in the compiler). The individual subroutines were still written "by hand" in machine language. From 1954 on, the term "algebraic compiler" appeared for a program that independently took over the conversion of formulas into machine code. The "algebraic" fell away in the course of time.

At the end of the 1950s, the term compiler was still controversial in the English-speaking world. Thus, the Fortran development team held on to the term "translator" for years to describe the compiler. This term is even included in the name of the programming language Fortran itself: Fortran is composed of Formula and Translation, meaning roughly formula translation. It was not until 1964 that the term compiler prevailed over the term translator in connection with Fortran. According to Carsten Busch, there is a "particular irony of history" in the fact that the term compiler is translated into German as "translator". However, some German publications also use the English technical term compiler instead of translator.

In a narrower sense, however, some German-language publications use the technical term compiler only when the source language is a higher programming language than the target language. Typical use cases are the translation of a higher programming language into the machine language of a computer, as well as the translation into bytecode of a virtual machine. The target language of compilers (in this sense) can also be an assembly language. A translator for transferring assembly language source programs into machine language is called an assembler or assembler.

History

Already for the first designed higher programming language, the plan calculus by Konrad Zuse, he planned - according to today's terminology - a compiler. Zuse referred to a single program as a computational plan and as early as 1944 had the idea for a so-called plan production device, which was to automatically generate a punched punched tape with a corresponding machine plan for the Zuse Z4 computer from a mathematically formulated computational plan.

More concrete than Zuse's idea of a plan production device was a concept by Heinz Rutishauser for automatic computational plan production. In a lecture to the Society for Applied Mathematics and Mechanics (GAMM), as well as in 1951 in his post-doctoral thesis at the ETH Zurich, he described which additional programming commands (instructions) and hardware additions were necessary on the Z4 then in use at the ETHZ in order to also use the computer as a tool for automatic program production.

An early compiler was conceived by mathematician Grace Hopper in 1949. Until then, programmers had to write machine code directly. (The first assembler was written between 1948 and 1950 by Nathaniel Rochester for an IBM 701). To simplify this process, Grace Hopper developed a method for expressing programs and their subroutines in a manner more closely aligned with human than machine language. On May 3, 1952, Hopper introduced the first compiler, A-0, which retrieved algorithms from a catalog, rewrote code, assembled them in appropriate order, reserved memory space, and organized the allocation of memory addresses. By early 1955, Hopper had already presented a prototype of the B-0 compiler, which generated programs according to English, French, or German instructions. Hopper called her presentation on the first compiler "The Education of a Computer".

The history of compiler construction was shaped by the respective current programming languages (cf. Timetable of Programming Languages) and hardware architectures. Other early milestones include the first Fortran compiler in 1957 and the first COBOL compiler in 1960. However, many architectural features of today's compilers were not developed until the 1960s.

In the past, programs that merge subroutines were sometimes called compilers. This misses the core task of a compiler today, because nowadays subroutines can be inserted by other means: Either in the source code itself, for example by a preprocessor (see also precompiler) or, in the case of translated components, by an independent linker.

Related articles

Author

AlegsaOnline.com Compiler (computer program)

URL: https://en.alegsaonline.com/art/22240

Share