trolls of 2013ryan/presentations/2013_mwrc... · 2013-04-08 · mwrc 2013, salt lake city, ut...
TRANSCRIPT
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbTrolls of 2013
Trolls of 2013
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbTrolls of 2013
• Followup of my talk, “Occupy Ruby: Why We Need to Moderate the 1%”
• 130 Slides in 30 minutes. 4.3 spm
• I must go quickly, so please hold questions.
• Ummm... no.
Setting Expectations
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Let’s Wr!e an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Setting Expectations
• 160 Slides in 30 minutes. 5.3 spm.
• Boatloads of content. Almost all code.
• I was asked to “Hurt Brains”.
• TODO
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Expanded to 45 minutes?!?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Added15 minutes of kittens
to the end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
OMG WHY?!?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
BecauseI’m a pervert!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Wa!… No!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Because we can!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
"e “Uby”Interpreter
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Branching Logic:if/else/elsif
if condition then true_codeelse false_codeend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Loops: whilewhile condition codeend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Local Variablesmeaning = 42pi = 3
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Functionsdef fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Functions
recursive function calls
local variables
“primitive” function callsdef fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Uby Roadmap
Variables Conditionals
Runtime
Environment
Functions
Parser
Loops
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Parsing: ruby_parser
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
ConditionalsLoops
Runtime
Environment
Functions
Parser
Variables
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
RubyParser.new.parse " def fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) end end"
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
:defn
:fib
:args:n
:if
:call
:lvar :n
:<
:lit 2
:lit 1
:call
:call
nil
:fib
:call
:lvar :n
:-
:lit 2:+
:call nil :fib
:call
:lvar :n
:-
:lit 1
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
:defn
:fib
:args:n
:if
:call
:lvar :n
:<
:lit 2
:lit 1
:call
:call
nil
:fib
:call
:lvar :n
:-
:lit 2:+
:call nil :fib
:call
:lvar :n
:-
:lit 1
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
:defn
:fib
:args
:n
:if
:call
:lvar :n
:<
:lit 2
:lit 1
:call
:call
nil
:fib
:call
:lvar :n
:-
:lit 2:+
:call nil :fib
:call
:lvar :n
:-
:lit 1
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
:defn
:fib
:args
:n
:if
:call
:lvar :n
:<
:lit 2
:lit 1
:call
:call
nil
:fib
:call
:lvar :n
:-
:lit 2:+
:call nil :fib
:call
:lvar :n
:-
:lit 1
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
else
:call nil :fib
:call
:lvar :n
:-
:lit 1
:call nil :fib
:call
:lvar :n
:-
:lit 2
:call :+
condition
:call
:lvar :n
:<
:lit 2
:defn
:fib :args
:n
:if
then
:lit 1
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:defn, :fib, s(:args, :n), s(:if, s(:call, s(:lvar, :n), :<=, s(:lit, 2)), s(:lit, 1), s(:call, s(:call, nil, :fib, s(:call, s(:lvar, :n), :-, s(:lit, 2))), :+, s(:call, nil, :fib, s(:call, s(:lvar, :n), :-, s(:lit, 1))))))
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
S-Expression Vocabulary
s(:call, s(:lit, 3), :+, s(:lit, 4))
Sexp Sub-sexps
Rest(cdr)
Head/Type(car)
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
All for free using ruby_parser
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
OK…No more talk about
parsing.
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Further study on parsers:
Michael Jackson’sParsing Expressions in Ruby
MWRC 2011http://www.confreaks.com/videos/582
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Interpre#ng via sexp_processor
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
ConditionalsLoops
Environment
Variables
Functions
Parser
Runtime
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
How to get 7 from 3+4?
73 + 4 ??????
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Start with the source
3 + 4
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Parse it
3 + 4s(:call, s(:lit, 3), :+, s(:lit, 4))
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:call, s(:lit, 3), :+, s(:lit, 4))
Then process by type
3 + 4
process_call
process_lit
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:call, s(:lit, 3), :+, s(:lit, 4))
First with the inner values
3 + 4
process_lit
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:call, 3, :+, s(:lit, 4))
First with the inner values
3 + 4
process_lit
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:call, 3, :+, 4)
First with the inner values
3 + 4
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
s(:call, 3, :+, 4)
then with the outer
3 + 4
process_call
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
proc { |a, b| a + b }[3, 4]
then with the outer
3 + 4
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
proc { |a, b| a + b }[3, 4]
resulting in a final value
3 + 4 7
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
SexpProcessorclass UbyInterpreter def process_lit s s.last endend s(:lit, 3)
3
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Test Dr$en Interpreters
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Loops Conditionals
Runtime
Environment
Functions
Parser
Test
Dri
ven
Variables
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unit Testsdef test_sanity val = lang.eval("3 + 4") assert_equal 7, valend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unit TestsInput Source
Expected Value
def test_sanity val = lang.eval("3 + 4") assert_equal 7, valend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Premature Refactoring
Input SourceExpected Value
def assert_eval exp, src assert_equal exp, lang.eval(src)end
def test_sanity assert_eval 7, "3 + 4"end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
San% Test:3 + 4
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
ConditionalsLoops
Environment
Functions
Parser
Test
Dri
ven
Runtime
Variables
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Test Infrastructureclass TestUbyInterpreter < MiniTest::Unit::TestCase attr_accessor :int
def setup self.int = UbyInterpreter.new end
def assert_eval exp, src, msg = nil assert_equal exp, int.eval(src), msg endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Our First Test:class TestUbyInterpreter < MiniTest::Unit::TestCase attr_accessor :int
def setup self.int = UbyInterpreter.new end
def assert_eval exp, src assert_equal exp, ri.eval(src) end
def test_sanity assert_eval 3, "3" assert_eval 7, "3 + 4" endend
Old Code
New Code
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Our First Test:class TestUbyInterpreter < MiniTest::Unit::TestCase
# ...
def test_sanity assert_eval 3, "3" assert_eval 7, "3 + 4" endend
Old Code
New Code
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Our first error:# Running tests:
E
Finished tests in 0.000364s, 2747.2527 tests/s, 0.0000 assertions/s.
1) Error:TestUbyInterpreter#test_sanity:NameError: uninitialized constant TestUbyInterpreter::UbyInterpreter ./test/test_ruby_interpreter.rb:11:in `setup'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define the constantclass UbyInterpreter < SexpInterpreter VERSION = "1.0.0"end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Wash, rinse…# Running tests:
E
Finished tests in 0.000578s, 1730.1038 tests/s, 0.0000 assertions/s.
1) Error:TestUbyInterpreter#test_sanity:NoMethodError: private method `eval' called for #<UbyInterpreter:0x105be17d8> ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:19:in `test_sanity'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Implement eval & parseclass UbyInterpreter < SexpInterpreter # ... attr_accessor :parser
def initialize super
self.parser = Ruby19Parser.new end
def eval src process parse src end
def parse src self.parser.process src endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Finally!# Running tests:
E
Finished tests in 0.001365s, 732.6007 tests/s, 0.0000 assertions/s.
1) Error:TestUbyInterpreter#test_sanity:UnknownNodeError: Bug! Unknown node-type :lit to UbyInterpreter ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:19:in `test_sanity'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Implement process_litclass UbyInterpreter < SexpInterpreter
# ...
def process_lit s s.last endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Tada! Second Assertion! 1) Error:TestUbyInterpreter#test_sanity:UnknownNodeError: Bug! Unknown node-type :call to UbyInterpreter ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:20:in `test_sanity'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :call genericallyclass UbyInterpreter < SexpInterpreter
# ...
def process_call s raise "Boom: #{s.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
See sub-sexps 1) Error:TestUbyInterpreter#test_sanity:RuntimeError: Boom: s(:call, s(:lit, 3), :+, s(:lit, 4)) ./lib/ruby_interpreter.rb:35:in `process_call' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:17:in `assert_eval' ./test/test_ruby_interpreter.rb:22:in `test_sanity'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unpack sub-sexpsclass UbyInterpreter < SexpInterpreter
# ...
def process_call s _, recv, msg, *args = s
raise "Boom: #{recv}, #{msg}, #{args.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unpacked sub-sexps 1) Error:TestUbyInterpreter#test_sanity:RuntimeError: Boom: s(:lit, 3), +, [s(:lit, 4)] ./lib/ruby_interpreter.rb:31:in `process_call'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Process sub-sexpsclass UbyInterpreter < SexpInterpreter def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
raise "Boom: #{recv}, #{msg}, #{args.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Processed Values 1) Error:TestUbyInterpreter#test_sanity:RuntimeError: Boom: 3, +, [4] ./lib/ruby_interpreter.rb:43:in `process_call'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Cheat: Send to Rubyclass UbyInterpreter < SexpInterpreter def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
recv.send(msg, *args) # big ol' hack… endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Sanity!# Running tests:
.
Finished tests in 0.001625s, 615.3846 tests/s, 1230.7692 assertions/s.
1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!class UbyInterpreter < SexpInterpreter VERSION = "1.0.0"
attr_accessor :parser
def initialize super self.parser = Ruby19Parser.new end
def eval src process parse src end
def parse src self.parser.process src end
def process_lit s s.last end
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
recv.send(msg, *args) # big ol' hack… endend
Yay!
Overblown
Calculator!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Cond!ionals&
Truthiness
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Loops
Runtime
Environment
Variables
Functions
Parser
Test
Dri
ven
Conditionals
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Add :if testsclass TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def test_if assert_eval 42, "if true then 42 else 24 end" end
def test_if_falsey assert_eval 24, "if nil then 42 else 24 end" assert_eval 24, "if false then 42 else 24 end" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unknown :if 1) Error:TestUbyInterpreter#test_if:UnknownNodeError: Bug! Unknown node-type :if to UbyInterpreter ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:34:in `test_if'
2) Error:TestUbyInterpreter#test_if_falsey:UnknownNodeError: Bug! Unknown node-type :if to UbyInterpreter ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:38:in `test_if_falsey'
3 tests, 2 assertions, 0 failures, 2 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :if genericallyclass UbyInterpreter < SexpInterpreter # ...
def process_if s raise "Boom: #{s.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
See sub-sexps 1) Error:TestUbyInterpreter#test_if:RuntimeError: Boom: s(:if, s(:true), s(:lit, 42), s(:lit, 24)) ./lib/ruby_interpreter.rb:38:in `process_if' ... ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:34:in `test_if'
2) Error:TestUbyInterpreter#test_if_falsey:RuntimeError: Boom: s(:if, s(:nil), s(:lit, 42), s(:lit, 24)) ./lib/ruby_interpreter.rb:38:in `process_if' ... ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:38:in `test_if_falsey'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Process sub-sexpsclass UbyInterpreter < SexpInterpreter # ...
def process_if s _, c, t, f = s
c = process c
if c then process t else process f end endend
Why evaluate c before t &
f?
if true then puts "happy"else system "rm -rf /"end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Sub-sexps fail 1) Error:TestUbyInterpreter#test_if:UnknownNodeError: Bug! Unknown node-type :true to UbyInterpreter ./lib/ruby_interpreter.rb:40:in `process_if' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:34:in `test_if'
2) Error:TestUbyInterpreter#test_if_falsey:UnknownNodeError: Bug! Unknown node-type :nil to UbyInterpreter ./lib/ruby_interpreter.rb:40:in `process_if' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:38:in `test_if_falsey'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :nil and :trueclass UbyInterpreter < SexpInterpreter # ...
def process_nil s nil end
def process_true s true endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Third failure 1) Error:TestUbyInterpreter#test_if_falsey:UnknownNodeError: Bug! Unknown node-type :false to UbyInterpreter ./lib/ruby_interpreter.rb:40:in `process_if' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:39:in `test_if_falsey'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :falseclass UbyInterpreter < SexpInterpreter # ...
def process_false s false endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Voilà!# Running tests:
...
Finished tests in 0.002860s, 1048.9510 tests/s, 1748.2517 assertions/s.
3 tests, 5 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Test Driven Process
Processsub-sexps
Tests Pass
Add afailing test
Errornode-type
Add genericnode-type
Failure sub-sexpcomponents
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Yes, development this fast…
with autotest.
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Brain Hurt Yet?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Good
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Wait till I get going!
Where was I?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Local Variables
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Loops Conditionals
Runtime
Functions
Parser
Test
Dri
ven
Variables
Environment
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Local Variables!class TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def test_lvar assert_eval 42, "x = 42; x" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Block?!? 1) Error:TestUbyInterpreter#test_lvar:UnknownNodeError: Bug! Unknown node-type :block to UbyInterpreter ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:24:in `test_lvar'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :blockclass UbyInterpreter < SexpInterpreter # ...
def process_block s raise "Boom: #{s.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Ohhh… 1) Error:TestUbyInterpreter#test_lvar:RuntimeError: Boom: s(:block, s(:lasgn, :x, s(:lit, 42)), s(:lvar, :x)) ./lib/ruby_interpreter.rb:25:in `process_block' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:24:in `test_lvar'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Process all sub-sexpsclass UbyInterpreter < SexpInterpreter # ...
def process_block s result = nil s.rest.each do |sub| result = process sub end result endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
:lasgn is undefined 1) Error:TestUbyInterpreter#test_lvar:UnknownNodeError: Bug! Unknown node-type :lasgn to UbyInterpreter ./lib/ruby_interpreter.rb:27:in `process_block' ./lib/ruby_interpreter.rb:26:in `each' ./lib/ruby_interpreter.rb:26:in `process_block' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:24:in `test_lvar'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :lasgnclass UbyInterpreter < SexpInterpreter # ...
def process_lasgn s raise "Boom: #{s.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Looks like name/value 1) Error:TestUbyInterpreter#test_lvar:RuntimeError: Boom: s(:lasgn, :x, s(:lit, 42)) ./lib/ruby_interpreter.rb:58:in `process_lasgn' ./lib/ruby_interpreter.rb:27:in `process_block' ./lib/ruby_interpreter.rb:26:in `each' ./lib/ruby_interpreter.rb:26:in `process_block' ./lib/ruby_interpreter.rb:17:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:24:in `test_lvar'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Add a stupid tableclass UbyInterpreter < SexpInterpreter # ...
attr_accessor :env
def initialize # ... self.env = {} # omg this is horrible end
def process_lasgn s _, n, v = s
self.env[n] = process v endend
EnvironmentEnvironment
x 42
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Now we need to read 1) Error:TestUbyInterpreter#test_lvar:UnknownNodeError: Bug! Unknown node-type :lvar to UbyInterpreter ./lib/ruby_interpreter.rb:29:in `process_block' ./lib/ruby_interpreter.rb:28:in `each' ./lib/ruby_interpreter.rb:28:in `process_block' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:24:in `test_lvar'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Access the tableclass UbyInterpreter < SexpInterpreter # ...
def process_lvar s _, name = s
self.env[name] endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Voilà# Running tests:
....
Finished tests in 0.003666s, 1091.1075 tests/s, 1636.6612 assertions/s.
4 tests, 6 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Just wait…
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
It gets “better”
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Fun&ions
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Conditionals
Runtime
Environment
Variables
Parser
Test
Dri
ven
Loops
Functions
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Add :defn Testclass TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def test_defn assert_eval nil, <<-EOM def double n 2 * n end EOM
assert_eval 42, "double(21)" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unknown :defn 1) Error:TestUbyInterpreter#test_defn:UnknownNodeError: Bug! Unknown node-type :defn to UbyInterpreter ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:17:in `assert_eval' ./test/test_ruby_interpreter.rb:45:in `test_defn'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Generic :defnclass UbyInterpreter < SexpInterpreter # ...
def process_defn s raise "Boom: #{s.inspect}" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Examine sub-sexps 1) Error:TestUbyInterpreter#test_defn:RuntimeError: Boom: s(:defn, :double, s(:args, :n), s(:call, s(:lit, 2), :*, s(:lvar, :n))) ./lib/ruby_interpreter.rb:44:in `process_defn' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:17:in `assert_eval' ./test/test_ruby_interpreter.rb:45:in `test_defn'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unpack & Storeclass UbyInterpreter < SexpInterpreter # ...
def process_defn s _, name, args, *body = s
self.env[name] = [args, body]
nil endend
EnvironmentEnvironment
n 8
life 42
pi 3
double
[ s(:args, :n),
[s(:call, s(:lit, 2), :*, s(:lvar, :n))]]
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
What’s up with :call? 1) Error:TestUbyInterpreter#test_defn:NoMethodError: undefined method `double' for nil:NilClass ./lib/ruby_interpreter.rb:40:in `send' ./lib/ruby_interpreter.rb:40:in `process_call' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:17:in `assert_eval' ./test/test_ruby_interpreter.rb:54:in `test_defn'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
No NilClass#doubleclass UbyInterpreter < SexpInterpreter # ...
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
recv.send(msg, *args) # big ol' hack… endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Isolate the Problemclass UbyInterpreter < SexpInterpreter # ...
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
if recv then recv.send(msg, *args) # less of a hack else raise "argh" end endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Error, Isolated 1) Error:TestUbyInterpreter#test_defn:RuntimeError: argh ./lib/ruby_interpreter.rb:43:in `process_call' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:17:in `assert_eval' ./test/test_ruby_interpreter.rb:54:in `test_defn'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Set vars & run the codeclass UbyInterpreter < SexpInterpreter # ...
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
if recv then recv.send(msg, *args) # less of a hack else decls, body = self.env[msg]
decls.rest.zip(args).each do |name, val| self.env[name] = val end
process_block s(:block, *body) end endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
args... decls... zip bwuh?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
EnvironmentEnvironment
n 21
life 42
pi 3
double
[ s(:args, :n),
s(:call, s(:lit, 2), :*, s(:lvar, :n))]
EnvironmentEnvironment
n 8
life 42
pi 3
double
[ s(:args, :n),
s(:call, s(:lit, 2), :*, s(:lvar, :n))]
s(:call, nil, :double, s(:lit, 21))
decls.rest.zip(args).each do |k, v| self.env[k] = vend
[:n].zip([21]).each do |k, v| self.env[k] = vend
self.env[:n] = 21
decls
args
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Voilà!# Running tests:
.....
Finished tests in 0.011826s, 422.7972 tests/s, 676.4756 assertions/s.
5 tests, 8 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
“Getting to green just means you don’t have enough
tests.”– Kent Beck
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Fibonacci
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Conditionals
Runtime
Parser
Test
Dri
ven
Environment
Loops
Functions
Variables
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Finally Freakin’ Fibonacci!class TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def test_fib assert_eval nil, <<-END def fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) end end END
assert_eval 8, "fib(6)" endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Whoa… it ran… but failed 1) Failure:TestUbyInterpreter#test_fib [./test/test_ruby_interpreter.rb:71]:Expected: 8 Actual: 3
6 tests, 10 assertions, 1 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
EnvironmentEnvironment
n 4
life 42
pi 3
fib
[ s(:args, :n),
s(:if, ...)]
EnvironmentEnvironment
n 6
life 42
pi 3
fib
[ s(:args, :n),
s(:if, ...)]
EnvironmentEnvironment
n 8
life 42
pi 3
fib
[ s(:args, :n),
s(:if, ...)]
That stupid Table?Yeah...
def fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) endendn = 8; fib(6)n = 6; fib(4) + fib(5)n = 4; ... and so on...
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
[ s(:args, :n),
s(:if, ...)]
fib
3pi
42life
n 8
[ s(:args, :n),
s(:if, ...)]
fib
3pi
42life
n 5
[ s(:args, :n),
s(:if, ...)]
fib
3pi
42life
n 3
[ s(:args, :n),
s(:if, ...)]
fib
3pi
42life
n 1
Wanted: Stacked Hashn 1
n 3
n 5
[ s(:args, :n),
s(:if, ...)]
fib
3pi
42life
n 8
fib(1)
fib(3)
fib(5)
original
but acts like:
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
6z
5y
4x
2b
3c
42x
1a
z 6
y 5
x 42
3c
2b
1a
Environment Classenv[:x] == ?
env[:x] = 42
all:
scope:
scope:
scope:
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!class UbyInterpreter < SexpInterpreter # ...
class Environment def [] k self.all[k] end
def []= k, v @env.last[k] = v end
def all @env.inject(&:merge) end
def scope @env.push({})
yield ensure @env.pop end
def initialize @env = [{}] end endend
Writes to top layer only
Reads from everything
Flattened. Newest wins
Automatic layering
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Replace stupid tableclass UbyInterpreter < SexpInterpreter # ...
def initialize # ... self.env = Environment.new end
# ...end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Scope every callclass UbyInterpreter < SexpInterpreter # ...
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
if recv then recv.send(msg, *args) # less of a hack else self.env.scope do decls.rest.zip(args).each do |name, val| self.env[name] = val end
process_block s(:block, *body) end end endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Finally# Running tests:
......
Finished tests in 0.016849s, 356.1042 tests/s, 712.2084 assertions/s.
6 tests, 12 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
While Loops
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Runtime
Environment
Variables
Functions
Parser
Test
Dri
ven
ConditionalsLoops
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Refactor Fibonnaciclass TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def define_fib assert_eval nil, <<-END def fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) end end END endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Add :while testsclass TestUbyInterpreter < MiniTest::Unit::TestCase # ...
def test_while_sum_of_fibs define_fib
assert_eval 1+1+2+3+5+8+13+21+34+55, <<-EOM n = 1 sum = 0 while n <= 10 sum += fib(n) n += 1 end sum EOM endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Unknown :while 1) Error:TestUbyInterpreter#test_while_fib:UnknownNodeError: Bug! Unknown node-type :while to UbyInterpreter ./lib/ruby_interpreter.rb:29:in `process_block' ./lib/ruby_interpreter.rb:28:in `each' ./lib/ruby_interpreter.rb:28:in `process_block' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:86:in `test_while_fib'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :while genericallyclass UbyInterpreter < SexpInterpreter # ...
def process_while s raise "Boom: #{s.inspect} endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
See sub-sexps 1) Error:TestUbyInterpreter#test_while:RuntimeError: Boom: s(:while, s(:call, s(:lvar, :n), :<, s(:lit, 41)), s(:lasgn, :n, s(:call, s(:lvar, :n), :+, s(:lit, 1))), true) ./lib/ruby_interpreter.rb:104:in `process_while' ./lib/ruby_interpreter.rb:29:in `process_block' ./lib/ruby_interpreter.rb:28:in `each' ./lib/ruby_interpreter.rb:28:in `process_block' ./lib/ruby_interpreter.rb:19:in `eval' ./test/test_ruby_interpreter.rb:15:in `assert_eval' ./test/test_ruby_interpreter.rb:62:in `test_while'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Define :whileclass UbyInterpreter < SexpInterpreter # ...
def process_while s _, cond, *body = s body.pop # pre vs post condition -- ignore for now
while process cond process_block s(:block, *body) end endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Voilà# Running tests:
.......
Finished tests in 0.020218s, 346.2261 tests/s, 544.0696 assertions/s.
7 tests, 11 assertions, 0 failures, 0 errors, 0 skips
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
What Have We Done?
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!require "ruby_parser"require "sexp_processor"
class UbyInterpreter < SexpInterpreter VERSION = "1.0.0"
attr_accessor :parser attr_accessor :env
def initialize super
self.parser = Ruby19Parser. new self.env = Environment.new end
def eval src process parse src end
def parse src self.parser.process src end
def process_block s result = nil s.rest.each do |sub| result = process sub end result end
def process_call s _, recv, msg, *args = s
recv = process recv args.map! { |sub| process sub }
if recv then recv.send(msg, *args) else d, body = self.env[msg]
self.env.scope do d.rest.zip(args). each do |k, v| self.env[k] = v end
process_block s(:block, *body) end end end
def process_defn s _, name, args, *body = s
self.env[name] = [args, body]
nil end
def process_false s false end
def process_if s _, c, t, f = s
c = process c
if c then process t else process f end end
def process_lasgn s _, name, val = s
self.env[name] = process val end
def process_lit s s.last end
def process_lvar s _, name = s
self.env[name] end
def process_nil s nil end
def process_true s true end
def process_while s _, cond, *body = s body.pop
while process cond process_block s(:block, *body) end end
class Environment def [] k self.all[k] end
def []= k, v @env.last[k] = v end
def all @env.inject(&:merge) end
def scope @env.push({})
yield ensure @env.pop end
def initialize @env = [{}] end endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
class TestUbyInterpreter < MiniTest::Unit::TestCase attr_accessor :int
def setup self.int = UbyInterpreter.new end
def assert_eval exp, src, msg = nil assert_equal exp, int.eval(src), msg end
def define_fib assert_eval nil, <<-END def fib n if n <= 2 then 1 else fib(n-2) + fib(n-1) end end END end
def test_sanity assert_eval 3, "3" assert_eval 7, "3 + 4" end
def test_defn assert_eval nil, <<-EOM n = 24 def double n 2 * n end EOM
assert_eval 42, "double(21)" end
def test_fib define_fib
assert_eval 8, "fib(6)" end
def test_if assert_eval 42, "if true then 42 else 24 end" end
def test_if_falsey assert_eval 24, "if nil then 42 else 24 end" assert_eval 24, "if false then 42 else 24 end" end
def test_lvar assert_eval 42, "x = 42; x" end
def test_while_fib define_fib
assert_eval 1+1+2+3+5+8+13+21+34+55, <<-EOM n = 1 sum = 0 while n <= 10 sum += fib(n) n += 1 end sum EOM endend
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
“Uby” Language
• Basic numeric types, true, false, nil.• Conditional branching and looping.• Primitive & user defined functions.• Local variables & variable scoping.• Test-driven, extensible, patterns-based design.• ~2 hours, ~130 LOC impl, ~70 LOC test.• Fits in one head.
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
What Else Can We Do?• Add richer types: strings, arrays, hashes, etc.
• Enforce different scoping rules (eg. ruby's opaque def).
• Implement recursive tail-calls.
• Add an object system.
• Change the way functions are called.
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Further Study
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Fantastic Books
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
No time for questions?
Please grab me in the hallway.
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
"ank You…
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Bonus:Life T'
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Typeface:L$o(
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Rubyb g k p q" ) ∂
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Scoring Ligatured Wordsligatures = /NN|OO|TT|Qu|fff|tt|www|[HMN]E|[HN]K|(?:ff|[Tcfs])h|(?:ff|[cfs])k|(?:ff|[cfi])t|(?:ff|it|tt|[frt])y|[is]p|tt?i|O[CG]|i[vw]|ff?[bj]/
dict = File.readlines("/usr/share/dict/words").map(&:chomp)words = Hash.new 0
dict.each do |word| start = 0
hits = word.scan(ligatures) words[word] = hits.size unless hits.empty?end
words.sort_by { |w,v| [-v, w] }.each do |word, score| puts "%2d: %s" % [score, word]end
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
Ar+!e&onicapen!en#a(,'an!produ"#$
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
MWRC 2013, Salt Lake City, UT
Ryan Davis, Seattle.rbLet’s Write an Interpreter!
"ank You