Skip to content

Instantly share code, notes, and snippets.

@jackfirth
Created October 29, 2015 16:42
Show Gist options
  • Save jackfirth/453ca33baea6f04b7e04 to your computer and use it in GitHub Desktop.
Save jackfirth/453ca33baea6f04b7e04 to your computer and use it in GitHub Desktop.
Fooling around with grammar definition syntaxes
(define (zero-or-more term)
(one-of term
(sequence-of term (zero-or-more term))))
(define nat-addition-grammar
(grammar [NUMBER (one-of DIGIT
(sequence-of NONZERO-DIGIT (zero-or-more DIGIT)))]
[DIGIT (one-of NONZERO-DIGIT
(literal 0))]
[NONZERO-DIGIT (one-of (literal 1) (literal 2) (literal 3) (literal 4) (literal 5) (literal 6) (literal 7) (literal 8) (literal 9))]
[EXPRESSION (sequence-of NUMBER (zero-or-more (sequence-of PLUS NUMBER)))]
[PLUS (literal "+")]))
(define-syntax-rule (grammar [term-id term] ...)
(letrec ([term-id term] ...)
(grammar (make-immutable-hash (('term-id . term-id) ...)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment