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

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

@ -1,6 +1,8 @@
#lang br
(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)
(raise (change-line-signal num-expr)))

@ -1,6 +1,6 @@
#lang br
(require "struct.rkt")
(provide (all-defined-out))
(provide b-rem b-print b-let b-input)
(define (b-rem val) (void))
@ -13,5 +13,3 @@
#'(b-let ID (let* ([str (read-line)]
[num (string->number (string-trim 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-num : INTEGER
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-return | b-for | b-next | b-if
b-end : /"end"

@ -1,8 +1,8 @@
#lang brag
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-statement : b-rem | b-end | b-print | b-goto
@b-statement : b-end | b-print | b-goto
b-rem : REM
b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])*

Loading…
Cancel
Save