tp_plus 0.0.87 → 0.0.88

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +87 -87
  3. data/Rakefile +35 -35
  4. data/bin/tpp +92 -92
  5. data/lib/tp_plus/interpreter.rb +153 -152
  6. data/lib/tp_plus/namespace.rb +66 -66
  7. data/lib/tp_plus/nodes/abort_node.rb +9 -9
  8. data/lib/tp_plus/nodes/acc_node.rb +24 -19
  9. data/lib/tp_plus/nodes/address_node.rb +22 -22
  10. data/lib/tp_plus/nodes/argument_node.rb +20 -20
  11. data/lib/tp_plus/nodes/assignment_node.rb +52 -52
  12. data/lib/tp_plus/nodes/base_node.rb +9 -9
  13. data/lib/tp_plus/nodes/call_node.rb +34 -34
  14. data/lib/tp_plus/nodes/case_condition_node.rb +26 -26
  15. data/lib/tp_plus/nodes/case_node.rb +33 -33
  16. data/lib/tp_plus/nodes/comment_node.rb +18 -18
  17. data/lib/tp_plus/nodes/conditional_node.rb +60 -60
  18. data/lib/tp_plus/nodes/definition_node.rb +22 -22
  19. data/lib/tp_plus/nodes/digit_node.rb +22 -22
  20. data/lib/tp_plus/nodes/empty_stmt_node.rb +9 -9
  21. data/lib/tp_plus/nodes/eval_node.rb +13 -13
  22. data/lib/tp_plus/nodes/expression_node.rb +71 -68
  23. data/lib/tp_plus/nodes/for_node.rb +20 -20
  24. data/lib/tp_plus/nodes/header_node.rb +27 -27
  25. data/lib/tp_plus/nodes/indirect_node.rb +27 -27
  26. data/lib/tp_plus/nodes/inline_conditional_node.rb +36 -36
  27. data/lib/tp_plus/nodes/io_method_node.rb +55 -55
  28. data/lib/tp_plus/nodes/io_node.rb +31 -31
  29. data/lib/tp_plus/nodes/jpos_node.rb +13 -13
  30. data/lib/tp_plus/nodes/jump_node.rb +23 -23
  31. data/lib/tp_plus/nodes/label_definition_node.rb +21 -21
  32. data/lib/tp_plus/nodes/lpos_node.rb +13 -13
  33. data/lib/tp_plus/nodes/motion_node.rb +62 -62
  34. data/lib/tp_plus/nodes/namespace_node.rb +16 -16
  35. data/lib/tp_plus/nodes/namespaced_var_node.rb +38 -38
  36. data/lib/tp_plus/nodes/numreg_node.rb +26 -26
  37. data/lib/tp_plus/nodes/offset_node.rb +27 -27
  38. data/lib/tp_plus/nodes/operator_node.rb +78 -80
  39. data/lib/tp_plus/nodes/paren_expression_node.rb +17 -17
  40. data/lib/tp_plus/nodes/pause_node.rb +9 -9
  41. data/lib/tp_plus/nodes/position_data_node.rb +66 -66
  42. data/lib/tp_plus/nodes/position_node.rb +26 -26
  43. data/lib/tp_plus/nodes/posreg_node.rb +64 -64
  44. data/lib/tp_plus/nodes/raise_node.rb +13 -13
  45. data/lib/tp_plus/nodes/real_node.rb +27 -27
  46. data/lib/tp_plus/nodes/return_node.rb +9 -9
  47. data/lib/tp_plus/nodes/set_skip_node.rb +14 -14
  48. data/lib/tp_plus/nodes/skip_node.rb +22 -22
  49. data/lib/tp_plus/nodes/speed_node.rb +29 -29
  50. data/lib/tp_plus/nodes/string_node.rb +13 -13
  51. data/lib/tp_plus/nodes/string_register_node.rb +26 -26
  52. data/lib/tp_plus/nodes/termination_node.rb +29 -23
  53. data/lib/tp_plus/nodes/terminator_node.rb +16 -16
  54. data/lib/tp_plus/nodes/time_node.rb +24 -24
  55. data/lib/tp_plus/nodes/timer_method_node.rb +33 -33
  56. data/lib/tp_plus/nodes/timer_node.rb +16 -16
  57. data/lib/tp_plus/nodes/unary_expression_node.rb +40 -39
  58. data/lib/tp_plus/nodes/units_node.rb +20 -20
  59. data/lib/tp_plus/nodes/use_node.rb +21 -21
  60. data/lib/tp_plus/nodes/user_alarm_node.rb +16 -16
  61. data/lib/tp_plus/nodes/var_method_node.rb +23 -23
  62. data/lib/tp_plus/nodes/var_node.rb +39 -39
  63. data/lib/tp_plus/nodes/vision_register_node.rb +22 -22
  64. data/lib/tp_plus/nodes/wait_for_node.rb +57 -50
  65. data/lib/tp_plus/nodes/wait_until_node.rb +61 -61
  66. data/lib/tp_plus/nodes/while_node.rb +40 -40
  67. data/lib/tp_plus/parser.rb +1749 -1749
  68. data/lib/tp_plus/scanner.rb +295 -295
  69. data/lib/tp_plus/token.rb +101 -101
  70. data/lib/tp_plus/version.rb +3 -3
  71. data/lib/tp_plus.rb +72 -72
  72. data/test/test_helper.rb +5 -5
  73. data/test/tp_plus/test_interpreter.rb +1378 -1372
  74. data/test/tp_plus/test_parser.rb +502 -502
  75. data/test/tp_plus/test_scanner.rb +591 -591
  76. data/tp_plus.gemspec +31 -31
  77. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '089886adc4bbf71b0c7e877d2f8273979b72a521'
