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

@ -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)

@ -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

Loading…
Cancel
Save