turmali 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75974b5214de62ac8e5c6f8d7adae49d6039834e
4
- data.tar.gz: 67991b4258c5b5f2f90961c14f44f531a8f02f03
3
+ metadata.gz: 9933a3719549c259b1563d70bbd652554aae16d9
4
+ data.tar.gz: 317bbc633bc618b4b249119a045f51fd7b3ce12d
5
5
  SHA512:
6
- metadata.gz: c0216246bc2cc359ba1daf650a3e6ddbb1224c4c5950e7384f4d710f3e8935a5141d9af6cb816068c4984854303960ca8ebb9f338c4254a4aad461d14c919796
7
- data.tar.gz: e38c41b1ac77d3d2f9aba43f5902d0d6f7524a71b943e2df1c22f3b04f86fa3a969b6d1527201ca43cab7e651fdddbd4245e2f29380b86e101e3c41740bb8bae
6
+ metadata.gz: 291ff83a3a34dc538dfadf989a34b678941a331ceb17e1c00779ac951af724511b9e8ed5bc17dc5568ad1df42ca1cbcdea84824719b364e9a306f67440d352cc
7
+ data.tar.gz: 56449014334e5e508cdd717c4a64f8076711e3e8491ebb0c3c9ff11c97e8b7653f1b0d8fa1ce45a82558047a9f6108eabc4733b9df2e4662edc28bf203c1de62
@@ -1,5 +1,7 @@
1
1
  class Parser
2
2
 
3
+ # We need to tell the parser what tokens to expect. So each type of token produced
4
+ # by our lexer needs to be declared here.
3
5
  token IF
4
6
  token DEF
5
7
  token CLASS
@@ -10,7 +12,11 @@ token TRUE FALSE NIL
10
12
  token IDENTIFIER
11
13
  token CONSTANT
12
14
  token INDENT DEDENT
15
+ token WHILE
13
16
 
17
+ # Here is the Operator Precedence Table. As presented before, it tells the parser in
18
+ # which order to parse expressions containing operators.
19
+ # This table is based on the [C and C++ Operator Precedence Table](http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence).
14
20
  prechigh
15
21
  left '.'
16
22
  right '!'
@@ -24,13 +30,41 @@ prechigh
24
30
  left ','
25
31
  preclow
26
32
 
27
-
33
+ # In the following `rule` section, we define the parsing rules.
34
+ # All rules are declared using the following format:
35
+ #
36
+ # RuleName:
37
+ # OtherRule TOKEN AnotherRule { result = Node.new }
38
+ # | OtherRule { ... }
39
+ # ;
40
+ #
41
+ # In the action section (inside the `{...}` on the right), you can do the following:
42
+ #
43
+ # * Assign to `result` the value returned by the rule, usually a node for the AST.
44
+ # * Use `val[index of expression]` to get the `result` of a matched
45
+ # expressions on the left.
28
46
  rule
47
+ # First, parsers are dumb, we need to explicitly tell it how to handle empty
48
+ # programs. This is what the first rule does. Note that everything between `/* ... */` is
49
+ # a comment.
29
50
  Program:
30
51
  /* nothing */ { result = Nodes.new([]) }
31
52
  | Expressions { result = val[0] }
32
53
  ;
33
54
 
55
+ # Next, we define what a list of expressions is. Simply put, it's series of expressions separated by a
56
+ # terminator (a new line or `;` as defined later). But once again, we need to explicitly
57
+ # define how to handle trailing and orphans line breaks (the last two lines).
58
+ #
59
+ # One very powerful trick we'll use to define variable rules like this one
60
+ # (rules which can match any number of tokens) is *left-recursion*. Which means we reference
61
+ # the rule itself, directly or indirectly, on the left side **only**. This is true for the current
62
+ # type of parser we're using (LR). For other types of parsers like ANTLR (LL), it's the opposite,
63
+ # you can only use right-recursion.
64
+ #
65
+ # As you'll see bellow, the `Expressions` rule references `Expressions` itself.
66
+ # In other words, a list of expressions can be another list of expressions followed by
67
+ # another expression.
34
68
  Expressions:
