Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

OMeta/JS Parser/Generator DSL

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]]]

Name: Anonymous 2011-08-23 3:57

I also forgot to ask, but is there anything mature like this that is native to Common Lisp that can handle arbitrary context-free grammars or parsing expression grammars? I know there's a port of OMeta to CL, but I couldn't get it to work, and the code looks shoddy.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List