Remove keywords and maps from k_prime to make it leaner

This commit is contained in:
Nathan Braswell
2020-04-12 00:25:11 -04:00
parent c4078aa5e1
commit cb54429d1a
2 changed files with 29 additions and 272 deletions

33
bf.kp
View File

@@ -1,34 +1,33 @@
; Now we have native BF support
(def! with_update (fn* [arr idx val]
(if
(= idx 0)
(cons val (rest arr))
(cons (first arr) (with_update (rest arr) (- idx 1) val)))))
(if (= idx 0)
(cons val (rest arr))
(cons (first arr) (with_update (rest arr) (- idx 1) val)))))
(add_grammer_rule :bfs_atom ["<"] (fn* [xs] (list 'left)))
(add_grammer_rule :bfs_atom [">"] (fn* [xs] (list 'right)))
(add_grammer_rule :bfs_atom ["\\+"] (fn* [xs] (list 'plus)))
(add_grammer_rule :bfs_atom ["-"] (fn* [xs] (list 'minus)))
(add_grammer_rule :bfs_atom [","] (fn* [xs] (list 'in)))
(add_grammer_rule :bfs_atom ["."] (fn* [xs] (list 'out)))
(add_grammer_rule 'bfs_atom ["<"] (fn* [xs] (list 'left)))
(add_grammer_rule 'bfs_atom [">"] (fn* [xs] (list 'right)))
(add_grammer_rule 'bfs_atom ["\\+"] (fn* [xs] (list 'plus)))
(add_grammer_rule 'bfs_atom ["-"] (fn* [xs] (list 'minus)))
(add_grammer_rule 'bfs_atom [","] (fn* [xs] (list 'in)))
(add_grammer_rule 'bfs_atom ["."] (fn* [xs] (list 'out)))
(add_grammer_rule :non_empty_bfs_list [:bfs_atom] (fn* [xs] (list (nth xs 0))))
(add_grammer_rule :non_empty_bfs_list [:bfs_atom :optional_WS :non_empty_bfs_list] (fn* [xs] (cons (nth xs 0) (nth xs 2))))
(add_grammer_rule 'non_empty_bfs_list ['bfs_atom] (fn* [xs] (list (nth xs 0))))
(add_grammer_rule 'non_empty_bfs_list ['bfs_atom 'optional_WS 'non_empty_bfs_list] (fn* [xs] (cons (nth xs 0) (nth xs 2))))
(add_grammer_rule :bfs_list [] (fn* [xs] xs))
(add_grammer_rule :bfs_list [:non_empty_bfs_list] (fn* [xs] (nth xs 0)))
(add_grammer_rule 'bfs_list [] (fn* [xs] xs))
(add_grammer_rule 'bfs_list ['non_empty_bfs_list] (fn* [xs] (nth xs 0)))
(add_grammer_rule :bfs_atom ["\\[" :bfs_list "]"] (fn* [xs]
(add_grammer_rule 'bfs_atom ["\\[" 'bfs_list "]"] (fn* [xs]
`(let* (f (fn* []
(if (= 0 (nth (deref arr) (deref ptr)))
nil
(do ,(nth xs 1) (f)))))
(f))))
(add_grammer_rule :bfs [:bfs_list] (fn* [xs] (nth xs 0)))
(add_grammer_rule 'bfs ['bfs_list] (fn* [xs] (nth xs 0)))
(add_grammer_rule :form ["bf" :optional_WS "{" :optional_WS :bfs :optional_WS "}"]
(add_grammer_rule 'form ["bf" 'optional_WS "{" 'optional_WS 'bfs 'optional_WS "}"]
(fn* [xs]
`(fn* [input]
(let* (