gd-racc 1.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +846 -0
  5. data/DEPENDS +4 -0
  6. data/Manifest.txt +100 -0
  7. data/README.ja.rdoc +96 -0
  8. data/README.rdoc +86 -0
  9. data/Rakefile +54 -0
  10. data/TODO +5 -0
  11. data/bin/racc +308 -0
  12. data/bin/racc2y +195 -0
  13. data/bin/y2racc +339 -0
  14. data/ext/racc/MANIFEST +4 -0
  15. data/ext/racc/cparse.c +828 -0
  16. data/ext/racc/depend +1 -0
  17. data/ext/racc/extconf.rb +7 -0
  18. data/fastcache/extconf.rb +2 -0
  19. data/fastcache/fastcache.c +185 -0
  20. data/lib/racc.rb +6 -0
  21. data/lib/racc/compat.rb +32 -0
  22. data/lib/racc/debugflags.rb +59 -0
  23. data/lib/racc/exception.rb +15 -0
  24. data/lib/racc/grammar.rb +1115 -0
  25. data/lib/racc/grammarfileparser.rb +559 -0
  26. data/lib/racc/info.rb +16 -0
  27. data/lib/racc/iset.rb +91 -0
  28. data/lib/racc/logfilegenerator.rb +211 -0
  29. data/lib/racc/parser-text.rb +631 -0
  30. data/lib/racc/parser.rb +626 -0
  31. data/lib/racc/parserfilegenerator.rb +512 -0
  32. data/lib/racc/pre-setup +13 -0
  33. data/lib/racc/sourcetext.rb +34 -0
  34. data/lib/racc/state.rb +971 -0
  35. data/lib/racc/statetransitiontable.rb +316 -0
  36. data/lib/racc/static.rb +5 -0
  37. data/misc/dist.sh +31 -0
  38. data/rdoc/en/NEWS.en.rdoc +282 -0
  39. data/rdoc/en/grammar.en.rdoc +230 -0
  40. data/rdoc/ja/NEWS.ja.rdoc +307 -0
  41. data/rdoc/ja/command.ja.html +94 -0
  42. data/rdoc/ja/debug.ja.rdoc +36 -0
  43. data/rdoc/ja/grammar.ja.rdoc +348 -0
  44. data/rdoc/ja/index.ja.html +10 -0
  45. data/rdoc/ja/parser.ja.rdoc +125 -0
  46. data/rdoc/ja/usage.ja.html +414 -0
  47. data/sample/array.y +67 -0
  48. data/sample/array2.y +59 -0
  49. data/sample/calc-ja.y +66 -0
  50. data/sample/calc.y +65 -0
  51. data/sample/conflict.y +15 -0
  52. data/sample/hash.y +60 -0
  53. data/sample/lalr.y +17 -0
  54. data/sample/lists.y +57 -0
  55. data/sample/syntax.y +46 -0
  56. data/sample/yyerr.y +46 -0
  57. data/setup.rb +1587 -0
  58. data/tasks/doc.rb +12 -0
  59. data/tasks/email.rb +55 -0
  60. data/test/assets/chk.y +126 -0
  61. data/test/assets/conf.y +16 -0
  62. data/test/assets/digraph.y +29 -0
  63. data/test/assets/echk.y +118 -0
  64. data/test/assets/err.y +60 -0
  65. data/test/assets/expect.y +7 -0
  66. data/test/assets/firstline.y +4 -0
  67. data/test/assets/ichk.y +102 -0
  68. data/test/assets/intp.y +546 -0
  69. data/test/assets/mailp.y +437 -0
  70. data/test/assets/newsyn.y +25 -0
  71. data/test/assets/noend.y +4 -0
  72. data/test/assets/nonass.y +41 -0
  73. data/test/assets/normal.y +27 -0
  74. data/test/assets/norule.y +4 -0
  75. data/test/assets/nullbug1.y +25 -0
  76. data/test/assets/nullbug2.y +15 -0
  77. data/test/assets/opt.y +123 -0
  78. data/test/assets/percent.y +35 -0
  79. data/test/assets/recv.y +97 -0
  80. data/test/assets/rrconf.y +14 -0
  81. data/test/assets/scan.y +72 -0
  82. data/test/assets/syntax.y +50 -0
  83. data/test/assets/unterm.y +5 -0
  84. data/test/assets/useless.y +12 -0
  85. data/test/assets/yyerr.y +46 -0
  86. data/test/bench.y +36 -0
  87. data/test/helper.rb +87 -0
  88. data/test/infini.y +8 -0
  89. data/test/scandata/brace +7 -0
  90. data/test/scandata/gvar +1 -0
  91. data/test/scandata/normal +4 -0
  92. data/test/scandata/percent +18 -0
  93. data/test/scandata/slash +10 -0
  94. data/test/src.intp +34 -0
  95. data/test/start.y +20 -0
  96. data/test/test_chk_y.rb +51 -0
  97. data/test/test_grammar_file_parser.rb +15 -0
  98. data/test/test_racc_command.rb +155 -0
  99. data/test/test_scan_y.rb +51 -0
  100. data/test/testscanner.rb +51 -0
  101. data/web/racc.en.rhtml +42 -0
  102. data/web/racc.ja.rhtml +51 -0
  103. metadata +212 -0
