Name: Anonymous 2011-08-23 3:12
This is a proof of concept s-expression parser in OMeta/JS I just made in about 10 minutes, produces Javascript nested lists as the resulting AST, although I could easily produce output text in a different language like C or C++. OMeta/JS is a Parsing Expression Grammar DSL which uses Javascript as the host language.
ometa SexprParser {
start = sexpr*,
sexpr = spaces (atom | list),
atom = symbol | number,
list = "(" sexpr:h sexpr*:t spaces ")" -> [h].concat(t)
| "(" sexpr:e spaces ")" -> [e]
| "(" blank ")" -> [],
symbol = firstAndRest(`letter, `letterOrDigit):s -> s.join(''),
digit = ^digit:d -> d.digitValue(),
number = number:n digit:d -> (n * 10 + d)
| digit
}
$> SexprParser.matchAll("""
(print (add 1 2))
(map xarnicate
(you me TheSussman)
(100 200 300))
""", `start)
$> [[print, [add, 1, 2]], [map, xarnicate, [you, me, TheSussman], [100, 200, 300]]]