update repl handling

pull/10/head
Matthew Butterick 8 years ago
parent 92a949c08e
commit 7ede91d508

@ -1,6 +1,6 @@
#lang br #lang br
(require "struct.rkt") (require "struct.rkt" "expr.rkt")
(provide b-rem b-print b-let b-input b-statements b-require) (provide b-rem b-print b-let b-input b-repl b-require)
(define (b-rem val) (void)) (define (b-rem val) (void))
@ -14,6 +14,10 @@
[num (string->number (string-trim str))]) [num (string->number (string-trim str))])
(or num str)))) (or num str))))
(define-macro (b-statements STMT ...) #'(begin STMT ...)) (define-macro (b-repl . ARGS)
(with-pattern ([STMTS (pattern-case-filter #'ARGS
[(b-expr . EXPR-ARGS) #'(b-print (b-expr . EXPR-ARGS))]
[OTHER-STMT #'OTHER-STMT])])
#'(begin . STMTS)))
(define-macro (b-require ID) #'(void)) (define-macro (b-require ID) #'(void))

@ -1,13 +1,12 @@
#lang brag #lang brag
b-program : [b-line] (/NEWLINE [b-line])* | b-statement /NEWLINE b-program : [b-line] (/NEWLINE [b-line])* | b-statement /NEWLINE
b-line : b-line-num b-statements [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-statements : [b-statement] (/":" [b-statement])*
@b-statement : b-end | b-print | b-goto @b-statement : b-end | b-print | b-goto
| b-let | b-input | b-if | b-let | b-input | b-if
| b-gosub | b-return | b-for | b-next | b-gosub | b-return | b-for | b-next
| b-def | b-require | b-expr | b-def | b-require
b-end : /"end" b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])* b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr @b-printable : STRING | b-expr
@ -37,4 +36,5 @@ b-expt : [b-expt ("^")] b-value
@b-value : b-number | b-id | /"(" b-expr /")" | b-func @b-value : b-number | b-id | /"(" b-expr /")" | b-func
b-func : ID /"(" b-input-list /")" b-func : ID /"(" b-input-list /")"
@b-input-list : (ID | b-expr) [/"," (ID | b-expr)]* @b-input-list : (ID | b-expr) [/"," (ID | b-expr)]*
@b-number : INTEGER | DECIMAL @b-number : INTEGER | DECIMAL
b-repl : (b-statement | b-expr) (/":" [b-repl])*

@ -4,7 +4,7 @@
(define basic-output-port (make-parameter (open-output-nowhere))) (define basic-output-port (make-parameter (open-output-nowhere)))
(define statement-parser (make-rule-parser b-statements)) (define repl-parser (make-rule-parser b-repl))
(define (configure-this!) (define (configure-this!)
(basic-output-port (current-output-port)) (basic-output-port (current-output-port))
@ -13,7 +13,7 @@
(define one-line (read-line port)) (define one-line (read-line port))
(if (eof-object? one-line) (if (eof-object? one-line)
eof eof
(statement-parser (make-tokenizer (open-input-string one-line))))) (repl-parser (make-tokenizer (open-input-string one-line)))))
(current-read-interaction read-one-line)) (current-read-interaction read-one-line))

Loading…
Cancel
Save