sol 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require_relative "sol/version"
2
+ require_relative "sol/interpreter"
3
+ require_relative "sol/lexer"
4
+ require_relative "sol/nodes"
5
+ require_relative "sol/parser"
6
+ require_relative "sol/runtime"
7
+ require_relative "sol/cli"
@@ -0,0 +1,57 @@
1
+ require "readline"
2
+ require_relative "interpreter"
3
+ require_relative "version"
4
+
5
+ module Sol
6
+
7
+ class CLI
8
+
9
+ def initialize
10
+
11
+ @interpreter = Interpreter.new
12
+
13
+ if file = ARGV.first
14
+
15
+ @interpreter.eval File.read(file)
16
+
17
+ else
18
+
19
+ repl()
20
+
21
+ end
22
+
23
+ end
24
+
25
+ def repl
26
+
27
+ Readline.completion_proc = proc {} # Disable tab
28
+
29
+ puts "Sol #{VERSION} running on ruby #{RUBY_VERSION}"
30
+
31
+ loop do
32
+
33
+ begin
34
+
35
+ line = Readline::readline('> ')
36
+
37
+ Readline::HISTORY.push(line)
38
+
39
+ value = @interpreter.eval(line)
40
+
41
+ puts "#{value.ruby_value.inspect}"
42
+
43
+ rescue Interrupt
44
+
45
+ puts "" # To fix the prompt not being printed on a newline
46
+
47
+ puts "Use quit(), exit() or Ctrl-D to exit the repl"
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,9 @@
1
+ func hello() {
2
+
3
+ print("hello, world")
4
+
5
+ print(1+1)
6
+
7
+ }
8
+
9
+ hello()
@@ -0,0 +1,456 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.9
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require "./lexer"
11
+
12
+
13
+ class Parser < Racc::Parser
14
+
15
+ module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 155)
16
+
17
+ # This code will be puts as-is in the Parser class
18
+ def parse(input, show_tokens=true)
19
+
20
+ @tokens = Lexer.new.tokenise(innput) # Tokenise the code using our lexer
21
+
22
+ puts @tokens.inspect if show_tokens
23
+
24
+ do_parse # Kickoff the parsing process
25
+
26
+ end
27
+
28
+ def next_token
29
+
30
+ @tokens.shift
31
+
32
+ end
33
+ ...end grammar.y/module_eval...
34
+ ##### State transition tables begin ###
35
+
36
+ racc_action_table = [
37
+ 23, 22, 13, 15, 16, 17, 18, 19, 20, 21,
38
+ 13, 23, 22, 13, 15, 16, 17, 18, 19, 20,
39
+ 21, 26, 66, 37, 38, 67, 12, 26, 14, 37,
40
+ 38, 35, 36, 41, 13, 40, 14, 12, 79, 14,
41
+ 23, 22, 26, 15, 16, 17, 18, 19, 20, 21,
42
+ 23, 22, 73, 15, 16, 17, 18, 19, 20, 21,
43
+ 14, 71, 42, 70, 23, 22, 12, 15, 16, 17,
44
+ 18, 19, 20, 21, 23, 22, 12, 15, 16, 17,
45
+ 18, 19, 20, 21, 26, 43, 37, 38, 23, 22,
46
+ 12, 15, 16, 17, 18, 19, 20, 21, 23, 22,
47
+ 12, 15, 16, 17, 18, 19, 20, 21, 71, 78,
48
+ 80, 77, 23, 22, 12, 15, 16, 17, 18, 19,
49
+ 20, 21, 23, 22, 12, 15, 16, 17, 18, 19,
50
+ 20, 21, 45, 69, 24, 26, 23, 22, 12, 15,
51
+ 16, 17, 18, 19, 20, 21, 23, 22, 12, 15,
52
+ 16, 17, 18, 19, 20, 21, 47, 67, 82, nil,
53
+ 23, 22, 12, 15, 16, 17, 18, 19, 20, 21,
54
+ 23, 22, 12, 15, 16, 17, 18, 19, 20, 21,
55
+ nil, nil, nil, nil, 23, 22, 12, 15, 16, 17,
56
+ 18, 19, 20, 21, 23, 22, 12, 15, 16, 17,
57
+ 18, 19, 20, 21, nil, nil, nil, nil, 23, 22,
58
+ 12, 15, 16, 17, 18, 19, 20, 21, 23, 22,
59
+ 12, 15, 16, 17, 18, 19, 20, 21, nil, nil,
60
+ nil, nil, 23, 22, 12, 15, 16, 17, 18, 19,
61
+ 20, 21, 23, 22, 12, 15, 16, 17, 18, 19,
62
+ 20, 21, nil, nil, nil, nil, 23, 22, 12, 15,
63
+ 16, 17, 18, 19, 20, 21, 23, 22, 12, 15,
64
+ 16, 17, 18, 19, 20, 21, nil, nil, nil, nil,
65
+ nil, 26, 12, 37, 38, 35, 36, 31, 32, 33,
66
+ 34, 26, 12, 37, 38, 35, 36, 31, 32, 33,
67
+ 34, 29, 30, 28, 27, nil, nil, nil, nil, 26,
68
+ 67, 37, 38, 35, 36, 31, 32, 33, 34, 29,
69
+ 30, 28, 27, nil, nil, 26, 60, 37, 38, 35,
70
+ 36, 31, 32, 33, 34, 29, 30, 28, 27, 26,
71
+ nil, 37, 38, 35, 36, 31, 32, 33, 34, 29,
72
+ 30, 28, 27, 26, nil, 37, 38, 35, 36, 31,
73
+ 32, 33, 34, 29, 30, 28, 27, 26, nil, 37,
74
+ 38, 35, 36, 31, 32, 33, 34, 29, 30, 28,
75
+ 27, 26, nil, 37, 38, 35, 36, 31, 32, 33,
76
+ 34, 29, 30, 28, 27, 26, nil, 37, 38, 35,
77
+ 36, 31, 32, 33, 34, 29, 30, 28, 27, 26,
78
+ nil, 37, 38, 35, 36, 31, 32, 33, 34, 29,
79
+ 30, 28, 26, nil, 37, 38, 35, 36, 31, 32,
80
+ 33, 34, 29, 30, 26, nil, 37, 38, 35, 36,
81
+ 31, 32, 33, 34, 26, nil, 37, 38, 35, 36,
82
+ 26, nil, 37, 38, 35, 36, 26, nil, 37, 38,
83
+ 35, 36 ]
84
+
85
+ racc_action_check = [
86
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87
+ 74, 67, 67, 67, 67, 67, 67, 67, 67, 67,
88
+ 67, 56, 43, 56, 56, 43, 0, 54, 0, 54,
89
+ 54, 54, 54, 20, 2, 20, 74, 67, 74, 67,
90
+ 27, 27, 59, 27, 27, 27, 27, 27, 27, 27,
91
+ 12, 12, 66, 12, 12, 12, 12, 12, 12, 12,
92
+ 2, 61, 21, 61, 69, 69, 27, 69, 69, 69,
93
+ 69, 69, 69, 69, 40, 40, 12, 40, 40, 40,
94
+ 40, 40, 40, 40, 57, 22, 57, 57, 23, 23,
95
+ 69, 23, 23, 23, 23, 23, 23, 23, 42, 42,
96
+ 40, 42, 42, 42, 42, 42, 42, 42, 75, 72,
97
+ 75, 72, 25, 25, 23, 25, 25, 25, 25, 25,
98
+ 25, 25, 41, 41, 42, 41, 41, 41, 41, 41,
99
+ 41, 41, 24, 47, 1, 58, 71, 71, 25, 71,
100
+ 71, 71, 71, 71, 71, 71, 28, 28, 41, 28,
101
+ 28, 28, 28, 28, 28, 28, 26, 77, 78, nil,
102
+ 29, 29, 71, 29, 29, 29, 29, 29, 29, 29,
103
+ 30, 30, 28, 30, 30, 30, 30, 30, 30, 30,
104
+ nil, nil, nil, nil, 31, 31, 29, 31, 31, 31,
105
+ 31, 31, 31, 31, 32, 32, 30, 32, 32, 32,
106
+ 32, 32, 32, 32, nil, nil, nil, nil, 33, 33,
107
+ 31, 33, 33, 33, 33, 33, 33, 33, 34, 34,
108
+ 32, 34, 34, 34, 34, 34, 34, 34, nil, nil,
109
+ nil, nil, 35, 35, 33, 35, 35, 35, 35, 35,
110
+ 35, 35, 36, 36, 34, 36, 36, 36, 36, 36,
111
+ 36, 36, nil, nil, nil, nil, 37, 37, 35, 37,
112
+ 37, 37, 37, 37, 37, 37, 38, 38, 36, 38,
113
+ 38, 38, 38, 38, 38, 38, nil, nil, nil, nil,
114
+ nil, 50, 37, 50, 50, 50, 50, 50, 50, 50,
115
+ 50, 44, 38, 44, 44, 44, 44, 44, 44, 44,
116
+ 44, 44, 44, 44, 44, nil, nil, nil, nil, 39,
117
+ 44, 39, 39, 39, 39, 39, 39, 39, 39, 39,
118
+ 39, 39, 39, nil, nil, 76, 39, 76, 76, 76,
119
+ 76, 76, 76, 76, 76, 76, 76, 76, 76, 3,
120
+ nil, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121
+ 3, 3, 3, 63, nil, 63, 63, 63, 63, 63,
122
+ 63, 63, 63, 63, 63, 63, 63, 64, nil, 64,
123
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
124
+ 64, 46, nil, 46, 46, 46, 46, 46, 46, 46,
125
+ 46, 46, 46, 46, 46, 62, nil, 62, 62, 62,
126
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 48,
127
+ nil, 48, 48, 48, 48, 48, 48, 48, 48, 48,
128
+ 48, 48, 49, nil, 49, 49, 49, 49, 49, 49,
129
+ 49, 49, 49, 49, 51, nil, 51, 51, 51, 51,
130
+ 51, 51, 51, 51, 53, nil, 53, 53, 53, 53,
131
+ 52, nil, 52, 52, 52, 52, 55, nil, 55, 55,
132
+ 55, 55 ]
133
+
134
+ racc_action_pointer = [
135
+ -2, 134, 30, 327, nil, nil, nil, nil, nil, nil,
136
+ nil, nil, 48, nil, nil, nil, nil, nil, nil, nil,
137
+ 7, 36, 75, 86, 132, 110, 146, 38, 144, 158,
138
+ 168, 182, 192, 206, 216, 230, 240, 254, 264, 297,
139
+ 72, 120, 96, -6, 279, nil, 369, 105, 397, 410,
140
+ 269, 422, 438, 432, 15, 444, 9, 72, 123, 30,
141
+ nil, 34, 383, 341, 355, nil, 42, 9, nil, 62,
142
+ nil, 134, 82, nil, 6, 81, 313, 126, 148, nil,
143
+ nil, nil, nil ]
144
+
145
+ racc_action_default = [
146
+ -1, -51, -2, -3, -6, -7, -8, -9, -10, -11,
147
+ -12, -13, -51, -15, -16, -17, -18, -19, -20, -21,
148
+ -22, -41, -51, -51, -51, -5, -51, -51, -51, -51,
149
+ -51, -51, -51, -51, -51, -51, -51, -51, -51, -51,
150
+ -26, -51, -51, -51, -51, 83, -4, -24, -29, -30,
151
+ -31, -32, -33, -34, -35, -36, -37, -38, -39, -40,
152
+ -14, -51, -27, -42, -43, -44, -46, -51, -49, -26,
153
+ -23, -51, -51, -47, -51, -51, -28, -51, -51, -50,
154
+ -25, -45, -48 ]
155
+
156
+ racc_goto_table = [
157
+ 25, 2, 39, 65, 68, 61, 1, 72, nil, nil,
158
+ nil, nil, nil, 44, nil, 46, nil, 48, 49, 50,
159
+ 51, 52, 53, 54, 55, 56, 57, 58, 59, nil,
160
+ 62, 63, 64, nil, 75, nil, nil, 81, nil, nil,
161
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
162
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 62,
163
+ nil, 76, nil, nil, nil, nil, nil, nil, 74, nil,
164
+ nil, nil, 25 ]
165
+
166
+ racc_goto_check = [
167
+ 4, 2, 3, 13, 13, 12, 1, 14, nil, nil,
168
+ nil, nil, nil, 3, nil, 3, nil, 3, 3, 3,
169
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, nil,
170
+ 3, 3, 3, nil, 12, nil, nil, 13, nil, nil,
171
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
172
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 3,
173
+ nil, 3, nil, nil, nil, nil, nil, nil, 2, nil,
174
+ nil, nil, 4 ]
175
+
176
+ racc_goto_pointer = [
177
+ nil, 6, 1, -10, -2, nil, nil, nil, nil, nil,
178
+ nil, nil, -35, -40, -59 ]
179
+
180
+ racc_goto_default = [
181
+ nil, nil, nil, 3, 4, 5, 6, 7, 8, 9,
182
+ 10, 11, nil, nil, nil ]
183
+
184
+ racc_reduce_table = [
185
+ 0, 0, :racc_error,
186
+ 0, 34, :_reduce_none,
187
+ 1, 34, :_reduce_none,
188
+ 1, 35, :_reduce_none,
189
+ 3, 35, :_reduce_none,
190
+ 2, 35, :_reduce_none,
191
+ 1, 35, :_reduce_none,
192
+ 1, 36, :_reduce_none,
193
+ 1, 36, :_reduce_none,
194
+ 1, 36, :_reduce_none,
195
+ 1, 36, :_reduce_none,
196
+ 1, 36, :_reduce_none,
197
+ 1, 36, :_reduce_none,
198
+ 1, 36, :_reduce_none,
199
+ 3, 36, :_reduce_none,
200
+ 1, 37, :_reduce_none,
201
+ 1, 37, :_reduce_none,
202
+ 1, 38, :_reduce_none,
203
+ 1, 38, :_reduce_none,
204
+ 1, 38, :_reduce_none,
205
+ 1, 38, :_reduce_none,
206
+ 1, 38, :_reduce_none,
207
+ 1, 39, :_reduce_none,
208
+ 4, 39, :_reduce_none,
209
+ 3, 39, :_reduce_none,
210
+ 6, 39, :_reduce_none,
211
+ 0, 45, :_reduce_none,
212
+ 1, 45, :_reduce_none,
213
+ 3, 45, :_reduce_none,
214
+ 3, 40, :_reduce_none,
215
+ 3, 40, :_reduce_none,
216
+ 3, 40, :_reduce_none,
217
+ 3, 40, :_reduce_none,
218
+ 3, 40, :_reduce_none,
219
+ 3, 40, :_reduce_none,
220
+ 3, 40, :_reduce_none,
221
+ 3, 40, :_reduce_none,
222
+ 3, 40, :_reduce_none,
223
+ 3, 40, :_reduce_none,
224
+ 3, 40, :_reduce_none,
225
+ 3, 40, :_reduce_none,
226
+ 1, 41, :_reduce_none,
227
+ 3, 42, :_reduce_none,
228
+ 3, 42, :_reduce_none,
229
+ 3, 43, :_reduce_none,
230
+ 6, 43, :_reduce_none,
231
+ 0, 47, :_reduce_none,
232
+ 1, 47, :_reduce_none,
233
+ 3, 47, :_reduce_none,
234
+ 3, 44, :_reduce_none,
235
+ 3, 46, :_reduce_none ]
236
+
237
+ racc_reduce_n = 51
238
+
239
+ racc_shift_n = 83
240
+
241
+ racc_token_table = {
242
+ false => 0,
243
+ :error => 1,
244
+ :IF => 2,
245
+ :FUNC => 3,
246
+ :NEWLINE => 4,
247
+ :NUMBER => 5,
248
+ :STRING => 6,
249
+ :TRUE => 7,
250
+ :FALSE => 8,
251
+ :NULL => 9,
252
+ :IDENTIFIER => 10,
253
+ :CONSTANT => 11,
254
+ "." => 12,
255
+ "!" => 13,
256
+ "*" => 14,
257
+ "/" => 15,
258
+ "+" => 16,
259
+ "-" => 17,
260
+ ">" => 18,
261
+ ">=" => 19,
262
+ "<" => 20,
263
+ "<=" => 21,
264
+ "==" => 22,
265
+ "!=" => 23,
266
+ "&&" => 24,
267
+ "||" => 25,
268
+ "=" => 26,
269
+ "," => 27,
270
+ "(" => 28,
271
+ ")" => 29,
272
+ ";" => 30,
273
+ "{" => 31,
274
+ "}" => 32 }
275
+
276
+ racc_nt_base = 33
277
+
278
+ racc_use_result_var = true
279
+
280
+ Racc_arg = [
281
+ racc_action_table,
282
+ racc_action_check,
283
+ racc_action_default,
284
+ racc_action_pointer,
285
+ racc_goto_table,
286
+ racc_goto_check,
287
+ racc_goto_default,
288
+ racc_goto_pointer,
289
+ racc_nt_base,
290
+ racc_reduce_table,
291
+ racc_token_table,
292
+ racc_shift_n,
293
+ racc_reduce_n,
294
+ racc_use_result_var ]
295
+
296
+ Racc_token_to_s_table = [
297
+ "$end",
298
+ "error",
299
+ "IF",
300
+ "FUNC",
301
+ "NEWLINE",
302
+ "NUMBER",
303
+ "STRING",
304
+ "TRUE",
305
+ "FALSE",
306
+ "NULL",
307
+ "IDENTIFIER",
308
+ "CONSTANT",
309
+ "\".\"",
310
+ "\"!\"",
311
+ "\"*\"",
312
+ "\"/\"",
313
+ "\"+\"",
314
+ "\"-\"",
315
+ "\">\"",
316
+ "\">=\"",
317
+ "\"<\"",
318
+ "\"<=\"",
319
+ "\"==\"",
320
+ "\"!=\"",
321
+ "\"&&\"",
322
+ "\"||\"",
323
+ "\"=\"",
324
+ "\",\"",
325
+ "\"(\"",
326
+ "\")\"",
327
+ "\";\"",
328
+ "\"{\"",
329
+ "\"}\"",
330
+ "$start",
331
+ "Root",
332
+ "Expressions",
333
+ "Expression",
334
+ "Terminator",
335
+ "Literal",
336
+ "Call",
337
+ "Operator",
338
+ "Constant",
339
+ "Assign",
340
+ "Func",
341
+ "If",
342
+ "ArgList",
343
+ "Block",
344
+ "ParamList" ]
345
+
346
+ Racc_debug_parser = true
347
+
348
+ ##### State transition tables end #####
349
+
350
+ # reduce 0 omitted
351
+
352
+ # reduce 1 omitted
353
+
354
+ # reduce 2 omitted
355
+
356
+ # reduce 3 omitted
357
+
358
+ # reduce 4 omitted
359
+
360
+ # reduce 5 omitted
361
+
362
+ # reduce 6 omitted
363
+
364
+ # reduce 7 omitted
365
+
366
+ # reduce 8 omitted
367
+
368
+ # reduce 9 omitted
369
+
370
+ # reduce 10 omitted
371
+
372
+ # reduce 11 omitted
373
+
374
+ # reduce 12 omitted
375
+
376
+ # reduce 13 omitted
377
+
378
+ # reduce 14 omitted
379
+
380
+ # reduce 15 omitted
381
+
382
+ # reduce 16 omitted
383
+
384
+ # reduce 17 omitted
385
+
386
+ # reduce 18 omitted
387
+
388
+ # reduce 19 omitted
389
+
390
+ # reduce 20 omitted
391
+
392
+ # reduce 21 omitted
393
+
394
+ # reduce 22 omitted
395
+
396
+ # reduce 23 omitted
397
+
398
+ # reduce 24 omitted
399
+
400
+ # reduce 25 omitted
401
+
402
+ # reduce 26 omitted
403
+
404
+ # reduce 27 omitted
405
+
406
+ # reduce 28 omitted
407
+
408
+ # reduce 29 omitted
409
+
410
+ # reduce 30 omitted
411
+
412
+ # reduce 31 omitted
413
+
414
+ # reduce 32 omitted
415
+
416
+ # reduce 33 omitted
417
+
418
+ # reduce 34 omitted
419
+
420
+ # reduce 35 omitted
421
+
422
+ # reduce 36 omitted
423
+
424
+ # reduce 37 omitted
425
+
426
+ # reduce 38 omitted
427
+
428
+ # reduce 39 omitted
429
+
430
+ # reduce 40 omitted
431
+
432
+ # reduce 41 omitted
433
+
434
+ # reduce 42 omitted
435
+
436
+ # reduce 43 omitted
437
+
438
+ # reduce 44 omitted
439
+
440
+ # reduce 45 omitted
441
+
442
+ # reduce 46 omitted
443
+
444
+ # reduce 47 omitted
445
+
446
+ # reduce 48 omitted
447
+
448
+ # reduce 49 omitted
449
+
450
+ # reduce 50 omitted
451
+
452
+ def _reduce_none(val, _values, result)
453
+ val[0]
454
+ end
455
+
456
+ end # class Parser