@@ -0,0 +1,626 @@
1
+ #
2
+ # $Id: 3c520ba1f2996b86abc21eeb54768934a7be9d0c $
3
+ #
4
+ # Copyright (c) 1999-2006 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute/modify this program under the same terms of ruby.
8
+ #
9
+ # As a special exception, when this code is copied by Racc
10
+ # into a Racc output file, you may use that output file
11
+ # without restriction.
12
+ #
13
+
14
+ require 'racc/info'
15
+
16
+ unless defined?(NotImplementedError)
17
+ NotImplementedError = NotImplementError # :nodoc:
18
+ end
19
+
20
+ module Racc
21
+ class ParseError < StandardError; end
22
+ end
23
+ unless defined?(::ParseError)
24
+ ParseError = Racc::ParseError
25
+ end
26
+
27
+ # Racc is a LALR(1) parser generator.
28
+ # It is written in Ruby itself, and generates Ruby programs.
29
+ #
30
+ # == Command-line Reference
31
+ #
32
+ # racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
33
+ # [-e<var>rubypath</var>] [--embedded=<var>rubypath</var>]
34
+ # [-v] [--verbose]
35
+ # [-O<var>filename</var>] [--log-file=<var>filename</var>]
36
+ # [-g] [--debug]
37
+ # [-E] [--embedded]
38
+ # [-l] [--no-line-convert]
39
+ # [-c] [--line-convert-all]
40
+ # [-a] [--no-omit-actions]
41
+ # [-C] [--check-only]
42
+ # [-S] [--output-status]
43
+ # [--version] [--copyright] [--help] <var>grammarfile</var>
44
+ #
45
+ # [+filename+]
46
+ # Racc grammar file. Any extention is permitted.
47
+ # [-o+outfile+, --output-file=+outfile+]
48
+ # A filename for output. default is <+filename+>.tab.rb
49
+ # [-O+filename+, --log-file=+filename+]
50
+ # Place logging output in file +filename+.
51
+ # Default log file name is <+filename+>.output.
52
+ # [-e+rubypath+, --executable=+rubypath+]
53
+ # output executable file(mode 755). where +path+ is the Ruby interpreter.
54
+ # [-v, --verbose]
55
+ # verbose mode. create +filename+.output file, like yacc's y.output file.
56
+ # [-g, --debug]
57
+ # add debug code to parser class. To display debuggin information,
58
+ # use this '-g' option and set @yydebug true in parser class.
59
+ # [-E, --embedded]
60
+ # Output parser which doesn't need runtime files (racc/parser.rb).
61
+ # [-C, --check-only]
62
+ # Check syntax of racc grammer file and quit.
63
+ # [-S, --output-status]
64
+ # Print messages time to time while compiling.
65
+ # [-l, --no-line-convert]
66
+ # turns off line number converting.
67
+ # [-c, --line-convert-all]
68
+ # Convert line number of actions, inner, header and footer.
69
+ # [-a, --no-omit-actions]
70
+ # Call all actions, even if an action is empty.
71
+ # [--version]
72
+ # print Racc version and quit.
73
+ # [--copyright]
74
+ # Print copyright and quit.
75
+ # [--help]
76
+ # Print usage and quit.
77
+ #
78
+ # == Generating Parser Using Racc
79
+ #
80
+ # To compile Racc grammar file, simply type:
81
+ #
82
+ # $ racc parse.y
83
+ #
84
+ # This creates Ruby script file "parse.tab.y". The -o option can change the output filename.
85
+ #
86
+ # == Writing A Racc Grammar File
87
+ #
88
+ # If you want your own parser, you have to write a grammar file.
89
+ # A grammar file contains the name of your parser class, grammar for the parser,
90
+ # user code, and anything else.
91
+ # When writing a grammar file, yacc's knowledge is helpful.
92
+ # If you have not used yacc before, Racc is not too difficult.
93
+ #
94
+ # Here's an example Racc grammar file.
95
+ #
96
+ # class Calcparser
97
+ # rule
98
+ # target: exp { print val[0] }
99
+ #
100
+ # exp: exp '+' exp
101
+ # | exp '*' exp
102
+ # | '(' exp ')'
103
+ # | NUMBER
104
+ # end
105
+ #
106
+ # Racc grammar files resemble yacc files.
107
+ # But (of course), this is Ruby code.
108
+ # yacc's $$ is the 'result', $0, $1... is
109
+ # an array called 'val', and $-1, $-2... is an array called '_values'.
110
+ #
111
+ # See the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for
112
+ # more information on grammar files.
113
+ #
114
+ # == Parser
115
+ #
116
+ # Then you must prepare the parse entry method. There are two types of
117
+ # parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
118
+ #
119
+ # Racc::Parser#do_parse is simple.
120
+ #
121
+ # It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
122
+ # This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
123
+ # EOF is [false, false].
124
+ # (TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
125
+ # If you want to change this, see the grammar reference.
126
+ #
127
+ # Racc::Parser#yyparse is little complicated, but useful.
128
+ # It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
129
+ #
130
+ # For example, <code>yyparse(obj, :scan)</code> causes
131
+ # calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
132
+ #
133
+ # == Debugging
134
+ #
135
+ # When debugging, "-v" or/and the "-g" option is helpful.
136
+ #
137
+ # "-v" creates verbose log file (.output).
138
+ # "-g" creates a "Verbose Parser".
139
+ # Verbose Parser prints the internal status when parsing.
140
+ # But it's _not_ automatic.
141
+ # You must use -g option and set +@yydebug+ to +true+ in order to get output.
142
+ # -g option only creates the verbose parser.
143
+ #
144
+ # === Racc reported syntax error.
145
+ #
146
+ # Isn't there too many "end"?
147
+ # grammar of racc file is changed in v0.10.
148
+ #
149
+ # Racc does not use '%' mark, while yacc uses huge number of '%' marks..
150
+ #
151
+ # === Racc reported "XXXX conflicts".
152
+ #
153
+ # Try "racc -v xxxx.y".
154
+ # It causes producing racc's internal log file, xxxx.output.
155
+ #
156
+ # === Generated parsers does not work correctly
157
+ #
158
+ # Try "racc -g xxxx.y".
159
+ # This command let racc generate "debugging parser".
160
+ # Then set @yydebug=true in your parser.
161
+ # It produces a working log of your parser.
162
+ #
163
+ # == Re-distributing Racc runtime
164
+ #
165
+ # A parser, which is created by Racc, requires the Racc runtime module;
166
+ # racc/parser.rb.
167
+ #
168
+ # Ruby 1.8.x comes with Racc runtime module,
169
+ # you need NOT distribute Racc runtime files.
170
+ #
171
+ # If you want to include the Racc runtime module with your parser.
172
+ # This can be done by using '-E' option:
173
+ #
174
+ # $ racc -E -omyparser.rb myparser.y
175
+ #
176
+ # This command creates myparser.rb which `includes' Racc runtime.
177
+ # Only you must do is to distribute your parser file (myparser.rb).
178
+ #
179
+ # Note: parser.rb is LGPL, but your parser is not.
180
+ # Your own parser is completely yours.
181
+ module Racc
182
+
183
+ unless defined?(Racc_No_Extentions)
184
+ Racc_No_Extentions = false # :nodoc:
185
+ end
186
+
187
+ class Parser
188
+
189
+ Racc_Runtime_Version = ::Racc::VERSION
190
+ Racc_Runtime_Revision = '$Id: 3c520ba1f2996b86abc21eeb54768934a7be9d0c $'
191
+
192
+ Racc_Runtime_Core_Version_R = ::Racc::VERSION
193
+ Racc_Runtime_Core_Revision_R = '$Id: 3c520ba1f2996b86abc21eeb54768934a7be9d0c $'.split[1]
194
+ begin
195
+ require 'racc/cparse'
196
+ # Racc_Runtime_Core_Version_C = (defined in extention)
197
+ Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
198
+ unless new.respond_to?(:_racc_do_parse_c, true)
199
+ raise LoadError, 'old cparse.so'
200
+ end
201
+ if Racc_No_Extentions
202
+ raise LoadError, 'selecting ruby version of racc runtime core'
203
+ end
204
+
205
+ Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
206
+ Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
207
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
208
+ Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc:
209
+ Racc_Runtime_Type = 'c' # :nodoc:
210
+ rescue LoadError
211
+ Racc_Main_Parsing_Routine = :_racc_do_parse_rb
212
+ Racc_YY_Parse_Method = :_racc_yyparse_rb
213
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
214
+ Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R
215
+ Racc_Runtime_Type = 'ruby'
216
+ end
217
+
218
+ def Parser.racc_runtime_type # :nodoc:
219
+ Racc_Runtime_Type
220
+ end
221
+
222
+ def _racc_setup
223
+ @yydebug = false unless self.class::Racc_debug_parser
224
+ @yydebug = false unless defined?(@yydebug)
225
+ if @yydebug
226
+ @racc_debug_out = $stderr unless defined?(@racc_debug_out)
227
+ @racc_debug_out ||= $stderr
228
+ end
229
+ arg = self.class::Racc_arg
230
+ arg[13] = true if arg.size < 14
231
+ arg
232
+ end
233
+
234
+ def _racc_init_sysvars
235
+ @racc_state = [0]
236
+ @racc_tstack = []
237
+ @racc_vstack = []
238
+
239
+ @racc_t = nil
240
+ @racc_val = nil
241
+
242
+ @racc_read_next = true
243
+
244
+ @racc_user_yyerror = false
245
+ @racc_error_status = 0
246
+ end
247
+
248
+ # The entry point of the parser. This method is used with #next_token.
249
+ # If Racc wants to get token (and its value), calls next_token.
250
+ #
251
+ # Example:
252
+ # def parse
253
+ # @q = [[1,1],
254
+ # [2,2],
255
+ # [3,3],
256
+ # [false, '$']]
257
+ # do_parse
258
+ # end
259
+ #
260
+ # def next_token
261
+ # @q.shift
262
+ # end
263
+ def do_parse
264
+ __send__(Racc_Main_Parsing_Routine, _racc_setup(), false)
265
+ end
266
+
267
+ # The method to fetch next token.
268
+ # If you use #do_parse method, you must implement #next_token.
269
+ #
270
+ # The format of return value is [TOKEN_SYMBOL, VALUE].
271
+ # +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
272
+ # for 'IDENT'. ";" (String) for ';'.
273
+ #
274
+ # The final symbol (End of file) must be false.
275
+ def next_token
276
+ raise NotImplementedError, "#{self.class}\#next_token is not defined"
277
+ end
278
+
279
+ def _racc_do_parse_rb(arg, in_debug)
280
+ action_table, action_check, action_default, action_pointer,
281
+ _, _, _, _,
282
+ _, _, token_table, * = arg
283
+
284
+ _racc_init_sysvars
285
+ tok = act = i = nil
286
+
287
+ catch(:racc_end_parse) {
288
+ while true
289
+ if i = action_pointer[@racc_state[-1]]
290
+ if @racc_read_next
291
+ if @racc_t != 0 # not EOF
292
+ tok, @racc_val = next_token()
293
+ unless tok # EOF
294
+ @racc_t = 0
295
+ else
296
+ @racc_t = (token_table[tok] or 1) # error token
297
+ end
298
+ racc_read_token(@racc_t, tok, @racc_val) if @yydebug
299
+ @racc_read_next = false
300
+ end
301
+ end
302
+ i += @racc_t
303
+ unless i >= 0 and
304
+ act = action_table[i] and
305
+ action_check[i] == @racc_state[-1]
306
+ act = action_default[@racc_state[-1]]
307
+ end
308
+ else
309
+ act = action_default[@racc_state[-1]]
310
+ end
311
+ while act = _racc_evalact(act, arg)
312
+ ;
313
+ end
314
+ end
315
+ }
316
+ end
317
+
318
+ # Another entry point for the parser.
319
+ # If you use this method, you must implement RECEIVER#METHOD_ID method.
320
+ #
321
+ # RECEIVER#METHOD_ID is a method to get next token.
322
+ # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
323
+ def yyparse(recv, mid)
324
+ __send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
325
+ end
326
+
327
+ def _racc_yyparse_rb(recv, mid, arg, c_debug)
328
+ action_table, action_check, action_default, action_pointer,
329
+ _, _, _, _,
330
+ _, _, token_table, * = arg
331
+
332
+ _racc_init_sysvars
333
+
334
+ catch(:racc_end_parse) {
335
+ until i = action_pointer[@racc_state[-1]]
336
+ while act = _racc_evalact(action_default[@racc_state[-1]], arg)
337
+ ;
338
+ end
339
+ end
340
+ recv.__send__(mid) do |tok, val|
341
+ unless tok
342
+ @racc_t = 0
343
+ else
344
+ @racc_t = (token_table[tok] or 1) # error token
345
+ end
346
+ @racc_val = val
347
+ @racc_read_next = false
348
+
349
+ i += @racc_t
350
+ unless i >= 0 and
351
+ act = action_table[i] and
352
+ action_check[i] == @racc_state[-1]
353
+ act = action_default[@racc_state[-1]]
354
+ end
355
+ while act = _racc_evalact(act, arg)
356
+ ;
357
+ end
358
+
359
+ while !(i = action_pointer[@racc_state[-1]]) ||
360
+ ! @racc_read_next ||
361
+ @racc_t == 0 # $
362
+ unless i and i += @racc_t and
363
+ i >= 0 and
364
+ act = action_table[i] and
365
+ action_check[i] == @racc_state[-1]
366
+ act = action_default[@racc_state[-1]]
367
+ end
368
+ while act = _racc_evalact(act, arg)
369
+ ;
370
+ end
371
+ end
372
+ end
373
+ }
374
+ end
375
+
376
+ ###
377
+ ### common
378
+ ###
379
+
380
+ def _racc_evalact(act, arg)
381
+ action_table, action_check, _, action_pointer,
382
+ _, _, _, _,
383
+ _, _, _, shift_n,
384
+ reduce_n, * = arg
385
+ nerr = 0 # tmp
386
+
387
+ if act > 0 and act < shift_n
388
+ #
389
+ # shift
390
+ #
391
+ if @racc_error_status > 0
392
+ @racc_error_status -= 1 unless @racc_t == 1 # error token
393
+ end
394
+ @racc_vstack.push @racc_val
395
+ @racc_state.push act
396
+ @racc_read_next = true
397
+ if @yydebug
398
+ @racc_tstack.push @racc_t
399
+ racc_shift @racc_t, @racc_tstack, @racc_vstack
400
+ end
401
+
402
+ elsif act < 0 and act > -reduce_n
403
+ #
404
+ # reduce
405
+ #
406
+ code = catch(:racc_jump) {
407
+ @racc_state.push _racc_do_reduce(arg, act)
408
+ false
409
+ }
410
+ if code
411
+ case code
412
+ when 1 # yyerror
413
+ @racc_user_yyerror = true # user_yyerror
414
+ return -reduce_n
415
+ when 2 # yyaccept
416
+ return shift_n
417
+ else
418
+ raise '[Racc Bug] unknown jump code'
419
+ end
420
+ end
421
+
422
+ elsif act == shift_n
423
+ #
424
+ # accept
425
+ #
426
+ racc_accept if @yydebug
427
+ throw :racc_end_parse, @racc_vstack[0]
428
+
429
+ elsif act == -reduce_n
430
+ #
431
+ # error
432
+ #
433
+ case @racc_error_status
434
+ when 0
435
+ unless arg[21] # user_yyerror
436
+ nerr += 1
437
+ on_error @racc_t, @racc_val, @racc_vstack
438
+ end
439
+ when 3
440
+ if @racc_t == 0 # is $
441
+ throw :racc_end_parse, nil
442
+ end
443
+ @racc_read_next = true
444
+ end
445
+ @racc_user_yyerror = false
446
+ @racc_error_status = 3
447
+ while true
448
+ if i = action_pointer[@racc_state[-1]]
449
+ i += 1 # error token
450
+ if i >= 0 and
451
+ (act = action_table[i]) and
452
+ action_check[i] == @racc_state[-1]
453
+ break
454
+ end
455
+ end
456
+ throw :racc_end_parse, nil if @racc_state.size <= 1
457
+ @racc_state.pop
458
+ @racc_vstack.pop
459
+ if @yydebug
460
+ @racc_tstack.pop
461
+ racc_e_pop @racc_state, @racc_tstack, @racc_vstack
462
+ end
463
+ end
464
+ return act
465
+
466
+ else
467
+ raise "[Racc Bug] unknown action #{act.inspect}"
468
+ end
469
+
470
+ racc_next_state(@racc_state[-1], @racc_state) if @yydebug
471
+
472
+ nil
473
+ end
474
+
475
+ def _racc_do_reduce(arg, act)
476
+ _, _, _, _,
477
+ goto_table, goto_check, goto_default, goto_pointer,
478
+ nt_base, reduce_table, _, _,
479
+ _, use_result, * = arg
480
+
481
+ state = @racc_state
482
+ vstack = @racc_vstack
483
+ tstack = @racc_tstack
484
+
485
+ i = act * -3
486
+ len = reduce_table[i]
487
+ reduce_to = reduce_table[i+1]
488
+ method_id = reduce_table[i+2]
489
+ void_array = []
490
+
491
+ tmp_t = tstack[-len, len] if @yydebug
492
+ tmp_v = vstack[-len, len]
493
+ tstack[-len, len] = void_array if @yydebug
494
+ vstack[-len, len] = void_array
495
+ state[-len, len] = void_array
496
+
497
+ # tstack must be updated AFTER method call
498
+ if use_result
499
+ vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
500
+ else
501
+ vstack.push __send__(method_id, tmp_v, vstack)
502
+ end
503
+ tstack.push reduce_to
504
+
505
+ racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
506
+
507
+ k1 = reduce_to - nt_base
508
+ if i = goto_pointer[k1]
509
+ i += state[-1]
510
+ if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
511
+ return curstate
512
+ end
513
+ end
514
+ goto_default[k1]
515
+ end
516
+
517
+ # This method is called when a parse error is found.
518
+ #
519
+ # ERROR_TOKEN_ID is an internal ID of token which caused error.
520
+ # You can get string representation of this ID by calling
521
+ # #token_to_str.
522
+ #
523
+ # ERROR_VALUE is a value of error token.
524
+ #
525
+ # value_stack is a stack of symbol values.
526
+ # DO NOT MODIFY this object.
527
+ #
528
+ # This method raises ParseError by default.
529
+ #
530
+ # If this method returns, parsers enter "error recovering mode".
531
+ def on_error(t, val, vstack)
532
+ raise ParseError, sprintf("\nparse error on value %s (%s)",
533
+ val.inspect, token_to_str(t) || '?')
534
+ end
535
+
536
+ # Enter error recovering mode.
537
+ # This method does not call #on_error.
538
+ def yyerror
539
+ throw :racc_jump, 1
540
+ end
541
+
542
+ # Exit parser.
543
+ # Return value is Symbol_Value_Stack[0].
544
+ def yyaccept
545
+ throw :racc_jump, 2
546
+ end
547
+
548
+ # Leave error recovering mode.
549
+ def yyerrok
550
+ @racc_error_status = 0
551
+ end
552
+
553
+ # For debugging output
554
+ def racc_read_token(t, tok, val)
555
+ @racc_debug_out.print 'read '
556
+ @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
557
+ @racc_debug_out.puts val.inspect
558
+ @racc_debug_out.puts
559
+ end
560
+
561
+ def racc_shift(tok, tstack, vstack)
562
+ @racc_debug_out.puts "shift #{racc_token2str tok}"
563
+ racc_print_stacks tstack, vstack
564
+ @racc_debug_out.puts
565
+ end
566
+
567
+ def racc_reduce(toks, sim, tstack, vstack)
568
+ out = @racc_debug_out
569
+ out.print 'reduce '
570
+ if toks.empty?
571
+ out.print ' <none>'
572
+ else
573
+ toks.each {|t| out.print ' ', racc_token2str(t) }
574
+ end
575
+ out.puts " --> #{racc_token2str(sim)}"
576
+ racc_print_stacks tstack, vstack
577
+ @racc_debug_out.puts
578
+ end
579
+
580
+ def racc_accept
581
+ @racc_debug_out.puts 'accept'
582
+ @racc_debug_out.puts
583
+ end
584
+
585
+ def racc_e_pop(state, tstack, vstack)
586
+ @racc_debug_out.puts 'error recovering mode: pop token'
587
+ racc_print_states state
588
+ racc_print_stacks tstack, vstack
589
+ @racc_debug_out.puts
590
+ end
591
+
592
+ def racc_next_state(curstate, state)
593
+ @racc_debug_out.puts "goto #{curstate}"
594
+ racc_print_states state
595
+ @racc_debug_out.puts
596
+ end
597
+
598
+ def racc_print_stacks(t, v)
599
+ out = @racc_debug_out
600
+ out.print ' ['
601
+ t.each_index do |i|
602
+ out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
603
+ end
604
+ out.puts ' ]'
605
+ end
606
+
607
+ def racc_print_states(s)
608
+ out = @racc_debug_out
609
+ out.print ' ['
610
+ s.each {|st| out.print ' ', st }
611
+ out.puts ' ]'
612
+ end
613
+
614
+ def racc_token2str(tok)
615
+ self.class::Racc_token_to_s_table[tok] or
616
+ raise "[Racc Bug] can't convert token #{tok} to string"
617
+ end
618
+
619
+ # Convert internal ID of token symbol to the string.
620
+ def token_to_str(t)
621
+ self.class::Racc_token_to_s_table[t]
622
+ end
623
+
624
+ end
625
+
626
+ end