35
69
  Expression { result = Nodes.new(val) }
36
70
  | Expressions Terminator Expression { result = val[0] << val[2] }
@@ -38,6 +72,7 @@ rule
38
72
  | Terminator { result = Nodes.new([]) }
39
73
  ;
40
74
 
75
+ # Every type of expression supported by our language is defined here.
41
76
  Expression:
42
77
  Literal
43
78
  | Call
@@ -49,14 +84,24 @@ rule
49
84
  | Def
50
85
  | Class
51
86
  | If
87
+ | While
52
88
  | '(' Expression ')' { result = val[1] }
53
89
  ;
54
90
 
91
+ # Notice how we implement support for parentheses using the previous rule.
92
+ # `'(' Expression ')'` will force the parsing of `Expression` in its
93
+ # entirety first. Parentheses will then be discarded leaving only the fully parsed expression.
94
+ #
95
+ # Terminators are tokens that can terminate an expression.
96
+ # When using tokens to define rules, we simply reference them by their type which we defined in
97
+ # the lexer.
55
98
  Terminator:
56
99
  NEWLINE
57
100
  | ";"
58
101
  ;
59
-
102
+
103
+ # Literals are the hard-coded values inside the program. If you want to add support
104
+ # for other literal types, such as arrays or hashes, this it where you'd do it.
60
105
  Literal:
61
106
  NUMBER { result = NumberNode.new(val[0]) }
62
107
  | STRING { result = StringNode.new(val[0]) }
@@ -64,7 +109,15 @@ rule
64
109
  | FALSE { result = FalseNode.new }
65
110
  | NIL { result = NilNode.new }
66
111
  ;
67
-
112
+
113
+ # Method calls can take three forms:
114
+ #
115
+ # * Without a receiver (`self` is assumed): `method(arguments)`.
116
+ # * With a receiver: `receiver.method(arguments)`.
117
+ # * And a hint of syntactic sugar so that we can drop
118
+ # the `()` if no arguments are given: `receiver.method`.
119
+ #
120
+ # Each one of those is handled by the following rule.
68
121
  Call:
69
122
  IDENTIFIER Arguments { result = CallNode.new(nil, val[0], val[1]) }
70
123
  | Expression "." IDENTIFIER
@@ -82,6 +135,13 @@ rule
82
135
  | ArgList "," Expression { result = val[0] << val[2] }
83
136
  ;
84
137
 
138
+
139
+ # In our language, like in Ruby, operators are converted to method calls.
140
+ # So `1 + 2` will be converted to `1.+(2)`.
141
+ # `1` is the receiver of the `+` method call, passing `2`
142
+ # as an argument.
143
+ # Operators need to be defined individually for the Operator Precedence Table to take
144
+ # action.
85
145
  Operator:
86
146
  Expression '||' Expression { result = CallNode.new(val[0], val[1], [val[2]]) }
87
147
  | Expression '&&' Expression { result = CallNode.new(val[0], val[1], [val[2]]) }
@@ -97,6 +157,7 @@ rule
97
157
  | Expression '/' Expression { result = CallNode.new(val[0], val[1], [val[2]]) }
98
158
  ;
99
159
 
160
+ # Then we have rules for getting and setting values of constants and local variables.
100
161
  GetConstant:
101
162
  CONSTANT { result = GetConstantNode.new(val[0]) }
102
163
  ;
@@ -113,10 +174,20 @@ rule
113
174
  IDENTIFIER "=" Expression { result = SetLocalNode.new(val[0], val[2]) }
114
175
  ;
115
176
 
177
+ # Our language uses indentation to separate blocks of code. But the lexer took care of all
178
+ # that complexity for us and wrapped all blocks in `INDENT ... DEDENT`. A block
179
+ # is simply an increment in indentation followed by some code and closing with an equivalent
180
+ # decrement in indentation.
181
+ #
182
+ # If you'd like to use curly brackets or `end` to delimit blocks instead, you'd
183
+ # simply need to modify this one rule.
184
+ # You'll also need to remove the indentation logic from the lexer.
116
185
  Block:
117
186
  INDENT Expressions DEDENT { result = val[1] }
118
187
  ;
119
-
188
+
189
+ # The `def` keyword is used for defining methods. Once again, we're introducing
190
+ # a bit of syntactic sugar here to allow skipping the parentheses when there are no parameters.
120
191
  Def:
121
192
  DEF IDENTIFIER Block { result = DefNode.new(val[1], [], val[2]) }
122
193
  | DEF IDENTIFIER
@@ -128,16 +199,25 @@ rule
128
199
  | IDENTIFIER { result = val }
129
200
  | ParamList "," IDENTIFIER { result = val[0] << val[2] }
130
201
  ;
131
-
202
+
203
+ # Class definition is similar to method definition.
204
+ # Class names are also constants because they start with a capital letter.
132
205
  Class:
133
206
  CLASS CONSTANT Block { result = ClassNode.new(val[1], val[2]) }
134
207
  ;
135
-
208
+
209
+ # Finally, `if` is similar to `class` but receives a *condition*.
136
210
  If:
137
211
  IF Expression Block { result = IfNode.new(val[1], val[2]) }
138
212
  ;
213
+
214
+ While:
215
+ WHILE Expression Block { result = WhileNode.new(val[1], val[2]) }
216
+ ;
139
217
  end
140
218
 
219
+ # The final code at the bottom of this Racc file will be put as-is in the generated `Parser` class.
220
+ # You can put some code at the top (`header`) and some inside the class (`inner`).
141
221
  ---- header
142
222
  require "turmali/lexer"
143
223
  require "turmali/nodes"
@@ -1,9 +1,9 @@
1
- require "turmali/parser"
1
+ require "turmali/runtime/bootstrap"
2
2
  require "turmali/runtime/object"
3
3
  require "turmali/runtime/method"
4
4
  require "turmali/runtime/context"
5
5
  require "turmali/runtime/class"
6
- require "turmali/runtime/bootstrap"
6
+ require "turmali/parser"
7
7
 
8
8
  class Interpreter
9
9
  def initialize
@@ -123,4 +123,13 @@ class IfNode
123
123
  Constants["nil"]
124
124
  end
125
125
  end
126
+ end
127
+
128
+ class WhileNode
129
+ def eval(context)
130
+ while @condition.eval(context).ruby_value
131
+ @body.eval(context)
132
+ end
133
+ Constants["nil"]
134
+ end
126
135
  end
data/lib/turmali/lexer.rb CHANGED
@@ -8,7 +8,7 @@ class Lexer
8
8
 
9
9
  current_indent = 0
10
10
  indent_stack = []
11
-
11
+
12
12
  i = 0
13
13
  while i < code.size
14
14
  chunk = code[i..-1]
@@ -20,7 +20,7 @@ class Lexer
20
20
  tokens << [:IDENTIFIER, identifier]
21
21
  end
22
22
  i += identifier.size
23
-
23
+
24
24
  elsif constant = chunk[/\A([A-Z]\w*)/, 1]
25
25
  tokens << [:CONSTANT, constant]
26
26
  i += constant.size
@@ -28,11 +28,11 @@ class Lexer
28
28
  elsif number = chunk[/\A([0-9]+)/, 1]
29
29
  tokens << [:NUMBER, number.to_i]
30
30
  i += number.size
31
-
31
+
32
32
  elsif string = chunk[/\A"([^"]*)"/, 1]
33
33
  tokens << [:STRING, string]
34
34
  i += string.size + 2
35
-
35
+
36
36
  elsif indent = chunk[/\A\:\n( +)/m, 1]
37
37
  if indent.size <= current_indent
38
38
  raise "Bad indent level, got #{indent.size} indents, " +
@@ -53,11 +53,11 @@ class Lexer
53
53
  tokens << [:DEDENT, indent.size]
54
54
  end
55
55
  tokens << [:NEWLINE, "\n"]
