simplify
This commit is contained in:
parent
67ac247f41
commit
12f7a3d332
|
@ -8,17 +8,9 @@
|
||||||
; http://www.atariarchives.org/basicgames/showpage.php?page=i12
|
; http://www.atariarchives.org/basicgames/showpage.php?page=i12
|
||||||
|
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(require racket/match racket/list)
|
(require racket/list)
|
||||||
(define (gather-unique-ids stx)
|
(define (gather-unique-ids stx)
|
||||||
(define ids empty)
|
(remove-duplicates (map syntax->datum (filter (λ(s) (syntax-property s 'id)) (syntax-flatten stx))) eq?)))
|
||||||
(let loop ([x (syntax->datum stx)])
|
|
||||||
(match x
|
|
||||||
[(or (list 'statement (? symbol? id-name) "=" etc ...)
|
|
||||||
(list 'statement "input" (list 'print-list etc ...) (? symbol? id-name) ...)
|
|
||||||
(list 'statement "for" (? symbol? id-name) etc ...)) (set! ids (cons id-name ids))]
|
|
||||||
[(? list?) (map loop x)]
|
|
||||||
[else #f]))
|
|
||||||
(remove-duplicates (flatten ids) eq?)))
|
|
||||||
|
|
||||||
(define-macro (basic-module-begin (basic-program PROGRAM-LINE ...))
|
(define-macro (basic-module-begin (basic-program PROGRAM-LINE ...))
|
||||||
(with-pattern
|
(with-pattern
|
||||||
|
|
|
@ -8,12 +8,12 @@ statement : "end" | "stop"
|
||||||
| "gosub" expr
|
| "gosub" expr
|
||||||
| "goto" expr
|
| "goto" expr
|
||||||
| "if" expr /"then" (statement | expr) [/"else" (statement | expr)]
|
| "if" expr /"then" (statement | expr) [/"else" (statement | expr)]
|
||||||
| "input" [print-list /";"] ID [/"," ID]*
|
| "input" [print-list /";"] id [/"," id]*
|
||||||
| [/"let"] ID "=" expr
|
| [/"let"] id "=" expr
|
||||||
| "print" [print-list]
|
| "print" [print-list]
|
||||||
| "return"
|
| "return"
|
||||||
| "for" ID /"=" value /"to" value [/"step" value]
|
| "for" id /"=" value /"to" value [/"step" value]
|
||||||
| "next" [ID]
|
| "next" [id]
|
||||||
|
|
||||||
print-list : expr [[";"] [print-list]]
|
print-list : expr [[";"] [print-list]]
|
||||||
|
|
||||||
|
@ -25,10 +25,12 @@ sum : [sum ("+" | "-")] product
|
||||||
|
|
||||||
product : [product ("*" | "/")] value
|
product : [product ("*" | "/")] value
|
||||||
|
|
||||||
@value : ID
|
@value : id
|
||||||
| id-expr
|
| id-expr
|
||||||
| /"(" expr /")"
|
| /"(" expr /")"
|
||||||
| NUMBER
|
| NUMBER
|
||||||
| STRING
|
| STRING
|
||||||
|
|
||||||
/id-expr : ID [/"(" expr [/"," expr]* /")"]
|
/id-expr : id [/"(" expr [/"," expr]* /")"]
|
||||||
|
|
||||||
|
@id : ID
|
||||||
|
|
Loading…
Reference in New Issue
Block a user