loxxy 0.0.22 → 0.0.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acd7b65477866aee4f022731a70f67cad63f482eae6ae5e3f5a35cd56c43f9b0
4
- data.tar.gz: 4980c1dafbd83c1ed0a41cf5da09d0decba43e912722c5052fc3e4f63626d73a
3
+ metadata.gz: aeb2808649debaf9bdbca836e459b0f7991442c90aad6bb4b174374fb66234df
4
+ data.tar.gz: 78b1b43091b11b5bde2b2444dd785e3c464252af044167acade6f04b830f95fa
5
5
  SHA512:
6
- metadata.gz: e8853388df750173e1a9e818e3aac92f33f98ff75cf5c575d0b583758c59938810a593823a73a6914a28413ba697d53147d7317b744484d43b4026c76a182bc4
7
- data.tar.gz: 3426ce17792625f908f2a31c879b0a312cbefbe18c82848f769d78bcac550d3700349fc1408bbeddb7738b47735ed583fd89355636c8c377a7cde3baf2f5071f
6
+ metadata.gz: 24113720fa7bcd7d711cf03668c86af5a10de3b06dcf9b02d6a5c3550d86e0a19d5374b0d0de6c641afd2a5a9de7c7baccee9da96f97fece6aaf37864d91a0d3
7
+ data.tar.gz: 0103b262f03272b23f297a57b7d0735c513f6ef0b82e9a2f13e20068845e0cb6ac1952c46a404247b23dde37e75c3fbc48b45f44c1b07470078e4554d5ed54c5
@@ -1,7 +1,17 @@
1
+ ## [0.0.23] - 2021-01-20
2
+ - Fix for variables without explicit initialization.
3
+
4
+ ### Added
5
+ - Method `Ast::ASTVisitor#visit_builtin` for visiting `Datatype::BuiltinDatatype` value.
6
+ - Method `BackEnd::Engine#before_visit_builtin` push the data value onto the stack.
7
+
8
+ ### Fixed
9
+ - Method `Ast::LoxVarStmt#initialize`: in case no explicit value provided then use `Datatype::Nil.instance`instead of Ruby `nil`
10
+
1
11
  ## [0.0.22] - 2021-01-17
2
12
  - The interpreter can retrieve the value of a variable.
3
13
 
4
- ## Added
14
+ ### Added
5
15
  - Method `Ast::ASTBuilder#declaration_plus_more` and `Ast::ASTBuilder#declaration_plus_end` to allow multiple expressions/statements
6
16
  - Method `Ast::ASTBuilder#reduce_var_expression` creates an `Ast::LoxVariableExpr` node
7
17
  - Method `Ast::ASTVisitor#visit_var_expr` for visiting `Ast::LoxVariableExpr` nodes
@@ -9,14 +19,14 @@
9
19
  - Class `Ast::LoxVarExpr` a node that represents a variable occurrence in an expression
10
20
  - Method `Engine::after_variable_expr`: retrieve the value of variable with given name
11
21
 
12
- ## Changed
22
+ ### Changed
13
23
  - Method `Ast::ASTBuilder#reduce_lox_program` to support multiple statements/declarations
14
24
  - File `README.md` updated.
15
25
 
16
26
  ## [0.0.21] - 2021-01-16
17
27
  - The interpreter supports the declaration global variables.
18
28
 
19
- ## Added
29
+ ### Added
20
30
  - Class `BackEnd::Entry`, mixin module for objects put in the symbol table
21
31
  - Class `BackEnd::Environment` that keeps track of variables in a given context.
22
32
  - Class `BackEnd::SymbolTable` that keeps track of environments.
@@ -29,7 +39,7 @@
29
39
  ## [0.0.20] - 2021-01-15
30
40
  - The interpreter supports the `if` ... `else` statement.
31
41
 
32
- ## Added
42
+ ### Added
33
43
  - Class `Ast::LoxItStmt`, AST node specific for `if` `else` statements
34
44
  - Method `Ast::ASTBuilder#reduce_if_stmt` as semantic action for if ... else
35
45
  - Method `Ast::ASTVisitor#visit_if_stmt` for visiting `LoxIfStmt` nodes
@@ -38,20 +48,20 @@
38
48
  ## [0.0.19] - 2021-01-14
39
49
  - The interpreter supports expressions between parentheses (grouping).
40
50
 
41
- ## Added
51
+ ### Added
42
52
  - Class `Ast::LoxLogicalExpr`
43
53
  - Method `Ast::ASTBuilder#reduce_grouping_expr` as semantic action for grouping expression
44
54
  - Method `Ast::ASTVisitor#visit_grouping_expr` for visiting grouping expressions
45
55
  - Method `Engine::after_grouping_expr`for the evaluation of grouping expressions
46
56
 
47
- ## Changed
57
+ ### Changed
48
58
  - File `grammar.rb` rules for if ... else were given names in order to activate semantic actions.
49
59
  - File `README.md` updated with little `if ... else` documentation.
50
60
 
51
61
  ## [0.0.18] - 2021-01-13
52
62
  - The interpreter can evaluate `and`, `or`expressions.
53
63
 
54
- ## Added
64
+ ### Added
55
65
  - Class `Ast::LoxLogicalExpr`
56
66
  - Method `Ast::ASTBuilder#reduce_logical_expr` for the semantic action require for `and`, `or`
57
67
  - Method `Ast::ASTVisitor#visit_logical_expr` for visiting logical expressions
@@ -61,7 +71,7 @@
61
71
  - The interpreter can evaluate all arithmetic and comparison operations.
62
72
  - It implements `==`, `!=` and the unary operations `!`, `-`
63
73
 
64
- ## Added
74
+ ### Added
65
75
  - Class `Ast::LoxUnaryExpr`
66
76
  - Method `Ast::ASTBuilder#reduce_unary_expr` to support the evaluation of `!` and ``-@`
67
77
  - Method `Ast::ASTVisitor#visit_unnary_expr` for visiting unary expressions
@@ -69,14 +79,14 @@
69
79
  - In class `Datatype::BuiltinDatatype` the methods `falsey?`, `truthy?`, `!`, `!=`
70
80
  - In class `Datatype::Number`the methods `<`, `<=`, ´>´, `>=` and `-@`
71
81
 
72
- ## Changed
82
+ ### Changed
73
83
  - File `README.md` updated.
74
84
 
75
85
  ## [0.0.16] - 2021-01-11
76
86
  - The interpreter can evaluate product and division of two numbers.
77
87
  - It also implements equality `==` and inequality `!=` operators
78
88
 
79
- ## Added
89
+ ### Added
80
90
  - Method `Datatype::False#==` for equality testing
81
91
  - Method `Datatype::False#!=` for inequality testing
82
92
  - Method `Datatype::LXString#==` for equality testing
@@ -90,17 +100,17 @@
90
100
  - Method `Datatype::True#==` for equality testing
91
101
  - Method `Datatype::True#!=` for inequality testing
92
102
 
93
- ## Changed
103
+ ### Changed
94
104
  - Method `BackEnd::Engine#after_binary_expr` to allow `*`, `/`, `==`, `!=` operators
95
105
  - File `README.md` updated for the newly implemented operators
96
106
 
97
107
  ## [0.0.15] - 2021-01-11
98
108
  - The interpreter can evaluate substraction between two numbers.
99
109
 
100
- ## Added
110
+ ### Added
101
111
  - Method `Datatype::Number#-` implmenting the subtraction operation
102
112
 
103
- ## Changed
113
+ ### Changed
104
114
  - File `README.md` minor editorial changes.
105
115
  - File `lx_string_spec.rb` Added test for string concatentation
106
116
  - File `number_spec.rb` Added tests for addition and subtraction operations
@@ -109,7 +119,7 @@
109
119
  ## [0.0.14] - 2021-01-10
110
120
  - The interpreter can evaluate addition of numbers and string concatenation
111
121
 
112
- ## Added
122
+ ### Added
113
123
  - Method `Ast::ASTVisitor#visit_binary_expr` for visiting binary expressions
114
124
  - Method `Ast::LoxBinaryExpr#accept` for visitor pattern
115
125
  - Method `BackEnd::Engine#after_binary_expr` to trigger execution of binary operator
@@ -117,79 +127,79 @@
117
127
  - Method `Datatype::LXString#+` implementation of the string concatenation
118
128
  - Method `Datatype::Number#+` implementation of the addition of numbers
119
129
 
120
- ## Changed
130
+ ### Changed
121
131
  - File `interpreter_spec.rb` Added tests for addition operation and string concatenation
122
132
 
123
133
 
124
134
  ## [0.0.13] - 2021-01-10
125
135
  - The interpreter can evaluate directly simple literals.
