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
|
#lang ragg
|
||||||
|
bf-program : expr*
|
||||||
<expr> : ">"
|
expr : ">"
|
||||||
| "<"
|
| "<"
|
||||||
| "+"
|
| "+"
|
||||||
| "-"
|
| "-"
|
||||||
| "."
|
| "."
|
||||||
| ","
|
| ","
|
||||||
| <loop>
|
| loop
|
||||||
<loop> : "["<expr>*"]"
|
loop : "[" expr* "]"
|
@ -1,24 +1,14 @@
|
|||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require parser-tools/lex ragg/support)
|
(require parser-tools/lex ragg/support racket/function)
|
||||||
(provide tokenize)
|
(provide tokenize lex)
|
||||||
|
|
||||||
(define (tokenize ip)
|
(define lex
|
||||||
(port-count-lines! ip)
|
(lexer-src-pos
|
||||||
|
[(char-set "><-.,+[]") lexeme]
|
||||||
|
[whitespace (token '_ lexeme #:skip? #t)]
|
||||||
|
[(eof) (void)]))
|
||||||
|
|
||||||
(define my-lexer
|
(define (tokenize ip)
|
||||||
(lexer-src-pos
|
(port-count-lines! ip)
|
||||||
[(repetition 1 +inf.0 numeric)
|
(define next-token-thunk (thunk (lex ip)))
|
||||||
(token 'INTEGER (string->number lexeme))]
|
next-token-thunk)
|
||||||
[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)
|
|
||||||
|
Loading…
Reference in New Issue