v6.3-exception
Matthew Butterick 7 years ago
parent 2b776d8ee0
commit 380f4a2d37

@ -7,17 +7,18 @@
(for/list ([tok (in-port read-char ip)]) (for/list ([tok (in-port read-char ip)])
tok)) tok))
(define (parse-char c) (define (parse toks)
(define int (modulo (char->integer c) 128)) (for/list ([tok (in-list toks)])
(for/list ([bit (in-range 7)]) (define int (modulo (char->integer tok) 128))
(if (bitwise-bit-set? int bit) (for/list ([bit (in-range 7)])
'taco (if (bitwise-bit-set? int bit)
null))) 'taco
null))))
(define (read-syntax src ip) (define (read-syntax src ip)
(define toks (tokenize ip)) (define toks (tokenize ip))
(define parse-tree (map parse-char toks)) (define parse-tree (parse toks))
(strip-context (strip-context
(with-syntax ([(PARSED-CHAR ...) parse-tree]) (with-syntax ([PT parse-tree])
#'(module tacofied racket #'(module tacofied racket
(for-each displayln '(PARSED-CHAR ...)))))) (for-each displayln 'PT)))))

@ -7,16 +7,17 @@
(for/list ([tok (in-port read ip)]) (for/list ([tok (in-port read ip)])
tok)) tok))
(define (parse tok) (define (parse toks)
(integer->char (for/list ([tok (in-list toks)])
(for/sum ([val (in-list tok)] (integer->char
[power (in-naturals)] (for/sum ([val (in-list tok)]
#:when (eq? val 'taco)) [power (in-naturals)]
(expt 2 power)))) #:when (eq? val 'taco))
(expt 2 power)))))
(define (read-syntax src ip) (define (read-syntax src ip)
(define toks (tokenize ip)) (define toks (tokenize ip))
(define parse-tree (map parse toks)) (define parse-tree (parse toks))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module untaco racket #'(module untaco racket

@ -7,16 +7,17 @@
(for/list ([tok (in-port read ip)]) (for/list ([tok (in-port read ip)])
tok)) tok))
(define (parse tok) (define (parse toks)
(integer->char (for/list ([tok (in-list toks)])
(for/sum ([val (in-list tok)] (integer->char
[power (in-naturals)] (for/sum ([val (in-list tok)]
#:when (eq? val 'taco)) [power (in-naturals)]
(expt 2 power)))) #:when (eq? val 'taco))
(expt 2 power)))))
(define (read-syntax src ip) (define (read-syntax src ip)
(define toks (tokenize ip)) (define toks (tokenize ip))
(define parse-tree (map parse toks)) (define parse-tree (parse toks))
(define src-string (list->string parse-tree)) (define src-string (list->string parse-tree))
(define racket-toks (define racket-toks
(for/list ([tok (in-port read (open-input-string src-string))]) (for/list ([tok (in-port read (open-input-string src-string))])

@ -5,27 +5,30 @@
(module+ reader (module+ reader
(provide read-syntax)) (provide read-syntax))
(define lex (define (tokenize ip)
(lexer (define lex
["#$" lexeme] (lexer
["%" lexeme] ["#$" lexeme]
[any-char (lex input-port)])) ["%" lexeme]
[any-char (lex input-port)]))
(lex ip))
(define (taco-program . pieces) pieces) (define (taco-program . pieces) pieces)
(define (taco-leaf . pieces) (define (taco-leaf . pieces)
(integer->char (integer->char
(for/sum ([bit (in-list pieces)] (for/sum ([taco-or-not (in-list pieces)]
[pow (in-naturals)]) [pow (in-naturals)])
(* bit (expt 2 pow))))) (* taco-or-not (expt 2 pow)))))
(define (taco) 1) (define (taco) 1)
(define (not-a-taco) 0) (define (not-a-taco) 0)
(define (read-syntax src ip) (define (read-syntax src ip)
(define parse-tree (parse (λ () (lex ip)))) (define token-thunk (λ () (tokenize ip)))
(define parse-tree (parse token-thunk))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module vic taco-victory-demo #'(module winner taco-victory-demo
(display (apply string PT)))))) (display (apply string PT))))))

@ -8,17 +8,20 @@
(for/list ([tok (in-port read-char ip)]) (for/list ([tok (in-port read-char ip)])
tok)) tok))
(define (leaf->char taco-leaf) (define (parse toks)
(integer->char (define parse-tree-datum (parse-to-datum toks))
(for/sum ([val (in-list (cdr taco-leaf))] (for/list ([leaf (in-list (cdr parse-tree-datum))])
[power (in-naturals)] (integer->char
#:when (equal? val '(taco))) (for/sum ([val (in-list (cdr leaf))]
(expt 2 power)))) [power (in-naturals)]
#:when (equal? val '(taco)))
(expt 2 power)))))
(define (read-syntax src ip) (define (read-syntax src ip)
(define parse-tree (parse-to-datum (tokenize ip))) (define toks (tokenize ip))
(define taco-branches (cdr parse-tree)) (define parse-tree (parse toks))
(strip-context (strip-context
(with-syntax ([CHARS (map leaf->char taco-branches)]) (with-syntax ([PT parse-tree])
#'(module untaco racket #'(module untaco racket
(display (list->string 'CHARS)))))) (display (list->string 'PT))))))

@ -17,16 +17,17 @@
(for/list ([tok (in-slice 7 toklets)]) (for/list ([tok (in-slice 7 toklets)])
tok)) tok))
(define (parse taco-rec-tok) (define (parse toks)
(integer->char (for/list ([tok (in-list toks)])
(for/sum ([val (in-list taco-rec-tok)] (integer->char
[power (in-naturals)] (for/sum ([val (in-list tok)]
#:when (eq? val 'taco)) [power (in-naturals)]
(expt 2 power)))) #:when (eq? val 'taco))
(expt 2 power)))))
(define (read-syntax src ip) (define (read-syntax src ip)
(define toks (tokenize ip)) (define toks (tokenize ip))
(define parse-tree (map parse toks)) (define parse-tree (parse toks))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module untaco racket #'(module untaco racket

Loading…
Cancel
Save