sense being made
parent
67a16a6b1d
commit
d6baa0508e
@ -0,0 +1,87 @@
|
|||||||
|
#lang br
|
||||||
|
(provide (all-defined-out)
|
||||||
|
#%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 ...)
|
||||||
|
#'(basic-run LINE ...))
|
||||||
|
|
||||||
|
(define (basic-run . lines)
|
||||||
|
(define program-lines (list->vector (filter (λ(x) x) lines)))
|
||||||
|
(void (for/fold ([line-idx 0])
|
||||||
|
([i (in-naturals)]
|
||||||
|
#:break (= line-idx (vector-length program-lines)))
|
||||||
|
(match-define (cons line-number proc)
|
||||||
|
(vector-ref program-lines line-idx))
|
||||||
|
(define maybe-jump-number (and proc (proc)))
|
||||||
|
(if (number? maybe-jump-number)
|
||||||
|
(let ([jump-number maybe-jump-number])
|
||||||
|
(for/or ([idx (in-range (vector-length program-lines))])
|
||||||
|
(and (= (car (vector-ref program-lines idx)) jump-number)
|
||||||
|
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
|
||||||
|
[#'(_ NUMBER . SEPARATED-STMTS)
|
||||||
|
#`(cons NUMBER
|
||||||
|
(λ _ (begin
|
||||||
|
#,@(for/list ([(item idx) (in-indexed (syntax->list #'SEPARATED-STMTS))]
|
||||||
|
#:when (even? idx))
|
||||||
|
item))))]
|
||||||
|
[#'(_ ARG ...) #'(line #f ARG ...)])
|
||||||
|
|
||||||
|
(define #'(statement NAME ARG ...) #'(NAME ARG ...))
|
||||||
|
|
||||||
|
(define #'(expression ITEM) #'ITEM)
|
||||||
|
(define #'(unsignedexpr ITEM) #'ITEM)
|
||||||
|
(define #'(term ITEM) #'ITEM)
|
||||||
|
(define #'(factor ITEM) #'ITEM)
|
||||||
|
(define #'(number ITEM) #'ITEM)
|
||||||
|
(define #'(varlist ITEM) #'ITEM)
|
||||||
|
(define #'(var ITEM) #'ITEM)
|
||||||
|
|
||||||
|
|
||||||
|
(define #'(printitem EXPR-OR-STRING) #'EXPR-OR-STRING)
|
||||||
|
|
||||||
|
;; 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)
|
||||||
|
(println 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)
|
||||||
|
|
||||||
|
(define vars (make-hasheq))
|
||||||
|
(define (INPUT id)
|
||||||
|
(hash-set! vars (string->symbol id) (read (open-input-string (read-line)))))
|
||||||
|
|
||||||
|
(define-cases #'expr-list
|
||||||
|
[#'(_ EXPR ...) #'(list EXPR ...)])
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
#lang ragg
|
||||||
|
;; adapted from http://www.ittybittycomputers.com/IttyBitty/TinyBasic/TBuserMan.txt
|
||||||
|
|
||||||
|
;; MS Basic extensions
|
||||||
|
;; http://www.atariarchives.org/basicgames/showpage.php?page=i12
|
||||||
|
|
||||||
|
;; games
|
||||||
|
;; http://www.vintage-basic.net/games.html
|
||||||
|
|
||||||
|
;; chipmunk basic
|
||||||
|
;; http://www.nicholson.com/rhn/basic/basic.man.html
|
||||||
|
|
||||||
|
basic-program : [CR] line [CR line]* [CR]
|
||||||
|
|
||||||
|
line: INTEGER statements
|
||||||
|
|
||||||
|
statements : statement [":" statement]*
|
||||||
|
|
||||||
|
statement : "END"
|
||||||
|
| "FOR" ID "=" expr "TO" expr ["STEP" expr]
|
||||||
|
| "GOTO" expr
|
||||||
|
| "IF" expr "THEN" (statement | expr) ; change: add expr
|
||||||
|
| "INPUT" id-list
|
||||||
|
| ["LET"] ID "=" expr ; change: make "LET" opt
|
||||||
|
| "NEXT" id-list
|
||||||
|
| "PRINT" print-list
|
||||||
|
| "REM" STRING
|
||||||
|
|
||||||
|
id-list : ID ["," id-list]
|
||||||
|
|
||||||
|
;value-list : value ["," value]*
|
||||||
|
|
||||||
|
;datum-list : datum ["," datum]*
|
||||||
|
|
||||||
|
;integer-list : INTEGER ["," INTEGER]*
|
||||||
|
|
||||||
|
expr-list : expr ["," expr]*
|
||||||
|
|
||||||
|
print-list : [expr [";" print-list]]
|
||||||
|
|
||||||
|
;expr : and-expr ["OR" expr]
|
||||||
|
;and-expr : not-expr ["AND" and-expr]
|
||||||
|
;not-expr : ["NOT"] compare-expr
|
||||||
|
;compare-expr : term [("=" | "<>" | "><" | ">" | ">=" | "<" | "<=") compare-expr]
|
||||||
|
|
||||||
|
expr : term [("=" | "<>" | "><" | ">" | ">=" | "<" | "<=") expr]
|
||||||
|
|
||||||
|
|
||||||
|
term : factor [("+" | "-") term]
|
||||||
|
|
||||||
|
factor : value [("*" | "/") factor]
|
||||||
|
|
||||||
|
;negate-expr : ["-"] power-expr
|
||||||
|
|
||||||
|
;power-expr : [power-expr "^"] value
|
||||||
|
|
||||||
|
value : "(" expr ")"
|
||||||
|
| ID ["(" expr-list ")"]
|
||||||
|
| datum
|
||||||
|
|
||||||
|
datum : INTEGER | STRING | REAL
|
@ -1,16 +1,3 @@
|
|||||||
#lang br/demo/basic
|
#lang br/demo/basic
|
||||||
10 PRINT TAB(30);"SINE WAVE"
|
10 PRINT TAB(30);"SINE WAVE"
|
||||||
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||||
30 PRINT: PRINT: PRINT: PRINT: PRINT
|
|
||||||
50 B=0
|
|
||||||
110 FOR T=0 TO 40 STEP .25
|
|
||||||
120 A=INT(26+25*SIN(T))
|
|
||||||
130 PRINT TAB(A);
|
|
||||||
140 IF B=1 THEN 180
|
|
||||||
150 PRINT "CREATIVE"
|
|
||||||
160 B=1
|
|
||||||
170 GOTO 200
|
|
||||||
180 PRINT "COMPUTING"
|
|
||||||
190 B=0
|
|
||||||
200 NEXT T
|
|
||||||
999 END
|
|
Loading…
Reference in New Issue