rVM 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,22 @@ require 'strscan'
2
2
  require 'rvm/functions/math/add'
3
3
  require 'rvm/functions/math/sub'
4
4
  require 'rvm/functions/io/print'
5
+
5
6
  module RVM
6
7
  module Languages
8
+ # This is a brainfuck compiler for the VM.
9
+ # It covers the compleat BF syntax and allows you to write files that are executed.
10
+ #
11
+ # Mostly a gimick I admit but it's a nice demonstration of how rVM works.
7
12
  class Brainfuck < RVM::Languages::Language
13
+
14
+ # This function compiles a string of BF code and returns the equivalent for the
15
+ # rVM.
16
+ def compile code
17
+ make_vmcode(make_tree(code))
18
+ end
19
+
20
+ private
8
21
  def make_tree str
9
22
  str.gsub!(/\/\/.*?\n/,'') #delete comments
10
23
  str.gsub!(/[^<>+\[\].,\d-]/,'')
@@ -55,10 +68,6 @@ module RVM
55
68
  tree
56
69
  end
57
70
 
58
- def compile code
59
- make_vmcode(make_tree(code))
60
- end
61
-
62
71
  def make_vmcode tree
63
72
  root = RVM::Interpreter::Sequence.new();
64
73
  ptr = Interpreter::Variable.new(Interpreter.const(:string,'ptr'))