126
136
 
127
- ## Changed
137
+ ### Changed
128
138
  - Class `AST::ASTBuilder` added `reduce_exprStmt` to support the evaluation of literals.
129
139
  - File `README.md` added one more example.
130
140
  - File `parser_spec.rb` Updated the tests to reflect the change in the AST.
131
141
  - File `interpreter_spec.rb` Added a test for literal expression.
132
142
 
133
- ## Fixed
143
+ ### Fixed
134
144
  - File `loxxy.rb`: shorthand method `lox_true` referenced the ... false object (oops).
135
145
 
136
146
  ## [0.0.12] - 2021-01-09
137
147
  - Initial interpreter capable of evaluating a tiny subset of Lox language.
138
148
 
139
- ## Added
149
+ ### Added
140
150
  - Class `AST::LoxNoopExpr`
141
151
  - Class `AST::LoxPrintStmt`
142
152
  - Class `BackEnd::Engine` implementation of the print statement logic
143
153
  - Class `Interpreter`
144
154
 
145
- ## Changed
155
+ ### Changed
146
156
  - Class `Ast::ASTVisitor` Added visit method
147
157
  - File `README.md` added Hello world example.
148
158
 
149
159
  ## [0.0.11] - 2021-01-08
150
160
  - AST node generation for logical expression (and, or).
151
161
 
152
- ## Changed
162
+ ### Changed
153
163
  - Class `AST::ASTBuilder` added `reduce_` methods for logical operations.
154
164
  - File `grammar.rb`added name to logical expression rules
155
165
  - File `README.md` added gem version and license badges, expanded roadmap section.
156
166
 
157
- ## Fixed
167
+ ### Fixed
158
168
  - File `grammar.rb`: a rule had incomplete non-terminal name `conjunct_` in its lhs.
159
169
 
160
170
 
161
171
  ## [0.0.10] - 2021-01-08
162
172
  - AST node generation for equality expression.
163
173
 
164
- ## Changed
174
+ ### Changed
165
175
  - Class `AST::ASTBuilder` refactoring and added `reduce_` methods for equality operations.
166
176
  - File `grammar.rb`added name to equality rules
167
177
  - File `README.md` added gem version and license badges, expanded roadmap section.
168
178
 
169
- ## Fixed
179
+ ### Fixed
170
180
  - File `grammar.rb`: a rule had still the discarded non-terminal `equalityTest_star` in its lhs.
171
181
 
172
182
  ## [0.0.9] - 2021-01-07
173
183
  - AST node generation for comparison expression.
174
184
 
175
- ## Changed
185
+ ### Changed
176
186
  - Class `AST::ASTBuilder` added `reduce_` methods for comparison operations.
177
187
  - File `grammar.rb`added name to comparison rules
178
188
 
179
189
  ## [0.0.8] - 2021-01-07
180
190
  - AST node generation for arithmetic operations of number literals.
181
191
 
182
- ## Changed
192
+ ### Changed
183
193
  - Class `AST::ASTBuilder` added `reduce_` methods for arithmetic operations.
184
194
  - File `grammar.rb`added name to arithmetic rules
185
195
 
186
- ## Fixed
196
+ ### Fixed
187
197
  - File `grammar.rb`: second rule for `factor` had a missing member in rhs.
188
198
 
189
199
  ## [0.0.7] - 2021-01-06
190
200
  - Lox grammar reworked, initial AST classes created.
191
201
 
192
- ## Added
202
+ ### Added
193
203
  - Class `Parser` this one generates AST's (Abstract Syntax Tree)
194
204
  - Class `AST::ASTVisitor` draft initial implementation.
195
205
  - Class `AST::BinaryExpr` draft initial implementation.
@@ -197,7 +207,7 @@
197
207
  - Class `AST::LiteralExpr` draft initial implementation.
198
208
  - Class `AST::LoxNode` draft initial implementation.
199
209
 
200
- ## Changed
210
+ ### Changed
201
211
  - File `spec_helper.rb`: removed Bundler dependency
202
212
  - Class `AST::ASTBuilder` added initial `reduce_` methods.
203
213
  - File `README.md` Removed example with AST generation since this is in flux.
@@ -205,31 +215,31 @@
205
215
  ## [0.0.6] - 2021-01-03
206
216
  - First iteration of a parser with AST generation.
207
217
 
