improvements
parent
96c14719cf
commit
948f40e002
@ -0,0 +1,2 @@
|
|||||||
|
#lang s-exp br-bf
|
||||||
|
(bf-program (op "+") (op "+") (op "+") (op "+") (op "+") (op "+") (op "+") (op (loop "[" (op ">") (op "+") (op "+") (op "+") (op "+") (op "+") (op "<") (op "-") "]")) (op ">") (op "."))
|
@ -0,0 +1,2 @@
|
|||||||
|
#lang br-bf
|
||||||
|
+++++++[>+++++<-]>.
|
@ -1,10 +1,7 @@
|
|||||||
#lang ragg
|
#lang ragg
|
||||||
bf-program : expr*
|
;; use uppercase TOKEN-IDENTIFIERS for classes of tokens
|
||||||
expr : ">"
|
;; too numerous to indicate individually
|
||||||
| "<"
|
;; (e.g., numbers, strings)
|
||||||
| "+"
|
bf-program : op*
|
||||||
| "-"
|
op : ">" | "<" | "+" | "-" | "." | "," | loop
|
||||||
| "."
|
loop : "[" op* "]"
|
||||||
| ","
|
|
||||||
| loop
|
|
||||||
loop : "[" expr* "]"
|
|
@ -1,14 +1,15 @@
|
|||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require parser-tools/lex ragg/support racket/function)
|
(require parser-tools/lex ragg/support)
|
||||||
(provide tokenize lex)
|
(provide tokenize)
|
||||||
|
|
||||||
(define lex
|
|
||||||
(lexer-src-pos
|
|
||||||
[(char-set "><-.,+[]") lexeme]
|
|
||||||
[whitespace (token '_ lexeme #:skip? #t)]
|
|
||||||
[(eof) (void)]))
|
|
||||||
|
|
||||||
(define (tokenize ip)
|
(define (tokenize ip)
|
||||||
(port-count-lines! ip)
|
(port-count-lines! ip)
|
||||||
(define next-token-thunk (thunk (lex ip)))
|
|
||||||
next-token-thunk)
|
(define lex
|
||||||
|
(lexer
|
||||||
|
[(char-set "><-.,+[]") lexeme]
|
||||||
|
[whitespace (token 'white #:skip? #t)]
|
||||||
|
[(eof) (void)]))
|
||||||
|
|
||||||
|
(define next-token-func (λ _ (lex ip)))
|
||||||
|
next-token-func)
|
||||||
|
Loading…
Reference in New Issue