4
- data.tar.gz: b228f3f69f31ccbeaaf352da048a12b5c20a2757
3
+ metadata.gz: e625891cef7f97673c897135088f39dc574b1cee
4
+ data.tar.gz: 146cdd66197a98786324ebd045a0299cb12babf9
5
5
  SHA512:
6
- metadata.gz: 9cde491b92e265e1987577f6d534e467c78260260b4f622ba22b199032b9c932ad8503333cf941c644f7cedf09eda9fa353f5d68a7a90d6636c24208c79901b1
7
- data.tar.gz: b03abc4d6ddbbfc6f887f88b2139bc3ab1c2c8f3a89a963f59d6b779bc2ccabacb612c37130c25dd9574375713476dbb6aa14b70a646ae4e680c7c9e8ddcd2de
6
+ metadata.gz: fd1eb2438aa05e9cd60ee6a53137b9192b9d1f68c7c94e7f1cd3b59f20501fd640c092befcd45a40e8eaa9b5df51b4ee201dd7ac6124e6dc148cb191febc1e95
7
+ data.tar.gz: f635933eddfe51873f116dd50957daccb7da56d02daefb8def07782ef88f653c4958d2ad3c2d5a8d47700effda3b4a0b1c9f0267b1e3c7db5fd183519b5664b2
data/README.md CHANGED
@@ -1,87 +1,87 @@
1
- TP+
2
- ===
3
-
4
- [![Build Status](https://travis-ci.org/onerobotics/tp_plus.svg?branch=master)](https://travis-ci.org/onerobotics/tp_plus)
5
-
6
- TP+ is a higher-level language abstraction that translates into FANUC
7
- TP. It features many useful utilities that makes creating TP programs
8
- easier:
9
-
10
- * Identifiers for registers, position registers, IO, etc.
11
- * Re-usable methods
12
- * If-else blocks
13
- * Readable motion statements
14
- * Automatic label numbering
15
-
16
- Of course adding another layer of abstraction takes you a step further
17
- away from the code the robot is running. However, it's hoped that the
18
- increased productivity and rigid syntax requirements will actually
19
- improve your TP code.
20
-
21
- Examples
22
- --------
23
-
24
- example_1.tpp
25
-
26
- foo := R[1]
27
- bar := DO[1]
28
- baz := DO[2]
29
-
30
- home := PR[1]
31
- lpos := PR[2]
32
-
33
- foo = 1
34
-
35
- @loop
36
- foo += 1
37
-
38
- jump_to @loop if foo < 10
39
-
40
- turn_on bar if foo == 5
41
- toggle baz
42
-
43
- linear_move.to(home).at(2000mm/s).term(0)
44
- get_linear_position(lpos)
45
-
46
-
47
- example_1.ls
48
-
49
- /PROG example_1
50
- /MN
51
- : R[1:foo] = 1 ;
52
- : ;
53
- : LBL[100:loop] ;
54
- : R[1:foo]=R[1:foo]+1 ;
55
- : IF R[1:foo]<10,JMP LBL[100] ;
56
- : ;
57
- : IF (R[1:foo]=5),DO[1:bar]=(ON) ;
58
- : DO[2:baz]=(!DO[2:baz]) ;
59
- : ;
60
- : L PR[1:home] 2000mm/sec CNT0 ;
61
- : PR[2:lpos]=LPOS ;
62
- /END
63
-
64
- For a more extensive example and test environment, visit http://tp-plus.herokuapp.com/.
65
-
66
- Usage
67
- -----
68
-
69
- 1. `gem install tp_plus`
70
- 2. `tpp filename.tpp -o filename.ls`
71
-
72
- See `tpp --help` for options.
73
-
74
- Development
75
- -----------
76
-
77
- 1. Install Ruby
78
- 2. Install git
79
- 3. Install bundler `gem install bundler`
80
- 4. Clone the repo `git clone https://github.com/onerobotics/tp_plus.git`
81
- 5. Install dependencies with `bundle`
82
- 6. Build the parser and run the tests with `rake`
83
-
84
- License
85
- -------
86
-
87
- TP+ is released under the [MIT License](http://www.opensource.org/licenses/MIT).
1
+ TP+
2
+ ===
3
+
4
+ [![Build Status](https://travis-ci.org/onerobotics/tp_plus.svg?branch=master)](https://travis-ci.org/onerobotics/tp_plus)
5
+
6
+ TP+ is a higher-level language abstraction that translates into FANUC
7
+ TP. It features many useful utilities that makes creating TP programs
8
+ easier:
9
+
10
+ * Identifiers for registers, position registers, IO, etc.
11
+ * Re-usable methods
12
+ * If-else blocks
13
+ * Readable motion statements
14
+ * Automatic label numbering
15
+
16
+ Of course adding another layer of abstraction takes you a step further
17
+ away from the code the robot is running. However, it's hoped that the
18
+ increased productivity and rigid syntax requirements will actually
19
+ improve your TP code.
20
+
21
+ Examples
22
+ --------
23
+
24
+ example_1.tpp
25
+
26
+ foo := R[1]
27
+ bar := DO[1]
28
+ baz := DO[2]
29
+
30
+ home := PR[1]
31
+ lpos := PR[2]
32
+
33
+ foo = 1
34
+
35
+ @loop
36
+ foo += 1
37
+
38
+ jump_to @loop if foo < 10
39
+
40
+ turn_on bar if foo == 5
41
+ toggle baz
42
+
43
+ linear_move.to(home).at(2000mm/s).term(0)
44
+ get_linear_position(lpos)
45
+
46
+
47
+ example_1.ls
48
+
49
+ /PROG example_1
50
+ /MN
51
+ : R[1:foo] = 1 ;
52
+ : ;
53
+ : LBL[100:loop] ;
54
+ : R[1:foo]=R[1:foo]+1 ;
55
+ : IF R[1:foo]<10,JMP LBL[100] ;
56
+ : ;
57
+ : IF (R[1:foo]=5),DO[1:bar]=(ON) ;
58
+ : DO[2:baz]=(!DO[2:baz]) ;
59
+ : ;
60
+ : L PR[1:home] 2000mm/sec CNT0 ;
61
+ : PR[2:lpos]=LPOS ;
62
+ /END
63
+
64
+ For a more extensive example and test environment, visit http://tp-plus.herokuapp.com/.
65
+
66
+ Usage
67
+ -----
68
+
69
+ 1. `gem install tp_plus`
70
+ 2. `tpp filename.tpp -o filename.ls`
71
+
72
+ See `tpp --help` for options.
73
+
74
+ Development
75
+ -----------
76
+
77
+ 1. Install Ruby
78
+ 2. Install git
79
+ 3. Install bundler `gem install bundler`
80
+ 4. Clone the repo `git clone https://github.com/onerobotics/tp_plus.git`
81
+ 5. Install dependencies with `bundle`
82
+ 6. Build the parser and run the tests with `rake`
83
+
84
+ License
85
+ -------
86
+
87
+ TP+ is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,35 +1,35 @@
1
- file "lib/tp_plus/parser.rb" => ["generators/parser.y"] do |t|
2
- sh "racc -l -t -v -o lib/tp_plus/parser.rb generators/parser.y"
3
- end
4
-
5
- namespace :compile do
6
- task :parser do
7
- Rake::Task["lib/tp_plus/parser.rb"].invoke
8
- end
9
- end
10
-
11
- task compile: ["compile:parser"]
12
-
13
- require 'rake/testtask'
14
-
15
- Rake::TestTask.new do |t|
16
- # build the parser if necessary
17
- Rake::Task["lib/tp_plus/parser.rb"].invoke
18
-
19
- t.libs << "test"
20
- t.test_files = FileList['test/**/test_*.rb']
21
- t.verbose = true
22
- end
23
-
24
- task default: :test
25
-
26
-
27
- desc "Run the TP+ benchmark"
28
- task :benchmark do
29
- ruby "./performance/benchmark.rb"
30
- end
31
-
32
- desc "Run the TP+ profiler"
33
- task :profile do
34
- ruby "./performance/profile.rb"
35
- end
1
+ file "lib/tp_plus/parser.rb" => ["generators/parser.y"] do |t|
2
+ sh "racc -l -t -v -o lib/tp_plus/parser.rb generators/parser.y"
3
+ end
4
+
5
+ namespace :compile do
6
+ task :parser do
7
+ Rake::Task["lib/tp_plus/parser.rb"].invoke
8
+ end
9
+ end
10
+
11
+ task compile: ["compile:parser"]
12
+
13
+ require 'rake/testtask'
14
+
15
+ Rake::TestTask.new do |t|
16
+ # build the parser if necessary
17
+ Rake::Task["lib/tp_plus/parser.rb"].invoke
18
+
19
+ t.libs << "test"
20
+ t.test_files = FileList['test/**/test_*.rb']
21
+ t.verbose = true
22
+ end
23
+
24
+ task default: :test
25
+
26
+
27
+ desc "Run the TP+ benchmark"
28
+ task :benchmark do
29
+ ruby "./performance/benchmark.rb"
30
+ end
31
+
32
+ desc "Run the TP+ profiler"
33
+ task :profile do
34
+ ruby "./performance/profile.rb"
35
+ end
data/bin/tpp CHANGED
@@ -1,92 +1,92 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../lib/tp_plus'
3
- require 'optparse'
4
-
5
- options = {}
6
- OptionParser.new do |opts|
7
- opts.banner = "Usage: tpp [options] filename"
8
-
9
- opts.on("-e", "--environment <file>", "Require an environment file <file> before parsing") do |e|
10
- options[:environment] = e
11
- end
12
-
13
- opts.on("-o", "--output <file>", "Write output to <file>") do |o|
14
- options[:output] = o
15
- end
16
-
17
- opts.on_tail("-h", "--help", "Show this message") do
18
- puts opts
19
- exit
20
- end
21
- end.parse!
22
-
23
- if ARGV.length != 1
24
- puts "Must provide filename argument. See tpp --help for details"
25
- exit
26
- end
27
-
28
- tpp_filename = File.basename(ARGV[0],".*")
29
-
30
- if options[:output]
31
- # ensure filename matches (FANUC parser will complain otherwise)
32
- output_filename = File.basename(options[:output], ".*")
33
- if output_filename != tpp_filename
34
- puts "Output filename <#{output_filename}> does not match input filename <#{tpp_filename}>"
35
- exit
36
- end
37
- end
38
-
39
- def contents(filename)
40
- if !File.exist?(filename)
41
- puts "File <#{filename}> does not exist"
42
- exit
43
- end
44
- f = File.open(filename,'rb')
45
- src = f.read
46
- f.close
47
- return src
48
- end
49
-
50
- scanner = TPPlus::Scanner.new
51
- parser = TPPlus::Parser.new(scanner)
52
- interpreter = parser.interpreter
53
- if options[:environment]
54
- interpreter.load_environment(contents(options[:environment]))
55
- end
56
-
57
- src = contents(ARGV[0])
58
-
59
- scanner.scan_setup(src)
60
- parser.parse
61
-
62
- lines = interpreter.eval
63
-
64
- output = %(/PROG #{tpp_filename.upcase}
65
- /ATTR
66
- COMMENT = "#{interpreter.header_data[:comment] || tpp_filename.upcase}";
67
- TCD: STACK_SIZE = 0,
68
- TASK_PRIORITY = 50,
69
- TIME_SLICE = 0,
70
- BUSY_LAMP_OFF = 0,
71
- ABORT_REQUEST = 0,
72
- PAUSE_REQUEST = #{interpreter.header_data[:ignore_pause] ? "7" : "0"};
73
- DEFAULT_GROUP = #{interpreter.header_data[:group_mask] || "1,*,*,*,*"};
74
- /MN\n)
75
-
76
- lines.each_line do |line|
77
- output += " : " + line
78
- end
79
-
80
- if interpreter.pos_section != ""
81
- output += "/POS\n"
82
- output += interpreter.pos_section
83
- end
84
-
85
- output += %(/END\n)
86
-
87
- if options[:output]
88
- # write to file
89
- File.write(options[:output], output)
90
- else
91
- print output
92
- end
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/tp_plus'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: tpp [options] filename"
8
+
9
+ opts.on("-e", "--environment <file>", "Require an environment file <file> before parsing") do |e|
10
+ options[:environment] = e
11
+ end
12
+
13
+ opts.on("-o", "--output <file>", "Write output to <file>") do |o|
14
+ options[:output] = o
15
+ end
16
+
17
+ opts.on_tail("-h", "--help", "Show this message") do
18
+ puts opts
19
+ exit
20
+ end
21
+ end.parse!
22
+
23
+ if ARGV.length != 1
24
+ puts "Must provide filename argument. See tpp --help for details"
25
+ exit
26
+ end
27
+
28
+ tpp_filename = File.basename(ARGV[0],".*")
29
+
30
+ if options[:output]
31
+ # ensure filename matches (FANUC parser will complain otherwise)
32
+ output_filename = File.basename(options[:output], ".*")
33
+ if output_filename != tpp_filename
34
+ puts "Output filename <#{output_filename}> does not match input filename <#{tpp_filename}>"
35
+ exit
36
+ end
37
+ end
38
+
39
+ def contents(filename)
40
+ if !File.exist?(filename)
41
+ puts "File <#{filename}> does not exist"
42
+ exit
43
+ end
44
+ f = File.open(filename,'rb')
45
+ src = f.read
46
+ f.close
47
+ return src
48
+ end
49
+
50
+ scanner = TPPlus::Scanner.new
51
+ parser = TPPlus::Parser.new(scanner)
52
+ interpreter = parser.interpreter
53
+ if options[:environment]
54
+ interpreter.load_environment(contents(options[:environment]))
55
+ end
56
+
57
+ src = contents(ARGV[0])
58
+
59
+ scanner.scan_setup(src)
60
+ parser.parse
61
+
62
+ lines = interpreter.eval
63
+
64
+ output = %(/PROG #{tpp_filename.upcase}
65
+ /ATTR
66
+ COMMENT = "#{interpreter.header_data[:comment] || tpp_filename.upcase}";
67
+ TCD: STACK_SIZE = 0,
68
+ TASK_PRIORITY = 50,
69
+ TIME_SLICE = 0,
70
+ BUSY_LAMP_OFF = 0,
71
+ ABORT_REQUEST = 0,
72
+ PAUSE_REQUEST = #{interpreter.header_data[:ignore_pause] ? "7" : "0"};
73
+ DEFAULT_GROUP = #{interpreter.header_data[:group_mask] || "1,*,*,*,*"};
74
+ /MN\n)
75
+
76
+ lines.each_line do |line|
77
+ output += " : " + line
78
+ end
79
+
80
+ if interpreter.pos_section != ""
81
+ output += "/POS\n"
82
+ output += interpreter.pos_section
83
+ end
84
+
85
+ output += %(/END\n)
86
+
87
+ if options[:output]
88
+ # write to file
89
+ File.write(options[:output], output)
90
+ else
91
+ print output
92
+ end