digits: charset "1234567890"
char: charset [#"a" - #"z" "+/-*"] ;; chars allowed in a symbol
not-quot: complement charset {"}
esc-string: [{\"} | not-quot]
bool: ["#t" | "#f"]
float: [opt "+-" any digits "." some digits]
number: [opt "+-" some digits]
symbol: [some char]
quot: [#"'" [sexp | atom]]
string: [{"} any esc-string {"}]
statement: [sexp | atom | space | newline]
sexp: ["(" any statement ")"]
atom: [bool | float | number | quot | symbol | string]
lisp-rule: [some statement]
NB. I wrote this "off the cuff" so I don't expect it to be flawless! Also there are no capture rules provided in my example (unlike perl6 grammars which provides this automatically).
It's worth noting that this grammar is a bit more restrictive than the Perl 6 equivalent. In particular, "\d" in Perl includes not only 0 through 9, but any Unicode character that's classified as a "digit". The Perl 6 grammar documentation features this in an example of using arbitrary methods in grammars: https://docs.perl6.org/language/grammars.html#Methods_in_Gra...
Comments
Here's that fun example written in Rebol parse:
NB. I wrote this "off the cuff" so I don't expect it to be flawless! Also there are no capture rules provided in my example (unlike perl6 grammars which provides this automatically).It's worth noting that this grammar is a bit more restrictive than the Perl 6 equivalent. In particular, "\d" in Perl includes not only 0 through 9, but any Unicode character that's classified as a "digit". The Perl 6 grammar documentation features this in an example of using arbitrary methods in grammars: https://docs.perl6.org/language/grammars.html#Methods_in_Gra...
I think the Perl 6 example should really use [0-9] instead of \d because it's unlikely that unicode numerals are allowed (in the Common Lisp spec).
Anyway neither example fully covers the Common Lisp spec for a number atom (for eg. scientific notation or rationals).
I don't think covering all of the Common Lisp spec is required to be Greenspun-compliant ;)
In that case Rebol is already Greenspun-compliant ;-)
... will print an answer of 9