Jump to content

Programming language implementation: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Reverted edits by Satoshin1975 (talk) to last version by ColRad85
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{short description|System for executing computer programs}}
{{short description|System for executing computer programs}}


In [[computer programming]], a '''programming language implementation''' is a system for executing [[computer programs]]. There are two general approaches to programming language implementation:<ref name="RantaBook">{{cite book |last1=Ranta |first1=Aarne |title=Implementing Programming Languages |date=9 May 2012 |publisher=College Publications |isbn=9781848900646 |pages=16–18 |url=http://www.cse.chalmers.se/edu/year/2012/course/DAT150/lectures/plt-book.pdf#page=16 |access-date=22 March 2020}}</ref>
In [[computer programming]], a '''programming language implementation''' is a system for executing [[computer programs]]. There are two general approaches to programming language implementation:<ref name="RantaBook">{{cite book |last1=Ranta |first1=Aarne |title=Implementing Programming Languages |date=February 6, 2012 |publisher=College Publications |isbn=9781848900646 |pages=16–18 |url=http://www.cse.chalmers.se/edu/year/2012/course/DAT150/lectures/plt-book.pdf#page=16 |access-date=22 March 2020 |url-status=live |archive-url=https://web.archive.org/web/20201107224313/http://www.cse.chalmers.se/edu/year/2012/course/DAT150/lectures/plt-book.pdf#page=16 |archive-date= Nov 7, 2020 }}</ref>
*''[[Interpreter (computing)|Interpretation]]:'' The program is read as input by an interpreter, which performs the actions written in the program.<ref name="LanguageGreg">{{cite web |last1=Baker |first1=Greg |title=Language Implementations |url=https://www2.cs.sfu.ca/~ggbaker/prog-langs/content/lang-implement.html |website=Computing Science - Simon Fraser University |access-date=22 March 2020}}</ref>
*''[[Interpreter (computing)|Interpretation]]:'' The program is read as input by an interpreter, which performs the actions written in the program.<ref name="LanguageGreg">{{cite web |last1=Baker |first1=Greg |title=Language Implementations |url=https://www2.cs.sfu.ca/~ggbaker/prog-langs/content/lang-implement.html |website=Computing Science - Simon Fraser University |access-date=22 March 2020 |url-status=live |archive-url= https://web.archive.org/web/20190308033517/http://www.cs.sfu.ca/~ggbaker/prog-langs/content/lang-implement.html |archive-date= Mar 8, 2019 }}</ref>
*''[[Compiler|Compilation]]:'' The program is read by a compiler, which translates it into some other language, such as [[bytecode]] or [[machine code]]. The translated code may either be directly [[Execution (computing)|executed]] by hardware, or serve as input to another interpreter or another compiler.<ref name="LanguageGreg" />
*''[[Compiler|Compilation]]:'' The program is read by a compiler, which translates it into some other language, such as [[bytecode]] or [[machine code]]. The translated code may either be directly [[Execution (computing)|executed]] by hardware or serve as input to another interpreter or another compiler.<ref name="LanguageGreg" />


==Interpreter==
==Interpreter==
{{Main|Interpreter (computing)}}
{{Main|Interpreter (computing)}}
An [[interpreter (computing)|interpreter]] is composed of two parts: a [[parser]] and an [[evaluator]]. After a program is read as input by an interpreter, it is processed by the parser. The parser breaks the program into [[Syntax (programming languages)|language components]] to form a [[parse tree]]. The evaluator then uses the parse tree to execute the program.<ref name="IntroToComputing">{{cite book |last1=Evans |first1=David |title=Introduction to Computing |date=19 August 2011 |location=University of Virginia |page=211 |url=https://computingbook.org/FullText.pdf#page=221 |access-date=22 March 2020}}</ref>
An [[interpreter (computing)|interpreter]] is composed of two parts: a [[parser]] and an [[evaluator]]. After a program is read as input by an interpreter, it is processed by the parser. The parser breaks the program into [[Syntax (programming languages)|language components]] to form a [[parse tree]]. The evaluator then uses the parse tree to execute the program.<ref name="IntroToComputing">{{cite book |last1=Evans |first1=David |title=Introduction to Computing |date=19 August 2011 |publisher=University of Virginia |page=211 |url=https://computingbook.org/FullText.pdf#page=221 |access-date=22 March 2020}}</ref>


===Virtual machine===
===Virtual machine===
A [[virtual machine]] is a special type of interpreter that interprets bytecode.<ref name="LanguageGreg" /> Bytecode is a [[Cross-platform software|portable]] low-level code similar to machine code, though it is generally executed on a virtual machine instead of a physical machine.<ref name="MakeUseOfVM">{{cite web |last1=Sridhar |first1=Jay |title=Why the Java Virtual Machine Helps Your Code Run Better |url=https://www.makeuseof.com/tag/why-java-virtual-machine-code-run-better/ |website=MakeUseOf |access-date=22 March 2020}}</ref> To improve their efficiencies, many programming languages such as [[Java (programming language)|Java]],<ref name="MakeUseOfVM" /> [[Python (programming language)|Python]],<ref name="PythonBytecode">{{cite web |last1=Bennett |first1=James |title=An introduction to Python bytecode |url=https://opensource.com/article/18/4/introduction-python-bytecode |website=Opensource.com |access-date=22 March 2020}}</ref> and [[C Sharp (programming language)|C#]]<ref name="CLR">{{cite web |last1=Ali |first1=Mirza Farrukh |title=Common Language Runtime(CLR) DotNet |url=https://medium.com/@mirzafarrukh13/common-language-runtime-dotnet-83e0218edcae |website=Medium |access-date=22 March 2020}}</ref> are compiled to bytecode before being interpreted.
A [[virtual machine]] is a special type of interpreter that interprets bytecode.<ref name="LanguageGreg" /> Bytecode is a [[Cross-platform software|portable]] low-level code similar to machine code, though it is generally executed on a virtual machine instead of a physical machine.<ref name="MakeUseOfVM">{{cite web |last1=Sridhar |first1=Jay |title=Why the Java Virtual Machine Helps Your Code Run Better |url=https://www.makeuseof.com/tag/why-java-virtual-machine-code-run-better/ |date=Aug 29, 2017 |website=MakeUseOf |access-date=22 March 2020}}</ref> To improve their efficiencies, many programming languages such as [[Java (programming language)|Java]],<ref name="MakeUseOfVM" /> [[Python (programming language)|Python]],<ref name="PythonBytecode">{{cite web |last1=Bennett |first1=James |title=An introduction to Python bytecode |url=https://opensource.com/article/18/4/introduction-python-bytecode |date=April 23, 2018 |website=Opensource.com |access-date=22 March 2020}}</ref> and [[C Sharp (programming language)|C#]]<ref name="CLR">{{cite web |last1=Ali |first1=Mirza Farrukh |title=Common Language Runtime(CLR) DotNet |url=https://medium.com/@mirzafarrukh13/common-language-runtime-dotnet-83e0218edcae |date=Oct 12, 2017 |website=Medium |access-date=22 March 2020}}</ref> are compiled to bytecode before being interpreted.


===Just-in-time compiler===
===Just-in-time compiler===

Latest revision as of 13:46, 6 October 2024

In computer programming, a programming language implementation is a system for executing computer programs. There are two general approaches to programming language implementation:[1]

  • Interpretation: The program is read as input by an interpreter, which performs the actions written in the program.[2]
  • Compilation: The program is read by a compiler, which translates it into some other language, such as bytecode or machine code. The translated code may either be directly executed by hardware or serve as input to another interpreter or another compiler.[2]

Interpreter

[edit]

An interpreter is composed of two parts: a parser and an evaluator. After a program is read as input by an interpreter, it is processed by the parser. The parser breaks the program into language components to form a parse tree. The evaluator then uses the parse tree to execute the program.[3]

Virtual machine

[edit]

A virtual machine is a special type of interpreter that interprets bytecode.[2] Bytecode is a portable low-level code similar to machine code, though it is generally executed on a virtual machine instead of a physical machine.[4] To improve their efficiencies, many programming languages such as Java,[4] Python,[5] and C#[6] are compiled to bytecode before being interpreted.

Just-in-time compiler

[edit]

Some virtual machines include a just-in-time (JIT) compiler to improve the efficiency of bytecode execution. While the bytecode is being executed by the virtual machine, if the JIT compiler determines that a portion of the bytecode will be used repeatedly, it compiles that particular portion to machine code. The JIT compiler then stores the machine code in memory so that it can be used by the virtual machine. JIT compilers try to strike a balance between longer compilation time and faster execution time.[2]

Compiler

[edit]

A compiler translates a program written in one language into another language. Most compilers are organized into three stages: a front end, an optimizer, and a back end. The front end is responsible for understanding the program. It makes sure the program is valid and transforms it into an intermediate representation, a data structure used by the compiler to represent the program. The optimizer improves the intermediate representation to increase the speed or reduce the size of the executable which is ultimately produced by the compiler. The back end converts the optimized intermediate representation into the output language of the compiler.[7]

If a compiler of a given high level language produces another high level language, it is called a transpiler. Transpilers can be used to extend existing languages or to simplify compiler development by exploiting portable and well-optimized implementations of other languages (such as C).[2]

Many combinations of interpretation and compilation are possible, and many modern programming language implementations include elements of both. For example, the Smalltalk programming language is conventionally implemented by compilation into bytecode, which is then either interpreted or compiled by a virtual machine. Since Smalltalk bytecode is run on a virtual machine, it is portable across different hardware platforms.[8]

Multiple implementations

[edit]

Programming languages can have multiple implementations. Different implementations can be written in different languages and can use different methods to compile or interpret code. For example, implementations of Python include:[9]

References

[edit]
  1. ^ Ranta, Aarne (February 6, 2012). Implementing Programming Languages (PDF). College Publications. pp. 16–18. ISBN 9781848900646. Archived (PDF) from the original on Nov 7, 2020. Retrieved 22 March 2020.
  2. ^ a b c d e Baker, Greg. "Language Implementations". Computing Science - Simon Fraser University. Archived from the original on Mar 8, 2019. Retrieved 22 March 2020.
  3. ^ Evans, David (19 August 2011). Introduction to Computing (PDF). University of Virginia. p. 211. Retrieved 22 March 2020.
  4. ^ a b Sridhar, Jay (Aug 29, 2017). "Why the Java Virtual Machine Helps Your Code Run Better". MakeUseOf. Retrieved 22 March 2020.
  5. ^ Bennett, James (April 23, 2018). "An introduction to Python bytecode". Opensource.com. Retrieved 22 March 2020.
  6. ^ Ali, Mirza Farrukh (Oct 12, 2017). "Common Language Runtime(CLR) DotNet". Medium. Retrieved 22 March 2020.
  7. ^ Cooper, Keith; Torczon, Linda (7 February 2011). Engineering a Compiler (2nd ed.). Morgan Kaufmann. pp. 6-9. ISBN 9780120884780.
  8. ^ Lewis, Simon (May 11, 1995). The Art and Science of Smalltalk (PDF). Prentice Hall. pp. 20–21. ISBN 9780133713459. Retrieved 23 March 2020.
  9. ^ "Alternative Python Implementations". Python.org. Retrieved 23 March 2020.
[edit]