<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
an	O
S-expression	B-Protocol
(	O
or	O
symbolic	O
expression	O
,	O
abbreviated	O
as	O
sexpr	B-Protocol
or	O
sexp	B-Protocol
)	O
is	O
an	O
expression	O
in	O
a	O
like-named	O
notation	O
for	O
nested	O
list	B-Data_Structure
(	O
tree-structured	O
)	O
data	O
.	O
</s>
<s>
S-expressions	B-Protocol
were	O
invented	O
for	O
and	O
popularized	O
by	O
the	O
programming	O
language	O
Lisp	B-Language
,	O
which	O
uses	O
them	O
for	O
source	O
code	O
as	O
well	O
as	O
data	O
.	O
</s>
<s>
y	O
)	O
where	O
x	O
and	O
y	O
are	O
S-expressions	B-Protocol
.	O
</s>
<s>
This	O
definition	O
reflects	O
LISP	B-Language
's	O
representation	O
of	O
a	O
list	B-Data_Structure
as	O
a	O
series	O
of	O
"	O
cells	O
"	O
,	O
each	O
one	O
an	O
ordered	O
pair	O
.	O
</s>
<s>
In	O
plain	O
lists	O
,	O
y	O
points	O
to	O
the	O
next	O
cell	O
(	O
if	O
any	O
)	O
,	O
thus	O
forming	O
a	O
list	B-Data_Structure
.	O
</s>
<s>
The	O
recursive	O
clause	O
of	O
the	O
definition	O
means	O
that	O
both	O
this	O
representation	O
and	O
the	O
S-expression	B-Protocol
notation	O
can	O
represent	O
any	O
binary	O
tree	B-Application
.	O
</s>
<s>
unless	O
a	O
convention	O
for	O
cross-reference	O
is	O
provided	O
(	O
analogous	O
to	O
SQL	B-Language
foreign	B-Application
keys	I-Application
,	O
SGML/XML	O
IDREFs	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
NIL	O
is	O
the	O
special	O
end-of-list	O
object	O
(	O
alternatively	O
written	O
(	O
)	O
,	O
which	O
is	O
the	O
only	O
representation	O
in	O
Scheme	B-Language
)	O
.	O
</s>
<s>
In	O
the	O
Lisp	B-Language
family	O
of	O
programming	O
languages	O
,	O
S-expressions	B-Protocol
are	O
used	O
to	O
represent	O
both	O
source	O
code	O
and	O
data	O
.	O
</s>
<s>
Other	O
uses	O
of	O
S-expressions	B-Protocol
are	O
in	O
Lisp-derived	O
languages	O
such	O
as	O
DSSSL	B-Language
,	O
and	O
as	O
mark-up	O
in	O
communication	O
protocols	O
like	O
IMAP	B-Protocol
and	O
John	O
McCarthy	O
's	O
CBCL	B-Language
.	O
</s>
<s>
It	O
's	O
also	O
used	O
as	O
text	O
representation	O
of	O
WebAssembly	B-Language
.	O
</s>
<s>
The	O
details	O
of	O
the	O
syntax	O
and	O
supported	O
data	O
types	O
vary	O
in	O
the	O
different	O
languages	O
,	O
but	O
the	O
most	O
common	O
feature	O
among	O
these	O
languages	O
is	O
the	O
use	O
of	O
S-expressions	B-Protocol
and	O
prefix	O
notation	O
.	O
</s>
<s>
There	O
are	O
many	O
variants	O
of	O
the	O
S-expression	B-Protocol
format	O
,	O
supporting	O
a	O
variety	O
of	O
different	O
syntaxes	O
for	O
different	O
datatypes	O
.	O
</s>
<s>
#x10	O
for	O
hexadecimal	O
integers	O
,	O
or	O
#	O
\C	O
for	O
characters	O
.	O
</s>
<s>
When	O
representing	O
source	O
code	O
in	O
Lisp	B-Language
,	O
the	O
first	O
element	O
of	O
an	O
S-expression	B-Protocol
is	O
commonly	O
an	O
operator	O
or	O
function	O
name	O
and	O
any	O
remaining	O
elements	O
are	O
treated	O
as	O
arguments	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
the	O
Boolean	O
expression	O
written	O
4	O
==	O
(	O
2	O
+	O
2	O
)	O
in	O
C	B-Language
,	O
is	O
represented	O
as	O
(=	O
4	O
( +	O
2	O
2	O
)	O
)	O
in	O
Lisp	B-Language
's	O
s-expr-based	O
prefix	O
notation	O
.	O
</s>
<s>
As	O
noted	O
above	O
,	O
the	O
precise	O
definition	O
of	O
"	O
atom	O
"	O
varies	O
across	O
LISP-like	O
languages	O
.	O
</s>
<s>
The	O
recursive	O
case	O
of	O
the	O
s-expr	B-Protocol
definition	O
is	O
traditionally	O
implemented	O
using	O
cons	B-Language
cells	I-Language
.	O
</s>
<s>
S-expressions	B-Protocol
were	O
originally	O
intended	O
only	O
for	O
data	O
to	O
be	O
manipulated	O
by	O
M-expressions	B-Language
,	O
but	O
the	O
first	O
implementation	O
of	O
Lisp	B-Language
was	O
an	O
interpreter	O
of	O
S-expression	B-Protocol
encodings	O
of	O
M-expressions	B-Language
,	O
and	O
Lisp	B-Language
programmers	O
soon	O
became	O
accustomed	O
to	O
using	O
S-expressions	B-Protocol
for	O
both	O
code	O
and	O
data	O
.	O
</s>
<s>
This	O
means	O
that	O
Lisp	B-Language
is	O
homoiconic	O
;	O
that	O
is	O
,	O
the	O
primary	O
representation	O
of	O
programs	O
is	O
also	O
a	O
data	B-General_Concept
structure	I-General_Concept
in	O
a	O
primitive	O
type	O
of	O
the	O
language	O
itself	O
.	O
</s>
<s>
Nested	O
lists	O
can	O
be	O
written	O
as	O
S-expressions	B-Protocol
:	O
((milk juice )	O
(	O
honey	O
marmalade	O
)	O
)	O
is	O
a	O
two-element	O
S-expression	B-Protocol
whose	O
elements	O
are	O
also	O
two-element	O
S-expressions	B-Protocol
.	O
</s>
<s>
The	O
whitespace-separated	O
notation	O
used	O
in	O
Lisp	B-Language
(	O
and	O
this	O
article	O
)	O
is	O
typical	O
.	O
</s>
<s>
This	O
is	O
a	O
simple	O
context-free	O
grammar	O
for	O
a	O
tiny	O
subset	O
of	O
English	O
written	O
as	O
an	O
S-expression	B-Protocol
(	O
Gazdar/Melish	O
,	O
Natural	O
Language	O
Processing	O
in	O
Lisp	B-Language
)	O
,	O
where	O
S=	O
sentence	O
,	O
NP	O
=	O
Noun	O
Phrase	O
,	O
VP	O
=	O
Verb	O
Phrase	O
,	O
V=	O
Verb	O
:	O
</s>
<s>
Program	O
code	O
can	O
be	O
written	O
in	O
S-expressions	B-Protocol
,	O
usually	O
using	O
prefix	O
notation	O
.	O
</s>
<s>
Example	O
in	O
Common	B-Language
Lisp	I-Language
:	O
</s>
<s>
S-expressions	B-Protocol
can	O
be	O
read	O
in	O
Lisp	B-Language
using	O
the	O
function	O
READ	O
.	O
</s>
<s>
READ	O
reads	O
the	O
textual	O
representation	O
of	O
an	O
S-expression	B-Protocol
and	O
returns	O
Lisp	B-Language
data	O
.	O
</s>
<s>
The	O
function	O
PRINT	O
can	O
be	O
used	O
to	O
output	O
an	O
S-expression	B-Protocol
.	O
</s>
<s>
Lisp	B-Language
has	O
readable	O
representations	O
for	O
numbers	O
,	O
strings	O
,	O
symbols	O
,	O
lists	O
and	O
many	O
other	O
data	O
types	O
.	O
</s>
<s>
Program	O
code	O
can	O
be	O
formatted	O
as	O
pretty	O
printed	O
S-expressions	B-Protocol
using	O
the	O
function	O
PPRINT	O
(	O
note	O
:	O
with	O
two	O
Ps	O
,	O
short	O
for	O
pretty-print	O
)	O
.	O
</s>
<s>
Lisp	B-Language
programs	O
are	O
valid	O
S-expressions	B-Protocol
,	O
but	O
not	O
all	O
S-expressions	B-Protocol
are	O
valid	O
Lisp	B-Language
programs	O
.	O
</s>
<s>
(	O
1.0	O
+	O
3.1	O
)	O
is	O
a	O
valid	O
S-expression	B-Protocol
,	O
but	O
not	O
a	O
valid	O
Lisp	B-Language
program	O
,	O
since	O
Lisp	B-Language
uses	O
prefix	O
notation	O
and	O
a	O
floating	O
point	O
number	O
(	O
here	O
1.0	O
)	O
is	O
not	O
valid	O
as	O
an	O
operation	O
(	O
the	O
first	O
element	O
of	O
the	O
expression	O
)	O
.	O
</s>
<s>
An	O
S-expression	B-Protocol
preceded	O
by	O
a	O
single	O
quotation	O
mark	O
,	O
as	O
in	O
'	O
x	O
,	O
is	O
syntactic	O
sugar	O
for	O
a	O
quoted	O
S-expression	B-Protocol
,	O
in	O
this	O
case	O
(	O
quote	O
x	O
)	O
.	O
</s>
<s>
S-expressions	B-Protocol
are	O
often	O
compared	O
to	O
XML	B-Protocol
:	O
the	O
key	O
difference	O
is	O
that	O
S-expressions	B-Protocol
have	O
just	O
one	O
form	O
of	O
containment	O
,	O
the	O
dotted	O
pair	O
,	O
while	O
XML	B-Protocol
tags	O
can	O
contain	O
simple	O
attributes	O
,	O
other	O
tags	O
,	O
or	O
CDATA	B-Language
,	O
each	O
using	O
different	O
syntax	O
.	O
</s>
<s>
For	O
simple	O
use	O
cases	O
,	O
S-expressions	B-Protocol
are	O
simpler	O
than	O
XML	B-Protocol
,	O
but	O
for	O
more	O
advanced	O
use	O
cases	O
,	O
XML	B-Protocol
has	O
a	O
query	O
language	O
so	O
called	O
XPath	B-Language
,	O
many	O
tools	O
and	O
third	O
party	O
libraries	O
to	O
simplify	O
the	O
handling	O
of	O
XML	B-Protocol
data	O
.	O
</s>
<s>
Standards	O
for	O
some	O
Lisp-derived	O
programming	O
languages	O
include	O
a	O
specification	O
for	O
their	O
S-expression	B-Protocol
syntax	O
.	O
</s>
<s>
These	O
include	O
Common	B-Language
Lisp	I-Language
(	O
ANSI	O
standard	O
document	O
ANSI	O
INCITS	O
226-1994	O
(	O
R2004	O
)	O
)	O
,	O
Scheme	B-Language
(	O
R5RS	B-Language
and	O
R6RS	O
)	O
,	O
and	O
ISLISP	B-Language
.	O
</s>
<s>
The	O
draft	O
defined	O
a	O
syntax	O
based	O
on	O
Lisp	B-Language
S-expressions	B-Protocol
but	O
intended	O
for	O
general-purpose	O
data	O
storage	O
and	O
exchange	O
(	O
similar	O
to	O
XML	B-Protocol
)	O
rather	O
than	O
specifically	O
for	O
programming	O
.	O
</s>
<s>
Rivest	O
's	O
format	O
defines	O
an	O
S-expression	B-Protocol
as	O
being	O
either	O
an	O
octet-string	O
(	O
a	O
series	O
of	O
bytes	B-Application
)	O
or	O
a	O
finite	O
list	B-Data_Structure
of	O
other	O
S-expressions	B-Protocol
.	O
</s>
<s>
One	O
is	O
the	O
"	O
advanced	O
transport	O
"	O
,	O
which	O
is	O
very	O
flexible	O
in	O
terms	O
of	O
formatting	O
,	O
and	O
is	O
syntactically	O
similar	O
to	O
Lisp-style	O
expressions	O
,	O
but	O
they	O
are	O
not	O
identical	O
.	O
</s>
<s>
The	O
advanced	O
transport	O
,	O
for	O
example	O
,	O
allows	O
octet-strings	O
to	O
be	O
represented	O
verbatim	O
(	O
the	O
string	O
's	O
length	O
followed	O
by	O
a	O
colon	O
and	O
the	O
entire	O
raw	O
string	O
)	O
,	O
a	O
quoted	O
form	O
allowing	O
escape	O
characters	O
,	O
hexadecimal	O
,	O
Base64	B-Protocol
,	O
or	O
placed	O
directly	O
as	O
a	O
"	O
token	O
"	O
if	O
it	O
meets	O
certain	O
conditions	O
.	O
</s>
<s>
(	O
Rivest	O
's	O
tokens	O
differ	O
from	O
Lisp	B-Language
tokens	O
in	O
that	O
the	O
former	O
are	O
just	O
for	O
convenience	O
and	O
aesthetics	O
,	O
and	O
treated	O
exactly	O
like	O
other	O
strings	O
,	O
while	O
the	O
latter	O
have	O
specific	O
syntactical	O
meaning	O
.	O
)	O
</s>
<s>
Rivest	O
's	O
draft	O
defines	O
a	O
canonical	B-Protocol
representation	I-Protocol
"	O
for	O
digital	O
signature	O
purposes	O
"	O
.	O
</s>
<s>
It	O
's	O
intended	O
to	O
be	O
compact	O
,	O
easier	O
to	O
parse	O
,	O
and	O
unique	O
for	O
any	O
abstract	O
S-expression	B-Protocol
.	O
</s>
<s>
Finally	O
there	O
is	O
the	O
"	O
basic	O
transport	O
representation	O
"	O
,	O
which	O
is	O
either	O
the	O
canonical	O
form	O
or	O
the	O
same	O
encoded	O
as	O
Base64	B-Protocol
and	O
surrounded	O
by	O
braces	O
,	O
the	O
latter	O
intended	O
to	O
safely	O
transport	O
a	O
canonically	O
encoded	O
S-expression	B-Protocol
in	O
a	O
system	O
which	O
might	O
change	O
spacing	O
(	O
e.g.	O
</s>
<s>
This	O
format	O
has	O
not	O
been	O
widely	O
adapted	O
for	O
use	O
outside	O
of	O
SPKI	O
(	O
some	O
of	O
the	O
users	O
being	O
GnuPG	B-Application
,	O
libgcrypt	O
,	O
Nettle	B-Application
,	O
and	O
GNU	B-Operating_System
lsh	O
)	O
.	O
</s>
<s>
Rivest	O
's	O
S-expressions	B-Protocol
web	O
page	O
provides	O
C	B-Language
source	O
code	O
for	O
a	O
parser	O
and	O
generator	O
(	O
available	O
under	O
the	B-License
MIT	I-License
license	I-License
)	O
,	O
which	O
could	O
be	O
adapted	O
and	O
embedded	O
into	O
other	O
programs	O
.	O
</s>
