phys-units 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/COPYING +674 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/phys/units.rb +7 -0
- data/lib/phys/units/Makefile +37 -0
- data/lib/phys/units/load_units.rb +5406 -0
- data/lib/phys/units/mixin.rb +12 -0
- data/lib/phys/units/parse.rb +777 -0
- data/lib/phys/units/parse.y +123 -0
- data/lib/phys/units/quantity.rb +252 -0
- data/lib/phys/units/unit.rb +446 -0
- data/lib/phys/units/unit_class.rb +185 -0
- data/lib/phys/units/utils.rb +91 -0
- data/lib/phys/units/version.rb +5 -0
- data/phys-units.gemspec +23 -0
- data/spec/helper.rb +4 -0
- data/spec/quantity_spec.rb +111 -0
- data/spec/unit_spec.rb +234 -0
- data/spec/utils_spec.rb +16 -0
- metadata +97 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require "phys/units"
|
2
|
+
|
3
|
+
class Numeric
|
4
|
+
alias method_missing_orig method_missing
|
5
|
+
def method_missing(method, *args, &block)
|
6
|
+
if unit=Phys::Unit.find_unit(method.to_s)
|
7
|
+
Phys::Quantity.new(self,nil,unit)
|
8
|
+
else
|
9
|
+
method_missing_orig(method,*args, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,777 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.9
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
###### racc/parser.rb begin
|
8
|
+
unless $".index 'racc/parser.rb'
|
9
|
+
$".push 'racc/parser.rb'
|
10
|
+
self.class.module_eval(<<'...end racc/parser.rb/module_eval...', 'racc/parser.rb', 1)
|
11
|
+
#
|
12
|
+
# $Id: ad1fffef443194fdfa1052d2eee6850552f94313 $
|
13
|
+
#
|
14
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
15
|
+
#
|
16
|
+
# This program is free software.
|
17
|
+
# You can distribute/modify this program under the same terms of ruby.
|
18
|
+
#
|
19
|
+
# As a special exception, when this code is copied by Racc
|
20
|
+
# into a Racc output file, you may use that output file
|
21
|
+
# without restriction.
|
22
|
+
#
|
23
|
+
|
24
|
+
unless defined?(NotImplementedError)
|
25
|
+
NotImplementedError = NotImplementError
|
26
|
+
end
|
27
|
+
|
28
|
+
module Racc
|
29
|
+
class ParseError < StandardError; end
|
30
|
+
end
|
31
|
+
unless defined?(::ParseError)
|
32
|
+
ParseError = Racc::ParseError
|
33
|
+
end
|
34
|
+
|
35
|
+
module Racc
|
36
|
+
|
37
|
+
unless defined?(Racc_No_Extentions)
|
38
|
+
Racc_No_Extentions = false
|
39
|
+
end
|
40
|
+
|
41
|
+
class Parser
|
42
|
+
|
43
|
+
Racc_Runtime_Version = '1.4.6'
|
44
|
+
Racc_Runtime_Revision = '$Id: ad1fffef443194fdfa1052d2eee6850552f94313 $'
|
45
|
+
|
46
|
+
Racc_Runtime_Core_Version_R = '1.4.6'
|
47
|
+
Racc_Runtime_Core_Revision_R = '$Id: ad1fffef443194fdfa1052d2eee6850552f94313 $'.split[1]
|
48
|
+
begin
|
49
|
+
require 'racc/cparse'
|
50
|
+
# Racc_Runtime_Core_Version_C = (defined in extention)
|
51
|
+
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
|
52
|
+
unless new.respond_to?(:_racc_do_parse_c, true)
|
53
|
+
raise LoadError, 'old cparse.so'
|
54
|
+
end
|
55
|
+
if Racc_No_Extentions
|
56
|
+
raise LoadError, 'selecting ruby version of racc runtime core'
|
57
|
+
end
|
58
|
+
|
59
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_c
|
60
|
+
Racc_YY_Parse_Method = :_racc_yyparse_c
|
61
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C
|
62
|
+
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C
|
63
|
+
Racc_Runtime_Type = 'c'
|
64
|
+
rescue LoadError
|
65
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
|
66
|
+
Racc_YY_Parse_Method = :_racc_yyparse_rb
|
67
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
|
68
|
+
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R
|
69
|
+
Racc_Runtime_Type = 'ruby'
|
70
|
+
end
|
71
|
+
|
72
|
+
def Parser.racc_runtime_type
|
73
|
+
Racc_Runtime_Type
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def _racc_setup
|
79
|
+
@yydebug = false unless self.class::Racc_debug_parser
|
80
|
+
@yydebug = false unless defined?(@yydebug)
|
81
|
+
if @yydebug
|
82
|
+
@racc_debug_out = $stderr unless defined?(@racc_debug_out)
|
83
|
+
@racc_debug_out ||= $stderr
|
84
|
+
end
|
85
|
+
arg = self.class::Racc_arg
|
86
|
+
arg[13] = true if arg.size < 14
|
87
|
+
arg
|
88
|
+
end
|
89
|
+
|
90
|
+
def _racc_init_sysvars
|
91
|
+
@racc_state = [0]
|
92
|
+
@racc_tstack = []
|
93
|
+
@racc_vstack = []
|
94
|
+
|
95
|
+
@racc_t = nil
|
96
|
+
@racc_val = nil
|
97
|
+
|
98
|
+
@racc_read_next = true
|
99
|
+
|
100
|
+
@racc_user_yyerror = false
|
101
|
+
@racc_error_status = 0
|
102
|
+
end
|
103
|
+
|
104
|
+
###
|
105
|
+
### do_parse
|
106
|
+
###
|
107
|
+
|
108
|
+
def do_parse
|
109
|
+
__send__(Racc_Main_Parsing_Routine, _racc_setup(), false)
|
110
|
+
end
|
111
|
+
|
112
|
+
def next_token
|
113
|
+
raise NotImplementedError, "#{self.class}\#next_token is not defined"
|
114
|
+
end
|
115
|
+
|
116
|
+
def _racc_do_parse_rb(arg, in_debug)
|
117
|
+
action_table, action_check, action_default, action_pointer,
|
118
|
+
_, _, _, _,
|
119
|
+
_, _, token_table, * = arg
|
120
|
+
|
121
|
+
_racc_init_sysvars
|
122
|
+
tok = act = i = nil
|
123
|
+
|
124
|
+
catch(:racc_end_parse) {
|
125
|
+
while true
|
126
|
+
if i = action_pointer[@racc_state[-1]]
|
127
|
+
if @racc_read_next
|
128
|
+
if @racc_t != 0 # not EOF
|
129
|
+
tok, @racc_val = next_token()
|
130
|
+
unless tok # EOF
|
131
|
+
@racc_t = 0
|
132
|
+
else
|
133
|
+
@racc_t = (token_table[tok] or 1) # error token
|
134
|
+
end
|
135
|
+
racc_read_token(@racc_t, tok, @racc_val) if @yydebug
|
136
|
+
@racc_read_next = false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
i += @racc_t
|
140
|
+
unless i >= 0 and
|
141
|
+
act = action_table[i] and
|
142
|
+
action_check[i] == @racc_state[-1]
|
143
|
+
act = action_default[@racc_state[-1]]
|
144
|
+
end
|
145
|
+
else
|
146
|
+
act = action_default[@racc_state[-1]]
|
147
|
+
end
|
148
|
+
while act = _racc_evalact(act, arg)
|
149
|
+
;
|
150
|
+
end
|
151
|
+
end
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
###
|
156
|
+
### yyparse
|
157
|
+
###
|
158
|
+
|
159
|
+
def yyparse(recv, mid)
|
160
|
+
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
|
161
|
+
end
|
162
|
+
|
163
|
+
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
164
|
+
action_table, action_check, action_default, action_pointer,
|
165
|
+
_, _, _, _,
|
166
|
+
_, _, token_table, * = arg
|
167
|
+
|
168
|
+
_racc_init_sysvars
|
169
|
+
|
170
|
+
catch(:racc_end_parse) {
|
171
|
+
until i = action_pointer[@racc_state[-1]]
|
172
|
+
while act = _racc_evalact(action_default[@racc_state[-1]], arg)
|
173
|
+
;
|
174
|
+
end
|
175
|
+
end
|
176
|
+
recv.__send__(mid) do |tok, val|
|
177
|
+
unless tok
|
178
|
+
@racc_t = 0
|
179
|
+
else
|
180
|
+
@racc_t = (token_table[tok] or 1) # error token
|
181
|
+
end
|
182
|
+
@racc_val = val
|
183
|
+
@racc_read_next = false
|
184
|
+
|
185
|
+
i += @racc_t
|
186
|
+
unless i >= 0 and
|
187
|
+
act = action_table[i] and
|
188
|
+
action_check[i] == @racc_state[-1]
|
189
|
+
act = action_default[@racc_state[-1]]
|
190
|
+
end
|
191
|
+
while act = _racc_evalact(act, arg)
|
192
|
+
;
|
193
|
+
end
|
194
|
+
|
195
|
+
while !(i = action_pointer[@racc_state[-1]]) ||
|
196
|
+
! @racc_read_next ||
|
197
|
+
@racc_t == 0 # $
|
198
|
+
unless i and i += @racc_t and
|
199
|
+
i >= 0 and
|
200
|
+
act = action_table[i] and
|
201
|
+
action_check[i] == @racc_state[-1]
|
202
|
+
act = action_default[@racc_state[-1]]
|
203
|
+
end
|
204
|
+
while act = _racc_evalact(act, arg)
|
205
|
+
;
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
###
|
213
|
+
### common
|
214
|
+
###
|
215
|
+
|
216
|
+
def _racc_evalact(act, arg)
|
217
|
+
action_table, action_check, _, action_pointer,
|
218
|
+
_, _, _, _,
|
219
|
+
_, _, _, shift_n,
|
220
|
+
reduce_n, * = arg
|
221
|
+
nerr = 0 # tmp
|
222
|
+
|
223
|
+
if act > 0 and act < shift_n
|
224
|
+
#
|
225
|
+
# shift
|
226
|
+
#
|
227
|
+
if @racc_error_status > 0
|
228
|
+
@racc_error_status -= 1 unless @racc_t == 1 # error token
|
229
|
+
end
|
230
|
+
@racc_vstack.push @racc_val
|
231
|
+
@racc_state.push act
|
232
|
+
@racc_read_next = true
|
233
|
+
if @yydebug
|
234
|
+
@racc_tstack.push @racc_t
|
235
|
+
racc_shift @racc_t, @racc_tstack, @racc_vstack
|
236
|
+
end
|
237
|
+
|
238
|
+
elsif act < 0 and act > -reduce_n
|
239
|
+
#
|
240
|
+
# reduce
|
241
|
+
#
|
242
|
+
code = catch(:racc_jump) {
|
243
|
+
@racc_state.push _racc_do_reduce(arg, act)
|
244
|
+
false
|
245
|
+
}
|
246
|
+
if code
|
247
|
+
case code
|
248
|
+
when 1 # yyerror
|
249
|
+
@racc_user_yyerror = true # user_yyerror
|
250
|
+
return -reduce_n
|
251
|
+
when 2 # yyaccept
|
252
|
+
return shift_n
|
253
|
+
else
|
254
|
+
raise '[Racc Bug] unknown jump code'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
elsif act == shift_n
|
259
|
+
#
|
260
|
+
# accept
|
261
|
+
#
|
262
|
+
racc_accept if @yydebug
|
263
|
+
throw :racc_end_parse, @racc_vstack[0]
|
264
|
+
|
265
|
+
elsif act == -reduce_n
|
266
|
+
#
|
267
|
+
# error
|
268
|
+
#
|
269
|
+
case @racc_error_status
|
270
|
+
when 0
|
271
|
+
unless arg[21] # user_yyerror
|
272
|
+
nerr += 1
|
273
|
+
on_error @racc_t, @racc_val, @racc_vstack
|
274
|
+
end
|
275
|
+
when 3
|
276
|
+
if @racc_t == 0 # is $
|
277
|
+
throw :racc_end_parse, nil
|
278
|
+
end
|
279
|
+
@racc_read_next = true
|
280
|
+
end
|
281
|
+
@racc_user_yyerror = false
|
282
|
+
@racc_error_status = 3
|
283
|
+
while true
|
284
|
+
if i = action_pointer[@racc_state[-1]]
|
285
|
+
i += 1 # error token
|
286
|
+
if i >= 0 and
|
287
|
+
(act = action_table[i]) and
|
288
|
+
action_check[i] == @racc_state[-1]
|
289
|
+
break
|
290
|
+
end
|
291
|
+
end
|
292
|
+
throw :racc_end_parse, nil if @racc_state.size <= 1
|
293
|
+
@racc_state.pop
|
294
|
+
@racc_vstack.pop
|
295
|
+
if @yydebug
|
296
|
+
@racc_tstack.pop
|
297
|
+
racc_e_pop @racc_state, @racc_tstack, @racc_vstack
|
298
|
+
end
|
299
|
+
end
|
300
|
+
return act
|
301
|
+
|
302
|
+
else
|
303
|
+
raise "[Racc Bug] unknown action #{act.inspect}"
|
304
|
+
end
|
305
|
+
|
306
|
+
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
|
307
|
+
|
308
|
+
nil
|
309
|
+
end
|
310
|
+
|
311
|
+
def _racc_do_reduce(arg, act)
|
312
|
+
_, _, _, _,
|
313
|
+
goto_table, goto_check, goto_default, goto_pointer,
|
314
|
+
nt_base, reduce_table, _, _,
|
315
|
+
_, use_result, * = arg
|
316
|
+
|
317
|
+
state = @racc_state
|
318
|
+
vstack = @racc_vstack
|
319
|
+
tstack = @racc_tstack
|
320
|
+
|
321
|
+
i = act * -3
|
322
|
+
len = reduce_table[i]
|
323
|
+
reduce_to = reduce_table[i+1]
|
324
|
+
method_id = reduce_table[i+2]
|
325
|
+
void_array = []
|
326
|
+
|
327
|
+
tmp_t = tstack[-len, len] if @yydebug
|
328
|
+
tmp_v = vstack[-len, len]
|
329
|
+
tstack[-len, len] = void_array if @yydebug
|
330
|
+
vstack[-len, len] = void_array
|
331
|
+
state[-len, len] = void_array
|
332
|
+
|
333
|
+
# tstack must be updated AFTER method call
|
334
|
+
if use_result
|
335
|
+
vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
|
336
|
+
else
|
337
|
+
vstack.push __send__(method_id, tmp_v, vstack)
|
338
|
+
end
|
339
|
+
tstack.push reduce_to
|
340
|
+
|
341
|
+
racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
|
342
|
+
|
343
|
+
k1 = reduce_to - nt_base
|
344
|
+
if i = goto_pointer[k1]
|
345
|
+
i += state[-1]
|
346
|
+
if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
|
347
|
+
return curstate
|
348
|
+
end
|
349
|
+
end
|
350
|
+
goto_default[k1]
|
351
|
+
end
|
352
|
+
|
353
|
+
def on_error(t, val, vstack)
|
354
|
+
raise ParseError, sprintf("\nparse error on value %s (%s)",
|
355
|
+
val.inspect, token_to_str(t) || '?')
|
356
|
+
end
|
357
|
+
|
358
|
+
def yyerror
|
359
|
+
throw :racc_jump, 1
|
360
|
+
end
|
361
|
+
|
362
|
+
def yyaccept
|
363
|
+
throw :racc_jump, 2
|
364
|
+
end
|
365
|
+
|
366
|
+
def yyerrok
|
367
|
+
@racc_error_status = 0
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# for debugging output
|
372
|
+
#
|
373
|
+
|
374
|
+
def racc_read_token(t, tok, val)
|
375
|
+
@racc_debug_out.print 'read '
|
376
|
+
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
|
377
|
+
@racc_debug_out.puts val.inspect
|
378
|
+
@racc_debug_out.puts
|
379
|
+
end
|
380
|
+
|
381
|
+
def racc_shift(tok, tstack, vstack)
|
382
|
+
@racc_debug_out.puts "shift #{racc_token2str tok}"
|
383
|
+
racc_print_stacks tstack, vstack
|
384
|
+
@racc_debug_out.puts
|
385
|
+
end
|
386
|
+
|
387
|
+
def racc_reduce(toks, sim, tstack, vstack)
|
388
|
+
out = @racc_debug_out
|
389
|
+
out.print 'reduce '
|
390
|
+
if toks.empty?
|
391
|
+
out.print ' <none>'
|
392
|
+
else
|
393
|
+
toks.each {|t| out.print ' ', racc_token2str(t) }
|
394
|
+
end
|
395
|
+
out.puts " --> #{racc_token2str(sim)}"
|
396
|
+
|
397
|
+
racc_print_stacks tstack, vstack
|
398
|
+
@racc_debug_out.puts
|
399
|
+
end
|
400
|
+
|
401
|
+
def racc_accept
|
402
|
+
@racc_debug_out.puts 'accept'
|
403
|
+
@racc_debug_out.puts
|
404
|
+
end
|
405
|
+
|
406
|
+
def racc_e_pop(state, tstack, vstack)
|
407
|
+
@racc_debug_out.puts 'error recovering mode: pop token'
|
408
|
+
racc_print_states state
|
409
|
+
racc_print_stacks tstack, vstack
|
410
|
+
@racc_debug_out.puts
|
411
|
+
end
|
412
|
+
|
413
|
+
def racc_next_state(curstate, state)
|
414
|
+
@racc_debug_out.puts "goto #{curstate}"
|
415
|
+
racc_print_states state
|
416
|
+
@racc_debug_out.puts
|
417
|
+
end
|
418
|
+
|
419
|
+
def racc_print_stacks(t, v)
|
420
|
+
out = @racc_debug_out
|
421
|
+
out.print ' ['
|
422
|
+
t.each_index do |i|
|
423
|
+
out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
|
424
|
+
end
|
425
|
+
out.puts ' ]'
|
426
|
+
end
|
427
|
+
|
428
|
+
def racc_print_states(s)
|
429
|
+
out = @racc_debug_out
|
430
|
+
out.print ' ['
|
431
|
+
s.each {|st| out.print ' ', st }
|
432
|
+
out.puts ' ]'
|
433
|
+
end
|
434
|
+
|
435
|
+
def racc_token2str(tok)
|
436
|
+
self.class::Racc_token_to_s_table[tok] or
|
437
|
+
raise "[Racc Bug] can't convert token #{tok} to string"
|
438
|
+
end
|
439
|
+
|
440
|
+
def token_to_str(t)
|
441
|
+
self.class::Racc_token_to_s_table[t]
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
445
|
+
|
446
|
+
end
|
447
|
+
|
448
|
+
...end racc/parser.rb/module_eval...
|
449
|
+
end
|
450
|
+
###### racc/parser.rb end
|
451
|
+
|
452
|
+
|
453
|
+
# -*- coding: utf-8 -*-
|
454
|
+
# parse.y, parse.rb
|
455
|
+
#
|
456
|
+
# by Masahiro Tanaka <masa16.tanaka@gmail.com>
|
457
|
+
#
|
458
|
+
module Phys
|
459
|
+
class Unit
|
460
|
+
class Parse < Racc::Parser
|
461
|
+
|
462
|
+
module_eval(<<'...end parse.y/module_eval...', 'parse.y', 63)
|
463
|
+
|
464
|
+
def build_num(ov,ud,pw)
|
465
|
+
if ud.nil? && pw.nil?
|
466
|
+
#ov.to_i
|
467
|
+
Rational(ov.to_i)
|
468
|
+
else
|
469
|
+
m1 = ud ? ud.size : 0
|
470
|
+
pw = pw ? pw.to_i : 0
|
471
|
+
m2 = pw-m1
|
472
|
+
ov = ov ? ov.to_i : 0
|
473
|
+
ud = ud ? ud.to_i : 0
|
474
|
+
a = ov*10**m1 + ud
|
475
|
+
b = 1
|
476
|
+
a *= 10**m2 if m2>0
|
477
|
+
b *= 10**(-m2) if m2<0
|
478
|
+
Rational(a,b)
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
def parse( str )
|
483
|
+
return Unit.new(str) if str.empty?
|
484
|
+
#p str
|
485
|
+
@q = []
|
486
|
+
|
487
|
+
c = Unit.unit_chars
|
488
|
+
|
489
|
+
while str.size > 0 do
|
490
|
+
case str
|
491
|
+
when /\A[\s]+/o
|
492
|
+
when /\A(\d+)(?:(?:\.(\d*))?(?:[eE]([+-]?\d+))?)/o
|
493
|
+
@q.push [:NUMBER, build_num($1,$2,$3)]
|
494
|
+
when /\A(sin|cos|tan|log|ln|log2)\b/o
|
495
|
+
@q.push [:UFUNC, $&]
|
496
|
+
when /\A\//o
|
497
|
+
@q.push [:DIV, $&]
|
498
|
+
when /\Aper\b/o
|
499
|
+
@q.push [:DIV, $&]
|
500
|
+
when /\A[^#{c}0-9,.-]+([^#{c}$-]*[^#{c}1-9,.])?/o
|
501
|
+
@q.push [:WORD, $&]
|
502
|
+
when /\A[%'"]'?/o
|
503
|
+
@q.push [:WORD, $&]
|
504
|
+
when /\A\^|\A\*\*/o
|
505
|
+
@q.push [:POW, $&]
|
506
|
+
when /\A./o
|
507
|
+
@q.push [$&,$&]
|
508
|
+
end
|
509
|
+
str = $' #'
|
510
|
+
end
|
511
|
+
@q.push [false, '$end']
|
512
|
+
|
513
|
+
do_parse
|
514
|
+
end
|
515
|
+
|
516
|
+
def next_token
|
517
|
+
@q.shift
|
518
|
+
end
|
519
|
+
|
520
|
+
...end parse.y/module_eval...
|
521
|
+
##### State transition tables begin ###
|
522
|
+
|
523
|
+
racc_action_table = [
|
524
|
+
8, 10, 6, 11, 12, 15, 3, 16, 6, 5,
|
525
|
+
8, 10, 6, 11, 8, 10, 6, 11, 15, 30,
|
526
|
+
16, 21, 24, 5, 8, 10, 6, 11, 8, 10,
|
527
|
+
6, 11, 15, 5, 19, 8, 19, 5, 8, 10,
|
528
|
+
6, 11, 8, 10, 6, 11, nil, 5, 15, nil,
|
529
|
+
16, 5, 13, 14, 32, 15, nil, 16, nil, 13,
|
530
|
+
14, 19, 8, 10, 6, 11, 19, 8, 10, 6,
|
531
|
+
11, 19, 8, 10, 6, 11, 19, 8, 10, 6,
|
532
|
+
11, 8, 10, 6, 11, 8, 10, 6, 11, 8,
|
533
|
+
10, 6, 11 ]
|
534
|
+
|
535
|
+
racc_action_check = [
|
536
|
+
0, 0, 0, 0, 1, 26, 0, 26, 21, 0,
|
537
|
+
19, 19, 19, 19, 8, 8, 8, 8, 25, 19,
|
538
|
+
25, 7, 12, 8, 15, 15, 15, 15, 14, 14,
|
539
|
+
14, 14, 28, 15, 29, 11, 33, 14, 13, 13,
|
540
|
+
13, 13, 16, 16, 16, 16, nil, 13, 22, nil,
|
541
|
+
22, 16, 22, 22, 22, 2, nil, 2, nil, 2,
|
542
|
+
2, 17, 17, 17, 17, 17, 18, 18, 18, 18,
|
543
|
+
18, 4, 4, 4, 4, 4, 20, 20, 20, 20,
|
544
|
+
20, 3, 3, 3, 3, 5, 5, 5, 5, 30,
|
545
|
+
30, 30, 30 ]
|
546
|
+
|
547
|
+
racc_action_pointer = [
|
548
|
+
-4, 4, 47, 77, 68, 81, nil, 19, 10, nil,
|
549
|
+
nil, 31, 22, 34, 24, 20, 38, 58, 63, 6,
|
550
|
+
73, 2, 40, nil, nil, 10, -3, nil, 24, 31,
|
551
|
+
85, nil, nil, 33 ]
|
552
|
+
|
553
|
+
racc_action_default = [
|
554
|
+
-19, -19, -1, -19, -3, -19, -9, -12, -19, -13,
|
555
|
+
-14, -19, -19, -19, -19, -19, -19, -2, -15, -19,
|
556
|
+
-4, -19, -19, -18, 34, -5, -6, -7, -8, -16,
|
557
|
+
-19, -10, -11, -17 ]
|
558
|
+
|
559
|
+
racc_goto_table = [
|
560
|
+
17, 18, 20, 1, 31, 2, 23, nil, nil, nil,
|
561
|
+
nil, nil, nil, 22, 18, 18, 29, 18, 25, 26,
|
562
|
+
27, 28, nil, nil, nil, nil, 18, 33, nil, nil,
|
563
|
+
18 ]
|
564
|
+
|
565
|
+
racc_goto_check = [
|
566
|
+
3, 3, 3, 1, 4, 2, 5, nil, nil, nil,
|
567
|
+
nil, nil, nil, 2, 3, 3, 3, 3, 2, 2,
|
568
|
+
2, 2, nil, nil, nil, nil, 3, 3, nil, nil,
|
569
|
+
3 ]
|
570
|
+
|
571
|
+
racc_goto_pointer = [
|
572
|
+
nil, 3, 5, -3, -17, -5 ]
|
573
|
+
|
574
|
+
racc_goto_default = [
|
575
|
+
nil, nil, nil, 4, 7, 9 ]
|
576
|
+
|
577
|
+
racc_reduce_table = [
|
578
|
+
0, 0, :racc_error,
|
579
|
+
1, 16, :_reduce_none,
|
580
|
+
2, 16, :_reduce_2,
|
581
|
+
1, 17, :_reduce_none,
|
582
|
+
2, 17, :_reduce_4,
|
583
|
+
3, 17, :_reduce_5,
|
584
|
+
3, 17, :_reduce_6,
|
585
|
+
3, 17, :_reduce_7,
|
586
|
+
3, 17, :_reduce_8,
|
587
|
+
1, 19, :_reduce_none,
|
588
|
+
3, 19, :_reduce_10,
|
589
|
+
3, 20, :_reduce_11,
|
590
|
+
1, 18, :_reduce_none,
|
591
|
+
1, 18, :_reduce_none,
|
592
|
+
1, 18, :_reduce_14,
|
593
|
+
2, 18, :_reduce_15,
|
594
|
+
3, 18, :_reduce_16,
|
595
|
+
4, 18, :_reduce_17,
|
596
|
+
2, 18, :_reduce_18 ]
|
597
|
+
|
598
|
+
racc_reduce_n = 19
|
599
|
+
|
600
|
+
racc_shift_n = 34
|
601
|
+
|
602
|
+
racc_token_table = {
|
603
|
+
false => 0,
|
604
|
+
:error => 1,
|
605
|
+
"|" => 2,
|
606
|
+
:POW => 3,
|
607
|
+
"(" => 4,
|
608
|
+
:WORD => 5,
|
609
|
+
:NUMBER => 6,
|
610
|
+
:UFUNC => 7,
|
611
|
+
"*" => 8,
|
612
|
+
:MULTIPLY => 9,
|
613
|
+
:DIV => 10,
|
614
|
+
:UNARY => 11,
|
615
|
+
"+" => 12,
|
616
|
+
"-" => 13,
|
617
|
+
")" => 14 }
|
618
|
+
|
619
|
+
racc_nt_base = 15
|
620
|
+
|
621
|
+
racc_use_result_var = true
|
622
|
+
|
623
|
+
Racc_arg = [
|
624
|
+
racc_action_table,
|
625
|
+
racc_action_check,
|
626
|
+
racc_action_default,
|
627
|
+
racc_action_pointer,
|
628
|
+
racc_goto_table,
|
629
|
+
racc_goto_check,
|
630
|
+
racc_goto_default,
|
631
|
+
racc_goto_pointer,
|
632
|
+
racc_nt_base,
|
633
|
+
racc_reduce_table,
|
634
|
+
racc_token_table,
|
635
|
+
racc_shift_n,
|
636
|
+
racc_reduce_n,
|
637
|
+
racc_use_result_var ]
|
638
|
+
|
639
|
+
Racc_token_to_s_table = [
|
640
|
+
"$end",
|
641
|
+
"error",
|
642
|
+
"\"|\"",
|
643
|
+
"POW",
|
644
|
+
"\"(\"",
|
645
|
+
"WORD",
|
646
|
+
"NUMBER",
|
647
|
+
"UFUNC",
|
648
|
+
"\"*\"",
|
649
|
+
"MULTIPLY",
|
650
|
+
"DIV",
|
651
|
+
"UNARY",
|
652
|
+
"\"+\"",
|
653
|
+
"\"-\"",
|
654
|
+
"\")\"",
|
655
|
+
"$start",
|
656
|
+
"target",
|
657
|
+
"expr",
|
658
|
+
"list",
|
659
|
+
"numexpr",
|
660
|
+
"pexpr" ]
|
661
|
+
|
662
|
+
Racc_debug_parser = false
|
663
|
+
|
664
|
+
##### State transition tables end #####
|
665
|
+
|
666
|
+
# reduce 0 omitted
|
667
|
+
|
668
|
+
# reduce 1 omitted
|
669
|
+
|
670
|
+
module_eval(<<'.,.,', 'parse.y', 23)
|
671
|
+
def _reduce_2(val, _values, result)
|
672
|
+
result = Unit.inv(val[1])
|
673
|
+
result
|
674
|
+
end
|
675
|
+
.,.,
|
676
|
+
|
677
|
+
# reduce 3 omitted
|
678
|
+
|
679
|
+
module_eval(<<'.,.,', 'parse.y', 27)
|
680
|
+
def _reduce_4(val, _values, result)
|
681
|
+
result = -val[1]
|
682
|
+
result
|
683
|
+
end
|
684
|
+
.,.,
|
685
|
+
|
686
|
+
module_eval(<<'.,.,', 'parse.y', 28)
|
687
|
+
def _reduce_5(val, _values, result)
|
688
|
+
result = val[0] + val[2]
|
689
|
+
result
|
690
|
+
end
|
691
|
+
.,.,
|
692
|
+
|
693
|
+
module_eval(<<'.,.,', 'parse.y', 29)
|
694
|
+
def _reduce_6(val, _values, result)
|
695
|
+
result = val[0] - val[2]
|
696
|
+
result
|
697
|
+
end
|
698
|
+
.,.,
|
699
|
+
|
700
|
+
module_eval(<<'.,.,', 'parse.y', 30)
|
701
|
+
def _reduce_7(val, _values, result)
|
702
|
+
result = val[0] * val[2]
|
703
|
+
result
|
704
|
+
end
|
705
|
+
.,.,
|
706
|
+
|
707
|
+
module_eval(<<'.,.,', 'parse.y', 31)
|
708
|
+
def _reduce_8(val, _values, result)
|
709
|
+
result = val[0] / val[2]
|
710
|
+
result
|
711
|
+
end
|
712
|
+
.,.,
|
713
|
+
|
714
|
+
# reduce 9 omitted
|
715
|
+
|
716
|
+
module_eval(<<'.,.,', 'parse.y', 35)
|
717
|
+
def _reduce_10(val, _values, result)
|
718
|
+
result = Unit.rdiv(val[0],val[2])
|
719
|
+
result
|
720
|
+
end
|
721
|
+
.,.,
|
722
|
+
|
723
|
+
module_eval(<<'.,.,', 'parse.y', 38)
|
724
|
+
def _reduce_11(val, _values, result)
|
725
|
+
result = val[1]
|
726
|
+
result
|
727
|
+
end
|
728
|
+
.,.,
|
729
|
+
|
730
|
+
# reduce 12 omitted
|
731
|
+
|
732
|
+
# reduce 13 omitted
|
733
|
+
|
734
|
+
module_eval(<<'.,.,', 'parse.y', 43)
|
735
|
+
def _reduce_14(val, _values, result)
|
736
|
+
result = Unit.word(val[0])
|
737
|
+
result
|
738
|
+
end
|
739
|
+
.,.,
|
740
|
+
|
741
|
+
module_eval(<<'.,.,', 'parse.y', 44)
|
742
|
+
def _reduce_15(val, _values, result)
|
743
|
+
result = val[0] * val[1]
|
744
|
+
result
|
745
|
+
end
|
746
|
+
.,.,
|
747
|
+
|
748
|
+
module_eval(<<'.,.,', 'parse.y', 45)
|
749
|
+
def _reduce_16(val, _values, result)
|
750
|
+
result = val[0]** val[2]
|
751
|
+
result
|
752
|
+
end
|
753
|
+
.,.,
|
754
|
+
|
755
|
+
module_eval(<<'.,.,', 'parse.y', 46)
|
756
|
+
def _reduce_17(val, _values, result)
|
757
|
+
result = val[0]**(-val[3])
|
758
|
+
result
|
759
|
+
end
|
760
|
+
.,.,
|
761
|
+
|
762
|
+
module_eval(<<'.,.,', 'parse.y', 47)
|
763
|
+
def _reduce_18(val, _values, result)
|
764
|
+
result = Unit.func(val[0],val[1])
|
765
|
+
result
|
766
|
+
end
|
767
|
+
.,.,
|
768
|
+
|
769
|
+
def _reduce_none(val, _values, result)
|
770
|
+
val[0]
|
771
|
+
end
|
772
|
+
|
773
|
+
end # class Parse
|
774
|
+
|
775
|
+
|
776
|
+
end
|
777
|
+
end
|