Created
February 26, 2021 08:07
-
-
Save niyarin/da0c8cfc42bd71d2ffbb2caa488c0870 to your computer and use it in GitHub Desktop.
nanopass-compiler framework examples
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
(import (nanopass) (rnrs)) | |
(define (primitive-procedure? x) | |
(or (eq? x 'eq?) | |
(eq? x 'symbol?) | |
(eq? x 'boolean?))) | |
(define-language piyo-lang | |
(terminals | |
(primitive-procedure (proc)) | |
(boolean (b)) | |
(symbol (x))) | |
(Expression (e) | |
proc | |
b | |
x | |
(if e e1) | |
(if e e1 e2) | |
(e e* ...))) | |
(define-language piyo-removed-one-armedif-lang | |
(extends piyo-lang) | |
(Expression (e) | |
(- (if e e1)))) | |
(define-pass remove-one-armed-if : | |
piyo-lang (e) -> piyo-removed-one-armedif-lang () | |
(Expression : Expression (ir) -> Expression () | |
((if ,e ,e1) `(if ,e ,e1 #f )))) | |
(define-parser parse-piyo-lang piyo-lang) | |
(define-parser parse-piyo-removed-one-armedif-lang | |
piyo-removed-one-armedif-lang) | |
(display (unparse-piyo-removed-one-armedif-lang (remove-one-armed-if (parse-piyo-lang '(if a b))))) | |
(newline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment