mirror of
https://github.com/vonhyou/lisp-interpreter.git
synced 2025-06-08 02:02:01 +00:00
finish an incomplete lisp interpreter
This commit is contained in:
parent
6b82c52a52
commit
b42fe1ccef
1 changed files with 1 additions and 16 deletions
17
minlisp.rb
17
minlisp.rb
|
@ -52,8 +52,6 @@ def atom(token)
|
||||||
token.to_sym
|
token.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
# p parse '(def 1 2 (c 3.3 (r f r) e))'
|
|
||||||
|
|
||||||
##### Environments
|
##### Environments
|
||||||
|
|
||||||
def generate_env
|
def generate_env
|
||||||
|
@ -78,14 +76,6 @@ def generate_env
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# puts lisp_env[:+].call 1, 2, 3
|
|
||||||
# puts lisp_env[:-].call 1, 2, 3
|
|
||||||
# puts lisp_env[:*].call 2, 3, 4
|
|
||||||
# puts lisp_env[:/].call 9, 5, 1
|
|
||||||
# puts lisp_env[:>].call 1, 2
|
|
||||||
# p lisp_env[:car].call [1, 2, 3]
|
|
||||||
# p lisp_env[:cdr].call [1, 2, 3]
|
|
||||||
|
|
||||||
##### Lisp Eval
|
##### Lisp Eval
|
||||||
|
|
||||||
$global_env = generate_env
|
$global_env = generate_env
|
||||||
|
@ -109,10 +99,6 @@ def lisp_eval(elem, env = $global_env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# p lisp_eval(parse '(/ (+ 1 (* 2 3) 1 1 (+ 1 (- 7 2) 1)) 4)')
|
|
||||||
# lisp_eval(parse '(begin (def var1 7) (print (if (> var1 1) (+ 1 30) (- 10 2))))')
|
|
||||||
|
|
||||||
##### REPL
|
##### REPL
|
||||||
|
|
||||||
def repl(prompt='minlisp ƛ>> ')
|
def repl(prompt='minlisp ƛ>> ')
|
||||||
|
@ -128,5 +114,4 @@ def print_value(value)
|
||||||
puts ";Value: #{value.to_s}"
|
puts ";Value: #{value.to_s}"
|
||||||
end
|
end
|
||||||
|
|
||||||
repl()
|
# repl()
|
||||||
# p lisp_eval(parse('(if (> 7 8) (+ 3 11) (/ 7 3))'))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue