Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Created August 17, 2012 13:25
Show Gist options
  • Save Idorobots/3378676 to your computer and use it in GitHub Desktop.
Save Idorobots/3378676 to your computer and use it in GitHub Desktop.
Simple Lisp grammar
(grammar ((Expression < (/ String List Atom)))
((String <- (:"\"") "[^\"]*" (: "\"")))
((List < (: "\\(") (* Expression) (: "\\)"))
`($(car List)
$(cdr List)))
((Atom <- (/ Number Symbol)))
((Number <- "[+\\-]?[0-9]+(\\.[0-9]*)?")
`($(car Number)
($(str->num (caadr Number)))))
((Symbol <- (! Number) "[^\\(\\)\"';\\s]+")
`($(car Symbol)
($(str->symbol (caadr Symbol)))))
((Spacing <- (* (/ Comment "[\\s]+"))))
((Comment <- (: ";" "[^\n]*\n"))))
(Expression "(define (compose f g)
(lambda (arg) (f (g arg))))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment