antelope 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CONTRIBUTING.md +4 -4
  4. data/GENERATORS.md +61 -19
  5. data/README.md +84 -9
  6. data/TODO.md +58 -0
  7. data/examples/deterministic.ace +21 -9
  8. data/examples/example.ace +16 -10
  9. data/examples/example.output +213 -146
  10. data/examples/simple.ace +1 -1
  11. data/lib/antelope/ace/compiler.rb +52 -15
  12. data/lib/antelope/ace/errors.rb +7 -0
  13. data/lib/antelope/ace/grammar/generation.rb +3 -3
  14. data/lib/antelope/ace/grammar/precedences.rb +5 -7
  15. data/lib/antelope/ace/grammar/productions.rb +36 -11
  16. data/lib/antelope/ace/grammar/{terminals.rb → symbols.rb} +25 -2
  17. data/lib/antelope/ace/grammar.rb +12 -3
  18. data/lib/antelope/ace/precedence.rb +4 -0
  19. data/lib/antelope/ace/scanner/argument.rb +57 -0
  20. data/lib/antelope/ace/scanner/first.rb +32 -6
  21. data/lib/antelope/ace/scanner/second.rb +23 -8
  22. data/lib/antelope/ace/scanner.rb +32 -26
  23. data/lib/antelope/ace/token.rb +21 -2
  24. data/lib/antelope/cli.rb +22 -2
  25. data/lib/antelope/generation/constructor/first.rb +1 -1
  26. data/lib/antelope/generation/constructor.rb +2 -0
  27. data/lib/antelope/generation/null.rb +13 -0
  28. data/lib/antelope/generation/recognizer/rule.rb +4 -3
  29. data/lib/antelope/generation/recognizer/state.rb +18 -3
  30. data/lib/antelope/generation/recognizer.rb +19 -24
  31. data/lib/antelope/generation/tableizer.rb +30 -2
  32. data/lib/antelope/generation.rb +1 -0
  33. data/lib/antelope/generator/base.rb +150 -13
  34. data/lib/antelope/generator/c.rb +11 -0
  35. data/lib/antelope/generator/c_header.rb +105 -0
  36. data/lib/antelope/generator/c_source.rb +39 -0
  37. data/lib/antelope/generator/null.rb +5 -0
  38. data/lib/antelope/generator/output.rb +3 -3
  39. data/lib/antelope/generator/ruby.rb +23 -5
  40. data/lib/antelope/generator/templates/c_header.ant +36 -0
  41. data/lib/antelope/generator/templates/c_source.ant +202 -0
  42. data/lib/antelope/generator/templates/output.ant +68 -0
  43. data/lib/antelope/generator/templates/ruby.ant +146 -0
  44. data/lib/antelope/generator.rb +15 -3
  45. data/lib/antelope/template/compiler.rb +78 -0
  46. data/lib/antelope/template/errors.rb +9 -0
  47. data/lib/antelope/template/scanner.rb +111 -0
  48. data/lib/antelope/template.rb +60 -0
  49. data/lib/antelope/version.rb +1 -1
  50. data/lib/antelope.rb +1 -0
  51. data/spec/antelope/template_spec.rb +39 -0
  52. data/subl/Ace (Ruby).JSON-tmLanguage +94 -0
  53. data/subl/Ace (Ruby).tmLanguage +153 -0
  54. metadata +21 -8
  55. data/examples/deterministic.output +0 -131
  56. data/examples/simple.output +0 -121
  57. data/lib/antelope/generator/templates/output.erb +0 -56
  58. data/lib/antelope/generator/templates/ruby.erb +0 -63
@@ -1,17 +1,19 @@
1
1
  Productions:
2
- 0 $start: expression $
2
+ 0 $start: expression $end
3
3
  1 expression: NUMBER { |a| a[1] }
4
- 2 expression: expression "+" expression { |a, _, b| a + b }
5
- 3 expression: expression "-" expression { |a, _, b| a - b }
6
- 4 expression: expression "*" expression { |a, _, b| a * b }
7
- 5 expression: expression "/" expression { |a, _, b| a / b }
8
- 6 expression: "(" expression ")" { |_, a, _| a }
9
- 7 expression: "(" $error ")"
4
+ 2 expression: expression "^" expression { |a, _, b| a** b }
5
+ 3 expression: expression "+" expression { |a, _, b| a + b }
6
+ 4 expression: expression "-" expression { |a, _, b| a - b }
7
+ 5 expression: expression "*" expression { |a, _, b| a * b }
8
+ 6 expression: expression "/" expression { |a, _, b| a / b }
9
+ 7 expression: "(" expression ")" { |_, a, _| a }
10
+ 8 expression: "(" $error ")" { |_, e, _| e[1] }
11
+
10
12
 
11
13
  Precedence:
12
14
  --- highest
13
- nonassoc 4:
14
- {LPAREN, RPAREN}
15
+ right 4:
16
+ {EXPONENTIATE}
15
17
  left 3:
16
18
  {MULTIPLY, DIVIDE}
17
19
  left 2:
@@ -19,25 +21,28 @@ Precedence:
19
21
  nonassoc 1:
20
22
  {_}
21
23
  nonassoc 0:
22
- {$}
24
+ {$end}
23
25
  --- lowest
24
26
 
27
+
25
28
  State 0:
26
- 0/n0: $start → • expression $
29
+ 0/n0: $start → • expression $end
27
30
  {}
28
31
  1/n1: expression → • NUMBER
29
32
  {}
30
- 2/l2: expression → • expression "+" expression
33
+ 2/r4: expression → • expression "^" expression
31
34
  {}
32
- 3/l2: expression → • expression "-" expression
35
+ 3/l2: expression → • expression "+" expression
33
36
  {}
34
- 4/l3: expression → • expression "*" expression
37
+ 4/l2: expression → • expression "-" expression
35
38
  {}
36
- 5/l3: expression → • expression "/" expression
39
+ 5/l3: expression → • expression "*" expression
37
40
  {}
38
- 6/n4: expression → • "(" expression ")"
41
+ 6/l3: expression → • expression "/" expression
39
42
  {}
40
- 7/n4: expression → • "(" $error ")"
43
+ 7/n1: expression → • "(" expression ")"
44
+ {}
45
+ 8/n1: expression → • "(" $error ")"
41
46
  {}
42
47
  transitions:
43
48
  expression: State 1
@@ -45,274 +50,336 @@ Precedence:
45
50
  "(": State 3
46
51
 
47
52
  State 1:
48
- 8/n0: $start → expression • $
53
+ 9/n0: $start → expression • $end
54
+ {}
55
+ 10/r4: expression → expression • "^" expression
49
56
  {}
50
- 9/l2: expression → expression • "+" expression
57
+ 11/l2: expression → expression • "+" expression
51
58
  {}
52
- 10/l2: expression → expression • "-" expression
59
+ 12/l2: expression → expression • "-" expression
53
60
  {}
54
- 11/l3: expression → expression • "*" expression
61
+ 13/l3: expression → expression • "*" expression
55
62
  {}
56
- 12/l3: expression → expression • "/" expression
63
+ 14/l3: expression → expression • "/" expression
57
64
  {}
58
65
  transitions:
59
- $: State 4
60
- "+": State 5
61
- "-": State 6
62
- "*": State 7
63
- "/": State 8
66
+ $end: State 4
67
+ "^": State 5
68
+ "+": State 6
69
+ "-": State 7
70
+ "*": State 8
71
+ "/": State 9
64
72
 
65
73
  State 2:
66
- 13/n1: expression → NUMBER •
67
- {$, "+", "-", "*", "/", ")"}
74
+ 15/n1: expression → NUMBER •
75
+ {$end, "^", "+", "-", "*", "/", ")"}
68
76
  reductions:
69
- $: Rule 1
70
- "+": Rule 1
71
- "-": Rule 1
72
- "*": Rule 1
73
- "/": Rule 1
74
- ")": Rule 1
77
+ $default: Rule 1
75
78
 
76
79
  State 3:
77
- 14/n4: expression → "(" • expression ")"
80
+ 16/n1: expression → "(" • expression ")"
78
81
  {}
79
- 15/n1: expression → NUMBER
82
+ 17/n1: expression → "(" $error ")"
80
83
  {}
81
- 16/l2: expression → • expression "+" expression
84
+ 18/n1: expression → • NUMBER
82
85
  {}
83
- 17/l2: expression → • expression "-" expression
86
+ 19/r4: expression → • expression "^" expression
84
87
  {}
85
- 18/l3: expression → • expression "*" expression
88
+ 20/l2: expression → • expression "+" expression
86
89
  {}
87
- 19/l3: expression → • expression "/" expression
90
+ 21/l2: expression → • expression "-" expression
88
91
  {}
89
- 20/n4: expression → • "(" expression ")"
92
+ 22/l3: expression → • expression "*" expression
90
93
  {}
91
- 21/n4: expression → • "(" $error ")"
94
+ 23/l3: expression → • expression "/" expression
92
95
  {}
93
- 22/n4: expression → "(" $error ")"
96
+ 24/n1: expression → "(" expression ")"
97
+ {}
98
+ 25/n1: expression → • "(" $error ")"
94
99
  {}
95
100
  transitions:
96
- expression: State 9
101
+ expression: State 10
102
+ $error: State 11
97
103
  NUMBER: State 2
98
104
  "(": State 3
99
- $error: State 10
100
105
 
101
106
  State 4:
102
- 23/n0: $start → expression $ •
107
+ 26/n0: $start → expression $end
103
108
  {}
104
109
  accepting:
105
- $: Rule 0
110
+ $end: Rule 0
106
111
 
107
112
  State 5:
108
- 24/l2: expression → expression "+" • expression
113
+ 27/r4: expression → expression "^" • expression
114
+ {}
115
+ 28/n1: expression → • NUMBER
109
116
  {}
110
- 25/n1: expression → • NUMBER
117
+ 29/r4: expression → • expression "^" expression
111
118
  {}
112
- 26/l2: expression → • expression "+" expression
119
+ 30/l2: expression → • expression "+" expression
113
120
  {}
114
- 27/l2: expression → • expression "-" expression
121
+ 31/l2: expression → • expression "-" expression
115
122
  {}
116
- 28/l3: expression → • expression "*" expression
123
+ 32/l3: expression → • expression "*" expression
117
124
  {}
118
- 29/l3: expression → • expression "/" expression
125
+ 33/l3: expression → • expression "/" expression
119
126
  {}
120
- 30/n4: expression → • "(" expression ")"
127
+ 34/n1: expression → • "(" expression ")"
121
128
  {}
122
- 31/n4: expression → • "(" $error ")"
129
+ 35/n1: expression → • "(" $error ")"
123
130
  {}
124
131
  transitions:
125
- expression: State 11
132
+ expression: State 12
126
133
  NUMBER: State 2
127
134
  "(": State 3
128
135
 
129
136
  State 6:
130
- 32/l2: expression → expression "-" • expression
137
+ 36/l2: expression → expression "+" • expression
131
138
  {}
132
- 33/n1: expression → • NUMBER
139
+ 37/n1: expression → • NUMBER
133
140
  {}
134
- 34/l2: expression → • expression "+" expression
141
+ 38/r4: expression → • expression "^" expression
135
142
  {}
136
- 35/l2: expression → • expression "-" expression
143
+ 39/l2: expression → • expression "+" expression
137
144
  {}
138
- 36/l3: expression → • expression "*" expression
145
+ 40/l2: expression → • expression "-" expression
139
146
  {}
140
- 37/l3: expression → • expression "/" expression
147
+ 41/l3: expression → • expression "*" expression
141
148
  {}
142
- 38/n4: expression → • "(" expression ")"
149
+ 42/l3: expression → • expression "/" expression
143
150
  {}