@@ -0,0 +1,997 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.5
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require 'strscan'
11
+ require 'rvm/functions/math'
12
+ require 'rvm/functions/logic'
13
+ require 'rvm/functions/array'
14
+ require 'pp'
15
+
16
+ module RVM
17
+ module Languages
18
+ class ECMA < Racc::Parser
19
+
20
+ module_eval(<<'...end ecma.y/module_eval...', 'ecma.y', 194)
21
+ extend Plugin
22
+ plugin_host RVM::Languages
23
+ register_for :ecma
24
+
25
+ def compile(str)
26
+ @q = []
27
+ s = StringScanner.new(str)
28
+ while not s.eos?
29
+ if s.scan(/\/\/.*?\n/)
30
+ elsif s.scan(/\/*.*?*\//)
31
+ elsif s.scan(/('(\\.|[^'])*')/)
32
+ m = s.matched.gsub(/^'/,'').gsub(/'$/,'')
33
+ @q.push [:STRING, [m, s.pos]]
34
+ elsif s.scan(/("(\\.|[^"])*")/)
35
+ m = s.matched.gsub('\n',"\n").gsub(/^"/,'').gsub(/"$/,'')
36
+ @q.push [:STRING, [m, s.pos]]
37
+ elsif s.scan(/((\d+(\.\d+)?)|(\.\d+))(e-?\d+)?/)
38
+ @q.push [:NUMBER, [s.matched, s.pos]]
39
+ elsif s.scan(/\[/)
40
+ @q.push [:SBRACKET_OPEN, [s.matched, s.pos]]
41
+ elsif s.scan(/\]/)
42
+ @q.push [:SBRACKET_CLOSE, [s.matched, s.pos]]
43
+ elsif s.scan(/\{/)
44
+ @q.push [:CBRACKET_OPEN, [s.matched, s.pos]]
45
+ elsif s.scan(/\}/)
46
+ @q.push [:CBRACKET_CLOSE, [s.matched, s.pos]]
47
+ elsif s.scan(/[a-z_][a-z_0-9]*/i)
48
+ m = s.matched
49
+ type = case m
50
+ when 'function'
51
+ :KW_FUNCTION
52
+ when 'for'
53
+ :KW_FOR
54
+ when 'while'
55
+ :KW_WHILE
56
+ when 'do'
57
+ :KW_WHILE
58
+ when 'if'
59
+ :KW_IF
60
+ when 'return'
61
+ :KW_RETURN
62
+ when 'else'
63
+ :KW_ELSE
64
+ when 'new'
65
+ :KW_NEW
66
+ when 'this'
67
+ :KW_THIS
68
+ else
69
+ :IDENT
70
+ end
71
+ @q.push [type, [m, s.pos]]
72
+ elsif s.scan(/(([<>]=?)|([!=]=)|[.+*\/(){},=;\[\]-]|&&|\|\|)/) # This ones do not get a new line (sepperator added)
73
+ m = s.matched
74
+ @q.push [m, [m, s.pos]]
75
+ elsif s.scan(/\n+/)
76
+ elsif s.scan(/\s+/)
77
+ else
78
+ raise "Woops! I can daeal with char at #{s.pos}: #{s.pre_match} #{s.post_match}"
79
+ end
80
+ end
81
+ @q.push([false, '$end'])
82
+
83
+ do_parse
84
+ end
85
+
86
+ def next_token
87
+ @q.shift
88
+ end
89
+ ...end ecma.y/module_eval...
90
+ ##### State transition tables begin ###
91
+
92
+ racc_action_table = [
93
+ 33, 2, 61, 62, 113, 42, 61, 62, 69, 77,
94
+ 30, 35, 78, 7, 9, 13, 69, 18, 21, 24,
95
+ 28, 69, 103, 3, 71, 12, 69, 15, 33, 2,
96
+ 72, 26, 69, 33, 2, 112, 69, 69, 30, 35,
97
+ 61, 62, 52, 30, 35, 69, 69, 24, 61, 62,
98
+ 69, 3, 24, 61, 62, 15, 3, 33, 2, 26,
99
+ 15, 61, 62, 114, 26, 115, 110, 30, 35, 51,
100
+ 69, 9, 13, 51, 18, 21, 24, 28, 69, 132,
101
+ 3, 115, 12, 69, 15, 33, 2, 117, 26, 118,
102
+ 109, 69, 108, 69, 12, 30, 35, 106, 70, 9,
103
+ 13, 42, 18, 21, 24, 28, 73, 74, 3, 49,
104
+ 12, 47, 15, 33, 2, 44, 26, 12, 33, 2,
105
+ 42, 129, 130, 30, 35, 131, 82, 69, 30, 35,
106
+ 69, 43, 24, 42, 135, 40, 3, 24, nil, nil,
107
+ 15, 3, 33, 2, 26, 15, nil, nil, nil, 26,
108
+ nil, nil, 30, 35, nil, nil, 9, 13, nil, 18,
109
+ 21, 24, 28, nil, nil, 3, nil, 12, nil, 15,
110
+ 33, 2, nil, 26, nil, 33, 2, 33, 2, nil,
111
+ 30, 35, nil, nil, nil, 30, 35, 30, 35, 24,
112
+ nil, nil, nil, 3, 24, nil, 24, 15, 3, nil,
113
+ 3, 26, 15, nil, 15, 124, 26, nil, 26, 33,
114
+ 2, 61, 62, 63, 64, 65, 66, 67, 68, 30,
115
+ 35, nil, nil, 9, 13, nil, 18, 21, 24, 28,
116
+ nil, nil, 3, nil, 12, nil, 15, 33, 2, nil,
117
+ 26, 69, 33, 2, nil, nil, nil, 30, 35, nil,
118
+ nil, nil, 30, 35, nil, nil, 24, nil, nil, nil,
119
+ 3, 24, nil, nil, 15, 3, 33, 2, 26, 15,
120
+ nil, nil, nil, 26, nil, nil, 30, 35, nil, nil,
121
+ 9, 13, nil, 18, 21, 24, 28, nil, nil, 3,
122
+ nil, 12, nil, 15, 33, 2, nil, 26, nil, 33,
123
+ 2, nil, nil, nil, 30, 35, nil, nil, nil, 30,
124
+ 35, nil, nil, 24, nil, nil, nil, 3, 24, nil,
125
+ nil, 15, 3, 33, 2, 26, 15, nil, nil, nil,
126
+ 26, nil, nil, 30, 35, nil, nil, 9, 13, nil,
127
+ 18, 21, 24, 28, nil, nil, 3, nil, 12, nil,
128
+ 15, 33, 2, nil, 26, nil, 33, 2, nil, nil,
129
+ nil, 30, 35, nil, nil, nil, 30, 35, nil, nil,
130
+ 24, nil, nil, nil, 3, 24, nil, nil, 15, 3,
131
+ 33, 2, 26, 15, nil, nil, nil, 26, nil, nil,
132
+ 30, 35, nil, nil, 9, 13, nil, 18, 21, 24,
133
+ 28, nil, nil, 3, nil, 12, nil, 15, 33, 2,
134
+ nil, 26, nil, 33, 2, 33, 2, nil, 30, 35,
135
+ nil, nil, nil, 30, 35, 30, 35, 24, nil, nil,
136
+ nil, 3, 24, nil, 24, 15, 3, nil, 3, 26,
137
+ 15, 100, 15, nil, 26, nil, 26, 33, 2, 55,
138
+ 56, 57, 58, 54, nil, nil, nil, 30, 35, nil,
139
+ nil, nil, 33, 2, nil, nil, 24, nil, nil, nil,
140
+ 3, nil, 30, 35, 15, 7, 9, 13, 26, 18,
141
+ 21, 24, 28, nil, nil, 3, nil, 12, nil, 15,
142
+ 33, 2, nil, 26, nil, 33, 2, 33, 2, nil,
143
+ 30, 35, nil, nil, nil, 30, 35, 30, 35, 24,
144
+ nil, nil, nil, 3, 24, nil, 24, 15, 3, nil,
145
+ 3, 26, 15, nil, 15, nil, 26, nil, 26, 33,
146
+ 2, 33, 2, nil, 33, 2, 33, 2, nil, 30,
147
+ 35, 30, 35, nil, 30, 35, 30, 35, 24, nil,
148
+ 24, nil, 3, 24, 3, 24, 15, 3, 15, 3,
149
+ 26, 15, 26, 15, nil, 26, nil, 26, 33, 2,
150
+ 33, 2, nil, 33, 2, 33, 2, nil, 30, 35,
151
+ 30, 35, nil, 30, 35, 30, 35, 24, nil, 24,
152
+ nil, 3, 24, 3, 24, 15, 3, 15, 3, 26,
153
+ 15, 26, 15, nil, 26, nil, 26, 33, 2, 33,
154
+ 2, nil, 33, 2, 33, 2, nil, 30, 35, 30,
155
+ 35, nil, 30, 35, 30, 35, 24, nil, 24, nil,
156
+ 3, 24, 3, 24, 15, 3, 15, 3, 26, 15,
157
+ 26, 15, nil, 26, nil, 26, 61, 62, 63, 64,
158
+ 65, 66, 67, 68, nil, 61, 62, 63, 64, 65,
159
+ 66, 67, 68, 61, 62, 63, 64, 65, 66, 67,
160
+ 68, nil, 80, nil, nil, nil, 69, 111, nil, nil,
161
+ nil, nil, nil, nil, nil, 69, nil, nil, nil, nil,
162
+ nil, nil, nil, 69, 61, 62, 63, 64, 65, 66,
163
+ 67, 68, 61, 62, 63, 64, 65, 66, 67, 68,
164
+ 61, 62, 63, 64, 65, 66, 67, 68, nil, nil,
165
+ nil, nil, nil, nil, 69, nil, nil, nil, nil, nil,
166
+ nil, nil, 69, nil, nil, nil, nil, nil, nil, nil,
167
+ 69 ]
168
+
169
+ racc_action_check = [
170
+ 0, 0, 95, 95, 98, 74, 93, 93, 60, 45,
171
+ 0, 0, 45, 0, 0, 0, 90, 0, 0, 0,
172
+ 0, 91, 74, 0, 38, 0, 88, 0, 2, 2,
173
+ 38, 0, 95, 3, 3, 98, 93, 87, 2, 2,
174
+ 94, 94, 25, 3, 3, 86, 89, 2, 96, 96,
175
+ 85, 2, 3, 97, 97, 2, 3, 135, 135, 2,
176
+ 3, 92, 92, 99, 3, 99, 82, 135, 135, 25,
177
+ 94, 135, 135, 36, 135, 135, 135, 135, 96, 123,
178
+ 135, 123, 135, 97, 135, 130, 130, 105, 135, 105,
179
+ 81, 92, 79, 37, 103, 130, 130, 76, 35, 130,
180
+ 130, 69, 130, 130, 130, 130, 40, 41, 130, 18,
181
+ 130, 13, 130, 129, 129, 9, 130, 117, 115, 115,
182
+ 118, 119, 120, 129, 129, 122, 50, 125, 115, 115,
183
+ 53, 8, 129, 7, 133, 5, 129, 115, nil, nil,
184
+ 129, 115, 12, 12, 129, 115, nil, nil, nil, 115,
185
+ nil, nil, 12, 12, nil, nil, 12, 12, nil, 12,
186
+ 12, 12, 12, nil, nil, 12, nil, 12, nil, 12,
187
+ 113, 113, nil, 12, nil, 15, 15, 112, 112, nil,
188
+ 113, 113, nil, nil, nil, 15, 15, 112, 112, 113,
189
+ nil, nil, nil, 113, 15, nil, 112, 113, 15, nil,
190
+ 112, 113, 15, nil, 112, 112, 15, nil, 112, 21,
191
+ 21, 126, 126, 126, 126, 126, 126, 126, 126, 21,
192
+ 21, nil, nil, 21, 21, nil, 21, 21, 21, 21,
193
+ nil, nil, 21, nil, 21, nil, 21, 110, 110, nil,
194
+ 21, 126, 26, 26, nil, nil, nil, 110, 110, nil,
195
+ nil, nil, 26, 26, nil, nil, 110, nil, nil, nil,
196
+ 110, 26, nil, nil, 110, 26, 109, 109, 110, 26,
197
+ nil, nil, nil, 26, nil, nil, 109, 109, nil, nil,
198
+ 109, 109, nil, 109, 109, 109, 109, nil, nil, 109,
199
+ nil, 109, nil, 109, 28, 28, nil, 109, nil, 33,
200
+ 33, nil, nil, nil, 28, 28, nil, nil, nil, 33,
201
+ 33, nil, nil, 28, nil, nil, nil, 28, 33, nil,
202
+ nil, 28, 33, 108, 108, 28, 33, nil, nil, nil,
203
+ 33, nil, nil, 108, 108, nil, nil, 108, 108, nil,
204
+ 108, 108, 108, 108, nil, nil, 108, nil, 108, nil,
205
+ 108, 106, 106, nil, 108, nil, 61, 61, nil, nil,
206
+ nil, 106, 106, nil, nil, nil, 61, 61, nil, nil,
207
+ 106, nil, nil, nil, 106, 61, nil, nil, 106, 61,
208
+ 78, 78, 106, 61, nil, nil, nil, 61, nil, nil,
209
+ 78, 78, nil, nil, 78, 78, nil, 78, 78, 78,
210
+ 78, nil, nil, 78, nil, 78, nil, 78, 72, 72,
211
+ nil, 78, nil, 70, 70, 68, 68, nil, 72, 72,
212
+ nil, nil, nil, 70, 70, 68, 68, 72, nil, nil,
213
+ nil, 72, 70, nil, 68, 72, 70, nil, 68, 72,
214
+ 70, 70, 68, nil, 70, nil, 68, 67, 67, 27,
215
+ 27, 27, 27, 27, nil, nil, nil, 67, 67, nil,
216
+ nil, nil, 43, 43, nil, nil, 67, nil, nil, nil,
217
+ 67, nil, 43, 43, 67, 43, 43, 43, 67, 43,
218
+ 43, 43, 43, nil, nil, 43, nil, 43, nil, 43,
219
+ 44, 44, nil, 43, nil, 66, 66, 47, 47, nil,
220
+ 44, 44, nil, nil, nil, 66, 66, 47, 47, 44,
221
+ nil, nil, nil, 44, 66, nil, 47, 44, 66, nil,
222
+ 47, 44, 66, nil, 47, nil, 66, nil, 47, 65,
223
+ 65, 49, 49, nil, 64, 64, 51, 51, nil, 65,
224
+ 65, 49, 49, nil, 64, 64, 51, 51, 65, nil,
225
+ 49, nil, 65, 64, 49, 51, 65, 64, 49, 51,
226
+ 65, 64, 49, 51, nil, 64, nil, 51, 52, 52,
227
+ 63, 63, nil, 54, 54, 55, 55, nil, 52, 52,
228
+ 63, 63, nil, 54, 54, 55, 55, 52, nil, 63,
229
+ nil, 52, 54, 63, 55, 52, 54, 63, 55, 52,
230
+ 54, 63, 55, nil, 54, nil, 55, 56, 56, 57,
231
+ 57, nil, 58, 58, 62, 62, nil, 56, 56, 57,
232
+ 57, nil, 58, 58, 62, 62, 56, nil, 57, nil,
233
+ 56, 58, 57, 62, 56, 58, 57, 62, 56, 58,
234
+ 57, 62, nil, 58, nil, 62, 48, 48, 48, 48,
235
+ 48, 48, 48, 48, nil, 83, 83, 83, 83, 83,
236
+ 83, 83, 83, 34, 34, 34, 34, 34, 34, 34,
237
+ 34, nil, 48, nil, nil, nil, 48, 83, nil, nil,
238
+ nil, nil, nil, nil, nil, 83, nil, nil, nil, nil,
239
+ nil, nil, nil, 34, 39, 39, 39, 39, 39, 39,
240
+ 39, 39, 102, 102, 102, 102, 102, 102, 102, 102,
241
+ 101, 101, 101, 101, 101, 101, 101, 101, nil, nil,
242
+ nil, nil, nil, nil, 39, nil, nil, nil, nil, nil,
243
+ nil, nil, 102, nil, nil, nil, nil, nil, nil, nil,
244
+ 101 ]
245
+
246
+ racc_action_pointer = [
247
+ -10, nil, 18, 23, nil, 135, nil, 112, 92, 78,
248
+ nil, nil, 132, 74, nil, 165, nil, nil, 72, nil,
249
+ nil, 199, nil, nil, nil, 36, 232, 442, 284, nil,
250
+ nil, nil, nil, 289, 651, 61, 40, 51, -10, 682,
251
+ 106, 70, nil, 452, 480, -27, nil, 487, 634, 521,
252
+ 99, 526, 558, 88, 563, 565, 597, 599, 602, nil,
253
+ -34, 346, 604, 560, 524, 519, 485, 437, 405, 80,
254
+ 403, nil, 398, nil, -16, nil, 58, nil, 370, 54,
255
+ nil, 52, 29, 643, nil, 8, 3, -5, -16, 4,
256
+ -26, -21, 49, -6, 28, -10, 36, 41, -2, 25,
257
+ nil, 698, 690, 59, nil, 49, 341, nil, 313, 256,
258
+ 227, nil, 167, 160, nil, 108, nil, 82, 99, 82,
259
+ 96, nil, 87, 41, nil, 85, 199, nil, nil, 103,
260
+ 75, nil, nil, 96, nil, 47, nil ]
261
+
262
+ racc_action_default = [
263
+ -2, -52, -70, -70, -22, -70, -56, -70, -1, -70,
264
+ -53, -24, -70, -70, -25, -70, -26, -7, -70, -27,
265
+ -5, -70, -63, -6, -62, -54, -70, -46, -70, -23,
266
+ -61, -37, -51, -70, -16, -69, -54, -49, -70, -30,
267
+ -70, -70, -69, -9, -70, -70, -18, -70, -70, -70,
268
+ -70, -70, -70, -48, -70, -70, -70, -70, -70, -28,
269
+ -50, -70, -70, -70, -70, -70, -70, -70, -70, -70,
270
+ -70, -29, -70, 137, -70, -8, -70, -21, -20, -70,
271
+ -55, -70, -70, -70, -17, -33, -36, -34, -35, -32,
272
+ -44, -45, -39, -38, -42, -43, -40, -41, -57, -70,
273
+ -3, -14, -31, -70, -12, -70, -70, -19, -70, -70,
274
+ -70, -47, -70, -70, -4, -70, -10, -70, -70, -70,
275
+ -65, -67, -70, -70, -60, -58, -15, -11, -13, -70,
276
+ -70, -68, -59, -70, -64, -70, -66 ]
277
+
278
+ racc_goto_table = [
279
+ 25, 46, 17, 59, 99, 5, 116, 41, 105, 8,
280
+ 50, 45, 25, 38, nil, nil, nil, nil, nil, 76,
281
+ 127, 25, 79, nil, 81, nil, nil, 84, 25, nil,
282
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
283
+ nil, nil, nil, 25, 25, 75, 123, 25, nil, 25,
284
+ nil, nil, 25, nil, nil, nil, nil, nil, nil, nil,
285
+ nil, nil, nil, nil, nil, nil, nil, 107, nil, 98,
286
+ nil, nil, nil, nil, 104, nil, nil, nil, 25, nil,
287
+ nil, 119, nil, nil, nil, 122, nil, nil, nil, 37,
288
+ 39, nil, nil, nil, nil, nil, nil, 120, 121, nil,
289
+ nil, nil, 48, nil, 133, nil, 25, nil, 25, 25,
290
+ 25, nil, nil, 53, nil, nil, nil, nil, 128, 134,
291
+ 60, nil, nil, nil, 136, nil, nil, nil, nil, 25,
292
+ 25, nil, nil, nil, nil, 25, nil, nil, 83, nil,
293
+ nil, 85, 86, 87, 88, 89, nil, nil, 90, 91,
294
+ 92, 93, 94, 95, 96, 97, nil, 101, nil, 102,
295
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
296
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
297
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
298
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 101,
299
+ 125, nil, 126 ]
300
+
301
+ racc_goto_check = [
302
+ 8, 6, 5, 12, 4, 1, 9, 8, 10, 2,
303
+ 6, 13, 8, 19, nil, nil, nil, nil, nil, 12,
304
+ 9, 8, 12, nil, 12, nil, nil, 12, 8, nil,
305
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
306
+ nil, nil, nil, 8, 8, 5, 4, 8, nil, 8,
307
+ nil, nil, 8, nil, nil, nil, nil, nil, nil, nil,
308
+ nil, nil, nil, nil, nil, nil, nil, 6, nil, 8,
309
+ nil, nil, nil, nil, 8, nil, nil, nil, 8, nil,
310
+ nil, 12, nil, nil, nil, 12, nil, nil, nil, 11,
311
+ 11, nil, nil, nil, nil, nil, nil, 6, 6, nil,
312
+ nil, nil, 11, nil, 12, nil, 8, nil, 8, 8,
313
+ 8, nil, nil, 11, nil, nil, nil, nil, 8, 6,
314
+ 11, nil, nil, nil, 6, nil, nil, nil, nil, 8,
315
+ 8, nil, nil, nil, nil, 8, nil, nil, 11, nil,
316
+ nil, 11, 11, 11, 11, 11, nil, nil, 11, 11,
317
+ 11, 11, 11, 11, 11, 11, nil, 11, nil, 11,
318
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
319
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
320
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
321
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 11,
322
+ 11, nil, 11 ]
323
+
324
+ racc_goto_pointer = [
325
+ nil, 5, 9, nil, -66, 2, -11, nil, 0, -97,
326
+ -66, 87, -25, -1, nil, nil, nil, nil, nil, 10,
327
+ nil, nil, nil, nil, nil ]
328
+
329
+ racc_goto_default = [
330
+ nil, nil, nil, 10, nil, nil, 20, 23, 36, 29,
331
+ nil, 34, 4, nil, 11, 14, 16, 19, 22, nil,
332
+ 27, 31, 32, 1, 6 ]
333
+
334
+ racc_reduce_table = [
335
+ 0, 0, :racc_error,
336
+ 1, 44, :_reduce_none,
337
+ 0, 44, :_reduce_2,
338
+ 3, 46, :_reduce_3,
339
+ 4, 46, :_reduce_4,
340
+ 1, 48, :_reduce_none,
341
+ 1, 48, :_reduce_none,
342
+ 1, 45, :_reduce_7,
343
+ 3, 45, :_reduce_8,
344
+ 2, 45, :_reduce_none,
345
+ 5, 50, :_reduce_10,
346
+ 6, 50, :_reduce_11,
347
+ 1, 53, :_reduce_12,
348
+ 3, 53, :_reduce_13,
349
+ 1, 47, :_reduce_14,
350
+ 3, 47, :_reduce_15,
351
+ 1, 55, :_reduce_none,
352
+ 3, 55, :_reduce_17,
353
+ 1, 56, :_reduce_18,
354
+ 3, 56, :_reduce_19,
355
+ 2, 56, :_reduce_none,
356
+ 3, 52, :_reduce_21,
357
+ 1, 49, :_reduce_none,
358
+ 1, 49, :_reduce_none,
359
+ 1, 49, :_reduce_none,
360
+ 1, 49, :_reduce_none,
361
+ 1, 49, :_reduce_none,
362
+ 1, 49, :_reduce_none,
363
+ 2, 60, :_reduce_28,
364
+ 3, 61, :_reduce_29,
365
+ 1, 62, :_reduce_30,
366
+ 3, 62, :_reduce_31,
367
+ 3, 54, :_reduce_32,
368
+ 3, 54, :_reduce_33,
369
+ 3, 54, :_reduce_34,
370
+ 3, 54, :_reduce_35,
371
+ 3, 54, :_reduce_36,
372
+ 1, 54, :_reduce_none,
373
+ 3, 65, :_reduce_38,
374
+ 3, 65, :_reduce_39,
375
+ 3, 65, :_reduce_40,
376
+ 3, 65, :_reduce_41,
377
+ 3, 65, :_reduce_42,
378
+ 3, 65, :_reduce_43,
379
+ 3, 65, :_reduce_44,
380
+ 3, 65, :_reduce_45,
381
+ 1, 64, :_reduce_none,
382
+ 4, 64, :_reduce_47,
383
+ 2, 64, :_reduce_48,
384
+ 2, 64, :_reduce_49,
385
+ 2, 64, :_reduce_none,
386
+ 1, 64, :_reduce_none,
387
+ 1, 64, :_reduce_none,
388
+ 1, 64, :_reduce_none,
389
+ 1, 63, :_reduce_54,
390
+ 3, 63, :_reduce_55,
391
+ 1, 63, :_reduce_56,
392
+ 3, 66, :_reduce_57,
393
+ 5, 66, :_reduce_58,
394
+ 6, 66, :_reduce_59,
395
+ 5, 66, :_reduce_60,
396
+ 1, 67, :_reduce_61,
397
+ 1, 67, :_reduce_62,
398
+ 1, 67, :_reduce_none,
399
+ 7, 58, :_reduce_64,
400
+ 5, 58, :_reduce_65,
401
+ 9, 57, :_reduce_66,
402
+ 5, 59, :_reduce_67,
403
+ 6, 59, :_reduce_68,
404
+ 1, 51, :_reduce_69 ]
405
+
406
+ racc_reduce_n = 70
407
+
408
+ racc_shift_n = 137
409
+
410
+ racc_token_table = {
411
+ false => 0,
412
+ :error => 1,
413
+ :UMINUS => 2,
414
+ :UPLUS => 3,
415
+ :LNOT => 4,
416
+ :BNOT => 5,
417
+ "=" => 6,
418
+ "^" => 7,
419
+ "*" => 8,
420
+ "/" => 9,
421
+ "+" => 10,
422
+ "-" => 11,
423
+ "&&" => 12,
424
+ "||" => 13,
425
+ ">" => 14,
426
+ "<" => 15,
427
+ ">=" => 16,
428
+ "<=" => 17,
429
+ "==" => 18,
430
+ "!=" => 19,
431
+ :NUMBER => 20,
432
+ :IDENT => 21,
433
+ :O_IDENT => 22,
434
+ :KW_FUNCTION => 23,
435
+ :KW_FOR => 24,
436
+ :KW_IF => 25,
437
+ :KW_ELSE => 26,
438
+ :KW_WHILE => 27,
439
+ :KW_DO => 28,
440
+ :STRING => 29,
441
+ :KW_RETURN => 30,
442
+ :KW_NEW => 31,
443
+ :KW_THIS => 32,
444
+ :SBRACKET_OPEN => 33,
445
+ :SBRACKET_CLOSE => 34,
446
+ :CBRACKET_OPEN => 35,
447
+ :CBRACKET_CLOSE => 36,
448
+ "(" => 37,
449
+ ")" => 38,
450
+ ";" => 39,
451
+ "," => 40,
452
+ "!" => 41,
453
+ "." => 42 }
454
+
455
+ racc_nt_base = 43
456
+
457
+ racc_use_result_var = true
458
+
459
+ Racc_arg = [
460
+ racc_action_table,
461
+ racc_action_check,
462
+ racc_action_default,
463
+ racc_action_pointer,
464
+ racc_goto_table,
465
+ racc_goto_check,
466
+ racc_goto_default,
467
+ racc_goto_pointer,
468
+ racc_nt_base,
469
+ racc_reduce_table,
470
+ racc_token_table,
471
+ racc_shift_n,
472
+ racc_reduce_n,
473
+ racc_use_result_var ]
474
+
475
+ Racc_token_to_s_table = [
476
+ "$end",
477
+ "error",
478
+ "UMINUS",
479
+ "UPLUS",
480
+ "LNOT",
481
+ "BNOT",
482
+ "\"=\"",
483
+ "\"^\"",
484
+ "\"*\"",
485
+ "\"/\"",
486
+ "\"+\"",
487
+ "\"-\"",
488
+ "\"&&\"",
489
+ "\"||\"",
490
+ "\">\"",
491
+ "\"<\"",
492
+ "\">=\"",
493
+ "\"<=\"",
494
+ "\"==\"",
495
+ "\"!=\"",
496
+ "NUMBER",
497
+ "IDENT",
498
+ "O_IDENT",
499
+ "KW_FUNCTION",
500
+ "KW_FOR",
501
+ "KW_IF",
502
+ "KW_ELSE",
503
+ "KW_WHILE",
504
+ "KW_DO",
505
+ "STRING",
506
+ "KW_RETURN",
507
+ "KW_NEW",
508
+ "KW_THIS",
509
+ "SBRACKET_OPEN",
510
+ "SBRACKET_CLOSE",
511
+ "CBRACKET_OPEN",
512
+ "CBRACKET_CLOSE",
513
+ "\"(\"",
514
+ "\")\"",
515
+ "\";\"",
516
+ "\",\"",
517
+ "\"!\"",
518
+ "\".\"",
519
+ "$start",
520
+ "target",
521
+ "root_seq",
522
+ "fun",
523
+ "args",
524
+ "root_stmt",
525
+ "stmt",
526
+ "fun_def",
527
+ "ident",
528
+ "block",
529
+ "arg_def",
530
+ "exp",
531
+ "ass",
532
+ "seq",
533
+ "for",
534
+ "if",
535
+ "while",
536
+ "return",
537
+ "ARRAY",
538
+ "array_content",
539
+ "atom",
540
+ "exp0",
541
+ "comp",
542
+ "objcall",
543
+ "const" ]
544
+
545
+ Racc_debug_parser = false
546
+
547
+ ##### State transition tables end #####
548
+
549
+ # reduce 0 omitted
550
+
551
+ # reduce 1 omitted
552
+
553
+ module_eval(<<'.,.,', 'ecma.y', 31)
554
+ def _reduce_2(val, _values, result)
555
+ result = nil
556
+ result
557
+ end
558
+ .,.,
559
+
560
+ module_eval(<<'.,.,', 'ecma.y', 33)
561
+ def _reduce_3(val, _values, result)
562
+ result = RVM::Interpreter::FunctionCall.new(val[0], [])
563
+ result
564
+ end
565
+ .,.,
566
+
567
+ module_eval(<<'.,.,', 'ecma.y', 34)
568
+ def _reduce_4(val, _values, result)
569
+ result = RVM::Interpreter::FunctionCall.new(val[0], val[2])
570
+ result
571
+ end
572
+ .,.,
573
+
574
+ # reduce 5 omitted
575
+
576
+ # reduce 6 omitted
577
+
578
+ module_eval(<<'.,.,', 'ecma.y', 39)
579
+ def _reduce_7(val, _values, result)
580
+ result = RVM::Interpreter::Sequence.new([result])
581
+ result
582
+ end
583
+ .,.,
584
+
585
+ module_eval(<<'.,.,', 'ecma.y', 40)
586
+ def _reduce_8(val, _values, result)
587
+ result << val[2]
588
+ result
589
+ end
590
+ .,.,
591
+
592
+ # reduce 9 omitted
593
+
594
+ module_eval(<<'.,.,', 'ecma.y', 44)
595
+ def _reduce_10(val, _values, result)
596
+ #TODO: THIS
597
+ b = val[4]
598
+ ident = val[1]
599
+
600
+ if not b.is_a? RVM::Interpreter::Sequence
601
+ b = RVM::Interpreter::Sequence.new(b)
602
+ end
603
+ b << RVM::Interpreter::Return.new()
604
+
605
+ result = RVM::Interpreter::FunctionDefinition.new(ident, RVM::Classes::Block.new(b))
606
+
607
+ result
608
+ end
609
+ .,.,
610
+
611
+ module_eval(<<'.,.,', 'ecma.y', 56)
612
+ def _reduce_11(val, _values, result)
613
+ block = val[5]
614
+ i = 0
615
+ val[3].each do |a|
616
+ block.content.unshift RVM::Interpreter::Assignment.new(a, RVM::Interpreter::Parameter.new(RVM::Interpreter.const(:number,i)))
617
+ i +=1
618
+ end
619
+ result = RVM::Interpreter::FunctionDefinition.new(val[1], RVM::Classes::Block.new(block))
620
+
621
+ result
622
+ end
623
+ .,.,
624
+
625
+ module_eval(<<'.,.,', 'ecma.y', 65)
626
+ def _reduce_12(val, _values, result)
627
+ result = [result]
628
+ result
629
+ end
630
+ .,.,
631
+
632
+ module_eval(<<'.,.,', 'ecma.y', 66)
633
+ def _reduce_13(val, _values, result)
634
+ result << val[2]
635
+ result
636
+ end
637
+ .,.,
638
+
639
+ module_eval(<<'.,.,', 'ecma.y', 68)
640
+ def _reduce_14(val, _values, result)
641
+ result = [result]
642
+ result
643
+ end
644
+ .,.,
645
+
646
+ module_eval(<<'.,.,', 'ecma.y', 69)
647
+ def _reduce_15(val, _values, result)
648
+ result << val[2]
649
+ result
650
+ end
651
+ .,.,
652
+
653
+ # reduce 16 omitted
654
+
655
+ module_eval(<<'.,.,', 'ecma.y', 72)
656
+ def _reduce_17(val, _values, result)
657
+ result = RVM::Interpreter::Assignment.new(result, val[2])
658
+ result
659
+ end
660
+ .,.,
661
+
662
+ module_eval(<<'.,.,', 'ecma.y', 74)
663
+ def _reduce_18(val, _values, result)
664
+ result = RVM::Interpreter::Sequence.new([result])
665
+ result
666
+ end
667
+ .,.,
668
+
669
+ module_eval(<<'.,.,', 'ecma.y', 75)
670
+ def _reduce_19(val, _values, result)
671
+ result << val[2]
672
+ result
673
+ end
674
+ .,.,
675
+
676
+ # reduce 20 omitted
677
+
678
+ module_eval(<<'.,.,', 'ecma.y', 78)
679
+ def _reduce_21(val, _values, result)
680
+ result = RVM::Interpreter::Block.new(val[1])
681
+ result
682
+ end
683
+ .,.,
684
+
685
+ # reduce 22 omitted
686
+
687
+ # reduce 23 omitted
688
+
689
+ # reduce 24 omitted
690
+
691
+ # reduce 25 omitted
692
+
693
+ # reduce 26 omitted
694
+
695
+ # reduce 27 omitted
696
+
697
+ module_eval(<<'.,.,', 'ecma.y', 87)
698
+ def _reduce_28(val, _values, result)
699
+ result = RVM::Interpreter::Return.new(val[1])
700
+ result
701
+ end
702
+ .,.,
703
+
704
+ module_eval(<<'.,.,', 'ecma.y', 90)
705
+ def _reduce_29(val, _values, result)
706
+ seq = RVM::Interpreter::Sequence.new()
707
+ seq << RVM::Interpreter::Assignment.new(RVM::Interpreter.const(:string,'!temp'), RVM::Interpreter.const(:list, Array.new(val[1].size)))
708
+ val[1].size.times do |i|
709
+ seq << RVM::Interpreter::FunctionCall.new(:set_at, [RVM::Interpreter::Variable.new(RVM::Interpreter.const(:string,'!temp')), RVM::Interpreter.const(:number,val[1].size - i - 1), val[1][i]])
710
+ end
711
+ seq << RVM::Interpreter::Variable.new(RVM::Interpreter.const(:string,'!temp'))
712
+ result = RVM::Interpreter::Block.new(seq)
713
+
714
+ result
715
+ end
716
+ .,.,
717
+
718
+ module_eval(<<'.,.,', 'ecma.y', 99)
719
+ def _reduce_30(val, _values, result)
720
+ result = [result]
721
+ result
722
+ end
723
+ .,.,
724
+
725
+ module_eval(<<'.,.,', 'ecma.y', 100)
726
+ def _reduce_31(val, _values, result)
727
+ result.unshift val[2]
728
+ result
729
+ end
730
+ .,.,
731
+
732
+ module_eval(<<'.,.,', 'ecma.y', 102)
733
+ def _reduce_32(val, _values, result)
734
+ result = RVM::Interpreter::FunctionCall.new(:add, [result, val[2]])
735
+ result
736
+ end
737
+ .,.,
738
+
739
+ module_eval(<<'.,.,', 'ecma.y', 103)
740
+ def _reduce_33(val, _values, result)
741
+ result = RVM::Interpreter::FunctionCall.new(:sub, [result, val[2]])
742
+ result
743
+ end
744
+ .,.,
745
+
746
+ module_eval(<<'.,.,', 'ecma.y', 104)
747
+ def _reduce_34(val, _values, result)
748
+ result = RVM::Interpreter::FunctionCall.new(:mul, [result, val[2]])
749
+ result
750
+ end
751
+ .,.,
752
+
753
+ module_eval(<<'.,.,', 'ecma.y', 105)
754
+ def _reduce_35(val, _values, result)
755
+ result = RVM::Interpreter::FunctionCall.new(:sub, [result, val[2]])
756
+ result
757
+ end
758
+ .,.,
759
+
760
+ module_eval(<<'.,.,', 'ecma.y', 106)
761
+ def _reduce_36(val, _values, result)
762
+ result = RVM::Interpreter::FunctionCall.new(:power, [result, val[2]])
763
+ result
764
+ end
765
+ .,.,
766
+
767
+ # reduce 37 omitted
768
+
769
+ module_eval(<<'.,.,', 'ecma.y', 109)
770
+ def _reduce_38(val, _values, result)
771
+ result = RVM::Interpreter::FunctionCall.new(:lt, [result, val[2]])
772
+ result
773
+ end
774
+ .,.,
775
+
776
+ module_eval(<<'.,.,', 'ecma.y', 110)
777
+ def _reduce_39(val, _values, result)
778
+ result = RVM::Interpreter::FunctionCall.new(:gt, [result, val[2]])
779
+ result
780
+ end
781
+ .,.,
782
+
783
+ module_eval(<<'.,.,', 'ecma.y', 111)
784
+ def _reduce_40(val, _values, result)
785
+ result = RVM::Interpreter::FunctionCall.new(:eq, [result, val[2]])
786
+ result
787
+ end
788
+ .,.,
789
+
790
+ module_eval(<<'.,.,', 'ecma.y', 112)
791
+ def _reduce_41(val, _values, result)
792
+ result = RVM::Interpreter::FunctionCall.new(:neq, [result, val[2]])
793
+ result
794
+ end
795
+ .,.,
796
+
797
+ module_eval(<<'.,.,', 'ecma.y', 113)
798
+ def _reduce_42(val, _values, result)
799
+ result = RVM::Interpreter::FunctionCall.new(:gte, [result, val[2]])
800
+ result
801
+ end
802
+ .,.,
803
+
804
+ module_eval(<<'.,.,', 'ecma.y', 114)
805
+ def _reduce_43(val, _values, result)
806
+ result = RVM::Interpreter::FunctionCall.new(:lte, [result, val[2]])
807
+ result
808
+ end
809
+ .,.,
810
+
811
+ module_eval(<<'.,.,', 'ecma.y', 115)
812
+ def _reduce_44(val, _values, result)
813
+ result = RVM::Interpreter::FunctionCall.new(:and, [result, val[2]])
814
+ result
815
+ end
816
+ .,.,
817
+
818
+ module_eval(<<'.,.,', 'ecma.y', 116)
819
+ def _reduce_45(val, _values, result)
820
+ result = RVM::Interpreter::FunctionCall.new(:or, [result, val[2]])
821
+ result
822
+ end
823
+ .,.,
824
+
825
+ # reduce 46 omitted
826
+
827
+ module_eval(<<'.,.,', 'ecma.y', 119)
828
+ def _reduce_47(val, _values, result)
829
+ result = RVM::Interpreter::FunctionCall.new(:at, val[0])
830
+ result
831
+ end
832
+ .,.,
833
+
834
+ module_eval(<<'.,.,', 'ecma.y', 120)
835
+ def _reduce_48(val, _values, result)
836
+ result = RVM::Interpreter::FunctionCall.new(:not, [result, val[2]])
837
+ result
838
+ end
839
+ .,.,
840
+
841
+ module_eval(<<'.,.,', 'ecma.y', 121)
842
+ def _reduce_49(val, _values, result)
843
+ result = RVM::Interpreter::FunctionCall.new(:neg, [val[1]])
844
+ result
845
+ end
846
+ .,.,
847
+
848
+ # reduce 50 omitted
849
+
850
+ # reduce 51 omitted
851
+
852
+ # reduce 52 omitted
853
+
854
+ # reduce 53 omitted
855
+
856
+ module_eval(<<'.,.,', 'ecma.y', 128)
857
+ def _reduce_54(val, _values, result)
858
+ result = RVM::Interpreter::Variable.new(result)
859
+ result
860
+ end
861
+ .,.,
862
+
863
+ module_eval(<<'.,.,', 'ecma.y', 129)
864
+ def _reduce_55(val, _values, result)
865
+ result = val[1]
866
+ result
867
+ end
868
+ .,.,
869
+
870
+ module_eval(<<'.,.,', 'ecma.y', 130)
871
+ def _reduce_56(val, _values, result)
872
+ result
873
+ result
874
+ end
875
+ .,.,
876
+
877
+ module_eval(<<'.,.,', 'ecma.y', 132)
878
+ def _reduce_57(val, _values, result)
879
+ result = RVM::Interpreter::ObjectContext.new(val[0], RVM::Interpreter::Variable.new(val[2]))
880
+ result
881
+ end
882
+ .,.,
883
+
884
+ module_eval(<<'.,.,', 'ecma.y', 133)
885
+ def _reduce_58(val, _values, result)
886
+ result = RVM::Interpreter::ObjectContext.new(val[0], RVM::Interpreter::Assignment.new(val[2], val[4]))
887
+ result
888
+ end
889
+ .,.,
890
+
891
+ module_eval(<<'.,.,', 'ecma.y', 134)
892
+ def _reduce_59(val, _values, result)
893
+ result = RVM::Interpreter::ObjectContext.new(val[0],RVM::Interpreter::FunctionCall.new(val[2], val[3]))
894
+ result
895
+ end
896
+ .,.,
897
+
898
+ module_eval(<<'.,.,', 'ecma.y', 135)
899
+ def _reduce_60(val, _values, result)
900
+ result = RVM::Interpreter::ObjectContext.new(val[0],RVM::Interpreter::FunctionCall.new(val[2], []))
901
+ result
902
+ end
903
+ .,.,
904
+
905
+ module_eval(<<'.,.,', 'ecma.y', 137)
906
+ def _reduce_61(val, _values, result)
907
+ result = RVM::Interpreter.const(:number, val[0][0])
908
+ result
909
+ end
910
+ .,.,
911
+
912
+ module_eval(<<'.,.,', 'ecma.y', 138)
913
+ def _reduce_62(val, _values, result)
914
+ result = RVM::Interpreter.const(:string, val[0][0])
915
+ result
916
+ end
917
+ .,.,
918
+
919
+ # reduce 63 omitted
920
+
921
+ module_eval(<<'.,.,', 'ecma.y', 141)
922
+ def _reduce_64(val, _values, result)
923
+ result = RVM::Interpreter::Condition.new(val[2], val[4], val[6])
924
+ result
925
+ end
926
+ .,.,
927
+
928
+ module_eval(<<'.,.,', 'ecma.y', 142)
929
+ def _reduce_65(val, _values, result)
930
+ result = RVM::Interpreter::Condition.new(val[2], val[4])
931
+ result
932
+ end
933
+ .,.,
934
+
935
+ module_eval(<<'.,.,', 'ecma.y', 145)
936
+ def _reduce_66(val, _values, result)
937
+ init = val[2]
938
+ cond = val[4]
939
+ event = val[6]
940
+ command = val[8]
941
+
942
+ body = if command.is_a?(RVM::Interpreter::Block)
943
+ command.content << event
944
+ else
945
+ RVM::Interpreter::Sequence.new([command, event])
946
+ end
947
+
948
+ result = RVM::Interpreter::Block.new(
949
+ RVM::Interpreter::Sequence.new(
950
+ [init,RVM::Interpreter::Loop.new(cond, body)]
951
+ )
952
+ )
953
+
954
+ result
955
+ end
956
+ .,.,
957
+
958
+ module_eval(<<'.,.,', 'ecma.y', 164)
959
+ def _reduce_67(val, _values, result)
960
+ cond = val[2]
961
+ body = val[4]
962
+ result = RVM::Interpreter::Block.new(
963
+ RVM::Interpreter::Loop.new(cond, body)
964
+ )
965
+
966
+ result
967
+ end
968
+ .,.,
969
+
970
+ module_eval(<<'.,.,', 'ecma.y', 171)
971
+ def _reduce_68(val, _values, result)
972
+ cond = val[4]
973
+ body = val[1]
974
+ result = RVM::Interpreter::Block.new(
975
+ RVM::Interpreter::Sequence.new(
976
+ [block,RVM::Interpreter::Loop.new(cond, body)]
977
+ )
978
+ )
979
+
980
+ result
981
+ end
982
+ .,.,
983
+
984
+ module_eval(<<'.,.,', 'ecma.y', 180)
985
+ def _reduce_69(val, _values, result)
986
+ result = RVM::Interpreter.const(:string,result[0])
987
+ result
988
+ end
989
+ .,.,
990
+
991
+ def _reduce_none(val, _values, result)
992
+ val[0]
993
+ end
994
+
995
+ end # class ECMA
996
+ end # module Languages
997
+ end # module RVM