208
- ## Added
218
+ ### Added
209
219
  - Class `Parser` this one generates AST's (Abstract Syntax Tree)
210
220
  - Class `AST::ASTBuilder` default code to generate an AST.
211
221
 
212
- ## Changed
222
+ ### Changed
213
223
  - File `spec_helper.rb`: removed Bundler dependency
214
224
  - File `README.md` Added example with AST visualization.
215
225
 
216
- ## Fixed
226
+ ### Fixed
217
227
  - File `grammar.rb` ensure that the constant `Grammar` is created once only.
218
228
 
219
229
  ## [0.0.5] - 2021-01-02
220
230
  - Improved example in `README.md`, code re-styling to please `Rubocop` 1.7
221
231
 
222
- ## Changed
232
+ ### Changed
223
233
  - Code re-styling to please `Rubocop` 1.7
224
234
  - File `README.md` Improved example with better parse tree visualization.
225
235
 
226
236
  ## [0.0.4] - 2021-01-01
227
237
  - A first parser implementation able to parse Lox source code.
228
238
 
229
- ## Added
239
+ ### Added
230
240
  - Method `LXString::==` equality operator.
231
241
 
232
- ## Changed
242
+ ### Changed
233
243
  - class `Parser` renamed to `RawParser`
234
244
  - File `README.md` Added an example showing the use of `RawParser` class.
235
245
 
data/README.md CHANGED
@@ -270,6 +270,7 @@ foo; // Varible expression (= retrieving its value)
270
270
  ``` javascript
271
271
  var iAmAVariable = "my-initial-value";
272
272
  var iAmNil; // __Lox__ initializes variables to nil by default;
273
+ print iAmNil; // output: nil
273
274
  ```
274
275
 
275
276
  Warning: current version cannot assign a value to an existing variable.
@@ -149,18 +149,18 @@ module Loxxy
149
149
  end
150
150
 
151
151
  # rule('program' => 'declaration_plus EOF').as ''
152
- def reduce_lox_program(_production, range, tokens, theChildren)
152
+ def reduce_lox_program(_production, _range, tokens, theChildren)
153
153
  LoxSeqDecl.new(tokens[0].position, theChildren[0])
154
154
  end
155
155
 
156
156
  # rule('declaration_plus' => 'declaration_plus declaration').as ''
157
- def reduce_declaration_plus_more(_production, range, tokens, theChildren)
157
+ def reduce_declaration_plus_more(_production, _range, _tokens, theChildren)
158
158
  theChildren[0] << theChildren[1]
159
159
  end
160
160
 
161
161
  # rule('declaration_plus' => 'declaration')
162
- def reduce_declaration_plus_end(_production, range, tokens, theChildren)
163
- [ theChildren[0] ]
162
+ def reduce_declaration_plus_end(_production, _range, _tokens, theChildren)
163
+ [theChildren[0]]
164
164
  end
165
165
 
166
166
  # rule('exprStmt' => 'expression SEMICOLON')
@@ -180,7 +180,6 @@ module Loxxy
180
180
  Ast::LoxVarStmt.new(tokens[1].position, var_name, theChildren[3])
181
181
  end
182
182
 
183
-
184
183
  # rule('ifStmt' => 'IF ifCondition statement elsePart_opt')
185
184
  def reduce_if_stmt(_production, _range, tokens, theChildren)
186
185
  condition = theChildren[1]
@@ -307,8 +306,7 @@ module Loxxy
307
306
  def reduce_variable_expr(_production, _range, tokens, theChildren)
308
307
  var_name = theChildren[0].token.lexeme
309
308
  LoxVariableExpr.new(tokens[0].position, var_name)
310
- end#
311
-
309
+ end
312
310
  end # class
313
311
  end # module
314
312
  end # module
@@ -136,6 +136,13 @@ module Loxxy
136
136
  broadcast(:after_variable_expr, aVariableExpr, self)
137
137
  end
138
138
 
139
+ # Visit event. The visitor is about to visit the given terminal datatype value.
140
+ # @param aNonTerminalNode [Ast::BuiltinDattype] the built-in datatype value
141
+ def visit_builtin(aValue)
142
+ broadcast(:before_visit_builtin, aValue)
143
+ broadcast(:after_visit_builtin, aValue)
144
+ end
145
+
139
146
  # Visit event. The visitor is about to visit the given non terminal node.
140
147
  # @param aNonTerminalNode [Rley::PTree::NonTerminalNode] the node to visit.
