racc 1.4.13 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/COPYING +22 -515
- data/README.ja.rdoc +3 -4
- data/README.rdoc +6 -8
- data/Rakefile +30 -53
- data/bin/racc +39 -27
- data/ext/racc/com/headius/racc/Cparse.java +66 -23
- data/ext/racc/{cparse.c → cparse/cparse.c} +78 -47
- data/ext/racc/{extconf.rb → cparse/extconf.rb} +2 -1
- data/lib/racc/compat.rb +5 -4
- data/lib/racc/debugflags.rb +5 -4
- data/lib/racc/exception.rb +5 -4
- data/lib/racc/grammar.rb +25 -22
- data/lib/racc/grammarfileparser.rb +10 -8
- data/lib/racc/info.rb +6 -5
- data/lib/racc/iset.rb +6 -5
- data/lib/racc/logfilegenerator.rb +6 -5
- data/lib/racc/parser-text.rb +23 -24
- data/lib/racc/parser.rb +23 -24
- data/lib/racc/parserfilegenerator.rb +10 -10
- data/lib/racc/sourcetext.rb +5 -4
- data/lib/racc/state.rb +13 -12
- data/lib/racc/statetransitiontable.rb +7 -6
- data/rdoc/ja/command.ja.html +1 -1
- data/sample/array.y +1 -1
- data/sample/array2.y +1 -1
- data/sample/calc-ja.y +2 -2
- data/sample/calc.y +2 -2
- data/sample/conflict.y +1 -1
- data/sample/hash.y +1 -1
- data/sample/lalr.y +1 -1
- data/sample/lists.y +1 -1
- data/sample/syntax.y +1 -1
- data/sample/yyerr.y +1 -1
- data/test/assets/cadenza.y +170 -0
- data/test/assets/cast.y +926 -0
- data/test/assets/csspool.y +729 -0
- data/test/assets/edtf.y +583 -0
- data/test/assets/error_recovery.y +35 -0
- data/test/assets/huia.y +318 -0
- data/test/assets/intp.y +4 -4
- data/test/assets/journey.y +47 -0
- data/test/assets/liquor.y +313 -0
- data/test/assets/machete.y +423 -0
- data/test/assets/macruby.y +2197 -0
- data/test/assets/mailp.y +27 -27
- data/test/assets/mediacloth.y +599 -0
- data/test/assets/mof.y +649 -0
- data/test/assets/namae.y +302 -0
- data/test/assets/nasl.y +626 -0
- data/test/assets/nokogiri-css.y +255 -0
- data/test/assets/nullbug2.y +2 -2
- data/test/assets/opal.y +1807 -0
- data/test/assets/php_serialization.y +98 -0
- data/test/assets/recv.y +20 -20
- data/test/assets/riml.y +665 -0
- data/test/assets/ruby18.y +1943 -0
- data/test/assets/ruby19.y +2174 -0
- data/test/assets/ruby20.y +2350 -0
- data/test/assets/ruby21.y +2359 -0
- data/test/assets/ruby22.y +2381 -0
- data/test/assets/syntax.y +1 -1
- data/test/assets/tp_plus.y +622 -0
- data/test/assets/twowaysql.y +278 -0
- data/test/helper.rb +69 -41
- data/test/regress/cadenza +796 -0
- data/test/regress/cast +3428 -0
- data/test/regress/csspool +2314 -0
- data/test/regress/edtf +1794 -0
- data/test/regress/huia +1392 -0
- data/test/regress/journey +222 -0
- data/test/regress/liquor +885 -0
- data/test/regress/machete +833 -0
- data/test/regress/mediacloth +1463 -0
- data/test/regress/mof +1368 -0
- data/test/regress/namae +634 -0
- data/test/regress/nasl +2058 -0
- data/test/regress/nokogiri-css +836 -0
- data/test/regress/opal +6431 -0
- data/test/regress/php_serialization +336 -0
- data/test/regress/riml +3283 -0
- data/test/regress/ruby18 +6344 -0
- data/test/regress/ruby22 +7460 -0
- data/test/regress/tp_plus +1933 -0
- data/test/regress/twowaysql +556 -0
- data/test/test_chk_y.rb +1 -0
- data/test/test_racc_command.rb +186 -2
- data/test/test_scan_y.rb +1 -0
- data/test/testscanner.rb +1 -1
- metadata +60 -83
- data/DEPENDS +0 -4
- data/Manifest.txt +0 -101
- data/bin/racc2y +0 -195
- data/bin/y2racc +0 -339
- data/ext/racc/depend +0 -1
- data/fastcache/extconf.rb +0 -2
- data/fastcache/fastcache.c +0 -185
- data/misc/dist.sh +0 -31
- data/setup.rb +0 -1587
- data/tasks/doc.rb +0 -12
- data/tasks/email.rb +0 -55
@@ -1,9 +1,9 @@
|
|
1
1
|
/*
|
2
2
|
|
3
3
|
cparse.c -- Racc Runtime Core
|
4
|
-
|
4
|
+
|
5
5
|
Copyright (c) 1999-2006 Minero Aoki
|
6
|
-
|
6
|
+
|
7
7
|
This library is free software.
|
8
8
|
You can distribute/modify this program under the same terms of ruby.
|
9
9
|
|
@@ -13,11 +13,18 @@
|
|
13
13
|
|
14
14
|
#include <ruby.h>
|
15
15
|
|
16
|
+
#ifndef FALSE
|
17
|
+
#define FALSE 0
|
18
|
+
#endif
|
19
|
+
#ifndef TRUE
|
20
|
+
#define TRUE 1
|
21
|
+
#endif
|
22
|
+
|
16
23
|
/* -----------------------------------------------------------------------
|
17
24
|
Important Constants
|
18
25
|
----------------------------------------------------------------------- */
|
19
26
|
|
20
|
-
#define RACC_VERSION "1.4.
|
27
|
+
#define RACC_VERSION "1.4.15"
|
21
28
|
|
22
29
|
#define DEFAULT_TOKEN -1
|
23
30
|
#define ERROR_TOKEN 1
|
@@ -189,7 +196,7 @@ static VALUE racc_yyparse _((VALUE parser, VALUE lexer, VALUE lexmid,
|
|
189
196
|
VALUE arg, VALUE sysdebug));
|
190
197
|
|
191
198
|
static void call_lexer _((struct cparse_params *v));
|
192
|
-
static VALUE lexer_i _((
|
199
|
+
static VALUE lexer_i _((RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data)));
|
193
200
|
|
194
201
|
static VALUE assert_array _((VALUE a));
|
195
202
|
static long assert_integer _((VALUE n));
|
@@ -197,6 +204,7 @@ static VALUE assert_hash _((VALUE h));
|
|
197
204
|
static VALUE initialize_params _((VALUE vparams, VALUE parser, VALUE arg,
|
198
205
|
VALUE lexer, VALUE lexmid));
|
199
206
|
static void cparse_params_mark _((void *ptr));
|
207
|
+
static size_t cparse_params_memsize _((const void *ptr));
|
200
208
|
|
201
209
|
static void parse_main _((struct cparse_params *v,
|
202
210
|
VALUE tok, VALUE val, int resume));
|
@@ -204,7 +212,7 @@ static void extract_user_token _((struct cparse_params *v,
|
|
204
212
|
VALUE block_args, VALUE *tok, VALUE *val));
|
205
213
|
static void shift _((struct cparse_params* v, long act, VALUE tok, VALUE val));
|
206
214
|
static int reduce _((struct cparse_params* v, long act));
|
207
|
-
static
|
215
|
+
static rb_block_call_func reduce0;
|
208
216
|
|
209
217
|
#ifdef DEBUG
|
210
218
|
# define D_puts(msg) if (v->sys_debug) puts(msg)
|
@@ -214,35 +222,52 @@ static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
|
|
214
222
|
# define D_printf(fmt,arg)
|
215
223
|
#endif
|
216
224
|
|
225
|
+
#undef RUBY_UNTYPED_DATA_WARNING
|
226
|
+
#define RUBY_UNTYPED_DATA_WARNING 1
|
227
|
+
|
228
|
+
static const rb_data_type_t cparse_params_type = {
|
229
|
+
"racc/cparse",
|
230
|
+
{
|
231
|
+
cparse_params_mark,
|
232
|
+
RUBY_TYPED_DEFAULT_FREE,
|
233
|
+
cparse_params_memsize,
|
234
|
+
},
|
235
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
236
|
+
0, 0,
|
237
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
238
|
+
#endif
|
239
|
+
};
|
240
|
+
|
217
241
|
static VALUE
|
218
242
|
racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
|
219
243
|
{
|
220
|
-
|
244
|
+
VALUE vparams;
|
221
245
|
struct cparse_params *v;
|
222
246
|
|
223
|
-
vparams =
|
224
|
-
|
247
|
+
vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
|
248
|
+
&cparse_params_type, v);
|
225
249
|
D_puts("starting cparse");
|
226
250
|
v->sys_debug = RTEST(sysdebug);
|
227
251
|
vparams = initialize_params(vparams, parser, arg, Qnil, Qnil);
|
228
|
-
v->lex_is_iterator =
|
252
|
+
v->lex_is_iterator = FALSE;
|
229
253
|
parse_main(v, Qnil, Qnil, 0);
|
230
254
|
|
255
|
+
RB_GC_GUARD(vparams);
|
231
256
|
return v->retval;
|
232
257
|
}
|
233
258
|
|
234
259
|
static VALUE
|
235
260
|
racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
|
236
261
|
{
|
237
|
-
|
262
|
+
VALUE vparams;
|
238
263
|
struct cparse_params *v;
|
239
264
|
|
240
|
-
vparams =
|
241
|
-
|
265
|
+
vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
|
266
|
+
&cparse_params_type, v);
|
242
267
|
v->sys_debug = RTEST(sysdebug);
|
243
268
|
D_puts("start C yyparse");
|
244
269
|
vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
|
245
|
-
v->lex_is_iterator =
|
270
|
+
v->lex_is_iterator = TRUE;
|
246
271
|
D_puts("params initialized");
|
247
272
|
parse_main(v, Qnil, Qnil, 0);
|
248
273
|
call_lexer(v);
|
@@ -251,6 +276,7 @@ racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
|
|
251
276
|
rb_id2name(v->lexmid));
|
252
277
|
}
|
253
278
|
|
279
|
+
RB_GC_GUARD(vparams);
|
254
280
|
return v->retval;
|
255
281
|
}
|
256
282
|
|
@@ -264,9 +290,8 @@ call_lexer(struct cparse_params *v)
|
|
264
290
|
static VALUE
|
265
291
|
lexer_iter(VALUE data)
|
266
292
|
{
|
267
|
-
struct cparse_params *v;
|
293
|
+
struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
|
268
294
|
|
269
|
-
Data_Get_Struct(data, struct cparse_params, v);
|
270
295
|
rb_funcall(v->lexer, v->lexmid, 0);
|
271
296
|
return Qnil;
|
272
297
|
}
|
@@ -279,18 +304,17 @@ call_lexer(struct cparse_params *v)
|
|
279
304
|
#endif
|
280
305
|
|
281
306
|
static VALUE
|
282
|
-
lexer_i(
|
307
|
+
lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
|
283
308
|
{
|
284
|
-
struct cparse_params *v;
|
309
|
+
struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
|
285
310
|
VALUE tok, val;
|
286
311
|
|
287
|
-
Data_Get_Struct(data, struct cparse_params, v);
|
288
312
|
if (v->fin)
|
289
313
|
rb_raise(rb_eArgError, "extra token after EndOfToken");
|
290
314
|
extract_user_token(v, block_args, &tok, &val);
|
291
315
|
parse_main(v, tok, val, 1);
|
292
316
|
if (v->fin && v->fin != CP_FIN_ACCEPT)
|
293
|
-
rb_iter_break();
|
317
|
+
rb_iter_break();
|
294
318
|
return Qnil;
|
295
319
|
}
|
296
320
|
|
@@ -317,9 +341,8 @@ assert_integer(VALUE n)
|
|
317
341
|
static VALUE
|
318
342
|
initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
|
319
343
|
{
|
320
|
-
struct cparse_params *v;
|
344
|
+
struct cparse_params *v = rb_check_typeddata(vparams, &cparse_params_type);
|
321
345
|
|
322
|
-
Data_Get_Struct(vparams, struct cparse_params, v);
|
323
346
|
v->value_v = vparams;
|
324
347
|
v->parser = parser;
|
325
348
|
v->lexer = lexer;
|
@@ -348,7 +371,7 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
|
|
348
371
|
v->use_result_var = RTEST(rb_ary_entry(arg, 13));
|
349
372
|
}
|
350
373
|
else {
|
351
|
-
v->use_result_var =
|
374
|
+
v->use_result_var = TRUE;
|
352
375
|
}
|
353
376
|
|
354
377
|
v->tstack = v->debug ? NEW_STACK() : Qnil;
|
@@ -364,7 +387,7 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
|
|
364
387
|
v->retval = Qnil;
|
365
388
|
v->fin = 0;
|
366
389
|
|
367
|
-
v->lex_is_iterator =
|
390
|
+
v->lex_is_iterator = FALSE;
|
368
391
|
|
369
392
|
rb_iv_set(parser, "@vstack", v->vstack);
|
370
393
|
if (v->debug) {
|
@@ -402,6 +425,12 @@ cparse_params_mark(void *ptr)
|
|
402
425
|
rb_gc_mark(v->retval);
|
403
426
|
}
|
404
427
|
|
428
|
+
static size_t
|
429
|
+
cparse_params_memsize(const void *ptr)
|
430
|
+
{
|
431
|
+
return sizeof(struct cparse_params);
|
432
|
+
}
|
433
|
+
|
405
434
|
static void
|
406
435
|
extract_user_token(struct cparse_params *v, VALUE block_args,
|
407
436
|
VALUE *tok, VALUE *val)
|
@@ -413,12 +442,12 @@ extract_user_token(struct cparse_params *v, VALUE block_args,
|
|
413
442
|
return;
|
414
443
|
}
|
415
444
|
|
416
|
-
if (
|
445
|
+
if (!RB_TYPE_P(block_args, T_ARRAY)) {
|
417
446
|
rb_raise(rb_eTypeError,
|
418
|
-
"%s() %s %
|
447
|
+
"%s() %s %"PRIsVALUE" (must be Array[2])",
|
419
448
|
v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
|
420
449
|
v->lex_is_iterator ? "yielded" : "returned",
|
421
|
-
|
450
|
+
rb_obj_class(block_args));
|
422
451
|
}
|
423
452
|
if (RARRAY_LEN(block_args) != 2) {
|
424
453
|
rb_raise(rb_eArgError,
|
@@ -457,7 +486,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
|
|
457
486
|
|
458
487
|
if (resume)
|
459
488
|
goto resume;
|
460
|
-
|
489
|
+
|
461
490
|
while (1) {
|
462
491
|
D_puts("");
|
463
492
|
D_puts("---- enter new loop ----");
|
@@ -516,7 +545,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
|
|
516
545
|
act_fixed:
|
517
546
|
D_printf("act=%ld\n", act);
|
518
547
|
goto handle_act;
|
519
|
-
|
548
|
+
|
520
549
|
notfound:
|
521
550
|
D_puts("(act) not found: use default");
|
522
551
|
act_value = AREF(v->action_default, v->curstate);
|
@@ -576,7 +605,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
|
|
576
605
|
user_yyerror:
|
577
606
|
if (v->errstatus == 3) {
|
578
607
|
if (v->t == vFINAL_TOKEN) {
|
579
|
-
v->retval =
|
608
|
+
v->retval = Qnil;
|
580
609
|
v->fin = CP_FIN_EOT;
|
581
610
|
return;
|
582
611
|
}
|
@@ -617,7 +646,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
|
|
617
646
|
|
618
647
|
D_puts("(err) found: can handle error token");
|
619
648
|
break;
|
620
|
-
|
649
|
+
|
621
650
|
error_pop:
|
622
651
|
D_puts("(err) act not found: can't handle error token; pop");
|
623
652
|
|
@@ -679,9 +708,9 @@ reduce(struct cparse_params *v, long act)
|
|
679
708
|
}
|
680
709
|
|
681
710
|
static VALUE
|
682
|
-
reduce0(
|
711
|
+
reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data))
|
683
712
|
{
|
684
|
-
struct cparse_params *v;
|
713
|
+
struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
|
685
714
|
VALUE reduce_to, reduce_len, method_id;
|
686
715
|
long len;
|
687
716
|
ID mid;
|
@@ -689,7 +718,6 @@ reduce0(VALUE val, VALUE data, VALUE self)
|
|
689
718
|
long i, k1, k2;
|
690
719
|
VALUE goto_state;
|
691
720
|
|
692
|
-
Data_Get_Struct(data, struct cparse_params, v);
|
693
721
|
reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
|
694
722
|
reduce_to = rb_ary_entry(v->reduce_table, v->ruleno+1);
|
695
723
|
method_id = rb_ary_entry(v->reduce_table, v->ruleno+2);
|
@@ -792,11 +820,11 @@ void
|
|
792
820
|
Init_cparse(void)
|
793
821
|
{
|
794
822
|
VALUE Racc, Parser;
|
795
|
-
ID id_racc =
|
823
|
+
ID id_racc = rb_intern_const("Racc");
|
796
824
|
|
797
825
|
if (rb_const_defined(rb_cObject, id_racc)) {
|
798
826
|
Racc = rb_const_get(rb_cObject, id_racc);
|
799
|
-
Parser = rb_const_get_at(Racc,
|
827
|
+
Parser = rb_const_get_at(Racc, rb_intern_const("Parser"));
|
800
828
|
}
|
801
829
|
else {
|
802
830
|
Racc = rb_define_module("Racc");
|
@@ -810,19 +838,22 @@ Init_cparse(void)
|
|
810
838
|
rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
|
811
839
|
|
812
840
|
CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);
|
841
|
+
rb_undef_alloc_func(CparseParams);
|
842
|
+
rb_undef_method(CparseParams, "initialize");
|
843
|
+
rb_undef_method(CparseParams, "initialize_copy");
|
813
844
|
|
814
845
|
RaccBug = rb_eRuntimeError;
|
815
846
|
|
816
|
-
id_yydebug =
|
817
|
-
id_nexttoken =
|
818
|
-
id_onerror =
|
819
|
-
id_noreduce =
|
820
|
-
id_errstatus =
|
821
|
-
|
822
|
-
id_d_shift =
|
823
|
-
id_d_reduce =
|
824
|
-
id_d_accept =
|
825
|
-
id_d_read_token =
|
826
|
-
id_d_next_state =
|
827
|
-
id_d_e_pop =
|
847
|
+
id_yydebug = rb_intern_const("@yydebug");
|
848
|
+
id_nexttoken = rb_intern_const("next_token");
|
849
|
+
id_onerror = rb_intern_const("on_error");
|
850
|
+
id_noreduce = rb_intern_const("_reduce_none");
|
851
|
+
id_errstatus = rb_intern_const("@racc_error_status");
|
852
|
+
|
853
|
+
id_d_shift = rb_intern_const("racc_shift");
|
854
|
+
id_d_reduce = rb_intern_const("racc_reduce");
|
855
|
+
id_d_accept = rb_intern_const("racc_accept");
|
856
|
+
id_d_read_token = rb_intern_const("racc_read_token");
|
857
|
+
id_d_next_state = rb_intern_const("racc_next_state");
|
858
|
+
id_d_e_pop = rb_intern_const("racc_e_pop");
|
828
859
|
}
|
data/lib/racc/compat.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
#--
|
2
|
+
#
|
1
3
|
#
|
2
|
-
# $Id: 14fa1118eb3a23e85265e4f7afe2d5a297d69f9c $
|
3
4
|
#
|
4
5
|
# Copyright (c) 1999-2006 Minero Aoki
|
5
6
|
#
|
6
7
|
# This program is free software.
|
7
|
-
# You can distribute/modify this program under the terms of
|
8
|
-
# the
|
9
|
-
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
10
|
#
|
11
|
+
#++
|
11
12
|
|
12
13
|
unless Object.method_defined?(:__send)
|
13
14
|
class Object
|
data/lib/racc/debugflags.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
#--
|
2
|
+
#
|
1
3
|
#
|
2
|
-
# $Id: 74ff4369ce53c7f45cfc2644ce907785104ebf6e $
|
3
4
|
#
|
4
5
|
# Copyright (c) 1999-2006 Minero Aoki
|
5
6
|
#
|
6
7
|
# This program is free software.
|
7
|
-
# You can distribute/modify this program under the terms of
|
8
|
-
# the
|
9
|
-
# For details of LGPL, see the file "COPYING".
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
10
|
#
|
11
|
+
#++
|
11
12
|
|
12
13
|
module Racc
|
13
14
|
|
data/lib/racc/exception.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
#--
|
2
|
+
#
|
1
3
|
#
|
2
|
-
# $Id: a26517cc7b6a673ce1985c8c75fba88492e1e820 $
|
3
4
|
#
|
4
5
|
# Copyright (c) 1999-2006 Minero Aoki
|
5
6
|
#
|
6
7
|
# This program is free software.
|
7
|
-
# You can distribute/modify this program under the terms of
|
8
|
-
# the
|
9
|
-
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
10
|
#
|
11
|
+
#++
|
11
12
|
|
12
13
|
module Racc
|
13
14
|
class Error < StandardError; end
|
data/lib/racc/grammar.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
#--
|
2
|
+
#
|
1
3
|
#
|
2
|
-
# $Id: 733f7084ff1dca50994cba55c8a05aba8d82eb31 $
|
3
4
|
#
|
4
5
|
# Copyright (c) 1999-2006 Minero Aoki
|
5
6
|
#
|
6
7
|
# This program is free software.
|
7
|
-
# You can distribute/modify this program under the terms of
|
8
|
-
# the
|
9
|
-
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
10
|
#
|
11
|
+
#++
|
11
12
|
|
12
13
|
require 'racc/compat'
|
13
14
|
require 'racc/iset'
|
@@ -85,14 +86,15 @@ module Racc
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def n_useless_nonterminals
|
88
|
-
@n_useless_nonterminals ||=
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
@n_useless_nonterminals ||= each_useless_nonterminal.count
|
90
|
+
end
|
91
|
+
|
92
|
+
def each_useless_nonterminal
|
93
|
+
return to_enum __method__ unless block_given?
|
94
|
+
|
95
|
+
@symboltable.each_nonterminal do |sym|
|
96
|
+
yield sym if sym.useless?
|
97
|
+
end
|
96
98
|
end
|
97
99
|
|
98
100
|
def useless_rule_exist?
|
@@ -100,14 +102,15 @@ module Racc
|
|
100
102
|
end
|
101
103
|
|
102
104
|
def n_useless_rules
|
103
|
-
@n_useless_rules ||=
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
105
|
+
@n_useless_rules ||= each_useless_rule.count
|
106
|
+
end
|
107
|
+
|
108
|
+
def each_useless_rule
|
109
|
+
return to_enum __method__ unless block_given?
|
110
|
+
|
111
|
+
each do |r|
|
112
|
+
yield r if r.useless?
|
113
|
+
end
|
111
114
|
end
|
112
115
|
|
113
116
|
def nfa
|
@@ -571,7 +574,7 @@ module Racc
|
|
571
574
|
check_symbols_useless s
|
572
575
|
end until r.size == rs and s.size == ss
|
573
576
|
end
|
574
|
-
|
577
|
+
|
575
578
|
def check_rules_useless(rules)
|
576
579
|
rules.delete_if do |rule|
|
577
580
|
rule.useless = false
|
@@ -855,7 +858,7 @@ module Racc
|
|
855
858
|
end
|
856
859
|
|
857
860
|
private
|
858
|
-
|
861
|
+
|
859
862
|
def ptr_bug!
|
860
863
|
raise "racc: fatal: pointer not exist: self: #{to_s}"
|
861
864
|
end
|