change op & loop to use bf- prefix

pull/10/head
Matthew Butterick 8 years ago
parent 7a7e162988
commit 2eb46aaa81

@ -9,19 +9,19 @@
#'(void OP-OR-LOOP-ARG ...))
(provide bf-program)
(define-macro (loop "[" OP-OR-LOOP-ARG ... "]")
(define-macro (bf-loop "[" OP-OR-LOOP-ARG ... "]")
#'(until (zero? (current-byte))
OP-OR-LOOP-ARG ...))
(provide loop)
(provide bf-loop)
(define-macro-cases op
[(op ">") #'(gt)]
[(op "<") #'(lt)]
[(op "+") #'(plus)]
[(op "-") #'(minus)]
[(op ".") #'(period)]
[(op ",") #'(comma)])
(provide op)
(define-macro-cases bf-op
[(bf-op ">") #'(gt)]
[(bf-op "<") #'(lt)]
[(bf-op "+") #'(plus)]
[(bf-op "-") #'(minus)]
[(bf-op ".") #'(period)]
[(bf-op ",") #'(comma)])
(provide bf-op)
(define arr (make-vector 30000 0))
(define ptr 0)

@ -16,23 +16,23 @@
(void (fold-funcs first-apl (list OP-OR-LOOP-ARG ...)))))
(provide bf-program)
(define-macro (loop "[" OP-OR-LOOP-ARG ... "]")
(define-macro (bf-loop "[" OP-OR-LOOP-ARG ... "]")
#'(lambda (arr ptr)
(for/fold ([current-apl (list arr ptr)])
([i (in-naturals)]
#:break (zero? (apply current-byte
current-apl)))
(fold-funcs current-apl (list OP-OR-LOOP-ARG ...)))))
(provide loop)
(define-macro-cases op
[(op ">") #'gt]
[(op "<") #'lt]
[(op "+") #'plus]
[(op "-") #'minus]
[(op ".") #'period]
[(op ",") #'comma])
(provide op)
(provide bf-loop)
(define-macro-cases bf-op
[(bf-op ">") #'gt]
[(bf-op "<") #'lt]
[(bf-op "+") #'plus]
[(bf-op "-") #'minus]
[(bf-op ".") #'period]
[(bf-op ",") #'comma])
(provide bf-op)
(define (current-byte arr ptr) (vector-ref arr ptr))

@ -16,23 +16,23 @@
(void (fold-funcs first-apl (list OP-OR-LOOP-ARG ...)))))
(provide bf-program)
(define-macro (loop "[" OP-OR-LOOP-ARG ... "]")
(define-macro (bf-loop "[" OP-OR-LOOP-ARG ... "]")
#'(lambda (arr ptr)
(for/fold ([current-apl (list arr ptr)])
([i (in-naturals)]
#:break (zero? (apply current-byte
current-apl)))
(fold-funcs current-apl (list OP-OR-LOOP-ARG ...)))))
(provide loop)
(define-macro-cases op
[(op ">") #'gt]
[(op "<") #'lt]
[(op "+") #'plus]
[(op "-") #'minus]
[(op ".") #'period]
[(op ",") #'comma])
(provide op)
(provide bf-loop)
(define-macro-cases bf-op
[(bf-op ">") #'gt]
[(bf-op "<") #'lt]
[(bf-op "+") #'plus]
[(bf-op "-") #'minus]
[(bf-op ".") #'period]
[(bf-op ",") #'comma])
(provide bf-op)
(define (current-byte arr ptr) (vector-ref arr ptr))

@ -1,4 +1,4 @@
#lang brag
bf-program : (op | loop)*
op : ">" | "<" | "+" | "-" | "." | ","
loop : "[" (op | loop)* "]"
bf-program : (bf-op | bf-loop)*
bf-op : ">" | "<" | "+" | "-" | "." | ","
bf-loop : "[" (bf-op | bf-loop)* "]"
Loading…
Cancel
Save