144
- 39/n4: expression → • "(" $error ")"
151
+ 43/n1: expression → • "(" expression ")"
152
+ {}
153
+ 44/n1: expression → • "(" $error ")"
145
154
  {}
146
155
  transitions:
147
- expression: State 12
156
+ expression: State 13
148
157
  NUMBER: State 2
149
158
  "(": State 3
150
159
 
151
160
  State 7:
152
- 40/l3: expression → expression "*" • expression
161
+ 45/l2: expression → expression "-" • expression
162
+ {}
163
+ 46/n1: expression → • NUMBER
153
164
  {}
154
- 41/n1: expression → • NUMBER
165
+ 47/r4: expression → • expression "^" expression
155
166
  {}
156
- 42/l2: expression → • expression "+" expression
167
+ 48/l2: expression → • expression "+" expression
157
168
  {}
158
- 43/l2: expression → • expression "-" expression
169
+ 49/l2: expression → • expression "-" expression
159
170
  {}
160
- 44/l3: expression → • expression "*" expression
171
+ 50/l3: expression → • expression "*" expression
161
172
  {}
162
- 45/l3: expression → • expression "/" expression
173
+ 51/l3: expression → • expression "/" expression
163
174
  {}
164
- 46/n4: expression → • "(" expression ")"
175
+ 52/n1: expression → • "(" expression ")"
165
176
  {}
166
- 47/n4: expression → • "(" $error ")"
177
+ 53/n1: expression → • "(" $error ")"
167
178
  {}
168
179
  transitions:
169
- expression: State 13
180
+ expression: State 14
170
181
  NUMBER: State 2
171
182
  "(": State 3
172
183
 
173
184
  State 8:
174
- 48/l3: expression → expression "/" • expression
185
+ 54/l3: expression → expression "*" • expression
186
+ {}
187
+ 55/n1: expression → • NUMBER
175
188
  {}
176
- 49/n1: expression → • NUMBER
189
+ 56/r4: expression → • expression "^" expression
177
190
  {}
178
- 50/l2: expression → • expression "+" expression
191
+ 57/l2: expression → • expression "+" expression
179
192
  {}
180
- 51/l2: expression → • expression "-" expression
193
+ 58/l2: expression → • expression "-" expression
181
194
  {}
182
- 52/l3: expression → • expression "*" expression
195
+ 59/l3: expression → • expression "*" expression
183
196
  {}
184
- 53/l3: expression → • expression "/" expression
197
+ 60/l3: expression → • expression "/" expression
185
198
  {}
186
- 54/n4: expression → • "(" expression ")"
199
+ 61/n1: expression → • "(" expression ")"
187
200
  {}
188
- 55/n4: expression → • "(" $error ")"
201
+ 62/n1: expression → • "(" $error ")"
189
202
  {}
190
203
  transitions:
191
- expression: State 14
204
+ expression: State 15
192
205
  NUMBER: State 2
193
206
  "(": State 3
194
207
 
195
208
  State 9:
196
- 56/n4: expression → "(" expression ")"
209
+ 63/l3: expression → expression "/" • expression
210
+ {}
211
+ 64/n1: expression → • NUMBER
212
+ {}
213
+ 65/r4: expression → • expression "^" expression
214
+ {}
215
+ 66/l2: expression → • expression "+" expression
197
216
  {}
198
- 57/l2: expression → expression "+" expression
217
+ 67/l2: expression → expression "-" expression
199
218
  {}
200
- 58/l2: expression → expression "-" expression
219
+ 68/l3: expression → expression "*" expression
201
220
  {}
202
- 59/l3: expression → expression "*" expression
221
+ 69/l3: expression → expression "/" expression
203
222
  {}
204
- 60/l3: expression → expression • "/" expression
223
+ 70/n1: expression → • "(" expression ")"
224
+ {}
225
+ 71/n1: expression → • "(" $error ")"
205
226
  {}
206
227
  transitions:
207
- ")": State 15
208
- "+": State 5
209
- "-": State 6
210
- "*": State 7
211
- "/": State 8
228
+ expression: State 16
229
+ NUMBER: State 2
230
+ "(": State 3
212
231
 
213
232
  State 10:
214
- 61/n4: expression → "(" $error • ")"
233
+ 72/n1: expression → "(" expression • ")"
234
+ {}
235
+ 73/r4: expression → expression • "^" expression
236
+ {}
237
+ 74/l2: expression → expression • "+" expression
238
+ {}
239
+ 75/l2: expression → expression • "-" expression
240
+ {}
241
+ 76/l3: expression → expression • "*" expression
242
+ {}
243
+ 77/l3: expression → expression • "/" expression
215
244
  {}
216
245
  transitions:
217
- ")": State 16
246
+ ")": State 17
247
+ "^": State 5
248
+ "+": State 6
249
+ "-": State 7
250
+ "*": State 8
251
+ "/": State 9
218
252
 
219
253
  State 11:
220
- 62/l2: expression → expression "+" expression
221
- {$, "+", "-", "*", "/", ")"}
222
- 63/l2: expression → expression • "+" expression
254
+ 78/n1: expression → "(" $error")"
223
255
  {}
224
- 64/l2: expression → expression • "-" expression
256
+ transitions:
257
+ ")": State 18
258
+
259
+ State 12:
260
+ 79/r4: expression → expression "^" expression •
261
+ {$end, "^", "+", "-", "*", "/", ")"}
262
+ 80/r4: expression → expression • "^" expression
263
+ {}
264
+ 81/l2: expression → expression • "+" expression
265
+ {}
266
+ 82/l2: expression → expression • "-" expression
225
267
  {}
226
- 65/l3: expression → expression • "*" expression
268
+ 83/l3: expression → expression • "*" expression
227
269
  {}
228
- 66/l3: expression → expression • "/" expression
270
+ 84/l3: expression → expression • "/" expression
229
271
  {}
230
272
  transitions:
231
- "*": State 7
232
- "/": State 8
273
+ "^": State 5
233
274
  reductions:
234
275
  "+": Rule 2
235
276
  "-": Rule 2
236
- $: Rule 2
277
+ "*": Rule 2
278
+ "/": Rule 2
279
+ $end: Rule 2
237
280
  ")": Rule 2
238
281
 
239
- State 12:
240
- 67/l2: expression → expression "-" expression •
241
- {$, "+", "-", "*", "/", ")"}
242
- 68/l2: expression → expression • "+" expression
282
+ State 13:
283
+ 85/l2: expression → expression "+" expression •
284
+ {$end, "^", "+", "-", "*", "/", ")"}
285
+ 86/r4: expression → expression • "^" expression
286
+ {}
287
+ 87/l2: expression → expression • "+" expression
243
288
  {}
244
- 69/l2: expression → expression • "-" expression
289
+ 88/l2: expression → expression • "-" expression
245
290
  {}
246
- 70/l3: expression → expression • "*" expression
291
+ 89/l3: expression → expression • "*" expression
247
292
  {}
248
- 71/l3: expression → expression • "/" expression
293
+ 90/l3: expression → expression • "/" expression
249
294
  {}
250
295
  transitions:
251
- "*": State 7
252
- "/": State 8
296
+ "^": State 5
297
+ "*": State 8
298
+ "/": State 9
253
299
  reductions:
254
300
  "+": Rule 3
255
301
  "-": Rule 3
256
- $: Rule 3
302
+ $end: Rule 3
257
303
  ")": Rule 3
258
304
 
259
- State 13:
260
- 72/l3: expression → expression "*" expression •
261
- {$, "+", "-", "*", "/", ")"}
262
- 73/l2: expression → expression • "+" expression
305
+ State 14:
306
+ 91/l2: expression → expression "-" expression •
307
+ {$end, "^", "+", "-", "*", "/", ")"}
308
+ 92/r4: expression → expression • "^" expression
309
+ {}
310
+ 93/l2: expression → expression • "+" expression
263
311
  {}
