br-bf start

This commit is contained in:
Matthew Butterick 2016-04-07 12:42:28 -07:00
parent 6f5b70086a
commit 1181bdfed1
4 changed files with 58 additions and 0 deletions

14
br-bf/main.rkt Normal file
View File

@ -0,0 +1,14 @@
#lang br
(module reader syntax/module-reader
#:language 'br-bf
#:read bf-read
#:read-syntax bf-read-syntax
(require "tokenizer.rkt" "parser.rkt")
(define (bf-read in)
(syntax->datum (bf-read-syntax #f in)))
(define (bf-read-syntax src ip)
(list (parse src (tokenize ip)))))

10
br-bf/parser.rkt Normal file
View File

@ -0,0 +1,10 @@
#lang ragg
<expr> : ">"
| "<"
| "+"
| "-"
| "."
| ","
| <loop>
<loop> : "["<expr>*"]"

10
br-bf/reader.rkt Normal file
View File

@ -0,0 +1,10 @@
#lang ragg
<expr> : ">"
| "<"
| "+"
| "-"
| "."
| ","
| <loop>
<loop> : "["<expr>*"]"

24
br-bf/tokenizer.rkt Normal file
View File

@ -0,0 +1,24 @@
#lang racket/base
(require parser-tools/lex ragg/support)
(provide tokenize)
(define (tokenize ip)
(port-count-lines! ip)
(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)