br-bf starts to work
parent
d267498935
commit
96c14719cf
@ -0,0 +1,12 @@
|
||||
#lang br-bf
|
||||
+++++++++++
|
||||
>+>>>>++++++++++++++++++++++++++++++++++++++++++++
|
||||
>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
|
||||
+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
|
||||
<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
|
||||
-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
|
||||
>[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
|
||||
+++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
|
||||
++++++++++++++++++++++++++++++++++++++++++++.[-]<<
|
||||
<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
|
||||
[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
|
@ -0,0 +1,4 @@
|
||||
#lang racket
|
||||
(require "tokenizer.rkt" "parser.rkt" ragg/support)
|
||||
|
||||
(syntax->datum (parse (tokenize (open-input-string "[+-]>"))))
|
@ -1,10 +1,10 @@
|
||||
#lang ragg
|
||||
|
||||
<expr> : ">"
|
||||
bf-program : expr*
|
||||
expr : ">"
|
||||
| "<"
|
||||
| "+"
|
||||
| "-"
|
||||
| "."
|
||||
| ","
|
||||
| <loop>
|
||||
<loop> : "["<expr>*"]"
|
||||
| loop
|
||||
loop : "[" expr* "]"
|
@ -1,24 +1,14 @@
|
||||
#lang racket/base
|
||||
(require parser-tools/lex ragg/support)
|
||||
(provide tokenize)
|
||||
(require parser-tools/lex ragg/support racket/function)
|
||||
(provide tokenize lex)
|
||||
|
||||
(define (tokenize ip)
|
||||
(port-count-lines! ip)
|
||||
(define lex
|
||||
(lexer-src-pos
|
||||
[(char-set "><-.,+[]") lexeme]
|
||||
[whitespace (token '_ lexeme #:skip? #t)]
|
||||
[(eof) (void)]))
|
||||
|
||||
(define my-lexer
|
||||
(lexer-src-pos
|
||||
[(repetition 1 +inf.0 numeric)
|
||||
(token 'INTEGER (string->number lexeme))]
|
||||
[upper-case
|
||||
(token 'STRING lexeme)]
|
||||
["b"
|
||||
(token 'STRING " ")]
|
||||
[";"
|
||||
(token ";" lexeme)]
|
||||
[whitespace
|
||||
(token 'WHITESPACE lexeme #:skip? #t)]
|
||||
[(eof)
|
||||
(void)]))
|
||||
|
||||
(define (next-token) (my-lexer ip))
|
||||
next-token)
|
||||
(define (tokenize ip)
|
||||
(port-count-lines! ip)
|
||||
(define next-token-thunk (thunk (lex ip)))
|
||||
next-token-thunk)
|
||||
|
Loading…
Reference in New Issue