Created
October 29, 2015 16:42
-
-
Save jackfirth/453ca33baea6f04b7e04 to your computer and use it in GitHub Desktop.
Fooling around with grammar definition syntaxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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