<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
bootstrapping	B-Application
is	O
the	O
technique	O
for	O
producing	O
a	O
self-compiling	O
compiler	B-Language
–	O
that	O
is	O
,	O
a	O
compiler	B-Language
(	O
or	O
assembler	B-Language
)	O
written	O
in	O
the	O
source	O
programming	O
language	O
that	O
it	O
intends	O
to	O
compile	B-Language
.	O
</s>
<s>
An	O
initial	O
core	O
version	O
of	O
the	O
compiler	B-Language
(	O
the	O
bootstrap	B-Application
compiler	I-Application
)	O
is	O
generated	O
in	O
a	O
different	O
language	O
(	O
which	O
could	O
be	O
assembly	B-Language
language	I-Language
)	O
;	O
successive	O
expanded	O
versions	O
of	O
the	O
compiler	B-Language
are	O
developed	O
using	O
this	O
minimal	O
subset	O
of	O
the	O
language	O
.	O
</s>
<s>
The	O
problem	O
of	O
compiling	B-Language
a	O
self-compiling	O
compiler	B-Language
has	O
been	O
called	O
the	O
chicken-or-egg	O
problem	O
in	O
compiler	B-Language
design	O
,	O
and	O
bootstrapping	B-Application
is	O
a	O
solution	O
to	O
this	O
problem	O
.	O
</s>
<s>
Bootstrapping	B-Application
is	O
a	O
fairly	O
common	O
practice	O
when	O
creating	O
a	O
programming	O
language	O
.	O
</s>
<s>
Many	O
compilers	B-Language
for	O
many	O
programming	O
languages	O
are	O
bootstrapped	O
,	O
including	O
compilers	B-Language
for	O
BASIC	O
,	O
ALGOL	B-Language
,	O
C	B-Language
,	O
C#	B-Application
,	O
D	B-Application
,	O
Pascal	B-Application
,	O
PL/I	B-Language
,	O
Haskell	B-Language
,	O
Modula-2	B-Language
,	O
Oberon	B-Language
,	O
OCaml	B-Language
,	O
Common	B-Language
Lisp	I-Language
,	O
Scheme	B-Language
,	O
Go	B-Application
,	O
Java	B-Language
,	O
Elixir	B-Language
,	O
Rust	B-Application
,	O
Python	B-Language
,	O
Scala	B-Application
,	O
Nim	B-Application
,	O
Eiffel	B-Language
,	O
TypeScript	B-Language
,	O
Vala	B-Language
,	O
Zig	B-Application
and	O
more	O
.	O
</s>
<s>
Stage	O
0	O
:	O
preparing	O
an	O
environment	O
for	O
the	O
bootstrap	B-Application
compiler	I-Application
to	O
work	O
with	O
.	O
</s>
<s>
This	O
is	O
where	O
the	O
source	O
language	O
and	O
output	O
language	O
of	O
the	O
bootstrap	B-Application
compiler	I-Application
are	O
chosen	O
.	O
</s>
<s>
In	O
the	O
case	O
of	O
a	O
"	O
bare	O
machine	O
"	O
(	O
one	O
where	O
no	O
compiler	B-Language
for	O
any	O
language	O
exist	O
)	O
the	O
source	O
and	O
output	O
are	O
written	O
as	O
binary	O
machine	B-Language
code	I-Language
,	O
or	O
may	O
be	O
created	O
by	O
cross	B-Application
compiling	I-Application
on	O
some	O
other	O
machine	O
than	O
the	O
target	O
.	O
</s>
<s>
Otherwise	O
,	O
the	O
bootstrap	B-Application
compiler	I-Application
is	O
to	O
be	O
written	O
in	O
one	O
of	O
the	O
programming	O
languages	O
which	O
does	O
exist	O
on	O
the	O
target	O
machine	O
,	O
and	O
that	O
compiler	B-Language
will	O
generate	O
something	O
which	O
can	O
execute	O
on	O
the	O
target	O
,	O
including	O
a	O
high-level	B-Language
programming	I-Language
language	I-Language
,	O
an	O
assembly	B-Language
language	I-Language
,	O
an	O
object	B-Application
file	I-Application
,	O
or	O
even	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
Stage	O
1	O
:	O
the	O
bootstrap	B-Application
compiler	I-Application
is	O
produced	O
.	O
</s>
<s>
This	O
compiler	B-Language
is	O
enough	O
to	O
translate	O
its	O
own	O
source	O
into	O
a	O
program	O
which	O
can	O
be	O
executed	O
on	O
the	O
target	O
machine	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
all	O
further	O
development	O
is	O
done	O
using	O
the	O
language	O
defined	O
by	O
the	O
bootstrap	B-Application
compiler	I-Application
,	O
and	O
stage	O
2	O
begins	O
.	O
</s>
<s>
Stage	O
2	O
:	O
a	O
full	O
compiler	B-Language
is	O
produced	O
by	O
the	O
bootstrap	B-Application
compiler	I-Application
.	O
</s>
<s>
compiler	B-Language
for	O
version	O
X	O
of	O
the	O
language	O
will	O
be	O
able	O
to	O
compile	B-Language
features	O
from	O
version	O
X+1	O
,	O
but	O
that	O
compiler	B-Language
does	O
not	O
actually	O
use	O
those	O
features	O
.	O
</s>
<s>
Once	O
this	O
compiler	B-Language
has	O
been	O
tested	O
and	O
can	O
compile	B-Language
itself	O
,	O
now	O
version	O
X+1	O
features	O
may	O
be	O
used	O
by	O
subsequent	O
releases	O
of	O
the	O
compiler	B-Language
.	O
</s>
<s>
Stage	O
3	O
:	O
a	O
full	O
compiler	B-Language
is	O
produced	O
by	O
the	O
stage	O
2	O
full	O
compiler	B-Language
.	O
</s>
<s>
If	O
more	O
features	O
are	O
to	O
be	O
added	O
,	O
work	O
resumes	O
at	O
stage	O
2	O
,	O
with	O
the	O
current	O
stage	O
3	O
full	O
compiler	B-Language
replacing	O
the	O
bootstrap	B-Application
compiler	I-Application
.	O
</s>
<s>
The	O
full	O
compiler	B-Language
is	O
built	O
twice	O
in	O
order	O
to	O
compare	O
the	O
outputs	O
of	O
the	O
two	O
stages	O
.	O
</s>
<s>
If	O
they	O
are	O
different	O
,	O
either	O
the	O
bootstrap	O
or	O
the	O
full	O
compiler	B-Language
contains	O
a	O
bug	O
.	O
</s>
<s>
Bootstrapping	B-Application
a	O
compiler	B-Language
has	O
the	O
following	O
advantages	O
:	O
</s>
<s>
It	O
is	O
a	O
non-trivial	O
test	O
of	O
the	O
language	O
being	O
compiled	B-Language
,	O
and	O
as	O
such	O
is	O
a	O
form	O
of	O
dogfooding	O
.	O
</s>
<s>
Compiler	B-Language
developers	O
and	O
bug	O
reporters	O
only	O
need	O
to	O
know	O
the	O
language	O
being	O
compiled	B-Language
.	O
</s>
<s>
Compiler	B-Language
development	O
can	O
be	O
performed	O
in	O
the	O
higher-level	O
language	O
being	O
compiled	B-Language
.	O
</s>
<s>
Improvements	O
to	O
the	O
compiler	B-Language
's	O
back-end	O
improve	O
not	O
only	O
general-purpose	O
programs	O
but	O
also	O
the	O
compiler	B-Language
itself	O
.	O
</s>
<s>
Note	O
that	O
some	O
of	O
these	O
points	O
assume	O
that	O
the	O
language	O
runtime	B-Device
is	O
also	O
written	O
in	O
the	O
same	O
language	O
.	O
</s>
<s>
If	O
one	O
needs	O
to	O
compile	B-Language
a	O
compiler	B-Language
for	O
language	O
X	O
written	O
in	O
language	O
X	O
,	O
there	O
is	O
the	O
issue	O
of	O
how	O
the	O
first	O
compiler	B-Language
can	O
be	O
compiled	B-Language
.	O
</s>
<s>
Implementing	O
an	O
interpreter	B-Application
or	O
compiler	B-Language
for	O
language	O
X	O
in	O
language	O
Y	O
.	O
Niklaus	O
Wirth	O
reported	O
that	O
he	O
wrote	O
the	O
first	O
Pascal	B-Application
compiler	B-Language
in	O
Fortran	B-Application
.	O
</s>
<s>
Another	O
interpreter	B-Application
or	O
compiler	B-Language
for	O
X	O
has	O
already	O
been	O
written	O
in	O
another	O
language	O
Y	O
;	O
this	O
is	O
how	O
Scheme	B-Language
is	O
often	O
bootstrapped	O
.	O
</s>
<s>
Earlier	O
versions	O
of	O
the	O
compiler	B-Language
were	O
written	O
in	O
a	O
subset	O
of	O
X	O
for	O
which	O
there	O
existed	O
some	O
other	O
compiler	B-Language
;	O
this	O
is	O
how	O
some	O
supersets	O
of	O
Java	B-Language
,	O
Haskell	B-Language
,	O
and	O
the	O
initial	O
Free	B-Operating_System
Pascal	I-Operating_System
compiler	I-Operating_System
are	O
bootstrapped	O
.	O
</s>
<s>
A	O
compiler	B-Language
supporting	O
non-standard	O
language	O
extensions	O
or	O
optional	O
language	O
features	O
can	O
be	O
written	O
without	O
using	O
those	O
extensions	O
and	O
features	O
,	O
to	O
enable	O
it	O
being	O
compiled	B-Language
with	O
another	O
compiler	B-Language
supporting	O
the	O
same	O
base	O
language	O
but	O
a	O
different	O
set	O
of	O
extensions	O
and	O
features	O
.	O
</s>
<s>
The	O
main	O
parts	O
of	O
the	O
C++	B-Language
compiler	B-Language
clang	B-Application
were	O
written	O
in	O
a	O
subset	O
of	O
C++	B-Language
that	O
can	O
be	O
compiled	B-Language
by	O
both	O
g++	B-Application
and	O
Microsoft	B-Application
Visual	I-Application
C++	I-Application
.	O
</s>
<s>
Advanced	O
features	O
are	O
written	O
with	O
some	O
GCC	B-Application
extensions	O
.	O
</s>
<s>
The	O
compiler	B-Language
for	O
X	O
is	O
cross	B-Application
compiled	I-Application
from	O
another	O
architecture	O
where	O
there	O
exists	O
a	O
compiler	B-Language
for	O
X	O
;	O
this	O
is	O
how	O
compilers	B-Language
for	O
C	B-Language
are	O
usually	O
ported	O
to	O
other	O
platforms	O
.	O
</s>
<s>
Also	O
this	O
is	O
the	O
method	O
used	O
for	O
Free	B-Operating_System
Pascal	I-Operating_System
after	O
the	O
initial	O
bootstrap	O
.	O
</s>
<s>
Writing	O
the	O
compiler	B-Language
in	O
X	O
;	O
then	O
hand-compiling	O
it	O
from	O
source	O
(	O
most	O
likely	O
in	O
a	O
non-optimized	O
way	O
)	O
and	O
running	O
that	O
on	O
the	O
code	O
to	O
get	O
an	O
optimized	O
compiler	B-Language
.	O
</s>
<s>
Donald	O
Knuth	O
used	O
this	O
for	O
his	O
WEB	O
literate	B-Application
programming	I-Application
system	O
.	O
</s>
<s>
Methods	O
for	O
distributing	O
compilers	B-Language
in	O
source	O
code	O
include	O
providing	O
a	O
portable	O
bytecode	O
version	O
of	O
the	O
compiler	B-Language
,	O
so	O
as	O
to	O
bootstrap	O
the	O
process	O
of	O
compiling	B-Language
the	O
compiler	B-Language
with	O
itself	O
.	O
</s>
<s>
The	O
T-diagram	B-Application
is	O
a	O
notation	O
used	O
to	O
explain	O
these	O
compiler	B-Language
bootstrap	O
techniques	O
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
the	O
most	O
convenient	O
way	O
to	O
get	O
a	O
complicated	O
compiler	B-Language
running	O
on	O
a	O
system	O
that	O
has	O
little	O
or	O
no	O
software	O
on	O
it	O
involves	O
a	O
series	O
of	O
ever	O
more	O
sophisticated	O
assemblers	B-Language
and	O
compilers	B-Language
.	O
</s>
<s>
Assemblers	B-Language
were	O
the	O
first	O
language	O
tools	O
to	O
bootstrap	O
themselves	O
.	O
</s>
<s>
The	O
first	O
high-level	B-Language
language	I-Language
to	O
provide	O
such	O
a	O
bootstrap	O
was	O
NELIAC	B-Language
in	O
1958	O
.	O
</s>
<s>
The	O
first	O
widely	O
used	O
languages	O
to	O
do	O
so	O
were	O
Burroughs	B-Device
B5000	I-Device
Algol	B-Language
in	O
1961	O
and	O
LISP	B-Language
in	O
1962	O
.	O
</s>
<s>
Hart	O
and	O
Levin	O
wrote	O
a	O
LISP	B-Language
compiler	B-Language
in	O
LISP	B-Language
at	O
MIT	O
in	O
1962	O
,	O
testing	O
it	O
inside	O
an	O
existing	O
LISP	B-Language
interpreter	B-Application
.	O
</s>
<s>
Once	O
they	O
had	O
improved	O
the	O
compiler	B-Language
to	O
the	O
point	O
where	O
it	O
could	O
compile	B-Language
its	O
own	O
source	O
code	O
,	O
it	O
was	O
self-hosting	O
.	O
</s>
<s>
This	O
technique	O
is	O
only	O
possible	O
when	O
an	O
interpreter	B-Application
already	O
exists	O
for	O
the	O
very	O
same	O
language	O
that	O
is	O
to	O
be	O
compiled	B-Language
.	O
</s>
<s>
It	O
borrows	O
directly	O
from	O
the	O
notion	O
of	O
running	O
a	O
program	O
on	O
itself	O
as	O
input	O
,	O
which	O
is	O
also	O
used	O
in	O
various	O
proofs	O
in	O
theoretical	O
computer	B-General_Concept
science	I-General_Concept
,	O
such	O
as	O
the	O
variation	O
of	O
the	O
proof	O
that	O
the	O
halting	O
problem	O
is	O
undecidable	O
that	O
uses	O
Rice	O
's	O
Theorem	O
.	O
</s>
<s>
Due	O
to	O
security	O
concerns	O
regarding	O
the	O
Trusting	O
Trust	O
Attack	O
and	O
various	O
attacks	O
against	O
binary	O
trustworthiness	O
,	O
multiple	O
projects	O
are	O
working	O
to	O
reduce	O
the	O
effort	O
for	O
not	O
only	O
bootstrapping	B-Application
from	O
source	O
but	O
also	O
allowing	O
everyone	O
to	O
verify	O
that	O
source	O
and	O
executable	O
correspond	O
.	O
</s>
