interpreter (computing) program execution general concepts code translation compiler compiletime optimizing compiler intermediate representation ir execution runtime system runtime executable interpreter virtual machine types of code source code object code bytecode machine code microcode compilation strategies justintime jit tracing justintime aheadoftime aot transcompilation recompilation notable runtimes android runtime art common language runtime clr mono crt0 hhvm java virtual machine jvm objectivec v8 nodejs pypy zend engine notable compilers toolchains gnu compiler collection gcc llvm clang vte in computer science an interpreter is a computer program that directly executes ie performs instructions written in a programming or scripting language without requiring them previously to have been compiled into a machine language program an interpreter generally uses one of the following strategies for program execution parse the source code and perform its behavior directly translate source code into some efficient intermediate representation and immediately execute this explicitly execute stored precompiled code made by a compiler which is part of the interpreter system early versions of lisp programming language and dartmouth basic would be examples of the first type perl python matlab and ruby are examples of the second while ucsd pascal is an example of the third type source programs are compiled ahead of time and stored as machine independent code which is then linked at runtime and executed by an interpreter andor compiler for jit systems some systems such as smalltalk and contemporary versions of basic and java may also combine two and three interpreters of various types have also been constructed for many languages traditionally associated with compilation such as algol fortran cobol and cc while interpretation and compilation are the two main means by which programming languages are implemented they are not mutually exclusive as most interpreting systems also perform some translation work just like compilers the terms interpreted language or compiled language signify that the canonical implementation of that language is an interpreter or a compiler respectively a high level language is ideally an abstraction independent of particular implementations history interpreters were used as early as 1952 to ease programming within the limitations of computers at the time eg a shortage of program storage space or no native support for floating point numbers interpreters were also used to translate between lowlevel machine languages allowing code to be written for machines that were still under construction and tested on computers that already existed the result was a working lisp interpreter which could be used to run lisp programs or more properly evaluate lisp expressions compilers versus interpreters an illustration of the linking process object files and static libraries are assembled into a new library or executable programs written in a high level language are either directly executed by some kind of interpreter or converted into machine code by a compiler and assembler and linker for the cpu to execute while compilers and assemblers generally produce machine code directly executable by computer hardware they can often optionally produce an intermediate form called object code this is basically the same machine specific code but augmented with a symbol table with names and tags to make executable blocks or modules identifiable and relocatable compiled programs will typically use building blocks functions kept in a library of such object code modules a linker is used to combine premade library files with the object files of the application to form a single executable file the object files that are used to generate an executable file are thus often produced at different times and sometimes even by different languages capable of generating the same object format a simple interpreter written in a low level language eg assembly may have similar machine code blocks implementing functions of the high level language stored and executed when a functions entry in a look up table points to that code however an interpreter written in a high level language typically uses another approach such as generating and then walking a parse tree or by generating and executing intermediate softwaredefined instructions or both thus both compilers and interpreters generally turn source code text files into tokens both may or may not generate a parse tree and both may generate immediate instructions for a stack machine quadruple code or by other means the basic difference is that a compiler system including a built in or separate linker generates a standalone machine code program while an interpreter system instead performs the actions described by the high level program a compiler can thus make almost all the conversions from source code semantics to the machine level once and for all ie until the program has to be changed while an interpreter has to do some of this conversion work every time a statement or function is executed however in an efficient interpreter much of the translation work including analysis of types and similar is factored out and done only the first time a program module function or even statement is run thus quite akin to how a compiler works however a compiled program still runs much faster under most circumstances in part because compilers are designed to optimize code and may be given ample time for this this is especially true for simpler high level languages without many dynamic data structures checks or typechecks in traditional compilation the executable output of the linkers exe files or dll files or a library see picture is typically relocatable when run under a general operating system much like the object code modules are but with the difference that this relocation is done dynamically at run time ie when the program is loaded for execution on the other hand compiled and linked programs for small embedded systems are typically statically allocated often hard coded in a nor flash memory as there is often no secondary storage and no operating system in this sense historically most interpretersystems have had a selfcontained editor built in this is becoming more common also for compilers then often called an ide although some programmers prefer to use an editor of their choice and run the compiler linker and other tools manually historically compilers predate interpreters because hardware at that time could not support both the interpreter and interpreted code and the typical batch environment of the time limited the advantages of interpretation development cycle during the software development cycle programmers make frequent changes to source code when using a compiler each time a change is made to the source code they must wait for the compiler to translate the altered source files and link all of the binary code files together before the program can be executed the larger the program the longer the wait by contrast a programmer using an interpreter does a lot less waiting as the interpreter usually just needs to translate the code being worked on to an intermediate representation or not translate it at all thus requiring much less time before the changes can be tested effects are evident upon saving the source code and reloading the program compiled code is generally less readily debugged as editing compiling and linking are sequential processes that have to be conducted in the proper sequence with a proper set of commands for this reason many compilers also have an executive aid known as a make file and program the make file lists compiler and linker command lines and program source code files but might take a simple command line menu input eg make 3 which selects the third group set of instructions then issues the commands to the compiler and linker feeding the specified source code files distribution a compiler converts source code into binary instruction for a specific processors architecture thus making it less portable this conversion is made just once on the developers environment and after that the same binary can be distributed to the users machines where it can be executed without further translation a cross compiler can generate binary code for the user machine even if it has a different processor than the machine where the code is compiled an interpreted program can be distributed as source code it needs to be translated in each final machine which takes more time but makes the program distribution independent of the machines architecture however the portability of interpreted source code is dependent on the target machine actually having a suitable interpreter if the interpreter needs to be supplied along with the source the overall installation process is more complex than delivery of a monolithic executable since the interpreter itself is part of what need be installed the fact that interpreted code can easily be read and copied by humans can be of concern from the point of view of copyright however various systems of encryption and obfuscation exist delivery of intermediate code such as bytecode has a similar effect to obfuscation but bytecode could be decoded with a decompiler or disassembler efficiency the main disadvantage of interpreters is that an interpreted program typically runs slower than if it had been compiled the difference in speeds could be tiny or great often an order of magnitude and sometimes more it generally takes longer to run a program under an interpreter than to run the compiled code but it can take less time to interpret it than the total time required to compile and run it this is especially important when prototyping and testing code when an editinterpretdebug cycle can often be much shorter than an editcompilerundebug cycle interpreting code is slower than running the compiled code because the interpreter must analyze each statement in the program each time it is executed and then perform the desired action whereas the compiled code just performs the action within a fixed context determined by the compilation this runtime analysis is known as interpretive overhead access to variables is also slower in an interpreter because the mapping of identifiers to storage locations must be done repeatedly at runtime rather than at compile time there are various compromises between the development speed when using an interpreter and the execution speed when using a compiler some systems such as some lisps allow interpreted and compiled code to call each other and to share variables this means that once a routine has been tested and debugged under the interpreter it can be compiled and thus benefit from faster execution while other routines are being developed many interpreters do not execute the source code as it stands but convert it into some more compact internal form many basic interpreters replace keywords with single byte tokens which can be used to find the instruction in a jump table a few interpreters such as the pbasic interpreter achieve even higher levels of program compaction by using a bitoriented rather than a byteoriented program memory structure where commands tokens occupy perhaps 5 bits nominally 16bit constants are stored in a variablelength code requiring 3 6 10 or 18 bits and address operands include a bit offset many basic interpreters can store and read back their own tokenized internal representation toy c expression interpreter data types for abstract syntax tree enum kind kvar kconst ksum kdiff kmult kdiv kplus kminus knot struct variable int memory struct constant int value struct unaryoperation struct node right struct binaryoperation struct node left right struct node enum kind kind union expression struct variable variable struct constant constant struct binaryoperation binary struct unaryoperation unary e interpreter procedure int executeintexpressionconst struct node n int leftvalue rightvalue switch nkind case kvar return nevariablememory case kconst return neconstantvalue case ksum case kdiff case kmult case kdiv leftvalue executeintexpressionnebinaryleft rightvalue executeintexpressionnebinaryright switch nkind case ksum return leftvalue rightvalue case kdiff return leftvalue rightvalue case kmult return leftvalue rightvalue case kdiv if rightvalue 0 exceptiondivision by zero doesnt return return leftvalue rightvalue case kplus case kminus case knot rightvalue executeintexpressionneunaryright switch nkind case kplus return rightvalue case kminus return rightvalue case knot return rightvalue default exceptioninternal error illegal expression kind an interpreter might well use the same lexical analyzer and parser as the compiler and then interpret the resulting abstract syntax tree example data type definitions for the latter and a toy interpreter for syntax trees obtained from c expressions are shown in the box regression interpretation cannot be used as the sole method of execution even though an interpreter can itself be interpreted and so on a directly executed program is needed somewhere at the bottom of the stack because the code being interpreted is not by definition the same as the machine code that the cpu can execute variations bytecode interpreters bytecode there is a spectrum of possibilities between interpreting and compiling depending on the amount of analysis performed before the program is executed for example emacs lisp is compiled to bytecode which is a highly compressed and optimized representation of the lisp source but is not machine code and therefore not tied to any particular hardware this compiled code is then interpreted by a bytecode interpreter itself written in c the compiled code in this case is machine code for a virtual machine which is implemented not in hardware but in the bytecode interpreter such compiling interpreters are sometimes also called compreters in a bytecode interpreter each instruction starts with a byte and therefore bytecode interpreters have up to 256 instructions although not all may be used some bytecodes may take multiple bytes and may be arbitrarily complicated control tables that do not necessarily ever need to pass through a compiling phase dictate appropriate algorithmic control flow via customized interpreters in similar fashion to bytecode interpreters threaded code interpreters threaded code threaded code interpreters are similar to bytecode interpreters but instead of bytes they use pointers each instruction is a word that points to a function or an instruction sequence possibly followed by a parameter the threaded code interpreter either loops fetching instructions and calling the functions they point to or fetches the first instruction and jumps to it and every instruction sequence ends with a fetch and jump to the next instruction unlike bytecode there is no effective limit on the number of different instructions other than available memory and address space the classic example of threaded code is the forth code used in open firmware systems the source language is compiled into f code a bytecode which is then interpreted by a virtual machine abstract syntax tree interpreters abstract syntax tree in the spectrum between interpreting and compiling another approach is to transform the source code into an optimized abstract syntax tree ast then execute the program following this tree structure or use it to generate native code justintime thus using ast has been proposed as a better intermediate format for justintime compilers than bytecode also it allows the system to perform better analysis during runtime however for interpreters an ast causes more overhead than a bytecode interpreter because of nodes related to syntax performing no useful work of a less sequential representation requiring traversal of more pointers and of overhead visiting the tree justintime compilation justintime compilation further blurring the distinction between interpreters bytecode interpreters and compilation is justintime compilation jit a technique in which the intermediate representation is compiled to native machine code at runtime this confers the efficiency of running native code at the cost of startup time and increased memory use when the bytecode or ast is first compiled adaptive optimization is a complementary technique in which the interpreter profiles the running program and compiles its most frequently executed parts into native code both techniques are a few decades old appearing in languages such as smalltalk in the 1980s justintime compilation has gained mainstream attention amongst language implementers in recent years with java the net framework most modern javascript implementations and matlab now including jits selfinterpreter metacircular evaluator a selfinterpreter is a programming language interpreter written in a programming language which can interpret itself an example is a basic interpreter written in basic selfinterpreters are related to selfhosting compilers if no compiler exists for the language to be interpreted creating a selfinterpreter requires the implementation of the language in a host language which may be another programming language or assembler by having a first interpreter such as this the system is bootstrapped and new versions of the interpreter can be developed in the language itself it was in this way that donald knuth developed the tangle interpreter for the language web of the industrial standard tex typesetting system defining a computer language is usually done in relation to an abstract machine socalled operational semantics or as a mathematical function denotational semantics a language may also be defined by an interpreter in which the semantics of the host language is given the definition of a language by a selfinterpreter is not wellfounded it cannot define a language but a selfinterpreter tells a reader about the expressiveness and elegance of a language it also enables the interpreter to interpret its source code the first step towards reflective interpreting an important design dimension in the implementation of a selfinterpreter is whether a feature of the interpreted language is implemented with the same feature in the interpreters host language an example is whether a closure in a lisplike language is implemented using closures in the interpreter language or implemented manually with a data structure explicitly storing the environment the more features implemented by the same feature in the host language the less control the programmer of the interpreter has a different behavior for dealing with number overflows cannot be realized if the arithmetic operations are delegated to corresponding operations in the host language some languages have an elegant selfinterpreter such as lisp or prolog much research on selfinterpreters particularly reflective interpreters has been conducted in the scheme programming language a dialect of lisp in general however any turingcomplete language allows writing of its own interpreter lisp is such a language because lisp programs are lists of symbols and other lists xslt is such a language because xslt programs are written in xml a subdomain of metaprogramming is the writing of domainspecific languages dsls clive gifford introduced a measure quality of selfinterpreter the eigenratio the limit of the ratio between computer time spent running a stack of n selfinterpreters and time spent to run a stack of n 1 selfinterpreters as n goes to infinity this value does not depend on the program being run the book structure and interpretation of computer programs presents examples of metacircular interpretation for scheme and its dialects other examples of languages with a selfinterpreter are forth and pascal microcode microcode microcode is a very commonly used technique that imposes an interpreter between the hardware and the architectural level of a computer as such the microcode is a layer of hardwarelevel instructions that implement higherlevel machine code instructions or internal state machine sequencing in many digital processing elements microcode is used in generalpurpose central processing units as well as in more specialized processors such as microcontrollers digital signal processors channel controllers disk controllers network interface controllers network processors graphics processing units and in other hardware microcode typically resides in special highspeed memory and translates machine instructions state machine data or other input into sequences of detailed circuitlevel operations it separates the machine instructions from the underlying electronics so that instructions can be designed and altered more freely it also facilitates the building of complex multistep instructions while reducing the complexity of computer circuits writing microcode is often called microprogramming and the microcode in a particular processor implementation is sometimes called a microprogram more extensive microcoding allows small and simple microarchitectures to emulate more powerful architectures with wider word length more execution units and so on which is a relatively simple way to achieve software compatibility between different products in a processor family applications interpreters are frequently used to execute command languages and glue languages since each operator executed in command language is usually an invocation of a complex routine such as an editor or compiler selfmodifying code can easily be implemented in an interpreted language this relates to the origins of interpretation in lisp and artificial intelligence research virtualization machine code intended for a hardware architecture can be run using a virtual machine this is often used when the intended architecture is unavailable or among other uses for running multiple copies sandboxing while some types of sandboxes rely on operating system protections an interpreter or virtual machine is often used the actual hardware architecture and the originally intended hardware architecture may or may not be the same this may seem pointless except that sandboxes are not compelled to actually execute all the instructions the source code it is processing in particular it can refuse to execute code that violates any security constraints it is operating under emulators for running computer software written for obsolete and unavailable hardware on more modern equipment commandline interpreter compiled language dynamic compilation interpreted language metacircular evaluator partial evaluation homoiconicity notes and references ibm card interpreters page at columbia university theoretical foundations for practical totally functional programming chapter 7 especially doctoral dissertation tackling the problem of formalising what is an interpreter short animation explaining the key conceptual difference between interpreters and compilers vtemajor fields of computer sciencenote this template roughly follows the 2012 acm computing classification systemhardware printed circuit board peripheral integrated circuit very large scale integration systems on chip socs energy consumption green computing electronic design automation hardware acceleration computer systemsorganization computer architecture embedded system realtime computing dependability networks network architecture network protocol network components network scheduler network performance evaluation network service software organization interpreter middleware virtual machine operating system software quality software notationsand tools programming paradigm programming language compiler domainspecific language modeling language software framework integrated development environment software configuration management software library software repository software development software development process requirements analysis software design software construction software deployment software maintenance programming team opensource model theory of computation model of computation formal language automata theory computational complexity theory logic semantics algorithms algorithm design analysis of algorithms algorithmic efficiency randomized algorithm computational geometry mathematicsof computing discrete mathematics probability statistics mathematical software information theory mathematical analysis numerical analysis informationsystems database management system information storage systems enterprise information system social information systems geographic information system decision support system process control system multimedia information system data mining digital library computing platform digital marketing world wide web information retrieval security cryptography formal methods security services intrusion detection system hardware security network security information security application security humancomputerinteraction interaction design social computing ubiquitous computing visualization accessibility concurrency concurrent computing parallel computing distributed computing multithreading multiprocessing artificialintelligence natural language processing knowledge representation and reasoning computer vision automated planning and scheduling search methodology control method philosophy of artificial intelligence distributed artificial intelligence machine learning supervised learning unsupervised learning reinforcement learning multitask learning crossvalidation graphics animation rendering image manipulation graphics processing unit mixed reality virtual reality image compression solid modeling appliedcomputing ecommerce enterprise software computational mathematics computational physics computational chemistry computational biology computational social science computational engineering computational healthcare digital art electronic publishing cyberwarfare electronic voting video games word processing operations research educational technology document management book category portal wikiproject commons authority control bnf cb11938287v data gnd 41621293 lccn sh85067496 this article is based on material taken from the free online dictionary of computing prior to 1 november 2008 and incorporated under the relicensing terms of the gfdl version 13 or later 