dev-elider-3
Matthew Butterick 9 years ago
parent b410e97b8f
commit 7e605cd081

@ -27,8 +27,7 @@
(displayln (format "got unbound identifier: ~a" 'id)) (displayln (format "got unbound identifier: ~a" 'id))
(procedure-rename (λ xs (cons 'id xs)) (format-datum "undefined:~a" 'id)))) (procedure-rename (λ xs (cons 'id xs)) (format-datum "undefined:~a" 'id))))
(define #'(program LINE ...) (define #'(program LINE ...) #'(run (list LINE ...)))
#'(run (list LINE ...)))
(define (run lines) (define (run lines)
(define program-lines (list->vector (filter (λ(ln) (not (equal? ln "cr"))) lines))) (define program-lines (list->vector (filter (λ(ln) (not (equal? ln "cr"))) lines)))
@ -84,15 +83,20 @@
(define (PRINT args) (define (PRINT args)
(match args (match args
[(list) (displayln "")] [(list) (displayln "")]
[(list items ... ";" pl) (begin (for-each display items) (PRINT pl))] [(list print-list-item ... ";" pl) (begin (for-each display print-list-item) (PRINT pl))]
[(list items ... ";") (for-each display items)] [(list print-list-item ... ";") (for-each display print-list-item)]
[(list items ...) (for-each displayln items)])) [(list print-list-item ...) (for-each displayln print-list-item)]))
(define (TAB num) (make-string num #\space)) (define (TAB num) (make-string num #\space))
(define (INT num) (inexact->exact (round num))) (define (INT num) (inexact->exact (round num)))
(define (SIN num) (sin num)) (define (SIN num) (sin num))
(define (RND num) (* (random) num)) (define (RND num) (* (random) num))
(define #'(INPUT PRINT-LIST ";" ID)
#'(begin
(PRINT (append PRINT-LIST (list ";")))
(set! ID (read-line))))
(define (GOTO where) (define (GOTO where)
where) where)

@ -1,7 +1,7 @@
#lang ragg #lang ragg
;; recursive rules destucture easily in the expander ;; recursive rules destucture easily in the expander
program : line [CR line]* program : [line [CR line]*]
line: INTEGER statement+ line: INTEGER statement+
@ -9,7 +9,7 @@ statement : "END"
| "FOR" ID "=" expr "TO" expr ["STEP" expr] | "FOR" ID "=" expr "TO" expr ["STEP" expr]
| "GOTO" expr | "GOTO" expr
| "IF" expr "THEN" (statement | expr) ; change: add expr | "IF" expr "THEN" (statement | expr) ; change: add expr
| "INPUT" ID+ | "INPUT" print-list ";" ID
| ["LET"] ID "=" expr ; change: make "LET" opt | ["LET"] ID "=" expr ; change: make "LET" opt
| "NEXT" ID+ | "NEXT" ID+
| "PRINT" print-list | "PRINT" print-list

Loading…
Cancel
Save