56
- else
56
+ else
57
57
  raise "Missing ':'"
58
58
  end
59
59
  i += indent.size + 1
60
-
60
+
61
61
  elsif operator = chunk[/\A(\|\||&&|==|!=|<=|>=)/, 1]
62
62
  tokens << [operator, operator]
63
63
  i += operator.size
data/lib/turmali/nodes.rb CHANGED
@@ -43,4 +43,6 @@ class DefNode < Struct.new(:name, :params, :body); end
43
43
 
44
44
  class ClassNode < Struct.new(:name, :body); end
45
45
 
46
- class IfNode < Struct.new(:condition, :body); end
46
+ class IfNode < Struct.new(:condition, :body); end
47
+
48
+ class WhileNode < Struct.new(:condition, :body); end
@@ -1,13 +1,13 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.6
3
+ # This file is automatically generated by Racc 1.4.14
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
7
7
  require 'racc/parser.rb'
8
8
 
9
- require "turmali/lexer"
10
- require "turmali/nodes"
9
+ require "turmali/lexer"
10
+ require "turmali/nodes"
11
11
 
12
12
  class Parser < Racc::Parser
13
13
 
@@ -27,23 +27,23 @@ module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 220)
27
27
  racc_action_table = [
28
28
  27, 25, 26, 16, 18, 19, 20, 21, 22, 23,
29
29
  24, 27, 25, 26, 16, 18, 19, 20, 21, 22,
30
- 23, 24, 30, 72, 41, 42, 39, 40, 53, 15,
31
- 30, 17, 41, 42, 39, 40, 30, 16, 16, 30,
32
- 15, 74, 17, 27, 25, 26, 84, 18, 19, 20,
33
- 21, 22, 23, 24, 27, 25, 26, 45, 18, 19,
34
- 20, 21, 22, 23, 24, 17, 17, 30, 72, 41,
35
- 42, 47, 15, 68, 30, 82, 41, 42, 39, 40,
30
+ 23, 24, 30, 72, 41, 42, 39, 40, 88, 15,
31
+ 30, 17, 41, 42, 39, 40, 30, 16, 41, 42,
32
+ 15, 74, 17, 27, 25, 26, 51, 18, 19, 20,
33
+ 21, 22, 23, 24, 27, 25, 26, 49, 18, 19,
34
+ 20, 21, 22, 23, 24, 17, 16, 30, 48, 41,
35
+ 42, 47, 15, 68, 30, 84, 41, 42, 39, 40,
36
36
  27, 25, 26, 15, 18, 19, 20, 21, 22, 23,
37
- 24, 27, 25, 26, 48, 18, 19, 20, 21, 22,
38
- 23, 24, 30, 28, 41, 42, 27, 25, 26, 15,
37
+ 24, 27, 25, 26, 17, 18, 19, 20, 21, 22,
38
+ 23, 24, 46, 79, 45, 78, 27, 25, 26, 15,
39
39
  18, 19, 20, 21, 22, 23, 24, 27, 25, 26,
40
- 15, 18, 19, 20, 21, 22, 23, 24, 86, 79,
41
- 85, 78, 27, 25, 26, 15, 18, 19, 20, 21,
40
+ 15, 18, 19, 20, 21, 22, 23, 24, 86, 72,
41
+ 85, 45, 27, 25, 26, 15, 18, 19, 20, 21,
42
42
  22, 23, 24, 27, 25, 26, 15, 18, 19, 20,
43
- 21, 22, 23, 24, 46, 49, 45, 51, 27, 25,
43
+ 21, 22, 23, 24, 30, 30, 82, 28, 27, 25,
44
44
  26, 15, 18, 19, 20, 21, 22, 23, 24, 27,
45
45
  25, 26, 15, 18, 19, 20, 21, 22, 23, 24,
46
- 72, 88, nil, nil, 27, 25, 26, 15, 18, 19,
46
+ 72, 53, nil, nil, 27, 25, 26, 15, 18, 19,
47
47
  20, 21, 22, 23, 24, 27, 25, 26, 15, 18,
48
48
  19, 20, 21, 22, 23, 24, nil, nil, nil, nil,
49
49
  27, 25, 26, 15, 18, 19, 20, 21, 22, 23,
@@ -76,62 +76,62 @@ racc_action_table = [
76
76
  racc_action_check = [
77
77
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78
78
  0, 72, 72, 72, 72, 72, 72, 72, 72, 72,
79
- 72, 72, 61, 48, 61, 61, 61, 61, 30, 0,
80
- 60, 0, 60, 60, 60, 60, 64, 80, 2, 65,
81
- 72, 48, 72, 45, 45, 45, 80, 45, 45, 45,
82
- 45, 45, 45, 45, 29, 29, 29, 53, 29, 29,
83
- 29, 29, 29, 29, 29, 80, 2, 62, 49, 62,
84
- 62, 24, 45, 45, 58, 74, 58, 58, 58, 58,
85
- 15, 15, 15, 29, 15, 15, 15, 15, 15, 15,
86
- 15, 40, 40, 40, 25, 40, 40, 40, 40, 40,
87
- 40, 40, 63, 1, 63, 63, 41, 41, 41, 15,
88
- 41, 41, 41, 41, 41, 41, 41, 47, 47, 47,
89
- 40, 47, 47, 47, 47, 47, 47, 47, 81, 69,
90
- 81, 69, 46, 46, 46, 41, 46, 46, 46, 46,
91
- 46, 46, 46, 27, 27, 27, 47, 27, 27, 27,
92
- 27, 27, 27, 27, 23, 26, 23, 28, 39, 39,
93
- 39, 46, 39, 39, 39, 39, 39, 39, 39, 79,
94
- 79, 79, 27, 79, 79, 79, 79, 79, 79, 79,
95
- 85, 86, nil, nil, 42, 42, 42, 39, 42, 42,
96
- 42, 42, 42, 42, 42, 38, 38, 38, 79, 38,
97
- 38, 38, 38, 38, 38, 38, nil, nil, nil, nil,
79
+ 72, 72, 58, 48, 58, 58, 58, 58, 86, 0,
80
+ 59, 0, 59, 59, 59, 59, 63, 2, 63, 63,
81
+ 72, 48, 72, 45, 45, 45, 28, 45, 45, 45,
82
+ 45, 45, 45, 45, 40, 40, 40, 26, 40, 40,
83
+ 40, 40, 40, 40, 40, 2, 80, 62, 25, 62,
84
+ 62, 24, 45, 45, 60, 80, 60, 60, 60, 60,
85
+ 79, 79, 79, 40, 79, 79, 79, 79, 79, 79,
86
+ 79, 15, 15, 15, 80, 15, 15, 15, 15, 15,
87
+ 15, 15, 23, 69, 23, 69, 39, 39, 39, 79,
88
+ 39, 39, 39, 39, 39, 39, 39, 41, 41, 41,
89
+ 15, 41, 41, 41, 41, 41, 41, 41, 81, 49,
90
+ 81, 53, 47, 47, 47, 39, 47, 47, 47, 47,
91
+ 47, 47, 47, 46, 46, 46, 41, 46, 46, 46,
92
+ 46, 46, 46, 46, 64, 65, 74, 1, 27, 27,
93
+ 27, 47, 27, 27, 27, 27, 27, 27, 27, 29,
94
+ 29, 29, 46, 29, 29, 29, 29, 29, 29, 29,
95
+ 85, 30, nil, nil, 42, 42, 42, 27, 42, 42,
96
+ 42, 42, 42, 42, 42, 31, 31, 31, 29, 31,
97
+ 31, 31, 31, 31, 31, 31, nil, nil, nil, nil,
98
98
  32, 32, 32, 42, 32, 32, 32, 32, 32, 32,
99
- 32, 33, 33, 33, 38, 33, 33, 33, 33, 33,
99
+ 32, 33, 33, 33, 31, 33, 33, 33, 33, 33,
100
100
  33, 33, nil, nil, nil, nil, 34, 34, 34, 32,
101
101
  34, 34, 34, 34, 34, 34, 34, 35, 35, 35,
102
102
  33, 35, 35, 35, 35, 35, 35, 35, nil, nil,
103
103
  nil, nil, 36, 36, 36, 34, 36, 36, 36, 36,
104
104
  36, 36, 36, 37, 37, 37, 35, 37, 37, 37,
105
- 37, 37, 37, 37, nil, nil, nil, nil, 31, 31,
106
- 31, 36, 31, 31, 31, 31, 31, 31, 31, nil,
105
+ 37, 37, 37, 37, nil, nil, nil, nil, 38, 38,
106
+ 38, 36, 38, 38, 38, 38, 38, 38, 38, nil,
107
107
  nil, 43, 37, 43, 43, 43, 43, 43, 43, 43,
108
- 43, 43, 43, 43, 43, nil, nil, 31, 43, 50,
108
+ 43, 43, 43, 43, 43, nil, nil, 38, 43, 50,
109
109
  nil, 50, nil, 50, 50, 50, 50, 50, 50, 50,
110
- 50, 50, 50, 50, 50, 3, nil, 3, 3, 3,
111
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 52,
112
- nil, 52, 52, 52, 52, 52, 52, 52, 52, 52,
113
- 52, 52, 52, 83, nil, 83, 83, 83, 83, 83,
114
- 83, 83, 83, 83, 83, 83, 83, 70, nil, 70,
115
- 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
116
- 70, 71, nil, 71, 71, 71, 71, 71, 71, 71,
117
- 71, 71, 71, 71, 71, 67, nil, 67, 67, 67,
118
- 67, 67, 67, 67, 67, 67, 67, 67, 67, 54,
110
+ 50, 50, 50, 50, 50, 70, nil, 70, 70, 70,
111
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 71,
112
+ nil, 71, 71, 71, 71, 71, 71, 71, 71, 71,
113
+ 71, 71, 71, 83, nil, 83, 83, 83, 83, 83,
114
+ 83, 83, 83, 83, 83, 83, 83, 67, nil, 67,
115
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
116
+ 67, 3, nil, 3, 3, 3, 3, 3, 3, 3,
117
+ 3, 3, 3, 3, 3, 52, nil, 52, 52, 52,
118
+ 52, 52, 52, 52, 52, 52, 52, 52, 52, 54,
119
119
  nil, 54, 54, 54, 54, 54, 54, 54, 54, 54,
120
120
  54, 54, 55, nil, 55, 55, 55, 55, 55, 55,
121
- 55, 55, 55, 55, 57, nil, 57, 57, 57, 57,
122
- 57, 57, 57, 57, 56, nil, 56, 56, 56, 56,
123
- 56, 56, 56, 56, 59, nil, 59, 59, 59, 59 ]
121
+ 55, 55, 55, 55, 56, nil, 56, 56, 56, 56,
122
+ 56, 56, 56, 56, 57, nil, 57, 57, 57, 57,
123
+ 57, 57, 57, 57, 61, nil, 61, 61, 61, 61 ]
124
124
 
125
125
  racc_action_pointer = [
126
- -2, 103, 33, 320, nil, nil, nil, nil, nil, nil,
127
- nil, nil, nil, nil, nil, 78, nil, nil, nil, nil,
128
- nil, nil, nil, 125, 42, 83, 143, 141, 157, 52,
129
- 17, 286, 208, 219, 234, 245, 260, 271, 193, 156,
130
- 89, 104, 182, 286, nil, 41, 130, 115, 10, 55,
131
- 306, nil, 334, 26, 404, 417, 439, 429, 59, 449,
132
- 15, 7, 52, 87, 21, 24, nil, 390, nil, 99,
133
- 362, 376, 9, nil, 64, nil, nil, nil, nil, 167,
134
- 32, 98, nil, 348, nil, 167, 170, nil, nil ]
126
+ -2, 157, 32, 376, nil, nil, nil, nil, nil, nil,
127
+ nil, nil, nil, nil, nil, 89, nil, nil, nil, nil,
128
+ nil, nil, nil, 73, 42, 57, 45, 156, 46, 167,
129
+ 170, 193, 208, 219, 234, 245, 260, 271, 286, 104,
130
+ 52, 115, 182, 286, nil, 41, 141, 130, 10, 116,
131
+ 306, nil, 390, 100, 404, 417, 429, 439, 7, 15,
132
+ 59, 449, 52, 21, 139, 140, nil, 362, nil, 73,
133
+ 320, 334, 9, nil, 145, nil, nil, nil, nil, 78,
134
+ 61, 98, nil, 348, nil, 167, 17, nil, nil ]
135
135
 
