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 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)))
|
||||||
(define my-lexer
|
next-token-thunk)
|
||||||
(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)
|
|
||||||
|
Loading…
Reference in New Issue