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
|
(define (tokenize ip)
|
||||||
(lexer-src-pos
|
(port-count-lines! ip)
|
||||||
|
|
||||||
|
(define lex
|
||||||
|
(lexer
|
||||||
[(char-set "><-.,+[]") lexeme]
|
[(char-set "><-.,+[]") lexeme]
|
||||||
[whitespace (token '_ lexeme #:skip? #t)]
|
[whitespace (token 'white #:skip? #t)]
|
||||||
[(eof) (void)]))
|
[(eof) (void)]))
|
||||||
|
|
||||||
(define (tokenize ip)
|
(define next-token-func (λ _ (lex ip)))
|
||||||
(port-count-lines! ip)
|
next-token-func)
|
||||||
(define next-token-thunk (thunk (lex ip)))
|
|
||||||
next-token-thunk)
|
|
||||||
|
Loading…
Reference in New Issue