BOAST 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/BOAST.gemspec +1 -1
  2. data/lib/BOAST/Algorithm.rb +31 -25
  3. metadata +1 -1
data/BOAST.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'BOAST'
3
- s.version = "0.5"
3
+ s.version = "0.6"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://forge.imag.fr/projects/boast/"
@@ -250,19 +250,39 @@ module BOAST
250
250
  return Expression::new("-",nil,self)
251
251
  end
252
252
 
253
+ def Expression.to_str_base(op1, op2, oper)
254
+ s = ""
255
+ if op1 then
256
+ s += "(" if (oper == "*" or oper == "/")
257
+ s += op1.to_s
258
+ s += ")" if (oper == "*" or oper == "/")
259
+ end
260
+ s += " " unless oper == "++" or oper == "."
261
+ s += oper
262
+ s += " " unless oper == "." or oper == "&" or ( oper == "*" and op1.nil? )
263
+ if op2 then
264
+ s += "(" if (oper == "*" or oper == "/" or oper == "-")
265
+ s += op2.to_s
266
+ s += ")" if (oper == "*" or oper == "/" or oper == "-")
267
+ end
268
+ return s
269
+ end
270
+
253
271
  def to_var
254
272
  op1 = nil
255
- op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var)
273
+ op1 = @operand1.to_var if @operand1.respond_to?(:to_var)
256
274
  op2 = nil
257
- op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var)
258
- res_exp = Expression::new(@operator, op1.nil? ? @operand1 : op1, op2.nil? ? @operand2 : op2)
275
+ op2 = @operand2.to_var if @operand2.respond_to?(:to_var)
259
276
  if op1 and op2 then
260
277
  r_t, oper = BOAST::transition(op1, op2, @operator)
261
- return r_t.copy("#{res_exp}", :const => nil, :constant => nil)
262
- elsif op1
263
- return op1.copy("#{res_exp}", :const => nil, :constant => nil)
278
+ res_exp = BOAST::Expression::to_str_base(op1, op2, oper)
279
+ return r_t.copy(res_exp, :const => nil, :constant => nil)
264
280
  elsif op2
265
- return op2.copy("#{res_exp}", :const => nil, :constant => nil)
281
+ res_exp = BOAST::Expression::to_str_base(@operand1, op2, @operator)
282
+ return op2.copy(res_exp, :const => nil, :constant => nil)
283
+ elsif op1
284
+ res_exp = BOAST::Expression::to_str_base(op1, @operand2, @operator)
285
+ return op1.copy(res_exp, :const => nil, :constant => nil)
266
286
  else
267
287
  STDERR.puts "#{@operand1} #{@operand2}"
268
288
  raise "Expression on no operand!"
@@ -271,9 +291,9 @@ module BOAST
271
291
 
272
292
  def to_str
273
293
  op1 = nil
274
- op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var)
294
+ op1 = @operand1.to_var if @operand1.respond_to?(:to_var)
275
295
  op2 = nil
276
- op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var)
296
+ op2 = @operand2.to_var if @operand2.respond_to?(:to_var)
277
297
  if op1 and op2 then
278
298
  r_t, oper = BOAST::transition(op1, op2, @operator)
279
299
  else
@@ -282,22 +302,8 @@ module BOAST
282
302
 
283
303
  op1 = @operand1 if not op1
284
304
  op2 = @operand2 if not op2
285
-
286
- s = ""
287
- if op1 then
288
- s += "(" if (oper == "*" or oper == "/")
289
- s += op1.to_s
290
- s += ")" if (oper == "*" or oper == "/")
291
- end
292
- s += " " unless oper == "++" or oper == "."
293
- s += oper
294
- s += " " unless oper == "." or oper == "&" or ( oper == "*" and op1.nil? )
295
- if op2 then
296
- s += "(" if (oper == "*" or oper == "/" or oper == "-")
297
- s += op2.to_s
298
- s += ")" if (oper == "*" or oper == "/" or oper == "-")
299
- end
300
- return s
305
+
306
+ return BOAST::Expression::to_str_base(op1, op2, oper)
301
307
  end
302
308
 
303
309
  def print(final=true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BOAST
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: