<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
an	O
interpreter	B-Application
is	O
a	O
computer	B-Application
program	I-Application
that	O
directly	O
executes	B-General_Concept
instructions	O
written	O
in	O
a	O
programming	O
or	O
scripting	B-Language
language	I-Language
,	O
without	O
requiring	O
them	O
previously	O
to	O
have	O
been	O
compiled	B-Language
into	O
a	O
machine	B-Language
language	I-Language
program	O
.	O
</s>
<s>
An	O
interpreter	B-Application
generally	O
uses	O
one	O
of	O
the	O
following	O
strategies	O
for	O
program	O
execution	O
:	O
</s>
<s>
Parse	B-Language
the	O
source	O
code	O
and	O
perform	O
its	O
behavior	O
directly	O
;	O
</s>
<s>
Translate	B-Application
source	O
code	O
into	O
some	O
efficient	O
intermediate	B-Application
representation	I-Application
or	O
object	B-Language
code	I-Language
and	O
immediately	O
execute	B-General_Concept
that	O
;	O
</s>
<s>
Explicitly	O
execute	B-General_Concept
stored	O
precompiled	O
bytecode	O
made	O
by	O
a	O
compiler	B-Language
and	O
matched	O
with	O
the	O
interpreter	B-Application
Virtual	B-Architecture
Machine	I-Architecture
.	O
</s>
<s>
Early	O
versions	O
of	O
Lisp	B-Language
programming	I-Language
language	I-Language
and	O
minicomputer	B-Language
and	I-Language
microcomputer	I-Language
BASIC	I-Language
dialects	I-Language
would	O
be	O
examples	O
of	O
the	O
first	O
type	O
.	O
</s>
<s>
Perl	B-Language
,	O
Raku	B-Application
,	O
Python	B-Language
,	O
MATLAB	B-Language
,	O
and	O
Ruby	B-Language
are	O
examples	O
of	O
the	O
second	O
,	O
while	O
UCSD	B-Language
Pascal	I-Language
is	O
an	O
example	O
of	O
the	O
third	O
type	O
.	O
</s>
<s>
Source	O
programs	O
are	O
compiled	B-Language
ahead	O
of	O
time	O
and	O
stored	O
as	O
machine	O
independent	O
code	O
,	O
which	O
is	O
then	O
linked	B-Application
at	O
run-time	B-Library
and	O
executed	O
by	O
an	O
interpreter	B-Application
and/or	O
compiler	B-Language
(	O
for	O
JIT	O
systems	O
)	O
.	O
</s>
<s>
Some	O
systems	O
,	O
such	O
as	O
Smalltalk	B-Application
and	O
contemporary	O
versions	O
of	O
BASIC	B-Language
and	O
Java	B-Device
may	O
also	O
combine	O
two	O
and	O
three	O
.	O
</s>
<s>
Interpreters	B-Application
of	O
various	O
types	O
have	O
also	O
been	O
constructed	O
for	O
many	O
languages	O
traditionally	O
associated	O
with	O
compilation	B-Language
,	O
such	O
as	O
Algol	B-Language
,	O
Fortran	B-Application
,	O
Cobol	B-Application
,	O
C	B-Language
and	O
C++	B-Language
.	O
</s>
<s>
While	O
interpretation	O
and	O
compilation	B-Language
are	O
the	O
two	O
main	O
means	O
by	O
which	O
programming	O
languages	O
are	O
implemented	O
,	O
they	O
are	O
not	O
mutually	O
exclusive	O
,	O
as	O
most	O
interpreting	O
systems	O
also	O
perform	O
some	O
translation	O
work	O
,	O
just	O
like	O
compilers	B-Language
.	O
</s>
<s>
The	O
terms	O
"	O
interpreted	B-Application
language	I-Application
"	O
or	O
"	O
compiled	B-Language
language	I-Language
"	O
signify	O
that	O
the	O
canonical	O
implementation	O
of	O
that	O
language	O
is	O
an	O
interpreter	B-Application
or	O
a	O
compiler	B-Language
,	O
respectively	O
.	O
</s>
<s>
A	O
high-level	B-Language
language	I-Language
is	O
ideally	O
an	O
abstraction	B-Application
independent	O
of	O
particular	O
implementations	O
.	O
</s>
<s>
Interpreters	B-Application
were	O
used	O
as	O
early	O
as	O
1952	O
to	O
ease	O
programming	O
within	O
the	O
limitations	O
of	O
computers	O
at	O
the	O
time	O
(	O
e.g.	O
</s>
<s>
Interpreters	B-Application
were	O
also	O
used	O
to	O
translate	B-Application
between	O
low-level	O
machine	B-Language
languages	I-Language
,	O
allowing	O
code	O
to	O
be	O
written	O
for	O
machines	O
that	O
were	O
still	O
under	O
construction	O
and	O
tested	O
on	O
computers	O
that	O
already	O
existed	O
.	O
</s>
<s>
The	O
first	O
interpreted	O
high-level	B-Language
language	I-Language
was	O
Lisp	B-Language
.	O
</s>
<s>
Lisp	B-Language
was	O
first	O
implemented	O
in	O
1958	O
by	O
Steve	O
Russell	O
on	O
an	O
IBM	B-Device
704	I-Device
computer	O
.	O
</s>
<s>
Russell	O
had	O
read	O
John	O
McCarthy	O
's	O
paper	O
,	O
and	O
realized	O
(	O
to	O
McCarthy	O
's	O
surprise	O
)	O
that	O
the	O
Lisp	B-Language
eval	O
function	O
could	O
be	O
implemented	O
in	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
The	O
result	O
was	O
a	O
working	O
Lisp	B-Language
interpreter	B-Application
which	O
could	O
be	O
used	O
to	O
run	O
Lisp	B-Language
programs	O
,	O
or	O
more	O
properly	O
,	O
"	O
evaluate	O
Lisp	B-Language
expressions	O
"	O
.	O
</s>
<s>
An	O
interpreter	B-Application
usually	O
consists	O
of	O
a	O
set	O
of	O
known	O
commands	B-Application
it	O
can	O
execute	B-General_Concept
,	O
and	O
a	O
list	O
of	O
these	O
commands	B-Application
in	O
the	O
order	O
a	O
programmer	O
wishes	O
to	O
execute	B-General_Concept
them	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
interpreter	B-Application
might	O
read	O
ADD	O
Books	O
,	O
5	O
and	O
interpret	O
it	O
as	O
a	O
request	O
to	O
add	O
five	O
to	O
the	O
Books	O
variable	O
.	O
</s>
<s>
Interpreters	B-Application
have	O
a	O
wide	O
variety	O
of	O
instructions	O
which	O
are	O
specialized	O
to	O
perform	O
different	O
tasks	O
,	O
but	O
you	O
will	O
commonly	O
find	O
interpreter	B-Application
instructions	O
for	O
basic	B-Language
mathematical	O
operations	O
,	O
branching	B-General_Concept
,	O
and	O
memory	B-General_Concept
management	I-General_Concept
,	O
making	O
most	O
interpreters	B-Application
Turing	B-Algorithm
complete	I-Algorithm
.	O
</s>
<s>
Many	O
interpreters	B-Application
are	O
also	O
closely	O
integrated	O
with	O
a	O
garbage	B-General_Concept
collector	I-General_Concept
and	O
debugger	B-Application
.	O
</s>
<s>
Programs	O
written	O
in	O
a	O
high-level	B-Language
language	I-Language
are	O
either	O
directly	O
executed	O
by	O
some	O
kind	O
of	O
interpreter	B-Application
or	O
converted	O
into	O
machine	B-Language
code	I-Language
by	O
a	O
compiler	B-Language
(	O
and	O
assembler	B-Application
and	O
linker	B-Application
)	O
for	O
the	O
CPU	B-Device
to	O
execute	B-General_Concept
.	O
</s>
<s>
While	O
compilers	B-Language
(	O
and	O
assemblers	B-Application
)	O
generally	O
produce	O
machine	B-Language
code	I-Language
directly	O
executable	O
by	O
computer	O
hardware	O
,	O
they	O
can	O
often	O
(	O
optionally	O
)	O
produce	O
an	O
intermediate	B-Application
form	I-Application
called	O
object	B-Language
code	I-Language
.	O
</s>
<s>
This	O
is	O
basically	O
the	O
same	O
machine	O
specific	O
code	O
but	O
augmented	O
with	O
a	O
symbol	B-Application
table	I-Application
with	O
names	O
and	O
tags	O
to	O
make	O
executable	O
blocks	O
(	O
or	O
modules	O
)	O
identifiable	O
and	O
relocatable	O
.	O
</s>
<s>
Compiled	B-Language
programs	O
will	O
typically	O
use	O
building	O
blocks	O
(	O
functions	O
)	O
kept	O
in	O
a	O
library	O
of	O
such	O
object	B-Language
code	I-Language
modules	O
.	O
</s>
<s>
A	O
linker	B-Application
is	O
used	O
to	O
combine	O
(	O
pre-made	O
)	O
library	O
files	O
with	O
the	O
object	O
file(s )	O
of	O
the	O
application	O
to	O
form	O
a	O
single	O
executable	O
file	O
.	O
</s>
<s>
A	O
simple	O
interpreter	B-Application
written	O
in	O
a	O
low-level	O
language	O
(	O
e.g.	O
</s>
<s>
assembly	B-Language
)	O
may	O
have	O
similar	O
machine	B-Language
code	I-Language
blocks	O
implementing	O
functions	O
of	O
the	O
high-level	B-Language
language	I-Language
stored	O
,	O
and	O
executed	O
when	O
a	O
function	O
's	O
entry	O
in	O
a	O
look	O
up	O
table	O
points	O
to	O
that	O
code	O
.	O
</s>
<s>
However	O
,	O
an	O
interpreter	B-Application
written	O
in	O
a	O
high-level	B-Language
language	I-Language
typically	O
uses	O
another	O
approach	O
,	O
such	O
as	O
generating	O
and	O
then	O
walking	O
a	O
parse	B-Language
tree	O
,	O
or	O
by	O
generating	O
and	O
executing	O
intermediate	O
software-defined	O
instructions	O
,	O
or	O
both	O
.	O
</s>
<s>
Thus	O
,	O
both	O
compilers	B-Language
and	O
interpreters	B-Application
generally	O
turn	O
source	O
code	O
(	O
text	O
files	O
)	O
into	O
tokens	O
,	O
both	O
may	O
(	O
or	O
may	O
not	O
)	O
generate	O
a	O
parse	B-Language
tree	O
,	O
and	O
both	O
may	O
generate	O
immediate	O
instructions	O
(	O
for	O
a	O
stack	B-Application
machine	I-Application
,	O
quadruple	B-Application
code	I-Application
,	O
or	O
by	O
other	O
means	O
)	O
.	O
</s>
<s>
The	O
basic	B-Language
difference	O
is	O
that	O
a	O
compiler	B-Language
system	O
,	O
including	O
a	O
(	O
built	O
in	O
or	O
separate	O
)	O
linker	B-Application
,	O
generates	O
a	O
stand-alone	O
machine	B-Language
code	I-Language
program	O
,	O
while	O
an	O
interpreter	B-Application
system	O
instead	O
performs	O
the	O
actions	O
described	O
by	O
the	O
high-level	O
program	O
.	O
</s>
<s>
A	O
compiler	B-Language
can	O
thus	O
make	O
almost	O
all	O
the	O
conversions	O
from	O
source	O
code	O
semantics	O
to	O
the	O
machine	O
level	O
once	O
and	O
for	O
all	O
(	O
i.e.	O
</s>
<s>
until	O
the	O
program	O
has	O
to	O
be	O
changed	O
)	O
while	O
an	O
interpreter	B-Application
has	O
to	O
do	O
some	O
of	O
this	O
conversion	O
work	O
every	O
time	O
a	O
statement	O
or	O
function	O
is	O
executed	O
.	O
</s>
<s>
However	O
,	O
in	O
an	O
efficient	O
interpreter	B-Application
,	O
much	O
of	O
the	O
translation	O
work	O
(	O
including	O
analysis	O
of	O
types	O
,	O
and	O
similar	O
)	O
is	O
factored	O
out	O
and	O
done	O
only	O
the	O
first	O
time	O
a	O
program	O
,	O
module	O
,	O
function	O
,	O
or	O
even	O
statement	O
,	O
is	O
run	O
,	O
thus	O
quite	O
akin	O
to	O
how	O
a	O
compiler	B-Language
works	O
.	O
</s>
<s>
However	O
,	O
a	O
compiled	B-Language
program	O
still	O
runs	O
much	O
faster	O
,	O
under	O
most	O
circumstances	O
,	O
in	O
part	O
because	O
compilers	B-Language
are	O
designed	O
to	O
optimize	O
code	O
,	O
and	O
may	O
be	O
given	O
ample	O
time	O
for	O
this	O
.	O
</s>
<s>
This	O
is	O
especially	O
true	O
for	O
simpler	O
high-level	B-Language
languages	I-Language
without	O
(	O
many	O
)	O
dynamic	O
data	O
structures	O
,	O
checks	O
,	O
or	O
type	O
checking	O
.	O
</s>
<s>
In	O
traditional	O
compilation	B-Language
,	O
the	O
executable	O
output	O
of	O
the	O
linkers	B-Application
(	O
.exe	O
files	O
or	O
.dll	O
files	O
or	O
a	O
library	O
,	O
see	O
picture	O
)	O
is	O
typically	O
relocatable	O
when	O
run	O
under	O
a	O
general	O
operating	O
system	O
,	O
much	O
like	O
the	O
object	B-Language
code	I-Language
modules	O
are	O
but	O
with	O
the	O
difference	O
that	O
this	O
relocation	O
is	O
done	O
dynamically	O
at	O
run	B-Library
time	I-Library
,	O
i.e.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
compiled	B-Language
and	O
linked	B-Application
programs	O
for	O
small	O
embedded	B-Architecture
systems	I-Architecture
are	O
typically	O
statically	O
allocated	O
,	O
often	O
hard	O
coded	O
in	O
a	O
NOR	O
flash	O
memory	O
,	O
as	O
there	O
is	O
often	O
no	O
secondary	O
storage	O
and	O
no	O
operating	O
system	O
in	O
this	O
sense	O
.	O
</s>
<s>
Historically	O
,	O
most	O
interpreter	B-Application
systems	O
have	O
had	O
a	O
self-contained	O
editor	O
built	O
in	O
.	O
</s>
<s>
This	O
is	O
becoming	O
more	O
common	O
also	O
for	O
compilers	B-Language
(	O
then	O
often	O
called	O
an	O
IDE	B-Application
)	O
,	O
although	O
some	O
programmers	O
prefer	O
to	O
use	O
an	O
editor	O
of	O
their	O
choice	O
and	O
run	O
the	O
compiler	B-Language
,	O
linker	B-Application
and	O
other	O
tools	O
manually	O
.	O
</s>
<s>
Historically	O
,	O
compilers	B-Language
predate	O
interpreters	B-Application
because	O
hardware	O
at	O
that	O
time	O
could	O
not	O
support	O
both	O
the	O
interpreter	B-Application
and	O
interpreted	O
code	O
and	O
the	O
typical	O
batch	O
environment	O
of	O
the	O
time	O
limited	O
the	O
advantages	O
of	O
interpretation	O
.	O
</s>
<s>
When	O
using	O
a	O
compiler	B-Language
,	O
each	O
time	O
a	O
change	O
is	O
made	O
to	O
the	O
source	O
code	O
,	O
they	O
must	O
wait	O
for	O
the	O
compiler	B-Language
to	O
translate	B-Application
the	O
altered	O
source	O
files	O
and	O
link	B-Application
all	O
of	O
the	O
binary	O
code	O
files	O
together	O
before	O
the	O
program	O
can	O
be	O
executed	O
.	O
</s>
<s>
By	O
contrast	O
,	O
a	O
programmer	O
using	O
an	O
interpreter	B-Application
does	O
a	O
lot	O
less	O
waiting	O
,	O
as	O
the	O
interpreter	B-Application
usually	O
just	O
needs	O
to	O
translate	B-Application
the	O
code	O
being	O
worked	O
on	O
to	O
an	O
intermediate	B-Application
representation	I-Application
(	O
or	O
not	O
translate	B-Application
it	O
at	O
all	O
)	O
,	O
thus	O
requiring	O
much	O
less	O
time	O
before	O
the	O
changes	O
can	O
be	O
tested	O
.	O
</s>
<s>
Compiled	B-Language
code	O
is	O
generally	O
less	O
readily	O
debugged	O
as	O
editing	O
,	O
compiling	B-Language
,	O
and	O
linking	B-Application
are	O
sequential	O
processes	O
that	O
have	O
to	O
be	O
conducted	O
in	O
the	O
proper	O
sequence	O
with	O
a	O
proper	O
set	O
of	O
commands	B-Application
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
many	O
compilers	B-Language
also	O
have	O
an	O
executive	O
aid	O
,	O
known	O
as	O
a	O
Makefile	B-Application
and	O
program	O
.	O
</s>
<s>
The	O
Makefile	B-Application
lists	O
compiler	B-Language
and	O
linker	B-Application
command	O
lines	O
and	O
program	O
source	O
code	O
files	O
,	O
but	O
might	O
take	O
a	O
simple	O
command	O
line	O
menu	O
input	O
(	O
e.g.	O
</s>
<s>
"	O
Make	O
3	O
"	O
)	O
which	O
selects	O
the	O
third	O
group	O
(	O
set	O
)	O
of	O
instructions	O
then	O
issues	O
the	O
commands	B-Application
to	O
the	O
compiler	B-Language
,	O
and	O
linker	B-Application
feeding	O
the	O
specified	O
source	O
code	O
files	O
.	O
</s>
<s>
A	O
compiler	B-Language
converts	O
source	O
code	O
into	O
binary	O
instruction	O
for	O
a	O
specific	O
processor	O
's	O
architecture	O
,	O
thus	O
making	O
it	O
less	O
portable	B-Architecture
.	O
</s>
<s>
A	O
cross	B-Application
compiler	I-Application
can	O
generate	O
binary	O
code	O
for	O
the	O
user	O
machine	O
even	O
if	O
it	O
has	O
a	O
different	O
processor	O
than	O
the	O
machine	O
where	O
the	O
code	O
is	O
compiled	B-Language
.	O
</s>
<s>
However	O
,	O
the	O
portability	B-Architecture
of	O
interpreted	O
source	O
code	O
is	O
dependent	O
on	O
the	O
target	O
machine	O
actually	O
having	O
a	O
suitable	O
interpreter	B-Application
.	O
</s>
<s>
If	O
the	O
interpreter	B-Application
needs	O
to	O
be	O
supplied	O
along	O
with	O
the	O
source	O
,	O
the	O
overall	O
installation	O
process	O
is	O
more	O
complex	O
than	O
delivery	O
of	O
a	O
monolithic	O
executable	O
since	O
the	O
interpreter	B-Application
itself	O
is	O
part	O
of	O
what	O
need	O
to	O
be	O
installed	O
.	O
</s>
<s>
Delivery	O
of	O
intermediate	O
code	O
,	O
such	O
as	O
bytecode	O
,	O
has	O
a	O
similar	O
effect	O
to	O
obfuscation	O
,	O
but	O
bytecode	O
could	O
be	O
decoded	O
with	O
a	O
decompiler	B-Application
or	O
disassembler	O
.	O
</s>
<s>
The	O
main	O
disadvantage	O
of	O
interpreters	B-Application
is	O
that	O
an	O
interpreted	O
program	O
typically	O
runs	O
slower	O
than	O
if	O
it	O
had	O
been	O
compiled	B-Language
.	O
</s>
<s>
It	O
generally	O
takes	O
longer	O
to	O
run	O
a	O
program	O
under	O
an	O
interpreter	B-Application
than	O
to	O
run	O
the	O
compiled	B-Language
code	O
but	O
it	O
can	O
take	O
less	O
time	O
to	O
interpret	O
it	O
than	O
the	O
total	O
time	O
required	O
to	O
compile	B-Language
and	O
run	O
it	O
.	O
</s>
<s>
This	O
is	O
especially	O
important	O
when	O
prototyping	O
and	O
testing	O
code	O
when	O
an	O
edit-interpret-debug	O
cycle	O
can	O
often	O
be	O
much	O
shorter	O
than	O
an	O
edit-compile-run-debug	O
cycle	O
.	O
</s>
<s>
Interpreting	O
code	O
is	O
slower	O
than	O
running	O
the	O
compiled	B-Language
code	O
because	O
the	O
interpreter	B-Application
must	O
analyze	O
each	O
statement	O
in	O
the	O
program	O
each	O
time	O
it	O
is	O
executed	O
and	O
then	O
perform	O
the	O
desired	O
action	O
,	O
whereas	O
the	O
compiled	B-Language
code	O
just	O
performs	O
the	O
action	O
within	O
a	O
fixed	O
context	O
determined	O
by	O
the	O
compilation	B-Language
.	O
</s>
<s>
This	O
run-time	B-Library
analysis	O
is	O
known	O
as	O
"	O
interpretive	O
overhead	O
"	O
.	O
</s>
<s>
Access	O
to	O
variables	O
is	O
also	O
slower	O
in	O
an	O
interpreter	B-Application
because	O
the	O
mapping	O
of	O
identifiers	O
to	O
storage	O
locations	O
must	O
be	O
done	O
repeatedly	O
at	O
run-time	B-Library
rather	O
than	O
at	O
compile	B-Application
time	I-Application
.	O
</s>
<s>
There	O
are	O
various	O
compromises	O
between	O
the	O
development	O
speed	O
when	O
using	O
an	O
interpreter	B-Application
and	O
the	O
execution	O
speed	O
when	O
using	O
a	O
compiler	B-Language
.	O
</s>
<s>
Some	O
systems	O
(	O
such	O
as	O
some	O
Lisps	B-Language
)	O
allow	O
interpreted	O
and	O
compiled	B-Language
code	O
to	O
call	O
each	O
other	O
and	O
to	O
share	O
variables	O
.	O
</s>
<s>
This	O
means	O
that	O
once	O
a	O
routine	O
has	O
been	O
tested	O
and	O
debugged	O
under	O
the	O
interpreter	B-Application
it	O
can	O
be	O
compiled	B-Language
and	O
thus	O
benefit	O
from	O
faster	O
execution	O
while	O
other	O
routines	O
are	O
being	O
developed	O
.	O
</s>
<s>
Many	O
interpreters	B-Application
do	O
not	O
execute	B-General_Concept
the	O
source	O
code	O
as	O
it	O
stands	O
but	O
convert	O
it	O
into	O
some	O
more	O
compact	O
internal	O
form	O
.	O
</s>
<s>
Many	O
BASIC	B-Language
interpreters	I-Language
replace	O
keywords	O
with	O
single	O
byte	B-Application
tokens	O
which	O
can	O
be	O
used	O
to	O
find	O
the	O
instruction	O
in	O
a	O
jump	O
table	O
.	O
</s>
<s>
A	O
few	O
interpreters	B-Application
,	O
such	O
as	O
the	O
PBASIC	B-Language
interpreter	B-Application
,	O
achieve	O
even	O
higher	O
levels	O
of	O
program	O
compaction	O
by	O
using	O
a	O
bit-oriented	O
rather	O
than	O
a	O
byte-oriented	O
program	O
memory	O
structure	O
,	O
where	O
commands	B-Application
tokens	O
occupy	O
perhaps	O
5	O
bits	O
,	O
nominally	O
"	O
16-bit	O
"	O
constants	O
are	O
stored	O
in	O
a	O
variable-length	B-Algorithm
code	I-Algorithm
requiring	O
3	O
,	O
6	O
,	O
10	O
,	O
or	O
18	O
bits	O
,	O
and	O
address	O
operands	O
include	O
a	O
"	O
bit	O
offset	O
"	O
.	O
</s>
<s>
Many	O
BASIC	B-Language
interpreters	I-Language
can	O
store	O
and	O
read	O
back	O
their	O
own	O
tokenized	O
internal	O
representation	O
.	O
</s>
<s>
An	O
interpreter	B-Application
might	O
well	O
use	O
the	O
same	O
lexical	B-Application
analyzer	I-Application
and	O
parser	B-Language
as	O
the	O
compiler	B-Language
and	O
then	O
interpret	O
the	O
resulting	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
Example	O
data	O
type	O
definitions	O
for	O
the	O
latter	O
,	O
and	O
a	O
toy	O
interpreter	B-Application
for	O
syntax	O
trees	O
obtained	O
from	O
C	B-Language
expressions	O
are	O
shown	O
in	O
the	O
box	O
.	O
</s>
<s>
Interpretation	O
cannot	O
be	O
used	O
as	O
the	O
sole	O
method	O
of	O
execution	O
:	O
even	O
though	O
an	O
interpreter	B-Application
can	O
itself	O
be	O
interpreted	O
and	O
so	O
on	O
,	O
a	O
directly	O
executed	O
program	O
is	O
needed	O
somewhere	O
at	O
the	O
bottom	O
of	O
the	O
stack	O
because	O
the	O
code	O
being	O
interpreted	O
is	O
not	O
,	O
by	O
definition	O
,	O
the	O
same	O
as	O
the	O
machine	B-Language
code	I-Language
that	O
the	O
CPU	B-Device
can	O
execute	B-General_Concept
.	O
</s>
<s>
There	O
is	O
a	O
spectrum	O
of	O
possibilities	O
between	O
interpreting	O
and	O
compiling	B-Language
,	O
depending	O
on	O
the	O
amount	O
of	O
analysis	O
performed	O
before	O
the	O
program	O
is	O
executed	O
.	O
</s>
<s>
For	O
example	O
,	O
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
compiled	B-Language
to	O
bytecode	O
,	O
which	O
is	O
a	O
highly	O
compressed	O
and	O
optimized	O
representation	O
of	O
the	O
Lisp	B-Language
source	O
,	O
but	O
is	O
not	O
machine	B-Language
code	I-Language
(	O
and	O
therefore	O
not	O
tied	O
to	O
any	O
particular	O
hardware	O
)	O
.	O
</s>
<s>
This	O
"	O
compiled	B-Language
"	O
code	O
is	O
then	O
interpreted	O
by	O
a	O
bytecode	O
interpreter	B-Application
(	O
itself	O
written	O
in	O
C	B-Language
)	O
.	O
</s>
<s>
The	O
compiled	B-Language
code	O
in	O
this	O
case	O
is	O
machine	B-Language
code	I-Language
for	O
a	O
virtual	B-Architecture
machine	I-Architecture
,	O
which	O
is	O
implemented	O
not	O
in	O
hardware	O
,	O
but	O
in	O
the	O
bytecode	O
interpreter	B-Application
.	O
</s>
<s>
Such	O
compiling	B-Language
interpreters	B-Application
are	O
sometimes	O
also	O
called	O
compreters	O
.	O
</s>
<s>
In	O
a	O
bytecode	O
interpreter	B-Application
each	O
instruction	O
starts	O
with	O
a	O
byte	B-Application
,	O
and	O
therefore	O
bytecode	O
interpreters	B-Application
have	O
up	O
to	O
256	O
instructions	O
,	O
although	O
not	O
all	O
may	O
be	O
used	O
.	O
</s>
<s>
Some	O
bytecodes	O
may	O
take	O
multiple	O
bytes	B-Application
,	O
and	O
may	O
be	O
arbitrarily	O
complicated	O
.	O
</s>
<s>
Control	B-Application
tables	I-Application
-	O
that	O
do	O
not	O
necessarily	O
ever	O
need	O
to	O
pass	O
through	O
a	O
compiling	B-Language
phase	O
-	O
dictate	O
appropriate	O
algorithmic	O
control	O
flow	O
via	O
customized	O
interpreters	B-Application
in	O
similar	O
fashion	O
to	O
bytecode	O
interpreters	B-Application
.	O
</s>
<s>
Threaded	O
code	B-Application
interpreters	I-Application
are	O
similar	O
to	O
bytecode	O
interpreters	B-Application
but	O
instead	O
of	O
bytes	B-Application
they	O
use	O
pointers	O
.	O
</s>
<s>
The	O
threaded	O
code	B-Application
interpreter	I-Application
either	O
loops	O
fetching	O
instructions	O
and	O
calling	O
the	O
functions	O
they	O
point	O
to	O
,	O
or	O
fetches	O
the	O
first	O
instruction	O
and	O
jumps	O
to	O
it	O
,	O
and	O
every	O
instruction	O
sequence	O
ends	O
with	O
a	O
fetch	O
and	O
jump	O
to	O
the	O
next	O
instruction	O
.	O
</s>
<s>
The	O
classic	O
example	O
of	O
threaded	O
code	O
is	O
the	O
Forth	B-Application
code	O
used	O
in	O
Open	B-Architecture
Firmware	I-Architecture
systems	O
:	O
the	O
source	O
language	O
is	O
compiled	B-Language
into	O
"	O
F	O
code	O
"	O
(	O
a	O
bytecode	O
)	O
,	O
which	O
is	O
then	O
interpreted	O
by	O
a	O
virtual	B-Architecture
machine	I-Architecture
.	O
</s>
<s>
In	O
the	O
spectrum	O
between	O
interpreting	O
and	O
compiling	B-Language
,	O
another	O
approach	O
is	O
to	O
transform	O
the	O
source	O
code	O
into	O
an	O
optimized	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
(	O
AST	O
)	O
,	O
then	O
execute	B-General_Concept
the	O
program	O
following	O
this	O
tree	O
structure	O
,	O
or	O
use	O
it	O
to	O
generate	O
native	B-Language
code	I-Language
just-in-time	O
.	O
</s>
<s>
In	O
this	O
approach	O
,	O
each	O
sentence	O
needs	O
to	O
be	O
parsed	B-Language
just	O
once	O
.	O
</s>
<s>
Thus	O
,	O
using	O
AST	O
has	O
been	O
proposed	O
as	O
a	O
better	O
intermediate	O
format	O
for	O
just-in-time	O
compilers	B-Language
than	O
bytecode	O
.	O
</s>
<s>
Also	O
,	O
it	O
allows	O
the	O
system	O
to	O
perform	O
better	O
analysis	O
during	O
runtime	B-Library
.	O
</s>
<s>
However	O
,	O
for	O
interpreters	B-Application
,	O
an	O
AST	O
causes	O
more	O
overhead	O
than	O
a	O
bytecode	O
interpreter	B-Application
,	O
because	O
of	O
nodes	O
related	O
to	O
syntax	O
performing	O
no	O
useful	O
work	O
,	O
of	O
a	O
less	O
sequential	O
representation	O
(	O
requiring	O
traversal	O
of	O
more	O
pointers	O
)	O
and	O
of	O
overhead	O
visiting	O
the	O
tree	O
.	O
</s>
<s>
Further	O
blurring	O
the	O
distinction	O
between	O
interpreters	B-Application
,	O
bytecode	O
interpreters	B-Application
and	O
compilation	B-Language
is	O
just-in-time	O
(	O
JIT	O
)	O
compilation	B-Language
,	O
a	O
technique	O
in	O
which	O
the	O
intermediate	B-Application
representation	I-Application
is	O
compiled	B-Language
to	O
native	O
machine	B-Language
code	I-Language
at	B-Library
runtime	I-Library
.	O
</s>
<s>
This	O
confers	O
the	O
efficiency	O
of	O
running	O
native	B-Language
code	I-Language
,	O
at	O
the	O
cost	O
of	O
startup	O
time	O
and	O
increased	O
memory	O
use	O
when	O
the	O
bytecode	O
or	O
AST	O
is	O
first	O
compiled	B-Language
.	O
</s>
<s>
The	O
earliest	O
published	O
JIT	O
compiler	B-Language
is	O
generally	O
attributed	O
to	O
work	O
on	O
LISP	B-Language
by	O
John	O
McCarthy	O
in	O
1960	O
.	O
</s>
<s>
Adaptive	O
optimization	O
is	O
a	O
complementary	O
technique	O
in	O
which	O
the	O
interpreter	B-Application
profiles	O
the	O
running	O
program	O
and	O
compiles	B-Language
its	O
most	O
frequently	O
executed	O
parts	O
into	O
native	B-Language
code	I-Language
.	O
</s>
<s>
The	O
latter	O
technique	O
is	O
a	O
few	O
decades	O
old	O
,	O
appearing	O
in	O
languages	O
such	O
as	O
Smalltalk	B-Application
in	O
the	O
1980s	O
.	O
</s>
<s>
Just-in-time	O
compilation	B-Language
has	O
gained	O
mainstream	O
attention	O
amongst	O
language	O
implementers	O
in	O
recent	O
years	O
,	O
with	O
Java	B-Device
,	O
the	O
.NET	B-Application
Framework	I-Application
,	O
most	O
modern	O
JavaScript	B-Language
implementations	O
,	O
and	O
Matlab	B-Language
now	O
including	O
JIT	O
compilers	B-Language
.	O
</s>
<s>
Making	O
the	O
distinction	O
between	O
compilers	B-Language
and	O
interpreters	B-Application
yet	O
again	O
even	O
more	O
vague	O
is	O
a	O
special	O
interpreter	B-Application
design	O
known	O
as	O
a	O
template	O
interpreter	B-Application
.	O
</s>
<s>
Rather	O
than	O
implement	O
the	O
execution	O
of	O
code	O
by	O
virtue	O
of	O
a	O
large	O
switch	O
statement	O
containing	O
every	O
possible	O
bytecode	O
,	O
while	O
operating	O
on	O
a	O
software	O
stack	O
or	O
a	O
tree	O
walk	O
,	O
a	O
template	O
interpreter	B-Application
maintains	O
a	O
large	O
array	O
of	O
bytecode	O
(	O
or	O
any	O
efficient	O
intermediate	B-Application
representation	I-Application
)	O
mapped	O
directly	O
to	O
corresponding	O
native	O
machine	B-Language
instructions	I-Language
that	O
can	O
be	O
executed	O
on	O
the	O
host	O
hardware	O
as	O
key	O
value	O
pairs	O
(	O
or	O
in	O
more	O
efficient	O
designs	O
,	O
direct	O
addresses	O
to	O
the	O
native	O
instructions	O
)	O
,	O
known	O
as	O
a	O
"	O
Template	O
"	O
.	O
</s>
<s>
When	O
the	O
particular	O
code	O
segment	O
is	O
executed	O
the	O
interpreter	B-Application
simply	O
loads	O
or	O
jumps	O
to	O
the	O
opcode	O
mapping	O
in	O
the	O
template	O
and	O
directly	O
runs	O
it	O
on	O
the	O
hardware	O
.	O
</s>
<s>
Due	O
to	O
its	O
design	O
,	O
the	O
template	O
interpreter	B-Application
very	O
strongly	O
resembles	O
a	O
just-in-time	O
compiler	B-Language
rather	O
than	O
a	O
traditional	O
interpreter	B-Application
,	O
however	O
it	O
is	O
technically	O
not	O
a	O
JIT	O
due	O
to	O
the	O
fact	O
that	O
it	O
merely	O
translates	O
code	O
from	O
the	O
language	O
into	O
native	O
calls	O
one	O
opcode	O
at	O
a	O
time	O
rather	O
than	O
creating	O
optimized	O
sequences	O
of	O
CPU	B-Device
executable	O
instructions	O
from	O
the	O
entire	O
code	O
segment	O
.	O
</s>
<s>
Due	O
to	O
the	O
interpreter	B-Application
's	O
simple	O
design	O
of	O
simply	O
passing	O
calls	O
directly	O
to	O
the	O
hardware	O
rather	O
than	O
implementing	O
them	O
directly	O
,	O
it	O
is	O
much	O
faster	O
than	O
every	O
other	O
type	O
,	O
even	O
bytecode	O
interpreters	B-Application
,	O
and	O
to	O
an	O
extent	O
less	O
prone	O
to	O
bugs	B-Error_Name
,	O
but	O
as	O
a	O
tradeoff	O
is	O
more	O
difficult	O
to	O
maintain	O
due	O
to	O
the	O
interpreter	B-Application
having	O
to	O
support	O
translation	O
to	O
multiple	O
different	O
architectures	O
instead	O
of	O
a	O
platform	O
independent	O
virtual	O
machine/stack	O
.	O
</s>
<s>
To	O
date	O
,	O
the	O
only	O
template	O
interpreter	B-Application
implementations	O
of	O
widely	O
known	O
languages	O
to	O
exist	O
are	O
the	O
interpreter	B-Application
within	O
Java	B-Device
's	O
official	O
reference	O
implementation	O
,	O
the	O
Sun	O
HotSpot	O
Java	B-Device
Virtual	B-Architecture
Machine	I-Architecture
,	O
and	O
the	O
Ignition	O
Interpreter	B-Application
in	O
the	O
Google	O
V8	O
javascript	B-Language
execution	O
engine	O
.	O
</s>
<s>
A	O
self-interpreter	O
is	O
a	O
programming	O
language	O
interpreter	B-Application
written	O
in	O
a	O
programming	O
language	O
which	O
can	O
interpret	O
itself	O
;	O
an	O
example	O
is	O
a	O
BASIC	B-Language
interpreter	I-Language
written	O
in	O
BASIC	B-Language
.	O
</s>
<s>
Self-interpreters	O
are	O
related	O
to	O
self-hosting	O
compilers	B-Language
.	O
</s>
<s>
If	O
no	O
compiler	B-Language
exists	O
for	O
the	O
language	O
to	O
be	O
interpreted	O
,	O
creating	O
a	O
self-interpreter	O
requires	O
the	O
implementation	O
of	O
the	O
language	O
in	O
a	O
host	O
language	O
(	O
which	O
may	O
be	O
another	O
programming	O
language	O
or	O
assembler	B-Application
)	O
.	O
</s>
<s>
By	O
having	O
a	O
first	O
interpreter	B-Application
such	O
as	O
this	O
,	O
the	O
system	O
is	O
bootstrapped	B-Application
and	O
new	O
versions	O
of	O
the	O
interpreter	B-Application
can	O
be	O
developed	O
in	O
the	O
language	O
itself	O
.	O
</s>
<s>
It	O
was	O
in	O
this	O
way	O
that	O
Donald	O
Knuth	O
developed	O
the	O
TANGLE	O
interpreter	B-Application
for	O
the	O
language	O
WEB	O
of	O
the	O
industrial	O
standard	O
TeX	B-Application
typesetting	O
system	O
.	O
</s>
<s>
Defining	O
a	O
computer	O
language	O
is	O
usually	O
done	O
in	O
relation	O
to	O
an	O
abstract	O
machine	O
(	O
so-called	O
operational	O
semantics	O
)	O
or	O
as	O
a	O
mathematical	O
function	O
(	O
denotational	B-Application
semantics	I-Application
)	O
.	O
</s>
<s>
A	O
language	O
may	O
also	O
be	O
defined	O
by	O
an	O
interpreter	B-Application
in	O
which	O
the	O
semantics	O
of	O
the	O
host	O
language	O
is	O
given	O
.	O
</s>
<s>
The	O
definition	O
of	O
a	O
language	O
by	O
a	O
self-interpreter	O
is	O
not	O
well-founded	O
(	O
it	O
cannot	O
define	O
a	O
language	O
)	O
,	O
but	O
a	O
self-interpreter	O
tells	O
a	O
reader	O
about	O
the	O
expressiveness	O
and	O
elegance	O
of	O
a	O
language	O
.	O
</s>
<s>
It	O
also	O
enables	O
the	O
interpreter	B-Application
to	O
interpret	O
its	O
source	O
code	O
,	O
the	O
first	O
step	O
towards	O
reflective	O
interpreting	O
.	O
</s>
<s>
An	O
important	O
design	O
dimension	O
in	O
the	O
implementation	O
of	O
a	O
self-interpreter	O
is	O
whether	O
a	O
feature	O
of	O
the	O
interpreted	B-Application
language	I-Application
is	O
implemented	O
with	O
the	O
same	O
feature	O
in	O
the	O
interpreter	B-Application
's	O
host	O
language	O
.	O
</s>
<s>
An	O
example	O
is	O
whether	O
a	O
closure	B-Language
in	O
a	O
Lisp-like	O
language	O
is	O
implemented	O
using	O
closures	B-Language
in	O
the	O
interpreter	B-Application
language	O
or	O
implemented	O
"	O
manually	O
"	O
with	O
a	O
data	O
structure	O
explicitly	O
storing	O
the	O
environment	O
.	O
</s>
<s>
The	O
more	O
features	O
implemented	O
by	O
the	O
same	O
feature	O
in	O
the	O
host	O
language	O
,	O
the	O
less	O
control	O
the	O
programmer	O
of	O
the	O
interpreter	B-Application
has	O
;	O
a	O
different	O
behavior	O
for	O
dealing	O
with	O
number	O
overflows	O
cannot	O
be	O
realized	O
if	O
the	O
arithmetic	O
operations	O
are	O
delegated	O
to	O
corresponding	O
operations	O
in	O
the	O
host	O
language	O
.	O
</s>
<s>
Some	O
languages	O
such	O
as	O
Lisp	B-Language
and	O
Prolog	B-Language
have	O
elegant	O
self-interpreters	O
.	O
</s>
<s>
Much	O
research	O
on	O
self-interpreters	O
(	O
particularly	O
reflective	O
interpreters	B-Application
)	O
has	O
been	O
conducted	O
in	O
the	O
Scheme	B-Language
programming	I-Language
language	I-Language
,	O
a	O
dialect	O
of	O
Lisp	B-Language
.	O
</s>
<s>
In	O
general	O
,	O
however	O
,	O
any	O
Turing-complete	B-Algorithm
language	O
allows	O
writing	O
of	O
its	O
own	O
interpreter	B-Application
.	O
</s>
<s>
Lisp	B-Language
is	O
such	O
a	O
language	O
,	O
because	O
Lisp	B-Language
programs	O
are	O
lists	O
of	O
symbols	O
and	O
other	O
lists	O
.	O
</s>
<s>
A	O
sub-domain	O
of	O
metaprogramming	B-Application
is	O
the	O
writing	O
of	O
domain-specific	B-Language
languages	I-Language
(	O
DSLs	O
)	O
.	O
</s>
<s>
Clive	O
Gifford	O
introduced	O
a	O
measure	O
quality	O
of	O
self-interpreter	O
(	O
the	O
eigenratio	O
)	O
,	O
the	O
limit	O
of	O
the	O
ratio	O
between	O
computer	O
time	O
spent	O
running	O
a	O
stack	O
of	O
N	O
self-interpreters	O
and	O
time	O
spent	O
to	O
run	O
a	O
stack	O
of	O
self-interpreters	O
as	O
N	O
goes	O
to	O
infinity	O
.	O
</s>
<s>
The	O
book	O
Structure	B-Language
and	I-Language
Interpretation	I-Language
of	I-Language
Computer	I-Language
Programs	I-Language
presents	O
examples	O
of	O
meta-circular	B-Application
interpretation	I-Application
for	O
Scheme	O
and	O
its	O
dialects	O
.	O
</s>
<s>
Other	O
examples	O
of	O
languages	O
with	O
a	O
self-interpreter	O
are	O
Forth	B-Application
and	O
Pascal	B-Application
.	O
</s>
<s>
Microcode	O
is	O
a	O
very	O
commonly	O
used	O
technique	O
"	O
that	O
imposes	O
an	O
interpreter	B-Application
between	O
the	O
hardware	O
and	O
the	O
architectural	O
level	O
of	O
a	O
computer	O
"	O
.	O
</s>
<s>
As	O
such	O
,	O
the	O
microcode	O
is	O
a	O
layer	O
of	O
hardware-level	O
instructions	O
that	O
implement	O
higher-level	O
machine	B-Language
code	I-Language
instructions	O
or	O
internal	O
state	B-Architecture
machine	I-Architecture
sequencing	O
in	O
many	O
digital	B-General_Concept
processing	I-General_Concept
elements	O
.	O
</s>
<s>
Microcode	O
is	O
used	O
in	O
general-purpose	O
central	B-General_Concept
processing	I-General_Concept
units	I-General_Concept
,	O
as	O
well	O
as	O
in	O
more	O
specialized	O
processors	O
such	O
as	O
microcontrollers	B-Architecture
,	O
digital	B-Architecture
signal	I-Architecture
processors	I-Architecture
,	O
channel	B-Device
controllers	I-Device
,	O
disk	B-General_Concept
controllers	I-General_Concept
,	O
network	B-Protocol
interface	I-Protocol
controllers	I-Protocol
,	O
network	B-General_Concept
processors	I-General_Concept
,	O
graphics	B-Architecture
processing	I-Architecture
units	I-Architecture
,	O
and	O
in	O
other	O
hardware	O
.	O
</s>
<s>
Microcode	O
typically	O
resides	O
in	O
special	O
high-speed	O
memory	O
and	O
translates	O
machine	B-Language
instructions	I-Language
,	O
state	B-Architecture
machine	I-Architecture
data	O
or	O
other	O
input	O
into	O
sequences	O
of	O
detailed	O
circuit-level	O
operations	O
.	O
</s>
<s>
It	O
separates	O
the	O
machine	B-Language
instructions	I-Language
from	O
the	O
underlying	O
electronics	O
so	O
that	O
instructions	O
can	O
be	O
designed	O
and	O
altered	O
more	O
freely	O
.	O
</s>
<s>
More	O
extensive	O
microcoding	O
allows	O
small	O
and	O
simple	O
microarchitectures	B-General_Concept
to	O
emulate	B-Application
more	O
powerful	O
architectures	O
with	O
wider	O
word	O
length	O
,	O
more	O
execution	B-General_Concept
units	I-General_Concept
and	O
so	O
on	O
,	O
which	O
is	O
a	O
relatively	O
simple	O
way	O
to	O
achieve	O
software	O
compatibility	O
between	O
different	O
products	O
in	O
a	O
processor	O
family	O
.	O
</s>
<s>
Even	O
a	O
non	O
microcoding	O
computer	O
processor	O
itself	O
can	O
be	O
considered	O
to	O
be	O
a	O
parsing	B-Language
immediate	O
execution	O
interpreter	B-Application
that	O
is	O
written	O
in	O
a	O
general	O
purpose	O
hardware	O
description	O
language	O
such	O
as	O
VHDL	B-Language
to	O
create	O
a	O
system	O
that	O
parses	B-Language
the	O
machine	B-Language
code	I-Language
instructions	O
and	O
immediately	O
executes	B-General_Concept
them	O
.	O
</s>
<s>
Interpreters	B-Application
are	O
frequently	O
used	O
to	O
execute	B-General_Concept
command	B-Language
languages	I-Language
,	O
and	O
glue	O
languages	O
since	O
each	O
operator	O
executed	O
in	O
command	B-Language
language	I-Language
is	O
usually	O
an	O
invocation	O
of	O
a	O
complex	O
routine	O
such	O
as	O
an	O
editor	O
or	O
compiler	B-Language
.	O
</s>
<s>
Self-modifying	B-Application
code	I-Application
can	O
easily	O
be	O
implemented	O
in	O
an	O
interpreted	B-Application
language	I-Application
.	O
</s>
<s>
This	O
relates	O
to	O
the	O
origins	O
of	O
interpretation	O
in	O
Lisp	B-Language
and	O
artificial	B-Application
intelligence	I-Application
research	I-Application
.	O
</s>
<s>
Virtualization	B-General_Concept
.	O
</s>
<s>
Machine	B-Language
code	I-Language
intended	O
for	O
a	O
hardware	O
architecture	O
can	O
be	O
run	O
using	O
a	O
virtual	B-Architecture
machine	I-Architecture
.	O
</s>
<s>
Sandboxing	O
:	O
While	O
some	O
types	O
of	O
sandboxes	O
rely	O
on	O
operating	O
system	O
protections	O
,	O
an	O
interpreter	B-Application
or	O
virtual	B-Architecture
machine	I-Architecture
is	O
often	O
used	O
.	O
</s>
<s>
This	O
may	O
seem	O
pointless	O
,	O
except	O
that	O
sandboxes	O
are	O
not	O
compelled	O
to	O
actually	O
execute	B-General_Concept
all	O
the	O
instructions	O
the	O
source	O
code	O
it	O
is	O
processing	O
.	O
</s>
<s>
In	O
particular	O
,	O
it	O
can	O
refuse	O
to	O
execute	B-General_Concept
code	O
that	O
violates	O
any	O
security	O
constraints	O
it	O
is	O
operating	O
under	O
.	O
</s>
<s>
Emulators	B-Application
for	O
running	O
computer	O
software	O
written	O
for	O
obsolete	O
and	O
unavailable	O
hardware	O
on	O
more	O
modern	O
equipment	O
.	O
</s>
