tp_plus 0.0.73

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +65 -0
  3. data/Rakefile +21 -0
  4. data/bin/tpp +73 -0
  5. data/lib/tp_plus/interpreter.rb +129 -0
  6. data/lib/tp_plus/namespace.rb +66 -0
  7. data/lib/tp_plus/nodes/abort_node.rb +9 -0
  8. data/lib/tp_plus/nodes/argument_node.rb +19 -0
  9. data/lib/tp_plus/nodes/assignment_node.rb +45 -0
  10. data/lib/tp_plus/nodes/call_node.rb +34 -0
  11. data/lib/tp_plus/nodes/case_condition_node.rb +26 -0
  12. data/lib/tp_plus/nodes/case_node.rb +33 -0
  13. data/lib/tp_plus/nodes/comment_node.rb +22 -0
  14. data/lib/tp_plus/nodes/conditional_node.rb +54 -0
  15. data/lib/tp_plus/nodes/definition_node.rb +22 -0
  16. data/lib/tp_plus/nodes/digit_node.rb +21 -0
  17. data/lib/tp_plus/nodes/eval_node.rb +13 -0
  18. data/lib/tp_plus/nodes/expression_node.rb +65 -0
  19. data/lib/tp_plus/nodes/for_node.rb +20 -0
  20. data/lib/tp_plus/nodes/header_node.rb +27 -0
  21. data/lib/tp_plus/nodes/indirect_node.rb +49 -0
  22. data/lib/tp_plus/nodes/inline_conditional_node.rb +40 -0
  23. data/lib/tp_plus/nodes/io_method_node.rb +55 -0
  24. data/lib/tp_plus/nodes/io_node.rb +30 -0
  25. data/lib/tp_plus/nodes/jump_node.rb +23 -0
  26. data/lib/tp_plus/nodes/label_definition_node.rb +21 -0
  27. data/lib/tp_plus/nodes/motion_node.rb +62 -0
  28. data/lib/tp_plus/nodes/namespace_node.rb +16 -0
  29. data/lib/tp_plus/nodes/namespaced_var_node.rb +38 -0
  30. data/lib/tp_plus/nodes/numreg_node.rb +25 -0
  31. data/lib/tp_plus/nodes/offset_node.rb +27 -0
  32. data/lib/tp_plus/nodes/operator_node.rb +72 -0
  33. data/lib/tp_plus/nodes/pause_node.rb +9 -0
  34. data/lib/tp_plus/nodes/position_data_node.rb +50 -0
  35. data/lib/tp_plus/nodes/position_node.rb +25 -0
  36. data/lib/tp_plus/nodes/posreg_node.rb +48 -0
  37. data/lib/tp_plus/nodes/raise_node.rb +13 -0
  38. data/lib/tp_plus/nodes/real_node.rb +27 -0
  39. data/lib/tp_plus/nodes/set_node.rb +22 -0
  40. data/lib/tp_plus/nodes/skip_node.rb +22 -0
  41. data/lib/tp_plus/nodes/speed_node.rb +29 -0
  42. data/lib/tp_plus/nodes/string_node.rb +13 -0
  43. data/lib/tp_plus/nodes/string_register_node.rb +25 -0
  44. data/lib/tp_plus/nodes/termination_node.rb +18 -0
  45. data/lib/tp_plus/nodes/terminator_node.rb +16 -0
  46. data/lib/tp_plus/nodes/time_node.rb +24 -0
  47. data/lib/tp_plus/nodes/timer_method_node.rb +37 -0
  48. data/lib/tp_plus/nodes/timer_node.rb +21 -0
  49. data/lib/tp_plus/nodes/units_node.rb +20 -0
  50. data/lib/tp_plus/nodes/use_node.rb +21 -0
  51. data/lib/tp_plus/nodes/user_alarm_node.rb +15 -0
  52. data/lib/tp_plus/nodes/var_method_node.rb +23 -0
  53. data/lib/tp_plus/nodes/var_node.rb +39 -0
  54. data/lib/tp_plus/nodes/vision_register_node.rb +21 -0
  55. data/lib/tp_plus/nodes/wait_for_node.rb +54 -0
  56. data/lib/tp_plus/nodes/wait_until_node.rb +65 -0
  57. data/lib/tp_plus/nodes/while_node.rb +36 -0
  58. data/lib/tp_plus/parser.rb +1592 -0
  59. data/lib/tp_plus/scanner.rb +383 -0
  60. data/lib/tp_plus/version.rb +3 -0
  61. data/lib/tp_plus.rb +62 -0
  62. data/test/test_helper.rb +5 -0
  63. data/test/tp_plus/test_interpreter.rb +1168 -0
  64. data/test/tp_plus/test_parser.rb +489 -0
  65. data/test/tp_plus/test_scanner.rb +522 -0
  66. data/tp_plus.gemspec +28 -0
  67. metadata +156 -0
@@ -0,0 +1,383 @@
1
+ #--
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by rex 1.0.5
4
+ # from lexical definition file "generators/scanner.rex".
5
+ #++
6
+
7
+ require 'racc/parser'
8
+ class TPPlus::Scanner < Racc::Parser
9
+ require 'strscan'
10
+
11
+ class ScanError < StandardError ; end
12
+
13
+ attr_reader :lineno
14
+ attr_reader :filename
15
+ attr_accessor :state
16
+
17
+ def scan_setup(str)
18
+ @ss = StringScanner.new(str)
19
+ @lineno = 1
20
+ @state = nil
21
+ end
22
+
23
+ def action
24
+ yield
25
+ end
26
+
27
+ def scan_str(str)
28
+ scan_setup(str)
29
+ do_parse
30
+ end
31
+ alias :scan :scan_str
32
+
33
+ def load_file( filename )
34
+ @filename = filename
35
+ open(filename, "r") do |f|
36
+ scan_setup(f.read)
37
+ end
38
+ end
39
+
40
+ def scan_file( filename )
41
+ load_file(filename)
42
+ do_parse
43
+ end
44
+
45
+
46
+ def next_token
47
+ return if @ss.eos?
48
+
49
+ # skips empty actions
50
+ until token = _next_token or @ss.eos?; end
51
+ token
52
+ end
53
+
54
+ def _next_token
55
+ text = @ss.peek(1)
56
+ @lineno += 1 if text == "\n"
57
+ token = case @state
58
+ when nil
59
+ case
60
+ when (text = @ss.scan(/\#.*(?=\n?$)/i))
61
+ action { [:COMMENT, text] }
62
+
63
+ when (text = @ss.scan(/\b(true|false)\b/i))
64
+ action { [:TRUE_FALSE, text.downcase == "true"] }
65
+
66
+ when (text = @ss.scan(/R(?=\[)/i))
67
+ action { [:NUMREG, text] }
68
+
69
+ when (text = @ss.scan(/P(?=\[)/i))
70
+ action { [:POSITION, text] }
71
+
72
+ when (text = @ss.scan(/PR(?=\[)/i))
73
+ action { [:POSREG, text] }
74
+
75
+ when (text = @ss.scan(/VR(?=\[)/i))
76
+ action { [:VREG, text] }
77
+
78
+ when (text = @ss.scan(/SR(?=\[)/i))
79
+ action { [:SREG, text] }
80
+
81
+ when (text = @ss.scan(/AR(?=\[)/i))
82
+ action { [:ARG, text] }
83
+
84
+ when (text = @ss.scan(/TIMER(?=\[)/i))
85
+ action { [:TIMER, text] }
86
+
87
+ when (text = @ss.scan(/UALM(?=\[)/i))
88
+ action { [:UALM, text] }
89
+
90
+ when (text = @ss.scan(/F(?=\[)/i))
91
+ action { [:OUTPUT, text] }
92
+
93
+ when (text = @ss.scan(/DO(?=\[)/i))
94
+ action { [:OUTPUT, text] }
95
+
96
+ when (text = @ss.scan(/RO(?=\[)/i))
97
+ action { [:OUTPUT, text] }
98
+
99
+ when (text = @ss.scan(/UO(?=\[)/i))
100
+ action { [:OUTPUT, text] }
101
+
102
+ when (text = @ss.scan(/SO(?=\[)/i))
103
+ action { [:OUTPUT, text] }
104
+
105
+ when (text = @ss.scan(/DI(?=\[)/i))
106
+ action { [:INPUT, text] }
107
+
108
+ when (text = @ss.scan(/RI(?=\[)/i))
109
+ action { [:INPUT, text] }
110
+
111
+ when (text = @ss.scan(/UI(?=\[)/i))
112
+ action { [:INPUT, text] }
113
+
114
+ when (text = @ss.scan(/SI(?=\[)/i))
115
+ action { [:INPUT, text] }
116
+
117
+ when (text = @ss.scan(/\=\=/i))
118
+ action { [:EEQUAL, text] }
119
+
120
+ when (text = @ss.scan(/\=/i))
121
+ action { [:EQUAL, text] }
122
+
123
+ when (text = @ss.scan(/\:\=/i))
124
+ action { [:ASSIGN, text] }
125
+
126
+ when (text = @ss.scan(/\<\>|\!\=/i))
127
+ action { [:NOTEQUAL, text] }
128
+
129
+ when (text = @ss.scan(/\>\=/i))
130
+ action { [:GTE, text] }
131
+
132
+ when (text = @ss.scan(/\<\=/i))
133
+ action { [:LTE, text] }
134
+
135
+ when (text = @ss.scan(/\</i))
136
+ action { [:LT, text] }
137
+
138
+ when (text = @ss.scan(/\>/i))
139
+ action { [:GT, text] }
140
+
141
+ when (text = @ss.scan(/\+/i))
142
+ action { [:PLUS, text] }
143
+
144
+ when (text = @ss.scan(/\-/i))
145
+ action { [:MINUS, text] }
146
+
147
+ when (text = @ss.scan(/\*/i))
148
+ action { [:STAR, text] }
149
+
150
+ when (text = @ss.scan(/\//i))
151
+ action { [:SLASH, text] }
152
+
153
+ when (text = @ss.scan(/DIV/i))
154
+ action { [:DIV, text] }
155
+
156
+ when (text = @ss.scan(/&&/i))
157
+ action { [:AND, text] }
158
+
159
+ when (text = @ss.scan(/\|\|/i))
160
+ action { [:OR, text] }
161
+
162
+ when (text = @ss.scan(/\%/i))
163
+ action { [:MOD, text] }
164
+
165
+ when (text = @ss.scan(/\@/i))
166
+ action { @state = :LABEL; [:AT_SYM, text] }
167
+
168
+ when (text = @ss.scan(/\bTP_IGNORE_PAUSE\b/i))
169
+ action { [:TP_HEADER, text] }
170
+
171
+ when (text = @ss.scan(/\bTP_COMMENT\b/i))
172
+ action { [:TP_HEADER, text] }
173
+
174
+ when (text = @ss.scan(/\bTP_GROUPMASK\b/i))
175
+ action { [:TP_HEADER, text] }
176
+
177
+ when (text = @ss.scan(/\bTP_SUBTYPE\b/i))
178
+ action { [:TP_HEADER, text] }
179
+
180
+ when (text = @ss.scan(/\bset_uframe\b/i))
181
+ action { [:FANUC_SET, text] }
182
+
183
+ when (text = @ss.scan(/\bset_skip_condition\b/i))
184
+ action { [:FANUC_SET, text] }
185
+
186
+ when (text = @ss.scan(/\buse_payload\b/i))
187
+ action { [:FANUC_USE, text] }
188
+
189
+ when (text = @ss.scan(/\buse_uframe\b/i))
190
+ action { [:FANUC_USE, text] }
191
+
192
+ when (text = @ss.scan(/\buse_utool\b/i))
193
+ action { [:FANUC_USE, text] }
194
+
195
+ when (text = @ss.scan(/\babort\b/i))
196
+ action { [:ABORT, text] }
197
+
198
+ when (text = @ss.scan(/\bafter\b/i))
199
+ action { [:AFTER, text] }
200
+
201
+ when (text = @ss.scan(/\bat\b/i))
202
+ action { [:AT, text] }
203
+
204
+ when (text = @ss.scan(/\bcase\b/i))
205
+ action { [:CASE, text] }
206
+
207
+ when (text = @ss.scan(/\bcircular_move\b/i))
208
+ action { [:MOVE, text] }
209
+
210
+ when (text = @ss.scan(/\belse\b/i))
211
+ action { [:ELSE, text] }
212
+
213
+ when (text = @ss.scan(/\bend\b/i))
214
+ action { [:END, text] }
215
+
216
+ when (text = @ss.scan(/\beval\b/i))
217
+ action { [:EVAL, text] }
218
+
219
+ when (text = @ss.scan(/\bfor\b/i))
220
+ action { [:FOR, text] }
221
+
222
+ when (text = @ss.scan(/\bif\b/i))
223
+ action { [:IF, text] }
224
+
225
+ when (text = @ss.scan(/\bindirect\b/i))
226
+ action { [:INDIRECT, text] }
227
+
228
+ when (text = @ss.scan(/\bin\b/i))
229
+ action { [:IN, text] }
230
+
231
+ when (text = @ss.scan(/\bjoint_move\b/i))
232
+ action { [:MOVE, text] }
233
+
234
+ when (text = @ss.scan(/\bjump_to\b/i))
235
+ action { [:JUMP, text] }
236
+
237
+ when (text = @ss.scan(/\blinear_move\b/i))
238
+ action { [:MOVE, text] }
239
+
240
+ when (text = @ss.scan(/\bnamespace\b/i))
241
+ action { [:NAMESPACE, text] }
242
+
243
+ when (text = @ss.scan(/\boffset\b/i))
244
+ action { [:OFFSET, text] }
245
+
246
+ when (text = @ss.scan(/\bpause\b/i))
247
+ action { [:PAUSE, text] }
248
+
249
+ when (text = @ss.scan(/\bposition_data\b/i))
250
+ action { [:POSITION_DATA, text] }
251
+
252
+ when (text = @ss.scan(/\bpulse\b/i))
253
+ action { [:IO_METHOD, text] }
254
+
255
+ when (text = @ss.scan(/\braise\b/i))
256
+ action { [:RAISE, text] }
257
+
258
+ when (text = @ss.scan(/\breset\b/i))
259
+ action { [:TIMER_METHOD, :reset] }
260
+
261
+ when (text = @ss.scan(/\brestart\b/i))
262
+ action { [:TIMER_METHOD, :restart] }
263
+
264
+ when (text = @ss.scan(/\brun\b/i))
265
+ action { [:RUN, text] }
266
+
267
+ when (text = @ss.scan(/\bskip_to\b/i))
268
+ action { [:SKIP, text] }
269
+
270
+ when (text = @ss.scan(/\bstart\b/i))
271
+ action { [:TIMER_METHOD, :start] }
272
+
273
+ when (text = @ss.scan(/\bstop\b/i))
274
+ action { [:TIMER_METHOD, :stop] }
275
+
276
+ when (text = @ss.scan(/\bterm\b/i))
277
+ action { [:TERM, text] }
278
+
279
+ when (text = @ss.scan(/\btime_after\b/i))
280
+ action { [:TIME_SEGMENT, text] }
281
+
282
+ when (text = @ss.scan(/\btime_before\b/i))
283
+ action { [:TIME_SEGMENT, text] }
284
+
285
+ when (text = @ss.scan(/\btimeout_to\b/i))
286
+ action { [:TIMEOUT, text] }
287
+
288
+ when (text = @ss.scan(/\btoggle\b/i))
289
+ action { [:IO_METHOD, text] }
290
+
291
+ when (text = @ss.scan(/\btool_offset\b/i))
292
+ action { [:OFFSET, text] }
293
+
294
+ when (text = @ss.scan(/\bturn_on|turn_off\b/i))
295
+ action { [:IO_METHOD, text] }
296
+
297
+ when (text = @ss.scan(/\bto\b/i))
298
+ action { [:TO, text] }
299
+
300
+ when (text = @ss.scan(/\bunless\b/i))
301
+ action { [:UNLESS, text] }
302
+
303
+ when (text = @ss.scan(/\bvision_offset\b/i))
304
+ action { [:OFFSET, text] }
305
+
306
+ when (text = @ss.scan(/\bwait_for\b/i))
307
+ action { [:WAIT_FOR, text] }
308
+
309
+ when (text = @ss.scan(/\bwait_until\b/i))
310
+ action { [:WAIT_UNTIL, text] }
311
+
312
+ when (text = @ss.scan(/\bwhen\b/i))
313
+ action { [:WHEN, text] }
314
+
315
+ when (text = @ss.scan(/\bwhile\b/i))
316
+ action { [:WHILE, text] }
317
+
318
+ when (text = @ss.scan(/\r?\n/i))
319
+ action { [:NEWLINE, text] }
320
+
321
+ when (text = @ss.scan(/;/i))
322
+ action { [:SEMICOLON, text] }
323
+
324
+ when (text = @ss.scan(/\d+\.\d+|\.\d+/i))
325
+ action { [:REAL, text.to_f] }
326
+
327
+ when (text = @ss.scan(/\./i))
328
+ action { [:DOT, text] }
329
+
330
+ when (text = @ss.scan(/\d+/i))
331
+ action { [:DIGIT, text.to_i] }
332
+
333
+ when (text = @ss.scan(/\!/i))
334
+ action { [:BANG, text] }
335
+
336
+ when (text = @ss.scan(/\s+/i))
337
+ ;
338
+
339
+ when (text = @ss.scan(/[\w\?\!_]+/i))
340
+ action { [:WORD, text] }
341
+
342
+ when (text = @ss.scan(/"([^\n\r\f"]|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f']|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*'/i))
343
+ action { [:STRING, text[1,text.length-2]] }
344
+
345
+ when (text = @ss.scan(/./i))
346
+ action { [text, text] }
347
+
348
+ else
349
+ text = @ss.string[@ss.pos .. -1]
350
+ raise ScanError, "can not match: '" + text + "'"
351
+ end # if
352
+
353
+ when :LABEL
354
+ case
355
+ when (text = @ss.scan(/[\w_0-9]+\b/i))
356
+ action { @state = nil; [:WORD, text] }
357
+
358
+ else
359
+ text = @ss.string[@ss.pos .. -1]
360
+ raise ScanError, "can not match: '" + text + "'"
361
+ end # if
362
+
363
+ else
364
+ raise ScanError, "undefined state: '" + state.to_s + "'"
365
+ end # case state
366
+ token
367
+ end # def _next_token
368
+
369
+ end # class
370
+
371
+ if __FILE__ == $0
372
+ exit if ARGV.size != 1
373
+ filename = ARGV.shift
374
+ rex = TPPlus::Scanner.new
375
+ begin
376
+ rex.load_file filename
377
+ while token = rex.next_token
378
+ p token
379
+ end
380
+ rescue
381
+ $stderr.printf "%s:%d:%s\n", rex.filename, rex.lineno, $!.message
382
+ end
383
+ end
@@ -0,0 +1,3 @@
1
+ module TPPlus
2
+ VERSION = '0.0.73'
3
+ end
data/lib/tp_plus.rb ADDED
@@ -0,0 +1,62 @@
1
+ module TPPlus
2
+ end
3
+
4
+ require 'tp_plus/nodes/abort_node'
5
+ require 'tp_plus/nodes/argument_node'
6
+ require 'tp_plus/nodes/assignment_node'
7
+ require 'tp_plus/nodes/call_node'
8
+ require 'tp_plus/nodes/case_node'
9
+ require 'tp_plus/nodes/case_condition_node'
10
+ require 'tp_plus/nodes/comment_node'
11
+ require 'tp_plus/nodes/conditional_node'
12
+ require 'tp_plus/nodes/definition_node'
13
+ require 'tp_plus/nodes/digit_node'
14
+ require 'tp_plus/nodes/eval_node'
15
+ require 'tp_plus/nodes/expression_node'
16
+ require 'tp_plus/nodes/for_node'
17
+ require 'tp_plus/nodes/header_node'
18
+ require 'tp_plus/nodes/indirect_node'
19
+ require 'tp_plus/nodes/inline_conditional_node'
20
+ require 'tp_plus/nodes/io_node'
21
+ require 'tp_plus/nodes/io_method_node'
22
+ require 'tp_plus/nodes/jump_node'
23
+ require 'tp_plus/nodes/label_definition_node'
24
+ require 'tp_plus/nodes/motion_node'
25
+ require 'tp_plus/nodes/namespace_node'
26
+ require 'tp_plus/nodes/namespaced_var_node'
27
+ require 'tp_plus/nodes/numreg_node'
28
+ require 'tp_plus/nodes/offset_node'
29
+ require 'tp_plus/nodes/operator_node'
30
+ require 'tp_plus/nodes/pause_node'
31
+ require 'tp_plus/nodes/position_node'
32
+ require 'tp_plus/nodes/position_data_node'
33
+ require 'tp_plus/nodes/posreg_node'
34
+ require 'tp_plus/nodes/raise_node'
35
+ require 'tp_plus/nodes/real_node'
36
+ require 'tp_plus/nodes/set_node'
37
+ require 'tp_plus/nodes/skip_node'
38
+ require 'tp_plus/nodes/speed_node'
39
+ require 'tp_plus/nodes/string_node'
40
+ require 'tp_plus/nodes/string_register_node'
41
+ require 'tp_plus/nodes/termination_node'
42
+ require 'tp_plus/nodes/terminator_node'
43
+ require 'tp_plus/nodes/time_node'
44
+ require 'tp_plus/nodes/timer_node'
45
+ require 'tp_plus/nodes/timer_method_node'
46
+ require 'tp_plus/nodes/units_node'
47
+ require 'tp_plus/nodes/use_node'
48
+ require 'tp_plus/nodes/user_alarm_node'
49
+ require 'tp_plus/nodes/var_node'
50
+ require 'tp_plus/nodes/var_method_node'
51
+ require 'tp_plus/nodes/vision_register_node'
52
+ require 'tp_plus/nodes/wait_for_node'
53
+ require 'tp_plus/nodes/wait_until_node'
54
+ require 'tp_plus/nodes/while_node'
55
+
56
+ require 'tp_plus/interpreter'
57
+ require 'tp_plus/namespace'
58
+ require 'tp_plus/parser'
59
+ require 'tp_plus/scanner'
60
+ require 'tp_plus/version'
61
+
62
+
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'tp_plus'
5
+ require 'test/unit'