S-expressions

From Rosetta Code
Revision as of 14:01, 15 October 2011 by rosettacode>EMBee (S-Expressions draft)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
S-expressions is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

S-Expressions are one convenient way to parse and store data.

Write a simple reader and writer for S-Expressions that handles quoted and unquoted strings, integers and floats.

The reader should read a single but nested S-Expression from a string and store it in a suitable datastructure (list, array, etc). 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.

The reader should be able to read the following input <lang lips>((data "quoted data" 123 4.5)

(data ("(more" "data)" 123) (4.5)))</lang>

and eg. in python produce a list as:

<lang python>[["data", "quoted data", 123, 4.5]

["data", ["(more", "data)", 123], [4.5]]]</lang>

The writer should be able to take the produced list and turn it into a new S-Expression.