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.
beautiful-racket/beautiful-racket-demo/tacogram-demo/main.rkt

27 lines
727 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))
6 years ago
(define (parse toks)
(define parse-tree-datum (parse-to-datum toks))
(for/list ([leaf (in-list (cdr parse-tree-datum))])
(integer->char
(for/sum ([val (in-list (cdr leaf))]
[power (in-naturals)]
#:when (equal? val '(taco)))
(expt 2 power)))))
(define (read-syntax src ip)
6 years ago
(define toks (tokenize ip))
(define parse-tree (parse toks))
(strip-context
6 years ago
(with-syntax ([PT parse-tree])
#'(module untaco racket
6 years ago
(display (list->string 'PT))))))