136
136
  racc_action_default = [
137
137
  -1, -56, -2, -3, -6, -7, -8, -9, -10, -11,
@@ -145,7 +145,7 @@ racc_action_default = [
145
145
  -56, -56, -52, -31, -48, -56, -56, -50, -53 ]
146
146
 
147
147
  racc_goto_table = [
148
- 29, 2, 43, 73, 75, 76, 44, 1, 69, 81,
148
+ 29, 2, 43, 73, 75, 76, 44, 81, 69, 1,
149
149
  nil, nil, nil, nil, 50, nil, 52, nil, 54, 55,
150
150
  56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
151
151
  nil, nil, 67, 70, 71, nil, 77, nil, nil, nil,
@@ -155,7 +155,7 @@ racc_goto_table = [
155
155
  nil, nil, nil, 80, nil, nil, nil, nil, 29 ]
156
156
 
157
157
  racc_goto_check = [
158
- 4, 2, 3, 17, 17, 17, 15, 1, 16, 18,
158
+ 4, 2, 3, 17, 17, 17, 15, 18, 16, 1,
159
159
  nil, nil, nil, nil, 3, nil, 3, nil, 3, 3,
160
160
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
161
161
  nil, nil, 3, 3, 3, nil, 15, nil, nil, nil,
@@ -165,8 +165,8 @@ racc_goto_check = [
165
165
  nil, nil, nil, 2, nil, nil, nil, nil, 4 ]
166
166
 
167
167
  racc_goto_pointer = [
168
- nil, 7, 1, -13, -2, nil, nil, nil, nil, nil,
169
- nil, nil, nil, nil, nil, -17, -37, -45, -65 ]
168
+ nil, 9, 1, -13, -2, nil, nil, nil, nil, nil,
169
+ nil, nil, nil, nil, nil, -17, -37, -45, -67 ]
170
170
 
171
171
  racc_goto_default = [
172
172
  nil, nil, nil, 3, 4, 5, 6, 7, 8, 9,
@@ -27,3 +27,23 @@ Constants["Object"].def :print do |receiver, arguments|
27
27
  puts arguments.first.ruby_value
28
28
  Constants["nil"]
29
29
  end
30
+
31
+ Constants["Number"].def :+ do |receiver,arguments|
32
+ result = receiver.ruby_value + arguments.first.ruby_value
33
+ Constants["Number"].new_with_value(result)
34
+ end
35
+
36
+ Constants["Number"].def :- do |receiver,arguments|
37
+ result = receiver.ruby_value - arguments.first.ruby_value
38
+ Constants["Number"].new_with_value(result)
39
+ end
40
+
41
+ Constants["Number"].def :* do |receiver,arguments|
42
+ result = receiver.ruby_value * arguments.first.ruby_value
43
+ Constants["Number"].new_with_value(result)
44
+ end
45
+
46
+ Constants["Number"].def :/ do |receiver,arguments|
47
+ result = receiver.ruby_value / arguments.first.ruby_value
48
+ Constants["Number"].new_with_value(result)
49
+ end
@@ -5,7 +5,7 @@ class TurmaliObject
5
5
  @runtime_class = runtime_class
6
6
  @ruby_value = ruby_value
7
7
  end
8
-
8
+
9
9
  def call(method, arguments=[])
10
10
  @runtime_class.lookup(method).call(self, arguments)
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Turmali
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turmali
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eiffel Qiu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler