You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
642 B
Racket
24 lines
642 B
Racket
#lang br/quicklang
|
|
(require "grammar.rkt")
|
|
|
|
(module+ reader
|
|
(provide read-syntax))
|
|
|
|
(define (tokenize ip)
|
|
(for/list ([tok (in-port read-char ip)])
|
|
tok))
|
|
|
|
(define (leaf->char taco-leaf)
|
|
(integer->char
|
|
(for/sum ([val (in-list (cdr taco-leaf))]
|
|
[power (in-naturals)]
|
|
#:when (equal? val '(taco)))
|
|
(expt 2 power))))
|
|
|
|
(define (read-syntax src ip)
|
|
(define parse-tree (parse-to-datum (tokenize ip)))
|
|
(define taco-branches (cdr parse-tree))
|
|
(strip-context
|
|
(with-syntax ([CHARS (map leaf->char taco-branches)])
|
|
#'(module untaco racket
|
|
(display (list->string 'CHARS)))))) |