missinglisp 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/missinglisp.rb +34 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d439126ef5936974b06ea17de05495349e19c0a11118edc19092e873a736436
|
4
|
+
data.tar.gz: f132a6e170876980329bd8b84d20aa1bd7e06f100bf3872b0c0e763535b30505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84dc4fadf2b03da0d3c6e155b8eacc056bd6565438a4dd08d32bfbdcb4197727ac3000317f8f0b612808af346fd77771385c7731be852a06af7de72f8fe170cb
|
7
|
+
data.tar.gz: 9995f555865a9813a2505c79f2abd9f6823fda4b81311ed312f314f3537f0020d2fe8162067b9bc3740726abc86c4753f02d7544ca990ef066a9584f7e2ca5c0
|
data/lib/missinglisp.rb
CHANGED
@@ -16,7 +16,18 @@ class Lisp
|
|
16
16
|
gt: ->(a, b, *) { a > b },
|
17
17
|
geq: ->(a, b, *) { a >= b },
|
18
18
|
|
19
|
+
# string
|
20
|
+
aref: ->(s, at, *) { s[at] },
|
21
|
+
concatenate: ->(_type, *ls) { ls.reduce(:+) },
|
22
|
+
|
23
|
+
# char
|
24
|
+
codeChar: ->(c, *) { c.chr },
|
25
|
+
|
26
|
+
readLine: ->(*) { $stdin.readline.chomp },
|
27
|
+
|
19
28
|
p: ->(*ls) { p ls },
|
29
|
+
print: ->(*ls) { p ls },
|
30
|
+
writeLine: ->(s, *) { puts s },
|
20
31
|
|
21
32
|
t: true,
|
22
33
|
nil: []
|
@@ -25,6 +36,7 @@ class Lisp
|
|
25
36
|
|
26
37
|
def eval(exp, env)
|
27
38
|
return exp if exp.is_a? Numeric
|
39
|
+
return exp if exp.is_a? String
|
28
40
|
return env[exp] if exp.is_a? Symbol
|
29
41
|
|
30
42
|
# list
|
@@ -64,7 +76,6 @@ class Lisp
|
|
64
76
|
|
65
77
|
res = nil
|
66
78
|
exp.each do |stmt|
|
67
|
-
# p stmt
|
68
79
|
res = self.eval(stmt, env)
|
69
80
|
end
|
70
81
|
|
@@ -113,9 +124,12 @@ class Lisp
|
|
113
124
|
res = []
|
114
125
|
cur = ''
|
115
126
|
is_reading_digit = false
|
127
|
+
is_reading_string = false
|
116
128
|
s.each_char do |c|
|
117
129
|
case c
|
118
130
|
when '_'
|
131
|
+
cur += ' ' and next if is_reading_string
|
132
|
+
|
119
133
|
if cur != ''
|
120
134
|
if is_reading_digit
|
121
135
|
res.push cur.to_i
|
@@ -154,6 +168,25 @@ class Lisp
|
|
154
168
|
end
|
155
169
|
|
156
170
|
res.push :J
|
171
|
+
when 'Q'
|
172
|
+
if is_reading_string
|
173
|
+
res.push cur
|
174
|
+
cur = ''
|
175
|
+
is_reading_string = false
|
176
|
+
next
|
177
|
+
elsif is_reading_digit
|
178
|
+
res.push cur.to_i
|
179
|
+
cur = ''
|
180
|
+
is_reading_digit = false
|
181
|
+
is_reading_string = true
|
182
|
+
next
|
183
|
+
end
|
184
|
+
|
185
|
+
if cur != ''
|
186
|
+
cur += 'Q'
|
187
|
+
else
|
188
|
+
is_reading_string = true
|
189
|
+
end
|
157
190
|
when '0'..'9'
|
158
191
|
cur += c and next if cur != ''
|
159
192
|
|