---
title: S-Expressions
id: 59667989bf71cf555dd5d2ff
challengeType: 5
---
## Description
S-Expressions are one convenient way to parse and store data.
Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats.
The function should read a single but nested S-Expression from a string and
return it as a (nested) array.
Newlines and other whitespace may be ignored unless contained within a quoted string.
“()” inside quoted strings are not interpreted, but treated as part of the string.
Handling escaped quotes inside a string is optional; thus “(foo"bar)” maybe treated as a string “foo"bar”, or as an error.
For this, the reader need not recognize “\” for escaping, but should, in addition, recognize numbers if the language has appropriate datatypes.
Note that with the exception of “()"” (“\” if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes.
The reader should be able to read the following input
((data "quoted data" 123 4.5)
(data (!@# (4.5) "(more" "data)")))
and turn it into a native datastructure. (see the Pike, Python and Ruby implementations for examples of native data structures.)
## InstructionsparseSexpr
is a function.
testString: assert(typeof parseSexpr === 'function', 'parseSexpr
is a function.');
- text: parseSexpr('(data1 data2 data3)')
should return ['data1', 'data2', 'data3']
testString: assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution, "parseSexpr('(data1 data2 data3)')
should return ['data1', 'data2', 'data3']");
- text: parseSexpr('(data1 data2 data3)')
should return an array with 3 elements.
testString: assert.deepEqual(parseSexpr(basicSExpr), basicSolution, "parseSexpr('(data1 data2 data3)')
should return an array with 3 elements");
```