In
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, a programming language implementation is a system for executing
computer programs
A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
. There are two general approaches to programming language implementation:
*''
Interpretation:'' The program is read as input by an interpreter, which performs the actions written in the program.
*''
Compilation:'' The program is read by a compiler, which translates it into some other language, such as
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normal ...
or
machine code
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
. The translated code may either be directly
executed by hardware or serve as input to another interpreter or another compiler.
Interpreter
An
interpreter is composed of two parts: a
parser
Parsing, syntax analysis, or syntactic analysis is a process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar by breaking it into parts. The term '' ...
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
A parse tree or parsing tree (also known as a derivation tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar. The term ''parse tree'' itself is use ...
. The evaluator then uses the parse tree to execute the program.
Virtual machine
A
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
is a special type of interpreter that interprets bytecode.
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.
To improve their efficiencies, many programming languages such as
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
Python,
and
C# are compiled to bytecode before being interpreted.
Just-in-time compiler
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
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
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.
Compiler
A
compiler
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 primaril ...
translates programs 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 a program is valid and transforms it into an
intermediate representation
An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
, 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
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
which is ultimately produced by the compiler. The back end converts the optimized intermediate representation into the output language of the compiler.
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).
Many combinations of interpretation and compilation are possible, and many modern programming language implementations include elements of both. For example, the
Smalltalk
Smalltalk is a purely object oriented programming language (OOP) that was originally created in the 1970s for educational use, specifically for constructionist learning, but later found use in business. It was created at Xerox PARC by Learni ...
programming language is conventionally implemented by compilation into
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normal ...
, which is then either interpreted or compiled by a
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
. Since Smalltalk bytecode is run on a virtual machine, it is portable across different hardware platforms.
Multiple implementations
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:
*
CPython
CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language.
CPython can be defined as both an interpreter and a comp ...
, the
reference implementation
In the software development process, a reference implementation (or, less frequently, sample implementation or model implementation) is a program that implements all requirements from a corresponding specification. The reference implementation ...
of Python
*
IronPython, an implementation targeting the
.NET Framework (written in
C#)
*
Jython, an implementation targeting the
Java virtual machine
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
*
PyPy, an implementation designed for speed (written in RPython)
References
External links
*
{{DEFAULTSORT:Programming Language Implementation
Implementation
Implementation is the realization of an application, execution of a plan, idea, scientific modelling, model, design, specification, Standardization, standard, algorithm, policy, or the Management, administration or management of a process or Goal ...