rearrangements
parent
ff4bda8ee3
commit
642ebc436a
@ -0,0 +1,61 @@
|
||||
#lang br/quicklang
|
||||
|
||||
(define-macro (bf-module-begin PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
PARSE-TREE))
|
||||
(provide (rename-out [bf-module-begin #%module-begin]))
|
||||
|
||||
(define (fold-funcs apl bf-funcs)
|
||||
(for/fold ([current-apl apl])
|
||||
([bf-func (in-list bf-funcs)])
|
||||
(apply bf-func current-apl)))
|
||||
|
||||
(define-macro (bf-program OP-OR-LOOP-ARG ...)
|
||||
#'(begin
|
||||
(define first-apl (list (make-vector 30000 0) 0))
|
||||
(void (fold-funcs first-apl (list OP-OR-LOOP-ARG ...)))))
|
||||
(provide bf-program)
|
||||
|
||||
(define-macro (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)
|
||||
|
||||
(define (current-byte arr ptr) (vector-ref arr ptr))
|
||||
|
||||
(define (set-current-byte arr ptr val)
|
||||
(define new-arr (vector-copy arr))
|
||||
(vector-set! new-arr ptr val)
|
||||
new-arr)
|
||||
|
||||
(define (gt arr ptr) (list arr (add1 ptr)))
|
||||
(define (lt arr ptr) (list arr (sub1 ptr)))
|
||||
|
||||
(define (plus arr ptr)
|
||||
(list (set-current-byte arr ptr (add1 (current-byte arr ptr)))
|
||||
ptr))
|
||||
|
||||
(define (minus arr ptr)
|
||||
(list (set-current-byte arr ptr (sub1 (current-byte arr ptr)))
|
||||
ptr))
|
||||
|
||||
(define (period arr ptr)
|
||||
(write-byte (current-byte arr ptr))
|
||||
(list arr ptr))
|
||||
|
||||
(define (comma arr ptr)
|
||||
(list (set-current-byte arr ptr (read-byte)) ptr))
|
||||
|
@ -0,0 +1,3 @@
|
||||
#lang br
|
||||
(require "parser.rkt")
|
||||
(parse-tree "++++-+++-++-++[>++++-+++-++-++<-]>.")
|
@ -1,4 +1,4 @@
|
||||
#lang brag
|
||||
bf-program : (op | loop)*
|
||||
op : ">" | "<" | "+" | "-" | "." | ","
|
||||
loop : "[" (op | loop)* "]"
|
||||
op : ">" | "<" | "+" | "-" | "." | ","
|
||||
loop : "[" (op | loop)* "]"
|
@ -0,0 +1,6 @@
|
||||
#lang reader "funstacker.rkt"
|
||||
4
|
||||
8
|
||||
+
|
||||
3
|
||||
*
|
@ -1,8 +0,0 @@
|
||||
#lang reader br/demo/funstacker
|
||||
4
|
||||
8
|
||||
|
||||
+
|
||||
3
|
||||
|
||||
*
|
@ -1,14 +1,11 @@
|
||||
#lang br
|
||||
(require br/indent racket/gui/base)
|
||||
(require br/indent racket/gui/base racket/contract)
|
||||
(provide indent-jsonic)
|
||||
|
||||
(define indent-width 2)
|
||||
(define (left-bracket? c) (member c (list #\{ #\[)))
|
||||
(define (right-bracket? c) (member c (list #\} #\])))
|
||||
|
||||
;; if this line begins with } or ], outdent.
|
||||
;; if last line begins with { or [, indent.
|
||||
;; otherwise use previous indent
|
||||
(define/contract (indent-jsonic tbox [posn 0])
|
||||
((is-a?/c text%) exact-nonnegative-integer? . -> .
|
||||
(or/c exact-nonnegative-integer? #f))
|
@ -1,4 +1,4 @@
|
||||
#lang br/demo/jsonic-2
|
||||
#lang jsonic-demo-2
|
||||
// a line comment
|
||||
[
|
||||
@$ 'null $@,
|
@ -1,6 +1,5 @@
|
||||
#lang br
|
||||
(require "parser.rkt" "tokenizer.rkt"
|
||||
brag/support rackunit)
|
||||
(require "parser.rkt" "tokenizer.rkt" brag/support rackunit)
|
||||
|
||||
(check-equal?
|
||||
(parse-tree (apply-tokenizer tokenize "// line commment\n"))
|
@ -1,10 +1,10 @@
|
||||
#lang br/quicklang
|
||||
(require "tokenizer.rkt" "parser.rkt")
|
||||
(require "tokenizer.rkt" "parser.rkt" racket/contract)
|
||||
|
||||
(define/contract (read-syntax path port)
|
||||
(any/c input-port? . -> . syntax?)
|
||||
(define parse-tree (parse path (tokenize port)))
|
||||
(define module-datum `(module jsonic-module br/demo/jsonic-2/expander
|
||||
(define module-datum `(module jsonic-module jsonic-demo-2/expander
|
||||
,parse-tree))
|
||||
(datum->syntax #f module-datum))
|
||||
(provide read-syntax)
|
@ -1,5 +1,5 @@
|
||||
#lang br/quicklang
|
||||
(require brag/support)
|
||||
(require brag/support racket/contract)
|
||||
|
||||
(module+ test
|
||||
(require rackunit))
|
@ -1,8 +1,9 @@
|
||||
#lang br/quicklang
|
||||
(require "tokenizer.rkt" "parser.rkt")
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (tokenize port)))
|
||||
(define module-datum `(module jsonic-module br/demo/jsonic/expander
|
||||
(define module-datum `(module jsonic-module jsonic-demo/expander
|
||||
,parse-tree))
|
||||
(datum->syntax #f module-datum))
|
||||
(provide read-syntax)
|
@ -1,4 +1,4 @@
|
||||
#lang br/demo/wires
|
||||
#lang wires-demo
|
||||
x AND y -> d
|
||||
x OR y -> e
|
||||
x LSHIFT 2 -> f
|
Loading…
Reference in New Issue