|
|
|
@ -3,9 +3,11 @@
|
|
|
|
|
#%top-interaction
|
|
|
|
|
#%datum
|
|
|
|
|
(rename-out [basic-module-begin #%module-begin]))
|
|
|
|
|
(require (for-syntax racket/string))
|
|
|
|
|
|
|
|
|
|
(define #'(basic-module-begin PARSE-TREE ...)
|
|
|
|
|
#'(#%module-begin
|
|
|
|
|
(println (quote PARSE-TREE ...))
|
|
|
|
|
PARSE-TREE ...))
|
|
|
|
|
|
|
|
|
|
(define #'(basic-program LINE ...)
|
|
|
|
@ -13,7 +15,7 @@
|
|
|
|
|
|
|
|
|
|
(define (basic-run . lines)
|
|
|
|
|
(define program-lines (list->vector (filter (λ(x) x) lines)))
|
|
|
|
|
(for/fold ([line-idx 0])
|
|
|
|
|
(void (for/fold ([line-idx 0])
|
|
|
|
|
([i (in-naturals)]
|
|
|
|
|
#:break (= line-idx (vector-length program-lines)))
|
|
|
|
|
(match-define (cons line-number proc)
|
|
|
|
@ -24,13 +26,16 @@
|
|
|
|
|
(for/or ([idx (in-range (vector-length program-lines))])
|
|
|
|
|
(and (= (car (vector-ref program-lines idx)) jump-number)
|
|
|
|
|
idx)))
|
|
|
|
|
(add1 line-idx))))
|
|
|
|
|
(add1 line-idx)))))
|
|
|
|
|
|
|
|
|
|
(define #'(CR) #'#f)
|
|
|
|
|
|
|
|
|
|
(define #'(REM ARG ...) #'(void (list 'ARG ...)))
|
|
|
|
|
|
|
|
|
|
;; model each line as (cons line-number line-thunk)
|
|
|
|
|
(define-cases #'line
|
|
|
|
|
[#'(line 'end) #'#f]
|
|
|
|
|
[#'(_ NUMBER STATEMENT 'end) #'(cons NUMBER (λ _ STATEMENT))]
|
|
|
|
|
[#'(_ STATEMENT 'end) #'(cons #f (λ _ STATEMENT))])
|
|
|
|
|
[#'(_ NUMBER STATEMENT) #'(cons NUMBER (λ _ STATEMENT))]
|
|
|
|
|
[#'(_ STATEMENT) #'(cons #f (λ _ STATEMENT))])
|
|
|
|
|
|
|
|
|
|
(define #'(statement NAME ARG ...) #'(NAME ARG ...))
|
|
|
|
|
|
|
|
|
@ -42,11 +47,24 @@
|
|
|
|
|
|
|
|
|
|
(define #'(printitem EXPR-OR-STRING) #'EXPR-OR-STRING)
|
|
|
|
|
|
|
|
|
|
(define #'(printlist ITEM-OR-SEPARATOR ...) #'(list ITEM-OR-SEPARATOR ...))
|
|
|
|
|
;; skip separators
|
|
|
|
|
(define #'(printlist . SEPARATED-ITEMS) #`(list #,@(for/list ([(item idx) (in-indexed (syntax->list #'SEPARATED-ITEMS))]
|
|
|
|
|
#:when (even? idx))
|
|
|
|
|
item)))
|
|
|
|
|
|
|
|
|
|
(define #'(separator SEP) #'(void))
|
|
|
|
|
|
|
|
|
|
(define #'(function NAME EXP ")") #`(#,(string->symbol (string-trim (syntax->datum #'NAME) "(")) EXP))
|
|
|
|
|
|
|
|
|
|
(define (TAB expr)
|
|
|
|
|
(make-string expr #\space))
|
|
|
|
|
|
|
|
|
|
(define (PRINT args)
|
|
|
|
|
(for-each display args)
|
|
|
|
|
(define (PRINT . args)
|
|
|
|
|
(if (and (= (length args) 1) (list? (car args)))
|
|
|
|
|
(begin
|
|
|
|
|
(for-each display (car args))
|
|
|
|
|
(displayln ""))
|
|
|
|
|
(filter (λ(i) (and (equal? i ":") (displayln ""))) args)))
|
|
|
|
|
|
|
|
|
|
(define (GOTO where)
|
|
|
|
|
where)
|
|
|
|
|