Compiler

A compiler is a computer program that translates a computer program written in one computer language (called the source language) into a program written in another computer language (called the output or the target language).

Usually the translation is from a source code (generally a high level language) to a target code (generally a low level object code or machine language) that may be directly executed by a computer or a virtual machine. However, a compiler from a low level language to a high level one is also possible; this is normally known as a decompiler if it is reconstructing a high level language which (could have) generated the low level language. Compilers also exist which translate from one high level language to another, or sometimes to an intermediate language that still needs further processing; these are sometimes known as cascaders.

Typical compilers output so-called objectss that basically contain machine code augmented by information about the name and location of entry points and external calls (to functions not contained in the object). A set of object files, which need not have all come from a single compiler provided that the compilers used share a common output format, may then be linked together to create the final executable which can be run directly by a user.

Table of contents
1 Types of compilers
2 Compiler design
3 Compiler front end
4 Compiler back end
5 Compiled vs. Interpreted languages
6 Further reading

Types of compilers

A compiler may produce code intended to run on the same platform as the compiler itself runs on. This is sometimes called a native-code compiler. Alternatively, it might produce code designed to run on a different platform. This is known as a "cross compiler". Cross compilers are very useful when bringing up a new hardware platform for the first time (see bootstrapping).

Compiler design

In the past, compilers were divided into many passes to save space. When each pass is finished, the compiler can free the space needed during that pass.

Many modern compilers share a common 'two stage' design. The first stage, the 'compiler front end' translates the source language into an intermediate representation. The second stage, the 'compiler back end' works with the internal representation to produce code in the output language.

While compiler design is a complex task, this approach mitigates the complexity by allowing either the front end or back end to retarget the compiler's source or output language respectively. This way, modern compilers are often portable and allow multiple dialects of a language to be compiled.

Compiler front end

The compiler front end consists of multiple phases itself, each informed by formal language theory:

  1. Lexical analysis - breaking the source code text into small pieces ('tokens' or 'terminals'), each representing a single atomic unit of the language, for instance a keyword, identifier or symbol names. The token language is typically a regular language, so a finite state automaton constructed from a regular expression can be used to recognize it. This phase is also called lexing or scanning.
  2. Syntax analysis - Identifying syntactic structures of source code. It only focuses on the structure. In other words, it identifies the order of tokens and understand hierarchical structures in code. This phase is also called parsing.
  3. Semantic analysis is to recognize the meaning of program code and start to prepare for output. In that phrase, type checking is done and most of compiler errors show up.
  4. Intermediate language generation - an equivalent to the original program is created in an intermediate language.

Compiler back end

While there are applications where only the compiler front end is necessary, such as static language verification tools, a real compiler hands the intermediate representation generated by the front end to the back end, which produces a functional equivalent program in the output language. This is done in multiple steps:

  1. Optimization - the intermediate language representation is transformed into functionaly equivalent but faster (or smaller) forms.
  2. Code generation - the transformed intermediate language is translated into the output language, usually the native machine language of the system. This involves resource and storage decisions, such as deciding which variables to fit into registers and memory and the selection and scheduling of appropriate machine instructions.

Compiled vs. Interpreted languages

Many people divide higher level programming languages into two categories: compiled languages and interpreted languages. However, in fact most of these languages can be implemented either through compilation or interpretation, the categorisation merely reflecting which method is most commonly used to implement that language. (Some interpreted languages, however, cannot easily be implemented through compilation, especially those which allow self-modifying code.)

Further reading

Compilers: Principles, Techniques and Tools by Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman (ISBN 0201100886) is considered to be the standard authority on compiler basics, and makes a good primer for the techniques mentioned above. (It is often called the Dragon book because of the picture on its cover showing a Knight of Programming fighting the Dragon of Compiler Design.) [1]

Understanding and Writing Compilers: A Do It Yourself Guide (ISBN 0333217322) by Richard Bornat is an unusually helpful book, being one of the few that adequately explains the recursive generation of machine instructions from a parse-tree. Having learnt his subject in the early days of mainframes and minicomputers, the author has many useful insights that more recent books often fail to convey.

During the 1990s a large number of free compilers and compiler development tools have been developed for all kinds of languages, both as part of the GNU project and other open-source initiatives. Some of them are considered to be of high quality and their free source code makes a nice read for anyone interested in modern compiler concepts.

See also: assembler, interpreter (computer software), linker, Abstract interpretation, Parsing, Top-bottom parsing, Bottom-up parsing



In the News

Untangling the Incan Mystery
The Andean empire built great cities but left no written record -- just some mysterious knotted strings called khipu. Can an anthropologist and a few mathematicians crack the code? By Gareth Cook from Wired magazine.

Internet-based Stroke Exam Speeds Treatment In Rural Areas
An Internet-based examination system enables stroke patients to be treated as rapidly in rural communities as they are in bigger hospitals with stroke teams, researchers have found.

[Odd] A Romanian couple has named their son Yahoo as a sign of gratitu
Daily Libertatea said on Thursday Cornelia and Nonu Dragoman, both from Transylvania, met and decided they were meant for each other following a three-month relationship over the net.They married and had a baby this Christmas, whom they decided to name after one of the worldwide web's most popular portals."We named him Lucian Yahoo after my father and the net, the main beacon of my life,"Cornelia Dragoman was quoted as saying.

Disability Among Older Americans Continues Significant Decline
Chronic disability among older Americans has dropped dramatically, and the rate of decline has accelerated during the past two decades, according to a new analysis of data from the National Long Term Care Survey.

Rating Your Pain From Zero To Ten Might Not Help Your Doctor
The most commonly used measure for pain screening -- which asks patients in primary care to rate their current pain from 0 (no pain) to 10 (worst pain) -- may only be modestly accurate, according to new research.

Major Advance In The Fight Against Chronic Virus Infections
A major finding that could lead to a new approach for treating hepatitis C and other chronic virus infections was announced today by researchers at the La Jolla Institute for Allergy and Immunology. The research team, using controlled laboratory studies of mice, was able to eliminate a chronic virus infection in the animals by blocking a key messenger molecule in the immune system. The finding has particular relevance for hepatitis C, but may also be applicable to AIDS, cytomegalovirus and other chronic virus infections.

[Ironic] LONDON: A jailed cocaine dealer is working as Santa Claus on
John Tams, who dons beard, boots and red suit to work in a cafe's Christmas grotto, said he wanted to give something back to the community...

Keeping Workers Safe During Clean Up and Recovery Operations Following
News releases and audio of public service announcements from the Occupational Safety and Health Administration (OSHA) about dangers for workers associated with hurricane recovery. Topics include flooding, electrical, chainsaws, falls, and mold. Also includes fact sheets on natural disaster recovery and related information. Most materials are in English and Spanish.

Murrow, Edward R.
Profile of Edward R. Murrow, "the most distinguished and renowned figure in the history of American broadcast journalism. He was a seminal force in the creation and development of electronic newsgathering as both a craft and a profession."Features career highlights for Murrow, whose relationship with Sen. Joseph McCarthy is the subject of the 2005 feature film "Good Night, and Good Luck."Includes a brief bibliography. From the Museum of Broadcast Communications.

Endangered Rangers: A Study of the Severe Staffing Shortages Crippling
This March 2004 report explores staffing shortages in national parks due to "chronic under funding and increasing park responsibilities that do not come with additional funding, such as protecting the Statue of Liberty ... from the possibility of terrorist attack."The report describes the situation and includes case studies, suggests short-term solutions, and makes recommendations for the future. Includes a list of information sources. From the National Parks Conservation Association.


MP3 Music Downloads

Preview songs, Download Free Music,Burn CDs at ITunes.com
iTunes_RGB_9mm

 


Google




InformationQuickFind.com - Find Information Fast

Links