From 7e605cd081245e619aaa72c1a14dd23305570b38 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 19 Apr 2016 23:45:22 -0700 Subject: [PATCH] bam --- beautiful-racket/br/demo/basic/expander.rkt | 16 ++++++++++------ beautiful-racket/br/demo/basic/parser.rkt | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/beautiful-racket/br/demo/basic/expander.rkt b/beautiful-racket/br/demo/basic/expander.rkt index be0db79..541a058 100644 --- a/beautiful-racket/br/demo/basic/expander.rkt +++ b/beautiful-racket/br/demo/basic/expander.rkt @@ -6,7 +6,7 @@ (require (for-syntax racket/syntax racket/list br/datum)) (define-for-syntax alphasyms (for/list ([i (in-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]) - (string->symbol (format "~a" i)))) + (string->symbol (format "~a" i)))) (define-for-syntax stringsyms (map (λ(s) (format-datum "~a$" s)) alphasyms)) (define-syntax (basic-module-begin stx) @@ -27,8 +27,7 @@ (displayln (format "got unbound identifier: ~a" 'id)) (procedure-rename (λ xs (cons 'id xs)) (format-datum "undefined:~a" 'id)))) -(define #'(program LINE ...) - #'(run (list LINE ...))) +(define #'(program LINE ...) #'(run (list LINE ...))) (define (run lines) (define program-lines (list->vector (filter (λ(ln) (not (equal? ln "cr"))) lines))) @@ -84,15 +83,20 @@ (define (PRINT args) (match args [(list) (displayln "")] - [(list items ... ";" pl) (begin (for-each display items) (PRINT pl))] - [(list items ... ";") (for-each display items)] - [(list items ...) (for-each displayln items)])) + [(list print-list-item ... ";" pl) (begin (for-each display print-list-item) (PRINT pl))] + [(list print-list-item ... ";") (for-each display print-list-item)] + [(list print-list-item ...) (for-each displayln print-list-item)])) (define (TAB num) (make-string num #\space)) (define (INT num) (inexact->exact (round num))) (define (SIN num) (sin num)) (define (RND num) (* (random) num)) +(define #'(INPUT PRINT-LIST ";" ID) + #'(begin + (PRINT (append PRINT-LIST (list ";"))) + (set! ID (read-line)))) + (define (GOTO where) where) diff --git a/beautiful-racket/br/demo/basic/parser.rkt b/beautiful-racket/br/demo/basic/parser.rkt index 125619c..9ef7a9e 100644 --- a/beautiful-racket/br/demo/basic/parser.rkt +++ b/beautiful-racket/br/demo/basic/parser.rkt @@ -1,7 +1,7 @@ #lang ragg ;; recursive rules destucture easily in the expander -program : line [CR line]* +program : [line [CR line]*] line: INTEGER statement+ @@ -9,7 +9,7 @@ statement : "END" | "FOR" ID "=" expr "TO" expr ["STEP" expr] | "GOTO" expr | "IF" expr "THEN" (statement | expr) ; change: add expr -| "INPUT" ID+ +| "INPUT" print-list ";" ID | ["LET"] ID "=" expr ; change: make "LET" opt | "NEXT" ID+ | "PRINT" print-list