<s>
Camlp4	B-Language
is	O
a	O
software	O
system	O
for	O
writing	O
extensible	O
parsers	B-Language
for	O
programming	O
languages	O
.	O
</s>
<s>
It	O
provides	O
a	O
set	O
of	O
OCaml	B-Language
libraries	O
that	O
are	O
used	O
to	O
define	O
grammars	O
as	O
well	O
as	O
loadable	O
syntax	O
extensions	O
of	O
such	O
grammars	O
.	O
</s>
<s>
Camlp4	B-Language
stands	O
for	O
Caml	B-Language
Preprocessor	B-General_Concept
and	O
Pretty-Printer	B-Application
and	O
one	O
of	O
its	O
most	O
important	O
applications	O
was	O
the	O
definition	O
of	O
domain-specific	O
extensions	O
of	O
the	O
syntax	O
of	O
OCaml	B-Language
.	O
</s>
<s>
Camlp4	B-Language
was	O
part	O
of	O
the	O
official	O
OCaml	B-Language
distribution	O
which	O
is	O
developed	O
at	O
the	O
INRIA	O
.	O
</s>
<s>
OCaml	B-Language
version	O
3.10.0	O
,	O
released	O
in	O
May	O
2007	O
,	O
introduced	O
a	O
significantly	O
modified	O
and	O
backward-incompatible	B-General_Concept
version	O
of	O
Camlp4	B-Language
.	O
</s>
<s>
De	O
Rauglaudre	O
maintains	O
a	O
separate	O
backward-compatible	B-General_Concept
version	O
,	O
which	O
has	O
been	O
renamed	O
Camlp5	O
.	O
</s>
<s>
All	O
of	O
the	O
examples	O
below	O
are	O
for	O
Camlp5	O
or	O
the	O
previous	O
version	O
of	O
Camlp4	B-Language
(	O
versions	O
3.09	O
and	O
prior	O
)	O
.	O
</s>
<s>
It	O
is	O
currently	O
deprecated	O
;	O
instead	O
,	O
it	O
is	O
recommended	O
to	O
use	O
the	O
PPX	O
(	O
PreProcessor	B-General_Concept
eXtensions	O
)	O
libraries	O
.	O
</s>
<s>
A	O
Camlp4	B-Language
preprocessor	B-General_Concept
operates	O
by	O
loading	O
a	O
collection	O
of	O
compiled	B-Language
modules	O
which	O
define	O
a	O
parser	B-Language
as	O
well	O
as	O
a	O
pretty-printer	B-Application
:	O
the	O
parser	B-Language
converts	O
an	O
input	O
program	B-Application
into	O
an	O
internal	O
representation	O
.	O
</s>
<s>
This	O
internal	O
representation	O
constitutes	O
the	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
(	O
AST	O
)	O
.	O
</s>
<s>
it	O
can	O
be	O
passed	O
directly	O
to	O
one	O
of	O
the	O
OCaml	B-Language
compilers	B-Language
,	O
or	O
it	O
can	O
be	O
converted	O
back	O
into	O
a	O
clear	O
text	O
program	B-Application
.	O
</s>
<s>
For	O
instance	O
,	O
the	O
OCaml	B-Language
expression	O
(	O
1	O
+	O
2	O
)	O
can	O
also	O
be	O
written	O
( ( +	O
)	O
1	O
2	O
)	O
or	O
( ( ( +	O
)	O
1	O
)	O
2	O
)	O
.	O
</s>
<s>
The	O
difference	O
is	O
only	O
at	O
the	O
level	O
of	O
the	O
concrete	O
syntax	O
,	O
since	O
these	O
three	O
versions	O
are	O
equivalent	O
representations	O
of	O
the	O
same	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
As	O
demonstrated	O
by	O
the	O
definition	O
of	O
a	O
revised	O
syntax	O
for	O
OCaml	B-Language
,	O
the	O
same	O
programming	O
language	O
can	O
use	O
different	O
concrete	O
syntaxes	O
.	O
</s>
<s>
They	O
would	O
all	O
converge	O
to	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
in	O
a	O
unique	O
format	O
that	O
a	O
compiler	B-Language
can	O
handle	O
.	O
</s>
<s>
The	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
is	O
at	O
the	O
center	O
of	O
the	O
syntax	O
extensions	O
,	O
which	O
are	O
in	O
fact	O
OCaml	B-Language
programs	O
.	O
</s>
<s>
Although	O
the	O
definition	O
of	O
grammars	O
must	O
be	O
done	O
in	O
OCaml	B-Language
,	O
the	O
parser	B-Language
that	O
is	O
being	O
defined	O
or	O
extended	O
is	O
not	O
necessarily	O
related	O
to	O
OCaml	B-Language
,	O
in	O
which	O
case	O
the	O
syntax	O
tree	O
that	O
is	O
being	O
manipulated	O
is	O
not	O
the	O
one	O
of	O
OCaml	B-Language
.	O
</s>
<s>
Several	O
libraries	O
are	O
provided	O
which	O
facilitate	O
the	O
specific	O
manipulation	O
of	O
OCaml	B-Language
syntax	O
trees	O
.	O
</s>
<s>
Domain-specific	B-Language
languages	I-Language
are	O
a	O
major	O
application	O
of	O
Camlp4	B-Language
.	O
</s>
<s>
Since	O
OCaml	B-Language
is	O
a	O
multi-paradigm	O
language	O
,	O
with	O
an	O
interactive	O
toplevel	O
and	O
a	O
native	O
code	B-Language
compiler	I-Language
,	O
it	O
can	O
be	O
used	O
as	O
a	O
backend	O
for	O
any	O
kind	O
of	O
original	O
language	O
.	O
</s>
<s>
The	O
only	O
thing	O
that	O
the	O
developer	O
has	O
to	O
do	O
is	O
write	O
a	O
Camlp4	B-Language
grammar	O
which	O
converts	O
the	O
domain-specific	B-Language
language	I-Language
in	O
question	O
into	O
a	O
regular	O
OCaml	B-Language
program	B-Application
.	O
</s>
<s>
Other	O
target	O
languages	O
can	O
also	O
be	O
used	O
,	O
such	O
as	O
C	B-Language
.	O
</s>
<s>
If	O
the	O
target	O
language	O
is	O
OCaml	B-Language
,	O
simple	O
syntax	O
add-ons	O
or	O
syntactic	O
sugar	O
can	O
be	O
defined	O
,	O
in	O
order	O
to	O
provide	O
an	O
expressivity	O
which	O
is	O
not	O
easy	O
to	O
achieve	O
using	O
the	O
standard	O
features	O
of	O
the	O
OCaml	B-Language
language	O
.	O
</s>
<s>
A	O
syntax	O
extension	O
is	O
defined	O
by	O
a	O
compiled	B-Language
OCaml	B-Language
module	O
,	O
which	O
is	O
passed	O
to	O
the	O
camlp4o	O
executable	O
along	O
with	O
the	O
program	B-Application
to	O
process	O
.	O
</s>
<s>
Camlp4	B-Language
includes	O
a	O
domain-specific	B-Language
language	I-Language
as	O
it	O
provides	O
syntax	O
extensions	O
which	O
ease	O
the	O
development	O
of	O
syntax	O
extensions	O
.	O
</s>
<s>
deconstructing	O
and	O
constructing	O
abstract	B-Data_Structure
syntax	I-Data_Structure
trees	I-Data_Structure
in	O
concrete	O
syntax	O
.	O
</s>
<s>
The	O
following	O
example	O
defines	O
a	O
syntax	O
extension	O
of	O
OCaml	B-Language
.	O
</s>
<s>
It	O
provides	O
a	O
new	O
keyword	O
,	O
memo	O
,	O
which	O
can	O
be	O
used	O
as	O
a	O
replacement	O
for	O
function	O
and	O
provides	O
automatic	O
memoization	O
of	O
functions	O
with	O
pattern	B-Language
matching	I-Language
.	O
</s>
<s>
Example	O
of	O
program	B-Application
using	O
this	O
syntax	O
extension	O
:	O
</s>
<s>
The	O
output	O
of	O
the	O
program	B-Application
is	O
as	O
follows	O
,	O
showing	O
that	O
the	O
fac	O
function	O
(	O
factorial	O
)	O
only	O
computes	O
products	O
that	O
were	O
not	O
computed	O
previously	O
:	O
</s>
