Compiler: Difference between revisions

Jump to navigation Jump to search
imported>Tedickey
Undid revision 1295155047 by 27.123.240.231 (talk)
 
imported>Citation bot
Alter: title, template type. Add: isbn, arxiv, chapter-url, chapter. Removed or converted URL. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | Suggested by GoingBatty | Category:CS1 errors: dates | #UCB_Category | Whitelisted category 452/806
 
Line 1: Line 1:
{{Short description|Computer program which translates code from one programming language to another}}
{{Short description |Software that translates code from one programming language to another}}
{{About|software to translate computer languages|the manga|Compiler (manga)}}
{{About |software to translate computer languages |the manga |Compiler (manga)}}
{{Redirect2|Compile|Compiling|the software company|Compile (company)|other uses|Compilation (disambiguation){{!}}Compilation}}
{{Redirect2|Compile|Compiling|the software company |Compile (company)|other uses |Compilation (disambiguation){{!}}Compilation}}
{{Use dmy dates|date=October 2020}}
{{Use dmy dates |date=October 2020}}
{{Program execution}}
{{Program execution}}


In [[computing]], a '''compiler''' is a [[computer program]] that [[Translator (computing)|translates]] computer code written in one [[programming language]] (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that translate [[source code]] from a [[high-level programming language]] to a [[lower level language|low-level programming language]] (e.g. [[assembly language]], [[object code]], or [[machine code]]) to create an [[executable]] program.<ref>{{cite web |author= |date= |title=Encyclopedia: Definition of Compiler |url=https://www.pcmag.com/encyclopedia/term/compiler |access-date=2 July 2022 |work=PCMag.com}}</ref><ref name="dragon">[[Compilers: Principles, Techniques, and Tools]] by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman - Second Edition, 2007</ref>{{rp|p1}}<ref name="SUDARSANAM MALIK FUJITA 2002 pp. 506–515">{{cite book | last1=Sudarsanam | first1=Ashok | last2=Malik | first2=Sharad | last3=Fujita | first3=Masahiro | title=Readings in Hardware/Software Co-Design | chapter=A Retargetable Compilation Methodology for Embedded Digital Signal Processors Using a Machine-Dependent Code Optimization Library | publisher=Elsevier | date=2002 | doi=10.1016/b978-155860702-6/50045-4 | pages=506–515 | isbn=9781558607026 | quote=A compiler is a computer program that translates a program written in a high-level language (HLL), such as C, into an equivalent assembly language program [2]. }}</ref>
In [[computing]], a '''compiler''' is [[software]] that [[Translator (computing)|translates]] computer code written in one [[programming language]] (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that translate [[source code]] from a [[high-level programming language]] to a [[lower level language |low-level programming language]] (e.g. [[assembly language]], [[object code]], or [[machine code]]) to create an [[executable]] program.<ref>{{cite web |author= |date= |title=Encyclopedia: Definition of Compiler |url=https://www.pcmag.com/encyclopedia/term/compiler |access-date=2 July 2022 |work=PCMag.com}}</ref><ref name="dragon">[[Compilers: Principles, Techniques, and Tools]] by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman - Second Edition, 2007</ref>{{rp|p1}}<ref name="SUDARSANAM MALIK FUJITA 2002 pp. 506–515">{{cite book | last1=Sudarsanam | first1=Ashok | last2=Malik | first2=Sharad | last3=Fujita | first3=Masahiro | title=Readings in Hardware/Software Co-Design | chapter=A Retargetable Compilation Methodology for Embedded Digital Signal Processors Using a Machine-Dependent Code Optimization Library | publisher=Elsevier | date=2002 | doi=10.1016/b978-155860702-6/50045-4 | pages=506–515 | isbn=9781558607026 | quote=A compiler is a computer program that translates a program written in a high-level language (HLL), such as C, into an equivalent assembly language program [2]. }}</ref>


There are many different types of compilers which produce output in different useful forms. A ''[[cross-compiler]]''  produces code for a different [[Central processing unit|CPU]] or [[operating system]] than the one on which the cross-compiler itself runs.  A ''[[bootstrap compiler]]'' is often a temporary compiler, used for compiling a more permanent or better optimised compiler for a language.
There are many different types of compilers which produce output in different useful forms. A ''[[cross-compiler]]''  produces code for a different [[Central processing unit|CPU]] or [[operating system]] than the one on which the cross-compiler itself runs.  A ''[[bootstrap compiler]]'' is often a temporary compiler, used for compiling a more permanent or better optimized compiler for a language.


Related software include ''[[decompiler]]s'', programs that translate from low-level languages to higher level ones; programs that translate between high-level languages, usually called ''[[source-to-source compiler]]s'' or ''transpilers''; language ''[[rewriting|rewriter]]s'', usually programs that translate the form of [[Expression (computer science)|expressions]] without a change of language; and ''[[compiler-compiler]]s'', compilers that produce compilers (or parts of them), often in a generic and reusable way so as to be able to produce many differing compilers.
Related software include ''[[decompiler]]s'', programs that translate from low-level languages to higher-level ones; programs that translate between high-level languages, usually called ''[[source-to-source compiler]]s'' or ''transpilers''; language ''[[rewriting |rewriter]]s'', usually programs that translate the form of [[Expression (computer science)|expressions]] without a change of language; and ''[[compiler-compiler]]s'', compilers that produce compilers (or parts of them), often in a generic and reusable way so as to be able to produce many differing compilers.


A compiler is likely to perform some or all of the following operations, often called phases: [[Preprocessor|preprocessing]], [[lexical analysis]], [[parser|parsing]], [[Semantic analysis (compilers)|semantic analysis]] ([[syntax-directed translation]]), conversion of input programs to an [[intermediate representation]], [[code optimization]] and [[code generation (compiler)|machine specific code generation]]. Compilers generally implement these phases as modular components, promoting efficient design and correctness of [[program transformation|transformation]]s of source input to target output. Program faults caused by incorrect compiler behavior can be very difficult to track down and work around; therefore, compiler implementers invest significant effort to ensure [[compiler correctness]].<ref name="Sun2016">{{cite book |last1=Sun|first1=Chengnian|last2=Le|first2=Vu|last3=Zhang|first3=Qirun|last4=Su|first4=Zhendong|title=Proceedings of the 25th International Symposium on Software Testing and Analysis |chapter=Toward understanding compiler bugs in GCC and LLVM |date=2016|chapter-url=http://dl.acm.org/citation.cfm?doid=2931037.2931074|publisher=ACM|series=ISSTA 2016|pages=294–305|doi=10.1145/2931037.2931074|isbn=9781450343909|s2cid=8339241}}</ref>
A compiler is likely to perform some or all of the following operations, often called phases: [[Preprocessor |preprocessing]], [[lexical analysis]], [[parser |parsing]], [[Semantic analysis (compilers)|semantic analysis]] ([[syntax-directed translation]]), conversion of input programs to an [[intermediate representation]], [[code optimization]] and [[code generation (compiler)|machine specific code generation]]. Compilers generally implement these phases as modular components, promoting efficient design and correctness of [[program transformation|transformation]]s of source input to target output. Program faults caused by incorrect compiler behavior can be very difficult to track down and work around; therefore, compiler implementers invest significant effort to ensure [[compiler correctness]].<ref name="Sun2016">{{cite book |last1=Sun|first1=Chengnian|last2=Le|first2=Vu|last3=Zhang|first3=Qirun|last4=Su|first4=Zhendong|title=Proceedings of the 25th International Symposium on Software Testing and Analysis |chapter=Toward understanding compiler bugs in GCC and LLVM |date=2016|chapter-url=http://dl.acm.org/citation.cfm?doid=2931037.2931074|publisher=ACM|series=ISSTA 2016|pages=294–305|doi=10.1145/2931037.2931074|isbn=9781450343909|s2cid=8339241}}</ref>


==Comparison with interpreter==
==Comparison with interpreter==


With respect to making source code runnable, an [[interpreter (computing)|interpreter]] provides a similar function as a compiler, but via a different mechanism. An interpreter executes code without converting it to machine code.<ref name="dragon"/>{{rp|p2}} Some interpreters execute source code while others execute an intermediate form such as [[bytecode]].
With respect to making source code runnable, an [[interpreter (computing)|interpreter]] provides a similar function as a compiler, but via a different mechanism. An interpreter executes code without converting it to machine code.<ref name="dragon"/>{{rp|p2}} Therefore, some interpreters execute source code while others execute an intermediate form such as [[bytecode]].


A program compiled to native code tends to run faster than if interpreted. Environments with a bytecode intermediate form tend toward intermediate speed. [[Just-in-time compilation]] allows for native execution speed with a one-time startup processing time cost.
A program compiled to native code tends to run faster than when interpreted, while environments with a bytecode-intermediate-form tends toward intermediate-speed. Alternatively, [[Just-in-time compilation]] allows for native execution speed with a one-time startup processing time cost.


[[Low-level programming language]]s, such as [[assembly language|assembly]] and [[C (programming language)|C]], are typically compiled, especially when speed is a significant concern, rather than [[cross-platform]] support. For such languages, there are more one-to-one correspondences between the source code and the resulting [[machine code]], making it easier for programmers to control the use of hardware.
[[Low-level programming language]]s, such as [[assembly language |assembly]] and [[C (programming language)|C]], are typically compiled, especially when speed is a significant concern, rather than having [[cross-platform]] support. For such languages, there are more one-to-one correspondences between the source code and the resulting [[machine code]], making it easier for programmers to control the use of hardware.


In theory, a programming language can be used via either a compiler or an interpreter, but in practice, each language tends to be used with only one or the other. Nonetheless, it is possible to write a compiler for a language that is commonly interpreted. For example, [[Common Lisp]] can be compiled to Java bytecode (then interpreted by the [[Java virtual machine]]), C code (then compiled to native machine code), or directly to native code.
In theory, any programming language can be used via either a compiler or an interpreter, but in practice, languages tend to be used with only one or the other. Nonetheless, it is possible to write a compiler for a language that is commonly interpreted. For example, [[Common Lisp]] can be compiled to Java bytecode (and then interpreted by the [[Java virtual machine]]), to C code (which can then be compiled again to native machine code), or directly to native code.


== History ==
== History ==
{{Main|History of compiler construction}}
{{Main |History of compiler construction}}
[[File:Compiler.svg|upright=1.5|thumb |A diagram of the operation of a typical multi-language, multi-target compiler]]
[[File:Compiler.svg|upright=1.5|thumb |A diagram of the operation of a typical multi-language, multi-target compiler]]
Theoretical computing concepts developed by scientists, mathematicians, and engineers formed the basis of digital modern computing development during World War II. Primitive binary languages evolved because digital devices only understand ones and zeros and the circuit patterns in the underlying machine architecture. In the late 1940s, assembly languages were created to offer a more workable abstraction of the computer architectures.<ref>{{Cite web |last=Baghai |first=Christian |date=2023-04-04 |title=The Evolution of Programming Languages: From Primitive Binary to High-Level Abstractions |url=https://christianbaghai.medium.com/the-evolution-of-programming-languages-from-primitive-binary-to-high-level-abstractions-7b8e4b7a2521 |access-date=2024-07-10 |website=Medium |language=en}}</ref> Limited [[main memory|memory]] capacity of early computers led to substantial technical challenges when the first compilers were designed. Therefore, the compilation process needed to be divided into several small programs. The front end programs produce the analysis products used by the back end programs to generate target code. As computer technology provided more resources, compiler designs could align better with the compilation process.
Theoretical computing concepts developed by scientists, mathematicians, and engineers formed the basis of digital modern computing development during World War II. Primitive binary languages evolved because digital devices only understand ones and zeros and the circuit patterns in the underlying machine architecture. In the late 1940s, assembly languages were created to offer a more workable abstraction of the computer architectures.<ref>{{Cite web |last=Baghai |first=Christian |date=2023-04-04 |title=The Evolution of Programming Languages: From Primitive Binary to High-Level Abstractions |url=https://christianbaghai.medium.com/the-evolution-of-programming-languages-from-primitive-binary-to-high-level-abstractions-7b8e4b7a2521 |access-date=2024-07-10 |website=Medium |language=en}}</ref> Limited [[main memory|memory]] capacity of early computers led to substantial technical challenges when the first compilers were designed. Therefore, the compilation process needed to be divided into several small programs. The front end programs produce the analysis products used by the back end programs to generate target code. As computer technology provided more resources, compiler designs could align better with the compilation process.
Line 49: Line 49:


Some early milestones in the development of compiler technology:
Some early milestones in the development of compiler technology:
* ''May 1952'': [[Grace Hopper]]'s team at [[Remington Rand]] wrote the compiler for the [[A-0 System|A-0]] programming language (and coined the term ''compiler'' to describe it),<ref>{{cite book |last1=Hopper |first1=Grace Murray |title=Proceedings of the 1952 ACM national meeting (Pittsburgh) on - ACM '52 |chapter=The education of a computer |date=1952 |pages=243–249 |doi=10.1145/609784.609818 |s2cid=10081016|doi-access=free }}</ref><ref>{{cite book |last1=Ridgway |first1=Richard K. |title=Proceedings of the 1952 ACM national meeting (Toronto) on - ACM '52 |chapter=Compiling routines |date=1952 |pages=1–5 |doi=10.1145/800259.808980 |s2cid=14878552|doi-access=free }}</ref><ref>{{cite web | title=List of early compilers and assemblers | url=http://shape-of-code.coding-guidelines.com/2017/05/21/evidence-for-28-possible-compilers-in-1957}}</ref> although the A-0 compiler functioned more as a loader or [[Linker (computing)|linker]] than the modern notion of a full compiler.<ref>{{ cite conference |last=Hopper|first=Grace|title=Keynote Address|doi=10.1145/800025.1198341 |book-title=Proceedings of the ACM SIGPLAN History of Programming Languages (HOPL) conference, June 1978 | url=https://dl.acm.org/doi/pdf/10.1145/800025.1198341|url-access=subscription}}</ref><ref>{{ cite web |last=Bruderer|first=Herbert|title=Did Grace Hopper Create the First Compiler? |date=21 December 2022 | url=https://cacm.acm.org/blogs/blog-cacm/268001-did-grace-hopper-create-the-first-compiler/fulltext}}</ref><ref>{{cite journal |last1=Strawn |first1=George |last2=Strawn |first2=Candace |title=Grace Hopper: Compilers and Cobol | url = https://www.computer.org/csdl/magazine/it/2015/01/mit2015010062/13rRUxCitFF |journal=IT Professional |date=2015 |volume=17 |issue=Jan.-Feb. 2015 |pages=62–64 |doi=10.1109/MITP.2015.6 |url-access=subscription }}</ref>
* ''May 1952'': [[Grace Hopper]]'s team at [[Remington Rand]] wrote the compiler for the [[A-0 System|A-0]] programming language (and coined the term ''compiler'' to describe it),<ref>{{cite book |last1=Hopper |first1=Grace Murray |title=Proceedings of the 1952 ACM national meeting (Pittsburgh) on - ACM '52 |chapter=The education of a computer |date=1952 |pages=243–249 |doi=10.1145/609784.609818 |s2cid=10081016|doi-access=free }}</ref><ref>{{cite book |last1=Ridgway |first1=Richard K. |title=Proceedings of the 1952 ACM national meeting (Toronto) on - ACM '52 |chapter=Compiling routines |date=1952 |pages=1–5 |doi=10.1145/800259.808980 |s2cid=14878552|doi-access=free }}</ref><ref>{{cite web | title=List of early compilers and assemblers | url=http://shape-of-code.coding-guidelines.com/2017/05/21/evidence-for-28-possible-compilers-in-1957}}</ref> although the A-0 compiler functioned more as a loader or [[Linker (computing)|linker]] than the modern notion of a full compiler.<ref>{{ cite conference |last=Hopper|first=Grace|title=Keynote Address|doi=10.1145/800025.1198341 |book-title=Proceedings of the ACM SIGPLAN History of Programming Languages (HOPL) conference, June 1978 | url=https://dl.acm.org/doi/pdf/10.1145/800025.1198341|url-access=subscription}}</ref><ref>{{ cite web |last=Bruderer|first=Herbert|title=Did Grace Hopper Create the First Compiler? |date=21 December 2022 | url=https://cacm.acm.org/blogs/blog-cacm/268001-did-grace-hopper-create-the-first-compiler/fulltext}}</ref><ref>{{cite journal |last1=Strawn |first1=George |last2=Strawn |first2=Candace |title=Grace Hopper: Compilers and Cobol | url = https://www.computer.org/csdl/magazine/it/2015/01/mit2015010062/13rRUxCitFF |journal=IT Professional |date=2015 |volume=17 |issue=Jan.-Feb. 2015 |pages=62–64 |doi=10.1109/MITP.2015.6 |bibcode=2015ITPro..17a..62S |url-access=subscription }}</ref>
* ''1952, before September'': An [[Autocode]] compiler developed by [[Alick Glennie]] for the [[Manchester Mark I]] computer at the University of Manchester is considered by some to be the first compiled programming language.<ref>Knuth, Donald E.; Pardo, Luis Trabb, "Early development of programming languages", Encyclopedia of Computer Science and Technology (Marcel Dekker) 7: 419–493</ref>
* ''1952, before September'': An [[Autocode]] compiler developed by [[Alick Glennie]] for the [[Manchester Mark I]] computer at the University of Manchester is considered by some to be the first compiled programming language.<ref>[[Donald Knuth|Knuth, Donald E.]]; Pardo, Luis Trabb, "Early development of programming languages", Encyclopedia of Computer Science and Technology (Marcel Dekker) 7: 419–493</ref>
* ''1954–1957'': A team led by [[John Backus]] at [[IBM]] developed [[Fortran|FORTRAN]] which is usually considered the first high-level language. In 1957, they completed a FORTRAN compiler that is generally credited as having introduced the first unambiguously complete compiler.<ref>{{Citation |last=Backus |first=John |title=The history of Fortran I, II, and III |date=1978-06-01 |work=History of programming languages |pages=25–74 |url=https://dl.acm.org/doi/10.1145/800025.1198345 |access-date=2024-10-09 |place=New York, NY, USA |publisher=Association for Computing Machinery |doi=10.1145/800025.1198345 |isbn=978-0-12-745040-7|url-access=subscription }}</ref>
* ''1954–1957'': A team led by [[John Backus]] at [[IBM]] developed [[Fortran|FORTRAN]] which is usually considered the first high-level language. In 1957, they completed a FORTRAN compiler that is generally credited as having introduced the first unambiguously complete compiler.<ref>{{Citation |last=Backus |first=John |title=The history of Fortran I, II, and III |date=1978-06-01 |work=History of programming languages |pages=25–74 |url=https://dl.acm.org/doi/10.1145/800025.1198345 |access-date=2024-10-09 |place=New York, NY, USA |publisher=Association for Computing Machinery |doi=10.1145/800025.1198345 |isbn=978-0-12-745040-7|url-access=subscription }}</ref>
* ''1959'': The Conference on Data Systems Language (CODASYL) initiated development of [[COBOL]]. The COBOL design drew on A-0 and FLOW-MATIC. By the early 1960s COBOL was compiled on multiple architectures.
* ''1959'': The Conference on Data Systems Language (CODASYL) initiated development of [[COBOL]]. The COBOL design drew on A-0 and FLOW-MATIC. By the early 1960s COBOL was compiled on multiple architectures.
Line 90: Line 90:


== Compiler construction ==
== Compiler construction ==
{{main | Programming language design and implementation }}
{{more footnotes needed|section|date=December 2019}}
{{more footnotes needed|section|date=December 2019}}
A compiler implements a formal transformation from a high-level source program to a low-level target program. Compiler design can define an end-to-end solution or tackle a defined subset that interfaces with other compilation tools e.g. preprocessors, assemblers, linkers. Design requirements include rigorously defined interfaces both internally between compiler components and externally between supporting toolsets.
A compiler implements a formal transformation from a high-level source program to a low-level target program. Compiler design can define an end-to-end solution or tackle a defined subset that interfaces with other compilation tools e.g. preprocessors, assemblers, linkers. Design requirements include rigorously defined interfaces both internally between compiler components and externally between supporting toolsets.
Line 97: Line 98:
A compiler for a relatively simple language written by one person might be a single, monolithic piece of software. However, as the source language grows in complexity the design may be split into a number of interdependent phases. Separate phases provide design improvements that focus development on the functions in the compilation process.
A compiler for a relatively simple language written by one person might be a single, monolithic piece of software. However, as the source language grows in complexity the design may be split into a number of interdependent phases. Separate phases provide design improvements that focus development on the functions in the compilation process.


=== One-pass vis-à-vis multi-pass compilers{{anchor|Single-pass}} ===
=== One-pass vs multi-pass compilers{{anchor|Single-pass}} ===
Classifying compilers by number of passes has its background in the hardware resource limitations of computers. Compiling involves performing much work and early computers did not have enough memory to contain one program that did all of this work. As a result, compilers were split up into smaller programs which each made a pass over the source (or some representation of it) performing some of the required analysis and translations.
Classifying compilers by number of passes has its background in the hardware resource limitations of computers. Compiling involves performing much work and early computers did not have enough memory to contain one program that did all of this work. As a result, compilers were split up into smaller programs which each made a pass over the source (or some representation of it) performing some of the required analysis and translations.


Line 118: Line 119:


==== Front end ====
==== Front end ====
[[File:Xxx Scanner and parser example for C.gif|thumb|right|400px|[[Lexical analysis|Lexer]] and [[Parsing|parser]] example for [[C (programming language)|C]]. Starting from the sequence of characters "<code>if(net>0.0)total+=net*(1.0+tax/100.0);</code>", the scanner composes a sequence of [[Lexical analysis#token|tokens]], and categorizes each of them, for example as {{color|#600000|identifier}}, {{color|#606000|reserved word}}, {{color|#006000|number literal}}, or {{color|#000060|operator}}. The latter sequence is transformed by the parser into a [[abstract syntax tree|syntax tree]], which is then treated by the remaining compiler phases. The scanner and parser handles the [[regular grammar|regular]] and properly [[context-free grammar|context-free]] parts of the [[C syntax|grammar for C]], respectively.]]
[[File:Xxx Scanner and parser example for C.gif|thumb|[[Lexical analysis|Lexer]] and [[Parsing|parser]] example for [[C (programming language)|C]]. Starting from the sequence of characters "<code>if(net>0.0)total+=net*(1.0+tax/100.0);</code>", the scanner composes a sequence of [[Lexical analysis#token|tokens]], and categorizes each of them, for example as {{color|#600000|identifier}}, {{color|#606000|reserved word}}, {{color|#006000|number literal}}, or {{color|#000060|operator}}. The latter sequence is transformed by the parser into a [[abstract syntax tree|syntax tree]], which is then treated by the remaining compiler phases. The scanner and parser handles the [[regular grammar|regular]] and properly [[context-free grammar|context-free]] parts of the [[C syntax|grammar for C]], respectively.]]


The front end analyzes the source code to build an internal representation of the program, called the [[intermediate representation]] (IR). It also manages the [[symbol table]], a data structure mapping each symbol in the source code to associated information such as location, type and scope.
The front end analyzes the source code to build an internal representation of the program, called the [[intermediate representation]] (IR). It also manages the [[symbol table]], a data structure mapping each symbol in the source code to associated information such as location, type and scope.
Line 162: Line 163:
Interpretation does not replace compilation completely. It only hides it from the user and makes it gradual. Even though an interpreter can itself be interpreted, a set of directly executed machine instructions is needed somewhere at the bottom of the execution stack (see [[machine language]]).
Interpretation does not replace compilation completely. It only hides it from the user and makes it gradual. Even though an interpreter can itself be interpreted, a set of directly executed machine instructions is needed somewhere at the bottom of the execution stack (see [[machine language]]).


Furthermore, for optimization compilers can contain interpreter functionality, and interpreters may include ahead of time compilation techniques. For example, where an expression can be executed during compilation and the results inserted into the output program, then it prevents it having to be recalculated each time the program runs, which can greatly speed up the final program. Modern trends toward [[just-in-time compilation]] and [[bytecode|bytecode interpretation]] at times blur the traditional categorizations of compilers and interpreters even further.
Furthermore, for optimization compilers can contain interpreter functionality, and interpreters may include ahead of time compilation techniques. For example, where an expression can be executed during compilation and the results inserted into the output program, then it prevents it having to be recalculated each time the program runs, which can greatly speed up the final program. Modern trends toward [[just-in-time compilation]] and [[bytecode|bytecode interpretation]] at times blur the traditional categorizations of compilers and interpreters even further. [[Meta-tracing]] is an automated compiler synthesis approach which takes this further and can be used to synthesize a compiler from a language interpreter.


Some language specifications spell out that implementations ''must'' include a compilation facility; for example, [[Common Lisp]]. However, there is nothing inherent in the definition of Common Lisp that stops it from being interpreted. Other languages have features that are very easy to implement in an interpreter, but make writing a compiler much harder; for example, [[APL (programming language)|APL]], [[SNOBOL4]],<ref>{{Cite web |date=2023-10-27 |title=SNOBOL4 Programming Language |url=https://sourceforge.net/projects/snobol4/ |access-date=2025-05-25 |website=SourceForge |language=en}}</ref> and many scripting languages allow programs to construct arbitrary source code at runtime with regular string operations, and then execute that code by passing it to a special [[eval|evaluation function]]. To implement these features in a compiled language, programs must usually be shipped with a [[runtime library]] that includes a version of the compiler itself.
Some language specifications spell out that implementations ''must'' include a compilation facility; for example, [[Common Lisp]]. However, there is nothing inherent in the definition of Common Lisp that stops it from being interpreted. Other languages have features that are very easy to implement in an interpreter, but make writing a compiler much harder; for example, [[APL (programming language)|APL]], [[SNOBOL4]],<ref>{{Cite web |date=2023-10-27 |title=SNOBOL4 Programming Language |url=https://sourceforge.net/projects/snobol4/ |access-date=2025-05-25 |website=SourceForge |language=en}}</ref> and many scripting languages allow programs to construct arbitrary source code at runtime with regular string operations, and then execute that code by passing it to a special [[eval|evaluation function]]. To implement these features in a compiled language, programs must usually be shipped with a [[runtime library]] that includes a version of the compiler itself.
Line 184: Line 185:
* [[silicon compiler|Hardware compilers]] (also known as synthesis tools) are compilers whose input is a [[hardware description language]] and whose output is a description, in the form of a [[netlist]] or otherwise, of a hardware configuration.
* [[silicon compiler|Hardware compilers]] (also known as synthesis tools) are compilers whose input is a [[hardware description language]] and whose output is a description, in the form of a [[netlist]] or otherwise, of a hardware configuration.
** The output of these compilers target [[computer hardware]] at a very low level, for example a [[field-programmable gate array]] (FPGA) or structured [[application-specific integrated circuit]] (ASIC).<ref>{{cite book|last1=Swartz|first1=Jordan S.|last2=Betz |first2=Vaugh |last3 =Rose|first3=Jonathan|title=Proceedings of the 1998 ACM/SIGDA sixth international symposium on Field programmable gate arrays - FPGA '98 |chapter=A fast routability-driven router for FPGAs |location=Monterey, CA|publisher=[[Association for Computing Machinery|ACM]]|chapter-url= http://www.eecg.toronto.edu/~vaughn/papers/fpga98.pdf |url-status=live|archive-url=https://web.archive.org/web/20170809012611/http://www.eecg.toronto.edu/~vaughn/papers/fpga98.pdf|archive-date=9 August 2017|date =22-25 February 1998|doi = 10.1145/275107.275134 |pages=140–149|isbn=978-0897919784|s2cid=7128364}}</ref>{{primary source inline|date=March 2017}} Such compilers are said to be hardware compilers, because the source code they compile effectively controls the final configuration of the hardware and how it operates. The output of the compilation is only an interconnection of [[transistor]]s or [[lookup table]]s.
** The output of these compilers target [[computer hardware]] at a very low level, for example a [[field-programmable gate array]] (FPGA) or structured [[application-specific integrated circuit]] (ASIC).<ref>{{cite book|last1=Swartz|first1=Jordan S.|last2=Betz |first2=Vaugh |last3 =Rose|first3=Jonathan|title=Proceedings of the 1998 ACM/SIGDA sixth international symposium on Field programmable gate arrays - FPGA '98 |chapter=A fast routability-driven router for FPGAs |location=Monterey, CA|publisher=[[Association for Computing Machinery|ACM]]|chapter-url= http://www.eecg.toronto.edu/~vaughn/papers/fpga98.pdf |url-status=live|archive-url=https://web.archive.org/web/20170809012611/http://www.eecg.toronto.edu/~vaughn/papers/fpga98.pdf|archive-date=9 August 2017|date =22-25 February 1998|doi = 10.1145/275107.275134 |pages=140–149|isbn=978-0897919784|s2cid=7128364}}</ref>{{primary source inline|date=March 2017}} Such compilers are said to be hardware compilers, because the source code they compile effectively controls the final configuration of the hardware and how it operates. The output of the compilation is only an interconnection of [[transistor]]s or [[lookup table]]s.
** An example of hardware compiler is XST, the Xilinx Synthesis Tool used for configuring FPGAs.<ref>{{cite web|author=Xilinx Staff|date=2009|title=XST Synthesis Overview|publisher=Xilinx, Inc.|url=http://www.xilinx.com/support/documentation/sw_manuals/xilinx11/ise_c_using_xst_for_synthesis.htm|access-date=28 February 2017|url-status=live|archive-url=https://web.archive.org/web/20161102004019/http://www.xilinx.com/support/documentation/sw_manuals/xilinx11/ise_c_using_xst_for_synthesis.htm|archive-date=2 November 2016}}</ref>{{primary source inline|date=March 2017}} Similar tools are available from Altera,<ref>{{cite web|author=Altera Staff|date=2017|title=Spectra-Q™ Engine|publisher=Altera.com|url=https://www.altera.com/products/design-software/fpga-design/quartus-prime/features/spectra-q.html|access-date=28 February 2017|url-status=dead|archive-url=https://web.archive.org/web/20161010221724/https://www.altera.com/products/design-software/fpga-design/quartus-prime/features/spectra-q.html|archive-date=10 October 2016}}</ref>{{primary source inline|date=March 2017}} Synplicity, Synopsys and other hardware vendors.{{citation needed|date=March 2017}}
** An example of hardware compiler is XST, the Xilinx Synthesis Tool used for configuring FPGAs.<ref>{{cite web|author=Xilinx Staff|date=2009|title=XST Synthesis Overview|publisher=Xilinx, Inc.|url=http://www.xilinx.com/support/documentation/sw_manuals/xilinx11/ise_c_using_xst_for_synthesis.htm|access-date=28 February 2017|url-status=live|archive-url=https://web.archive.org/web/20161102004019/http://www.xilinx.com/support/documentation/sw_manuals/xilinx11/ise_c_using_xst_for_synthesis.htm|archive-date=2 November 2016}}</ref>{{primary source inline|date=March 2017}} Similar tools are available from Altera,<ref>{{cite web|author=Altera Staff|date=2017|title=Spectra-Q™ Engine|publisher=Altera.com|url=https://www.altera.com/products/design-software/fpga-design/quartus-prime/features/spectra-q.html|access-date=28 February 2017|url-status=dead|archive-url=https://web.archive.org/web/20161010221724/https://www.altera.com/products/design-software/fpga-design/quartus-prime/features/spectra-q.html|archive-date=10 October 2016}}</ref>{{primary source inline|date=March 2017}} Synplicity, Synopsys and other hardware vendors.<ref>{{cite book |last1= Nigam |first1= Rachit |last2= Thomas |first2= Samuel |last3= Li |first3= Zhijing |last4= Sampson |first4= Adrian |chapter= A compiler infrastructure for accelerator generators |title= Proceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems |date= April 2021 |pages= 804–817 |chapter-url= https://dl.acm.org/doi/10.1145/3445814.3446712 |access-date= 2026-05-20 |doi= 10.1145/3445814.3446712 |arxiv= 2102.09713 |isbn= 978-1-4503-8317-2 }}</ref>
** Research systems compile subsets of high level serial languages, such as Python or C++, directly into parallelized digital logic. This is typically easier to do for functional languages or functional subsets of multi-paradigm languages.<ref>{{cite conference |last1=Jurkans |first1=K |last2=Fox |first2=C |title=Python Subset to Digital Logic Dataflow Compiler for Robots and IoT |conference=IEEE International Conference on Trust, Security and Privacy in Computing and Communications (TrustCom-2023) |year=2023}}</ref>
** Research systems compile subsets of high level serial languages, such as Python or C++, directly into parallelized digital logic. This is typically easier to do for functional languages or functional subsets of multi-paradigm languages.<ref>{{cite conference |last1=Jurkans |first1=K |last2=Fox |first2=C |title=Python Subset to Digital Logic Dataflow Compiler for Robots and IoT |conference=IEEE International Conference on Trust, Security and Privacy in Computing and Communications (TrustCom-2023) |year=2023}}</ref>
* A program that translates from a low-level language to a higher level one is a [[decompiler]].<ref>{{cite book |doi=10.1016/B978-1-59749-574-5.00003-9 |chapter=Tools of the Trade |title=Managed Code Rootkits |date=2011 |last1=Metula |first1=Erez |pages=39–62 |isbn=978-1-59749-574-5 }}</ref>
* A program that translates from a low-level language to a higher level one is a [[decompiler]].<ref>{{cite book |doi=10.1016/B978-1-59749-574-5.00003-9 |chapter=Tools of the Trade |title=Managed Code Rootkits |date=2011 |last1=Metula |first1=Erez |pages=39–62 |isbn=978-1-59749-574-5 }}</ref>
Line 203: Line 204:
* [[Metacompilation]]
* [[Metacompilation]]
* [[Program transformation]]
* [[Program transformation]]
* [[Software build]]
{{div col end}}
{{div col end}}