pull/10/head
Matthew Butterick 8 years ago
parent 32acbeb501
commit 0652df09eb

@ -7,9 +7,9 @@
(with-pattern (with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)] ([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))] [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
[(VAR-NAME ...) (find-unique-var-names #'(LINE ...))]) [(VAR-ID ...) (find-unique-var-ids #'(LINE ...))])
#'(#%module-begin #'(#%module-begin
(define VAR-NAME 0) ... (define VAR-ID 0) ...
LINE ... LINE ...
(define line-table (define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...))) (apply hasheqv (append (list NUM LINE-FUNC) ...)))
@ -17,10 +17,10 @@
(begin-for-syntax (begin-for-syntax
(require racket/list) (require racket/list)
(define (find-unique-var-names stx) (define (find-unique-var-ids line-stxs)
(remove-duplicates (remove-duplicates
(for/list ([var-stx (in-list (syntax-flatten stx))] (for/list ([stx (in-list (syntax-flatten line-stxs))]
#:when (syntax-property var-stx 'b-id)) #:when (syntax-property stx 'b-id))
var-stx) stx)
#:key syntax->datum))) #:key syntax->datum)))

@ -1,6 +1,8 @@
#lang br #lang br
(require "struct.rkt" "line.rkt" "misc.rkt") (require "struct.rkt" "line.rkt" "misc.rkt")
(provide b-goto b-gosub b-return b-for b-next) (provide b-end b-goto b-gosub b-return b-for b-next)
(define (b-end) (raise (end-program-signal)))
(define (b-goto num-expr) (define (b-goto num-expr)
(raise (change-line-signal num-expr))) (raise (change-line-signal num-expr)))

@ -1,6 +1,6 @@
#lang br #lang br
(require "struct.rkt") (require "struct.rkt")
(provide (all-defined-out)) (provide b-rem b-print b-let b-input)
(define (b-rem val) (void)) (define (b-rem val) (void))
@ -12,6 +12,4 @@
(define-macro (b-input ID) (define-macro (b-input ID)
#'(b-let ID (let* ([str (read-line)] #'(b-let ID (let* ([str (read-line)]
[num (string->number (string-trim str))]) [num (string->number (string-trim str))])
(or num str)))) (or num str))))
(define (b-end) (raise (end-program-signal)))

@ -4,7 +4,7 @@ b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem] b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER @b-line-num : INTEGER
b-rem : REM b-rem : REM
@b-statement : b-rem | b-end | b-print | b-goto | b-let @b-statement : b-end | b-print | b-goto | b-let
| b-input | b-def | b-gosub | b-input | b-def | b-gosub
| b-return | b-for | b-next | b-if | b-return | b-for | b-next | b-if
b-end : /"end" b-end : /"end"

@ -1,8 +1,8 @@
#lang brag #lang brag
b-program : [b-line] (/NEWLINE [b-line])* b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-num [b-statement] (/":" [b-statement])* b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER @b-line-num : INTEGER
@b-statement : b-rem | b-end | b-print | b-goto @b-statement : b-end | b-print | b-goto
b-rem : REM b-rem : REM
b-end : /"end" b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])* b-print : /"print" [b-printable] (/";" [b-printable])*

Loading…
Cancel
Save