264
- 74/l2: expression → expression • "-" expression
312
+ 94/l2: expression → expression • "-" expression
265
313
  {}
266
- 75/l3: expression → expression • "*" expression
314
+ 95/l3: expression → expression • "*" expression
267
315
  {}
268
- 76/l3: expression → expression • "/" expression
316
+ 96/l3: expression → expression • "/" expression
269
317
  {}
318
+ transitions:
319
+ "^": State 5
320
+ "*": State 8
321
+ "/": State 9
270
322
  reductions:
271
323
  "+": Rule 4
272
324
  "-": Rule 4
273
- "*": Rule 4
274
- "/": Rule 4
275
- $: Rule 4
325
+ $end: Rule 4
276
326
  ")": Rule 4
277
327
 
278
- State 14:
279
- 77/l3: expression → expression "/" expression •
280
- {$, "+", "-", "*", "/", ")"}
281
- 78/l2: expression → expression • "+" expression
328
+ State 15:
329
+ 97/l3: expression → expression "*" expression •
330
+ {$end, "^", "+", "-", "*", "/", ")"}
331
+ 98/r4: expression → expression • "^" expression
282
332
  {}
283
- 79/l2: expression → expression • "-" expression
333
+ 99/l2: expression → expression • "+" expression
284
334
  {}
285
- 80/l3: expression → expression • "*" expression
335
+ 100/l2: expression → expression • "-" expression
286
336
  {}
287
- 81/l3: expression → expression • "/" expression
337
+ 101/l3: expression → expression • "*" expression
288
338
  {}
339
+ 102/l3: expression → expression • "/" expression
340
+ {}
341
+ transitions:
342
+ "^": State 5
289
343
  reductions:
290
344
  "+": Rule 5
291
345
  "-": Rule 5
292
346
  "*": Rule 5
293
347
  "/": Rule 5
294
- $: Rule 5
348
+ $end: Rule 5
295
349
  ")": Rule 5
296
350
 
297
- State 15:
298
- 82/n4: expression → "(" expression ")"
299
- {$, "+", "-", "*", "/", ")"}
351
+ State 16:
352
+ 103/l3: expression → expression "/" expression •
353
+ {$end, "^", "+", "-", "*", "/", ")"}
354
+ 104/r4: expression → expression • "^" expression
355
+ {}
356
+ 105/l2: expression → expression • "+" expression
357
+ {}
358
+ 106/l2: expression → expression • "-" expression
359
+ {}
360
+ 107/l3: expression → expression • "*" expression
361
+ {}
362
+ 108/l3: expression → expression • "/" expression
363
+ {}
364
+ transitions:
365
+ "^": State 5
300
366
  reductions:
301
- $: Rule 6
302
367
  "+": Rule 6
303
368
  "-": Rule 6
304
369
  "*": Rule 6
305
370
  "/": Rule 6
371
+ $end: Rule 6
306
372
  ")": Rule 6
307
373
 
308
- State 16:
309
- 83/n4: expression → "(" $error ")" •
310
- {$, "+", "-", "*", "/", ")"}
374
+ State 17:
375
+ 109/n1: expression → "(" expression ")" •
376
+ {$end, "^", "+", "-", "*", "/", ")"}
377
+ reductions:
378
+ $default: Rule 7
379
+
380
+ State 18:
381
+ 110/n1: expression → "(" $error ")" •
382
+ {$end, "^", "+", "-", "*", "/", ")"}
311
383
  reductions:
312
- $: Rule 7
313
- "+": Rule 7
314
- "-": Rule 7
315
- "*": Rule 7
316
- "/": Rule 7
317
- ")": Rule 7
384
+ $default: Rule 8
318
385
 
data/examples/simple.ace CHANGED
@@ -1,5 +1,5 @@
1
1
  %require "~> 0.1"
2
- %type "ruby"
2
+ %generator "ruby"
3
3
 
4
4
  %terminal IDENT
5
5
  %terminal STAR "*"