antelope 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/antelope.gemspec +0 -2
  4. data/bin/antelope +3 -20
  5. data/examples/deterministic.output +97 -103
  6. data/examples/example.ace +0 -1
  7. data/examples/example.output +259 -333
  8. data/examples/simple.output +85 -87
  9. data/lib/antelope/ace/compiler.rb +14 -16
  10. data/lib/antelope/ace/errors.rb +9 -3
  11. data/lib/antelope/ace/grammar/generation.rb +38 -7
  12. data/lib/antelope/ace/grammar/precedences.rb +59 -0
  13. data/lib/antelope/ace/grammar/production.rb +24 -25
  14. data/lib/antelope/ace/grammar/productions.rb +8 -8
  15. data/lib/antelope/ace/grammar.rb +3 -3
  16. data/lib/antelope/ace/{presidence.rb → precedence.rb} +11 -11
  17. data/lib/antelope/ace/scanner/second.rb +2 -2
  18. data/lib/antelope/ace/token.rb +1 -1
  19. data/lib/antelope/ace.rb +2 -2
  20. data/lib/antelope/cli.rb +33 -0
  21. data/lib/antelope/errors.rb +6 -0
  22. data/lib/antelope/generation/constructor/first.rb +40 -6
  23. data/lib/antelope/generation/constructor/follow.rb +83 -25
  24. data/lib/antelope/generation/constructor/nullable.rb +24 -2
  25. data/lib/antelope/generation/constructor.rb +39 -13
  26. data/lib/antelope/generation/errors.rb +15 -0
  27. data/lib/antelope/generation/recognizer/rule.rb +111 -11
  28. data/lib/antelope/generation/recognizer/state.rb +53 -5
  29. data/lib/antelope/generation/recognizer.rb +31 -1
  30. data/lib/antelope/generation/tableizer.rb +42 -10
  31. data/lib/antelope/generation.rb +1 -1
  32. data/lib/antelope/generator/templates/output.erb +19 -18
  33. data/lib/antelope/version.rb +1 -1
  34. data/lib/antelope.rb +3 -2
  35. metadata +7 -36
  36. data/lib/antelope/ace/grammar/presidence.rb +0 -59
  37. data/lib/antelope/automaton.rb +0 -36
  38. data/lib/antelope/generation/conflictor/conflict.rb +0 -7
  39. data/lib/antelope/generation/conflictor.rb +0 -45
  40. data/lib/antelope/generation/constructor/lookahead.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8be2515bbd6f23ce46428a4e16b2c6f768ba50b
4
- data.tar.gz: e89dee7b835a49a2d2f06ae30a8e2bbf506a6f53
3
+ metadata.gz: ac4549b5e4618c5599316bc58c0838ff573edc2c
4
+ data.tar.gz: d7fc04521edb6b4f6d49c500e1410f683863f1a9
5
5
  SHA512:
6
- metadata.gz: 17a9544c4be3edbf56c002f892192e33400bb45c0592aebef58d130beaa743bacff7bd96e734397c7b327f7a45aabee7e5d99f7f5b86afd3c2dbb580fcce9d9f
7
- data.tar.gz: 3213b6b2ca1756ad32075e6924098212d53ff00e8240be9726b71b5d7834647bc73a69c461b611a1c56b342dfdcab0b64d257e28cf17f18fa5d2c160f2accb7f
6
+ metadata.gz: 86e201447c094f12642b131464f225e4a4b8c743813800b93b296b95ad0e77c5e2516b1a3ff43e06a1502991c2980764528ad1fa6e6a79d03b741c92d253626a
7
+ data.tar.gz: cfca26b2b0d3c01934c6647bcf01f79ee3403acd898718c3c80fe62fcaa1bd415fded4d97cb7c0d167b35180a564711c9d632764ec20534293a76d4688383b50
data/.yardopts CHANGED
@@ -1,4 +1,5 @@
1
1
  --protected
2
+ --private
2
3
  -m markdown
3
4
  -
4
5
  LICENSE.txt
data/antelope.gemspec CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "liquid", "~> 2.6"
22
- spec.add_dependency "sourcify", "~> 0.5"
23
21
  spec.add_dependency "hashie", "~> 3.0"
24
22
  spec.add_dependency "thor", "~> 0.19"
25
23
 
data/bin/antelope CHANGED
@@ -1,24 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << File.expand_path("../../lib", __FILE__) << Dir.pwd
3
+ $: << File.expand_path("../../lib", __FILE__)
4
4
  require "antelope"
5
- require "pathname"
5
+ require "antelope/cli"
6
6
 
7
- ARGV.each do |program|
8
- grammar = Antelope::Ace::Grammar.from_file(program)
9
-
10
- out = grammar.generate
11
-
12
- #pass = Hash[[:recognizer,
13
- # :constructor,
14
- # :conflictor,
15
- # :table].zip(out)]
16
-
17
- #program = Pathname.new(program)
18
-
19
- #file_name = program.parent + program.basename(".ace")
20
-
21
- #File.open("#{file_name}.output", "w") do |f|
22
- # f.write Antelope::Output.output(grammar, pass)
23
- #end
24
- end
7
+ Antelope::CLI.start(ARGV)
@@ -1,32 +1,38 @@
1
1
  Productions:
2
- 0/n0: $start(0) s(0:1) $
3
- 1/n1: s(0:1) e(0:2)
4
- 2/n1: e(9:11) → t(0:3) ";"
5
- 3/n1: e(9:11) t(0:3) "+" e(9:11)
6
- 4/n1: t(9:3) → NUMBER
7
- 5/n1: t(9:3) "(" e(6:10) ")"
8
- 13/n1: e(9:11) → t(6:3) ";"
9
- 14/n1: e(9:11) → t(6:3) "+" e(9:11)
10
- 20/n1: e(9:11) → t(9:3) ";"
11
- 21/n1: e(9:11) → t(9:3) "+" e(9:11)
12
-
13
- Original Productions:
14
- se
15
-
16
- e → t ";"
17
-
18
- e t "+" e
19
-
20
- tNUMBER
21
-
22
- t → "(" e ")"
23
-
24
- $start → s $
25
-
26
-
27
- Conflicts:
28
-
29
- Presidence:
2
+ se
3
+ et ";"
4
+ e → t "+" e
5
+ tNUMBER
6
+ t → "(" e ")"
7
+ $starts $
8
+
9
+ Productions, Again:
10
+ 0/n0: $start(0) → s(0:1) $
11
+ 1/n1: s(0:1) → e(0:2)
12
+ 2/n1: e(0:2) → t(0:3) ";"
13
+ 3/n1: e(0:2) → t(0:3) "+" e(9:11)
14
+ 4/n1: t(0:3) NUMBER
15
+ 5/n1: t(0:3) → "(" e(6:10) ")"
16
+ 13/n1: e(6:10) → t(6:3) ";"
17
+ 14/n1: e(6:10) → t(6:3) "+" e(9:11)
18
+ 15/n1: t(6:3) NUMBER
19
+ 16/n1: t(6:3) → "(" e(6:10) ")"
20
+ 20/n1: e(9:11) t(9:3) ";"
21
+ 21/n1: e(9:11) → t(9:3) "+" e(9:11)
22
+ 22/n1: t(9:3)NUMBER
23
+ 23/n1: t(9:3) → "(" e(6:10) ")"
24
+
25
+ FOLLOW:
26
+ $start(0): {}
27
+ s(0:1): {$}
28
+ e(0:2): {$}
29
+ t(0:3): {";", "+"}
30
+ e(6:10): {")"}
31
+ t(6:3): {";", "+"}
32
+ e(9:11): {$, ")"}
33
+ t(9:3): {";", "+"}
34
+
35
+ Precedence:
30
36
  --- highest