141
148
  def visit_nonterminal(_non_terminal_node)
@@ -32,4 +32,4 @@ module Loxxy
32
32
  end
33
33
  end # class
34
34
  end # module
35
- end # module
35
+ end # module
@@ -5,12 +5,6 @@ require_relative 'lox_compound_expr'
5
5
  module Loxxy
6
6
  module Ast
7
7
  class LoxSeqDecl < LoxCompoundExpr
8
- # @param aPosition [Rley::Lexical::Position] Position of the entry in the input stream.
9
- # @param declarations [Arrya<Loxxy::Ast::LoxNode>]
10
- def initialize(aPosition, declarations)
11
- super(aPosition, declarations)
12
- end
13
-
14
8
  # Part of the 'visitee' role in Visitor design pattern.
15
9
  # @param visitor [Ast::ASTVisitor] the visitor
16
10
  def accept(visitor)
@@ -13,7 +13,7 @@ module Loxxy
13
13
  # @param aName [String] name of the variable
14
14
  # @param aValue [Loxxy::Ast::LoxNode, NilClass] initial value for the variable
15
15
  def initialize(aPosition, aName, aValue)
16
- initial_value = aValue ? [aValue] : []
16
+ initial_value = aValue ? [aValue] : [Datatype::Nil.instance]
17
17
  super(aPosition, initial_value)
18
18
  @name = aName
19
19
  end
@@ -55,7 +55,7 @@ module Loxxy
55
55
  # Retrieve the result of the condition evaluation
56
56
  condition = stack.pop
57
57
  if condition.truthy?
58
- result = anIfStmt.then_stmt.accept(aVisitor)
58
+ anIfStmt.then_stmt.accept(aVisitor)
59
59
  elsif anIfStmt.else_stmt
60
60
  anIfStmt.else_stmt.accept(aVisitor)
61
61
  end
@@ -129,6 +129,7 @@ module Loxxy
129
129
  var_name = aVarExpr.name
130
130
  var = symbol_table.lookup(var_name)
131
131
  raise StandardError, "Unknown variable #{var_name}" unless var
132
+
132
133
  var.value.accept(aVisitor) # Evaluate the variable value
133
134
  end
134
135
 
@@ -136,6 +137,11 @@ module Loxxy
136
137
  def before_literal_expr(literalExpr)
137
138
  stack.push(literalExpr.literal)
138
139
  end
140
+
141
+ # @param aNonTerminalNode [Ast::BuiltinDattype] the built-in datatype value
142
+ def before_visit_builtin(aValue)
143
+ stack.push(aValue)
144
+ end
139
145
  end # class
140
146
  end # module
141
147
  end # module
@@ -11,7 +11,7 @@ module Loxxy
11
11
  =begin
12
12
  # @return [String] Suffix for building the internal name of the entry.
13
13
  attr_accessor :suffix
14
- =end
14
+ =end
15
15
 
16
16
  # Initialize the entry with given name
17
17
  # @param aName [String] The name of the entry
@@ -35,7 +35,7 @@ module Loxxy
35
35
  (suffix.nil? || suffix.empty?) ? label : suffix
36
36
  end
37
37
  end
38
- =end
38
+ =end
39
39
  end # module
40
40
  end # module
41
41
  end # module
@@ -9,7 +9,7 @@ module Loxxy
9
9
  # It is a named slot that can be associated with a value at the time.
10
10
  class Variable
11
11
  include Entry # Add expected behaviour for symbol table entries
12
-
12
+
13
13
  # @return [Datatype::BuiltinDatatype] the value assigned to the variable
14
14
  attr_accessor :value
15
15
 
@@ -62,6 +62,12 @@ module Loxxy
62
62
  value.to_s # Default implementation...
63
63
  end
64
64
 
65
+ # Part of the 'visitee' role in Visitor design pattern.
66
+ # @param visitor [Ast::ASTVisitor] the visitor
67
+ def accept(visitor)
68
+ visitor.visit_builtin(self)
69
+ end
70
+
65
71
  protected
66
72
 
67
73
  def validated_value(aValue)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loxxy
4
- VERSION = '0.0.22'
4
+ VERSION = '0.0.23'
5
5
  end
@@ -9,7 +9,7 @@ module Loxxy
9
9
  module BackEnd
10
10
  describe Environment do
11
11
  let(:foo) { Datatype::LXString.new('foo') }
