comparison share/delvs-master/delvs.rb @ 3840:38a5b4d8a98e

<oerjan> rm -R share/delvs-master; mv delvs-master share
author HackBot
date Wed, 25 Sep 2013 13:47:14 +0000
parents
children
comparison
equal deleted inserted replaced
3839:02b377019805 3840:38a5b4d8a98e
1 #!/usr/bin/env ruby
2 # NOTE: this proram was just made for the lulz, PLEASE DO NOT USE THIS
3 # Please use the actually semi-well written delvs interpreter writtin in C, because this isn't even close to the actual delvs interpreter
4 require 'io/console'
5
6 class RuntimeData
7 attr_accessor :c
8 attr_accessor :v
9 attr_accessor :i
10 attr_accessor :f
11 attr_accessor :p
12
13 def initialize
14 @c = ""
15 @i = 0
16 @v = Array.new 30000, 0
17 @p = 15000
18 @f = ""
19 end
20 end
21
22 def dummy_lexer d
23 while d.i <= d.c.length do
24 return d.i if d.c[d.i] == ']'
25 d.i += 1
26 end
27 end
28
29 def lexer d
30 while d.i <= d.c.length do
31 case d.c[d.i]
32 when '>' then
33 d.p += 1
34
35 when '<' then
36 d.p -= 1
37
38 when '+' then
39 d.v[d.p] += 1
40
41 when '-' then
42 d.v[d.p] -= 1
43
44 when '.' then
45 print d.v[d.p].chr
46
47 when ',' then
48 d.v[d.p] = IO.console.getch.ord
49
50 when '[' then
51 r = d.i + 1
52 d.i = dlexer d if !d.v[d.p]
53 while d.v[d.p] != 0 do
54 d.i = r
55 d = lexer d
56 end
57
58 when ']' then
59 return d
60
61 else
62 # Everything else is comments
63 end
64 d.i += 1
65 end
66 end
67
68 # example usage:
69 # data = RuntimeData.new
70 # data.c = "+++++ +++++ [ > +++++ +++++ > + << - ] > ++++ . + . > ."
71 # lexer data