31
37
  nonassoc 1:
32
38
  {_}
@@ -35,60 +41,48 @@ Presidence:
35
41
  --- lowest
36
42
 
37
43
  Table:
38
- {0=>
39
- {:s=>[:state, 1],
40
- :e=>[:state, 2],
41
- :t=>[:state, 3],
42
- :NUMBER=>[:state, 5],
43
- :LPAREN=>[:state, 6]},
44
- 1=>{:"$"=>[:state, 7]},
45
- 2=>{:"$"=>[:reduce, 1]},
46
- 3=>{:SEMICOLON=>[:state, 8], :ADD=>[:state, 9]},
47
- 4=>{:ADD=>[:state, 9]},
48
- 5=>{:SEMICOLON=>[:reduce, 4], :ADD=>[:reduce, 4]},
49
- 6=>
50
- {:e=>[:state, 10],
51
- :t=>[:state, 3],
52
- :NUMBER=>[:state, 5],
53
- :LPAREN=>[:state, 6]},
54
- 7=>{:"$"=>[:accept, 0]},
55
- 8=>{:"$"=>[:reduce, 2], :RPAREN=>[:reduce, 2]},
56
- 9=>
57
- {:e=>[:state, 11],
58
- :t=>[:state, 3],
59
- :NUMBER=>[:state, 5],
60
- :LPAREN=>[:state, 6]},
61
- 10=>{:RPAREN=>[:state, 12]},
62
- 11=>{:"$"=>[:reduce, 3], :RPAREN=>[:reduce, 3]},
63
- 12=>{:SEMICOLON=>[:reduce, 5], :ADD=>[:reduce, 5]}}
64
-
65
- [#<Antelope::Generation::Recognizer::Rule id=0 left=$start(0) right=[s(0:1) $] position=0>,
66
- #<Antelope::Generation::Recognizer::Rule id=1 left=s(0:1) right=[e(0:2)] position=0>,
67
- #<Antelope::Generation::Recognizer::Rule id=2 left=e(9:11) right=[t(0:3) ";"] position=0>,
68
- #<Antelope::Generation::Recognizer::Rule id=3 left=e(9:11) right=[t(0:3) "+" e(9:11)] position=0>,
69
- #<Antelope::Generation::Recognizer::Rule id=4 left=t(9:3) right=[NUMBER] position=0>,
70
- #<Antelope::Generation::Recognizer::Rule id=5 left=t(9:3) right=["(" e(6:10) ")"] position=0>,
71
- #<Antelope::Generation::Recognizer::Rule id=6 left=$start(0) right=[s $] position=1>,
72
- #<Antelope::Generation::Recognizer::Rule id=7 left=s(0:1) right=[e] position=1>,
73
- #<Antelope::Generation::Recognizer::Rule id=8 left=e(9:11) right=[t ";"] position=1>,
74
- nil,
75
- #<Antelope::Generation::Recognizer::Rule id=10 left=e(9:11) right=[t "+" e] position=1>,
76
- #<Antelope::Generation::Recognizer::Rule id=11 left=t(9:3) right=[NUMBER] position=1>,
77
- #<Antelope::Generation::Recognizer::Rule id=12 left=t(9:3) right=["(" e ")"] position=1>,
78
- #<Antelope::Generation::Recognizer::Rule id=13 left=e(9:11) right=[t(6:3) ";"] position=0>,
79
- #<Antelope::Generation::Recognizer::Rule id=14 left=e(9:11) right=[t(6:3) "+" e(9:11)] position=0>,
80
- #<Antelope::Generation::Recognizer::Rule id=15 left=t(9:3) right=[NUMBER] position=0>,
81
- #<Antelope::Generation::Recognizer::Rule id=16 left=t(9:3) right=["(" e(6:10) ")"] position=0>,
82
- #<Antelope::Generation::Recognizer::Rule id=17 left=$start(0) right=[s $] position=2>,
83
- #<Antelope::Generation::Recognizer::Rule id=18 left=e(9:11) right=[t ";"] position=2>,
84
- #<Antelope::Generation::Recognizer::Rule id=19 left=e(9:11) right=[t "+" e] position=2>,
85
- #<Antelope::Generation::Recognizer::Rule id=20 left=e(9:11) right=[t(9:3) ";"] position=0>,
86
- #<Antelope::Generation::Recognizer::Rule id=21 left=e(9:11) right=[t(9:3) "+" e(9:11)] position=0>,
87
- #<Antelope::Generation::Recognizer::Rule id=22 left=t(9:3) right=[NUMBER] position=0>,
88
- #<Antelope::Generation::Recognizer::Rule id=23 left=t(9:3) right=["(" e(6:10) ")"] position=0>,
89
- #<Antelope::Generation::Recognizer::Rule id=24 left=t(9:3) right=["(" e ")"] position=2>,
90
- #<Antelope::Generation::Recognizer::Rule id=25 left=e(9:11) right=[t "+" e] position=3>,
91
- #<Antelope::Generation::Recognizer::Rule id=26 left=t(9:3) right=["(" e ")"] position=3>]
44
+ State 0:
45
+ s : state (1)
46
+ e : state (2)
47
+ t : state (3)
48
+ NUMBER : state (5)
49
+ LPAREN : state (6)
50
+ State 1:
51
+ $ : state (7)
52
+ State 2:
53
+ $ : reduce (1)
54
+ State 3:
55
+ SEMICOLON: state (8)
56
+ ADD : state (9)
57
+ State 4:
58
+ ADD : state (9)
59
+ State 5:
60
+ SEMICOLON: reduce (4)
61
+ ADD : reduce (4)
62
+ State 6:
63
+ e : state (10)
64
+ t : state (3)
65
+ NUMBER : state (5)
66
+ LPAREN : state (6)
67
+ State 7:
68
+ $ : accept (0)
69
+ State 8:
70
+ $ : reduce (2)
71
+ RPAREN : reduce (2)
72
+ State 9:
73
+ e : state (11)
74
+ t : state (3)
75
+ NUMBER : state (5)
76
+ LPAREN : state (6)
77
+ State 10:
78
+ RPAREN : state (12)
79
+ State 11:
80
+ $ : reduce (3)
81
+ RPAREN : reduce (3)
82
+ State 12:
83
+ SEMICOLON: reduce (5)
84
+ ADD : reduce (5)
85
+
92
86
 
93
87
  State 0:
94
88
  rules:
@@ -96,13 +90,13 @@ State 0:
96
90
  {}
97
91
  1/n1: s(0:1) → • e(0:2)
98
92
  {}
99
- 2/n1: e(9:11) → • t(0:3) ";"
93
+ 2/n1: e(0:2) → • t(0:3) ";"
100
94
  {}
101
- 3/n1: e(9:11) → • t(0:3) "+" e(9:11)
95
+ 3/n1: e(0:2) → • t(0:3) "+" e(9:11)
102
96
  {}
103
- 4/n1: t(9:3) → • NUMBER
97
+ 4/n1: t(0:3) → • NUMBER
104
98
  {}
105
- 5/n1: t(9:3) → • "(" e(6:10) ")"
99
+ 5/n1: t(0:3) → • "(" e(6:10) ")"
106
100
  {}
107
101
 
108
102
  transitions:
@@ -114,7 +108,7 @@ State 0:
114
108
 
115
109
  State 1:
116
110
  rules:
117
- 6/n0: $start(0) → s • $
111
+ 6/n0: $start → s • $
118
112
  {}
119
113
 
120
114
  transitions:
@@ -122,16 +116,16 @@ State 1:
122
116
 
123
117
  State 2:
124
118
  rules:
125
- 7/n1: s(0:1) → e •
119
+ 7/n1: s → e •
126
120
  {$}
127
121
 
128
122
  transitions:
129
123
 
130
124
  State 3:
131
125
  rules:
132
- 8/n1: e(9:11) → t • ";"
126
+ 8/n1: e → t • ";"
133
127
  {}
134
- 10/n1: e(9:11) → t • "+" e
128
+ 10/n1: e → t • "+" e
135
129
  {}
136
130
 
137
131
  transitions:
@@ -140,7 +134,7 @@ State 3:
140
134
 
141
135
  State 4:
142
136
  rules:
143
- 10/n1: e(9:11) → t • "+" e
137
+ 10/n1: e → t • "+" e
144
138
  {}
145
139
 
146
140
  transitions:
@@ -148,22 +142,22 @@ State 4:
148
142
 
149
143
  State 5:
150
144
  rules:
151
- 11/n1: t(9:3) → NUMBER •
145
+ 11/n1: t → NUMBER •
152
146
  {";", "+"}
153
147
 
154
148
  transitions:
155
149
 
156
150
  State 6:
157
151
  rules:
158
- 12/n1: t(9:3) → "(" • e ")"
152
+ 12/n1: t → "(" • e ")"
159
153
  {}
160
- 13/n1: e(9:11) → • t(6:3) ";"
154
+ 13/n1: e(6:10) → • t(6:3) ";"
161
155
  {}
162
- 14/n1: e(9:11) → • t(6:3) "+" e(9:11)
156
+ 14/n1: e(6:10) → • t(6:3) "+" e(9:11)
163
157
  {}
164
- 15/n1: t(9:3) → • NUMBER
158
+ 15/n1: t(6:3) → • NUMBER
165
159
  {}
166
- 16/n1: t(9:3) → • "(" e(6:10) ")"
160
+ 16/n1: t(6:3) → • "(" e(6:10) ")"
167
161
  {}
168
162
 
169
163
  transitions:
@@ -174,21 +168,21 @@ State 6:
174
168
 
175
169
  State 7:
176
170
  rules:
177
- 17/n0: $start(0) → s $ •
171
+ 17/n0: $start → s $ •
178
172
  {}
179
173
 
180
174
  transitions:
181
175
 
182
176
  State 8:
183
177
  rules:
184
- 18/n1: e(9:11) → t ";" •
178
+ 18/n1: e → t ";" •
185
179
  {$, ")"}
186
180
 
187
181
  transitions:
188
182
 
189
183
  State 9:
190
184
  rules:
191
- 19/n1: e(9:11) → t "+" • e
185
+ 19/n1: e → t "+" • e
192
186
  {}
193
187
  20/n1: e(9:11) → • t(9:3) ";"
194
188
  {}
@@ -207,7 +201,7 @@ State 9:
207
201
 
208
202
  State 10:
209
203
  rules:
210
- 24/n1: t(9:3) → "(" e • ")"
204
+ 24/n1: t → "(" e • ")"
211
205
  {}
212
206
 
213
207
  transitions:
@@ -215,14 +209,14 @@ State 10:
215
209
 
216
210
  State 11:
217
211
  rules:
218
- 25/n1: e(9:11) → t "+" e •
212
+ 25/n1: e → t "+" e •
219
213
  {$, ")"}
220
214
 
221
215
  transitions:
222
216
 
223
217
  State 12:
224
218
  rules:
225
- 26/n1: t(9:3) → "(" e ")" •
219
+ 26/n1: t → "(" e ")" •
226
220
  {";", "+"}
227
221
 
228
222
  transitions:
data/examples/example.ace CHANGED
@@ -33,7 +33,6 @@ class ExampleParser
33
33
  end
34
34
  end
35
35
 
36
- input = [[:NUMBER, 2], [:ADD], [:NUMBER, 2]]
37
36
  input = [
38
37
  [:NUMBER, 2],
39
38
  [:ADD],