12
- let(:bar) { Datatype::LXString.new('bar') }
12
+ let(:bar) { Datatype::LXString.new('bar') }
13
13
  let(:mother) { Environment.new }
14
14
  subject { Environment.new(mother) }
15
15
 
@@ -46,8 +46,8 @@ module Loxxy
46
46
  end
47
47
 
48
48
  it 'should allow the addition of several labels for same env' do
49
- i_name = subject.insert(var('q'))
50
- #expect(i_name).to match(/^q_[0-9a-z]*$/)
49
+ subject.insert(var('q'))
50
+ # expect(i_name).to match(/^q_[0-9a-z]*$/)
51
51
 
52
52
  expect { subject.insert(var('x')) }.not_to raise_error
53
53
  expect(subject.name2envs['x']).to be_kind_of(Array)
@@ -17,10 +17,10 @@ module Loxxy
17
17
  it 'should be initialized with a name and a value, or...' do
18
18
  expect { Variable.new(sample_name, sample_value) }.not_to raise_error
19
19
  end
20
-
20
+
21
21
  it 'should be initialized with just a name' do
22
22
  expect { Variable.new(sample_name) }.not_to raise_error
23
- end
23
+ end
24
24
 
25
25
  it 'should know its name' do
26
26
  expect(subject.name).to eq(sample_name)
@@ -29,11 +29,11 @@ module Loxxy
29
29
  it 'should have a frozen name' do
30
30
  expect(subject.name).to be_frozen
31
31
  end
32
-
32
+
33
33
  it 'should know its value (if provided)' do
34
34
  expect(subject.value).to eq(sample_value)
35
35
  end
36
-
36
+
37
37
  it 'should have a nil value otherwise' do
38
38
  instance = Variable.new(sample_name)
39
39
  expect(instance.value).to eq(Datatype::Nil.instance)
@@ -53,10 +53,12 @@ module Loxxy
53
53
 
54
54
  context 'Evaluating Lox code:' do
55
55
  let(:hello_world) do
56
- lox =<<-LOX_END
56
+ lox = <<-LOX_END
57
57
  var greeting = "Hello"; // Declaring a variable
58
58
  print greeting + ", " + "world!"; // ... Playing with concatenation
59
59
  LOX_END
60
+
61
+ lox
60
62
  end
61
63
 
62
64
  it 'should evaluate core data types' do
@@ -240,7 +242,7 @@ LOX_END
240
242
  ['if (true) print "then-branch"; else print "else-branch";', 'then-branch'],
241
243
  ['if (false) print "then-branch"; else print "else-branch";', 'else-branch'],
242
244
  ['if (0) print "then-branch"; else print "else-branch";', 'then-branch'],
243
- ['if (nil) print "then-branch"; else print "else-branch";', 'else-branch'],
245
+ ['if (nil) print "then-branch"; else print "else-branch";', 'else-branch']
244
246
  # TODO: test with else block body
245
247
 
246
248
  # TODO: A dangling else binds to the right-most if.
@@ -250,7 +252,7 @@ LOX_END
250
252
  io = StringIO.new
251
253
  cfg = { ostream: io }
252
254
  lox = Loxxy::Interpreter.new(cfg)
253
- result = lox.evaluate(source)
255
+ lox.evaluate(source)
254
256
  expect(io.string).to eq(predicted)
255
257
  end
256
258
  end
@@ -267,12 +269,21 @@ LOX_END
267
269
  it 'should accept variable mention' do
268
270
  program = <<-LOX_END
269
271
  var foo = "bar";
270
- print foo;
272
+ print foo; // => bar
271
273
  LOX_END
272
274
  expect { subject.evaluate(program) }.not_to raise_error
273
275
  expect(sample_cfg[:ostream].string).to eq('bar')
274
276
  end
275
277
 
278
+ it 'should set uninitialized variables to nil' do
279
+ program = <<-LOX_END
280
+ var foo;
281
+ print foo; // => nil
282
+ LOX_END
283
+ expect { subject.evaluate(program) }.not_to raise_error
284
+ expect(sample_cfg[:ostream].string).to eq('nil')
285
+ end
286
+
276
287
  it 'should print the hello world message' do
277
288
  expect { subject.evaluate(hello_world) }.not_to raise_error
278
289
  expect(sample_cfg[:ostream].string).to eq('Hello, world!')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loxxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-17 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley