mkbison 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f79c8c38f183e824448e08975a261a84a3d7ebb
4
+ data.tar.gz: cbc9c678a8ca3ba6fca2e862edfd7a812935b1c8
5
+ SHA512:
6
+ metadata.gz: 9deb16d96d0bf833aa091d94969bc962e4c99af6ef28ebd857ea8cdd74f421270f86102c3203c07d61860d335f7dc20ee7a3a23f54a0d264531e1b3ba2c6d519
7
+ data.tar.gz: 62ed42614a334fb587029b663ccbb5c5f33bdd29b92ff2e6c56a0b26030b9cb692849eeffe6d0a00102059e7103661352a4f41bff26e528eda057ee3dbb1dd71
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bison.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Peter Woo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # mkbison
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mkbison'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mkbison
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/wioux/mkbison )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/extensiontask"
4
+
5
+ Rake::ExtensionTask.new "bison_parser" do |ext|
6
+ ext.lib_dir = "lib/bison_parser"
7
+ end
@@ -0,0 +1,5 @@
1
+ * Seems like you can hit EOF in the middle of action block and get wrong error msg
2
+ * Benchmark -- what takes so long on koa?
3
+ * Support multiple tokens on %left/%right lines, for same precedence
4
+ * Write to temp file, then move into place
5
+ * Move base module into the c extension
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'bison'
7
+ require 'fileutils'
8
+ require 'tempfile'
9
+ require 'optparse'
10
+ require 'ostruct'
11
+
12
+ def underscore(name)
13
+ name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
14
+ end
15
+
16
+ options = OpenStruct.new
17
+
18
+ opts = OptionParser.new do |opts|
19
+ opts.banner += ' grammar_file'
20
+
21
+ opts.on('-n NAME', '--name', 'Class name for the resulting parser') do |name|
22
+ options.name = name.strip
23
+ end
24
+
25
+ opts.on('-o DIR', '--output', 'Path to the output directory') do |outdir|
26
+ options.output = outdir
27
+ end
28
+ end
29
+
30
+ opts.parse!
31
+
32
+ grammar_file = ARGV.shift
33
+
34
+ grammar_file or abort(opts.help)
35
+ options.name or abort(opts.help)
36
+ options.output or abort(opts.help)
37
+
38
+ begin
39
+ bison = BisonParser.new(grammar_file).parse
40
+ rescue BisonParser::Error => e
41
+ abort(e.message)
42
+ end
43
+
44
+ bison.validate
45
+
46
+ bison.name = options.name
47
+ libdir = "#{options.output}/lib/#{underscore(options.name)}"
48
+ extdir = "#{options.output}/ext/#{underscore(options.name)}"
49
+
50
+ FileUtils.mkdir_p(libdir)
51
+ FileUtils.mkdir_p(extdir)
52
+
53
+ bison_file = File.open("#{extdir}/#{underscore(options.name)}.y", 'w')
54
+ extconf_file = File.open("#{extdir}/extconf.rb", 'w')
55
+ actions_file = File.open("#{libdir}/actions.rb", 'w')
56
+ base_file = File.open("#{libdir}/base.rb", 'w')
57
+ ruby_file = File.open("#{libdir}.rb", 'w')
58
+
59
+ bison.print_base_module(base_file)
60
+ bison.print_actions_module(actions_file)
61
+ bison.print_bison(bison_file)
62
+ bison.print_extconf(extconf_file)
63
+ bison.print_class(ruby_file)
64
+
65
+ [base_file, actions_file, bison_file, extconf_file, ruby_file].each(&:close)
66
+
67
+ # Do a dry run
68
+ Tempfile.new('bison-output.c').tap do |output|
69
+ bison = ENV['BISON_PATH'] || 'bison'
70
+ system(bison, '-o', output.path, bison_file.path)
71
+ end
@@ -0,0 +1,206 @@
1
+
2
+ %token IDENTIFIER
3
+ %token NUMBER
4
+ %token STRING
5
+ %token COLON
6
+ %token SEMICOLON
7
+ %token LBRACK
8
+ %token RBRACK
9
+ %token PIPE
10
+ %token HASH
11
+ %token DOUBLE_HASH
12
+ %token KW_TOKEN
13
+ %token KW_LEFT
14
+ %token KW_RIGHT
15
+ %token ACTIONS
16
+
17
+
18
+ %%
19
+
20
+ grammar_file :
21
+ token_list[tokens] DOUBLE_HASH grammar_rules[rules] optional_code[code]
22
+ { self.result = Bison::GrammarFile.new(tokens, rules, code) }
23
+ ;
24
+
25
+ optional_code :
26
+ { nil }
27
+ |
28
+ DOUBLE_HASH ACTIONS[actions]
29
+ { actions }
30
+ ;
31
+
32
+ token_list :
33
+ { [] }
34
+ |
35
+ token_list[list] token[token]
36
+ { list << token }
37
+ ;
38
+
39
+ token:
40
+ HASH KW_TOKEN IDENTIFIER[name]
41
+ { Bison::Token.new(name) }
42
+ |
43
+ HASH KW_LEFT IDENTIFIER[name]
44
+ { Bison::Token.new(name, :left) }
45
+ |
46
+ HASH KW_RIGHT IDENTIFIER[name]
47
+ { Bison::Token.new(name, :right) }
48
+ | token[token] NUMBER[num]
49
+ { token.tap{ |t| t.number = num } }
50
+ ;
51
+
52
+ grammar_rules:
53
+ { [] }
54
+ |
55
+ grammar_rules[list] grammar_rule[rule]
56
+ { list << rule }
57
+ ;
58
+
59
+ grammar_rule:
60
+ IDENTIFIER[name] COLON components[components] SEMICOLON
61
+ { Bison::Rule.new(name, components).tap{ |r| r.location = @name } }
62
+ ;
63
+
64
+ components:
65
+ sequence[sequence]
66
+ { [sequence] }
67
+ |
68
+ components[sequences] PIPE sequence[sequence]
69
+ { sequences << sequence }
70
+ ;
71
+
72
+
73
+ sequence:
74
+ { Bison::Sequence.new }
75
+ | sequence[sequence] ACTIONS[code]
76
+ { sequence << Bison::Action.new(code).tap{ |a| a.location = @code } }
77
+ |
78
+ sequence[sequence] IDENTIFIER[follower]
79
+ { sequence << Bison::Nonterminal.new(follower).tap{ |x| x.location = @follower } }
80
+ |
81
+ sequence[sequence] IDENTIFIER[follower] LBRACK IDENTIFIER[tag] RBRACK
82
+ { sequence << Bison::Nonterminal.new(follower, tag).tap{ |x| x.location = @follower } }
83
+ |
84
+ sequence[sequence] STRING[follower]
85
+ { sequence << Bison::String.new(follower).tap{ |x| x.location = @follower } }
86
+ ;
87
+
88
+ %%
89
+
90
+ class BisonParser
91
+ attr_accessor :section
92
+
93
+ def lex
94
+ x = real_lex
95
+ Tokens.constants.each do |const|
96
+ if Tokens.const_get(const) == x
97
+ warn "Lex'd #{const}\t: #{lex_value.inspect}" if ENV['DEBUG_GRAMMAR']
98
+ return x
99
+ end
100
+ end
101
+
102
+ warn "Lex'd #{x.inspect}" if ENV['DEBUG_GRAMMAR']
103
+
104
+ x
105
+ end
106
+
107
+ def real_lex
108
+ self.section ||= 0
109
+ self.lex_value = nil
110
+
111
+ if section == 2
112
+ self.lex_value = io.read
113
+ self.section += 2
114
+ return Tokens::ACTIONS
115
+ end
116
+
117
+ # skip space
118
+ while true
119
+ while (c = self.read) && c =~ /\s/
120
+ end
121
+
122
+ if c == '#'
123
+ while (char = self.read) && char != "\n"
124
+ end
125
+ else
126
+ break
127
+ end
128
+ end
129
+
130
+ return nil unless c
131
+
132
+ case c
133
+ when ':'
134
+ return Tokens::COLON
135
+ when ';'
136
+ return Tokens::SEMICOLON
137
+ when '|'
138
+ return Tokens::PIPE
139
+ when '%'
140
+ if self.peak == '%'
141
+ self.read
142
+ self.section += 1
143
+ return Tokens::DOUBLE_HASH
144
+ end
145
+ return Tokens::HASH
146
+ when '['
147
+ return Tokens::LBRACK
148
+ when ']'
149
+ return Tokens::RBRACK
150
+ when '{'
151
+ nesting = 1
152
+ action = ''
153
+ while (c = self.read) && nesting > 0
154
+ nesting += 1 if c == '{'
155
+ nesting -= 1 if c == '}'
156
+ action << c unless nesting.zero?
157
+ end
158
+ self.lex_value = action
159
+ return Tokens::ACTIONS
160
+ when '0'..'9'
161
+ number = c
162
+ while (c = self.peak) && ('0'..'9').include?(c)
163
+ number << self.read
164
+ end
165
+ self.lex_value = number.to_i
166
+ return Tokens::NUMBER
167
+ when '"'
168
+ string = ''
169
+ while (c = self.read) && c != '"'
170
+ string << c
171
+ end
172
+ self.lex_value = string
173
+ return Tokens::STRING
174
+ when "'"
175
+ string = ''
176
+ while (c = self.read) && c != "'"
177
+ string << c
178
+ end
179
+ self.lex_value = string
180
+ return Tokens::STRING
181
+ end
182
+
183
+ if c =~ /\w/
184
+ string = c
185
+ while (c = self.peak) && c =~ /\w/
186
+ self.read
187
+ string << c
188
+ end
189
+
190
+ if section.zero? && string == 'token'
191
+ return Tokens::KW_TOKEN
192
+ elsif section.zero? && string == 'left'
193
+ return Tokens::KW_LEFT
194
+ elsif section.zero? && string == 'right'
195
+ return Tokens::KW_RIGHT
196
+ else
197
+ self.lex_value = string
198
+ return Tokens::IDENTIFIER
199
+ end
200
+ end
201
+
202
+ warn "Yielding literal #{c.inspect}"
203
+
204
+ return c.ord
205
+ end
206
+ end
@@ -0,0 +1,1862 @@
1
+ /* A Bison parser, made by GNU Bison 3.0.2. */
2
+
3
+ /* Bison implementation for Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
+
20
+ /* As a special exception, you may create a larger work that contains
21
+ part or all of the Bison parser skeleton and distribute that work
22
+ under terms of your choice, so long as that work isn't itself a
23
+ parser generator using the skeleton or a modified version thereof
24
+ as a parser skeleton. Alternatively, if you modify or redistribute
25
+ the parser skeleton itself, you may (at your option) remove this
26
+ special exception, which will cause the skeleton and the resulting
27
+ Bison output files to be licensed under the GNU General Public
28
+ License without this special exception.
29
+
30
+ This special exception was added by the Free Software Foundation in
31
+ version 2.2 of Bison. */
32
+
33
+ /* C LALR(1) parser skeleton written by Richard Stallman, by
34
+ simplifying the original so-called "semantic" parser. */
35
+
36
+ /* All symbols defined below should begin with yy or YY, to avoid
37
+ infringing on user name space. This should be done even for local
38
+ variables, as they might otherwise be expanded by user macros.
39
+ There are some unavoidable exceptions within include files to
40
+ define necessary library symbols; they are noted "INFRINGES ON
41
+ USER NAME SPACE" below. */
42
+
43
+ /* Identify Bison output. */
44
+ #define YYBISON 1
45
+
46
+ /* Bison version. */
47
+ #define YYBISON_VERSION "3.0.2"
48
+
49
+ /* Skeleton name. */
50
+ #define YYSKELETON_NAME "yacc.c"
51
+
52
+ /* Pure parsers. */
53
+ #define YYPURE 1
54
+
55
+ /* Push parsers. */
56
+ #define YYPUSH 0
57
+
58
+ /* Pull parsers. */
59
+ #define YYPULL 1
60
+
61
+
62
+
63
+
64
+ /* Copy the first part of user declarations. */
65
+ #line 24 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:339 */
66
+
67
+ #include <ruby.h>
68
+ #define YYSTYPE VALUE
69
+
70
+ #line 71 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:339 */
71
+
72
+ # ifndef YY_NULLPTR
73
+ # if defined __cplusplus && 201103L <= __cplusplus
74
+ # define YY_NULLPTR nullptr
75
+ # else
76
+ # define YY_NULLPTR 0
77
+ # endif
78
+ # endif
79
+
80
+ /* Enabling verbose error messages. */
81
+ #ifdef YYERROR_VERBOSE
82
+ # undef YYERROR_VERBOSE
83
+ # define YYERROR_VERBOSE 1
84
+ #else
85
+ # define YYERROR_VERBOSE 1
86
+ #endif
87
+
88
+
89
+ /* Debug traces. */
90
+ #ifndef YYDEBUG
91
+ # define YYDEBUG 0
92
+ #endif
93
+ #if YYDEBUG
94
+ extern int yydebug;
95
+ #endif
96
+
97
+ /* Token type. */
98
+ #ifndef YYTOKENTYPE
99
+ # define YYTOKENTYPE
100
+ enum yytokentype
101
+ {
102
+ IDENTIFIER = 258,
103
+ NUMBER = 259,
104
+ STRING = 260,
105
+ COLON = 261,
106
+ SEMICOLON = 262,
107
+ LBRACK = 263,
108
+ RBRACK = 264,
109
+ PIPE = 265,
110
+ HASH = 266,
111
+ DOUBLE_HASH = 267,
112
+ KW_TOKEN = 268,
113
+ KW_LEFT = 269,
114
+ KW_RIGHT = 270,
115
+ ACTIONS = 271
116
+ };
117
+ #endif
118
+
119
+ /* Value type. */
120
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
121
+ typedef int YYSTYPE;
122
+ # define YYSTYPE_IS_TRIVIAL 1
123
+ # define YYSTYPE_IS_DECLARED 1
124
+ #endif
125
+
126
+ /* Location type. */
127
+ #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
128
+ typedef struct YYLTYPE YYLTYPE;
129
+ struct YYLTYPE
130
+ {
131
+ int first_line;
132
+ int first_column;
133
+ int last_line;
134
+ int last_column;
135
+ };
136
+ # define YYLTYPE_IS_DECLARED 1
137
+ # define YYLTYPE_IS_TRIVIAL 1
138
+ #endif
139
+
140
+
141
+
142
+ int yyparse (VALUE __actions);
143
+ /* "%code provides" blocks. */
144
+ #line 29 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:355 */
145
+
146
+ static int yylex(YYSTYPE *, YYLTYPE *, VALUE);
147
+ static void yyerror(YYLTYPE *, VALUE, const char *);
148
+
149
+ #line 150 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:355 */
150
+
151
+
152
+
153
+ /* Copy the second part of user declarations. */
154
+
155
+ #line 156 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:358 */
156
+
157
+ #ifdef short
158
+ # undef short
159
+ #endif
160
+
161
+ #ifdef YYTYPE_UINT8
162
+ typedef YYTYPE_UINT8 yytype_uint8;
163
+ #else
164
+ typedef unsigned char yytype_uint8;
165
+ #endif
166
+
167
+ #ifdef YYTYPE_INT8
168
+ typedef YYTYPE_INT8 yytype_int8;
169
+ #else
170
+ typedef signed char yytype_int8;
171
+ #endif
172
+
173
+ #ifdef YYTYPE_UINT16
174
+ typedef YYTYPE_UINT16 yytype_uint16;
175
+ #else
176
+ typedef unsigned short int yytype_uint16;
177
+ #endif
178
+
179
+ #ifdef YYTYPE_INT16
180
+ typedef YYTYPE_INT16 yytype_int16;
181
+ #else
182
+ typedef short int yytype_int16;
183
+ #endif
184
+
185
+ #ifndef YYSIZE_T
186
+ # ifdef __SIZE_TYPE__
187
+ # define YYSIZE_T __SIZE_TYPE__
188
+ # elif defined size_t
189
+ # define YYSIZE_T size_t
190
+ # elif ! defined YYSIZE_T
191
+ # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
192
+ # define YYSIZE_T size_t
193
+ # else
194
+ # define YYSIZE_T unsigned int
195
+ # endif
196
+ #endif
197
+
198
+ #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
199
+
200
+ #ifndef YY_
201
+ # if defined YYENABLE_NLS && YYENABLE_NLS
202
+ # if ENABLE_NLS
203
+ # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
204
+ # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
205
+ # endif
206
+ # endif
207
+ # ifndef YY_
208
+ # define YY_(Msgid) Msgid
209
+ # endif
210
+ #endif
211
+
212
+ #ifndef YY_ATTRIBUTE
213
+ # if (defined __GNUC__ \
214
+ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
215
+ || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
216
+ # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
217
+ # else
218
+ # define YY_ATTRIBUTE(Spec) /* empty */
219
+ # endif
220
+ #endif
221
+
222
+ #ifndef YY_ATTRIBUTE_PURE
223
+ # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
224
+ #endif
225
+
226
+ #ifndef YY_ATTRIBUTE_UNUSED
227
+ # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
228
+ #endif
229
+
230
+ #if !defined _Noreturn \
231
+ && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
232
+ # if defined _MSC_VER && 1200 <= _MSC_VER
233
+ # define _Noreturn __declspec (noreturn)
234
+ # else
235
+ # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
236
+ # endif
237
+ #endif
238
+
239
+ /* Suppress unused-variable warnings by "using" E. */
240
+ #if ! defined lint || defined __GNUC__
241
+ # define YYUSE(E) ((void) (E))
242
+ #else
243
+ # define YYUSE(E) /* empty */
244
+ #endif
245
+
246
+ #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
247
+ /* Suppress an incorrect diagnostic about yylval being uninitialized. */
248
+ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
249
+ _Pragma ("GCC diagnostic push") \
250
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
251
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
252
+ # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
253
+ _Pragma ("GCC diagnostic pop")
254
+ #else
255
+ # define YY_INITIAL_VALUE(Value) Value
256
+ #endif
257
+ #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
258
+ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
259
+ # define YY_IGNORE_MAYBE_UNINITIALIZED_END
260
+ #endif
261
+ #ifndef YY_INITIAL_VALUE
262
+ # define YY_INITIAL_VALUE(Value) /* Nothing. */
263
+ #endif
264
+
265
+
266
+ #if ! defined yyoverflow || YYERROR_VERBOSE
267
+
268
+ /* The parser invokes alloca or malloc; define the necessary symbols. */
269
+
270
+ # ifdef YYSTACK_USE_ALLOCA
271
+ # if YYSTACK_USE_ALLOCA
272
+ # ifdef __GNUC__
273
+ # define YYSTACK_ALLOC __builtin_alloca
274
+ # elif defined __BUILTIN_VA_ARG_INCR
275
+ # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
276
+ # elif defined _AIX
277
+ # define YYSTACK_ALLOC __alloca
278
+ # elif defined _MSC_VER
279
+ # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
280
+ # define alloca _alloca
281
+ # else
282
+ # define YYSTACK_ALLOC alloca
283
+ # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
284
+ # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
285
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
286
+ # ifndef EXIT_SUCCESS
287
+ # define EXIT_SUCCESS 0
288
+ # endif
289
+ # endif
290
+ # endif
291
+ # endif
292
+ # endif
293
+
294
+ # ifdef YYSTACK_ALLOC
295
+ /* Pacify GCC's 'empty if-body' warning. */
296
+ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
297
+ # ifndef YYSTACK_ALLOC_MAXIMUM
298
+ /* The OS might guarantee only one guard page at the bottom of the stack,
299
+ and a page size can be as small as 4096 bytes. So we cannot safely
300
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
301
+ to allow for a few compiler-allocated temporary stack slots. */
302
+ # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
303
+ # endif
304
+ # else
305
+ # define YYSTACK_ALLOC YYMALLOC
306
+ # define YYSTACK_FREE YYFREE
307
+ # ifndef YYSTACK_ALLOC_MAXIMUM
308
+ # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
309
+ # endif
310
+ # if (defined __cplusplus && ! defined EXIT_SUCCESS \
311
+ && ! ((defined YYMALLOC || defined malloc) \
312
+ && (defined YYFREE || defined free)))
313
+ # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
314
+ # ifndef EXIT_SUCCESS
315
+ # define EXIT_SUCCESS 0
316
+ # endif
317
+ # endif
318
+ # ifndef YYMALLOC
319
+ # define YYMALLOC malloc
320
+ # if ! defined malloc && ! defined EXIT_SUCCESS
321
+ void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
322
+ # endif
323
+ # endif
324
+ # ifndef YYFREE
325
+ # define YYFREE free
326
+ # if ! defined free && ! defined EXIT_SUCCESS
327
+ void free (void *); /* INFRINGES ON USER NAME SPACE */
328
+ # endif
329
+ # endif
330
+ # endif
331
+ #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
332
+
333
+
334
+ #if (! defined yyoverflow \
335
+ && (! defined __cplusplus \
336
+ || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
337
+ && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
338
+
339
+ /* A type that is properly aligned for any stack member. */
340
+ union yyalloc
341
+ {
342
+ yytype_int16 yyss_alloc;
343
+ YYSTYPE yyvs_alloc;
344
+ YYLTYPE yyls_alloc;
345
+ };
346
+
347
+ /* The size of the maximum gap between one aligned stack and the next. */
348
+ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
349
+
350
+ /* The size of an array large to enough to hold all stacks, each with
351
+ N elements. */
352
+ # define YYSTACK_BYTES(N) \
353
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
354
+ + 2 * YYSTACK_GAP_MAXIMUM)
355
+
356
+ # define YYCOPY_NEEDED 1
357
+
358
+ /* Relocate STACK from its old location to the new one. The
359
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
360
+ elements in the stack, and YYPTR gives the new location of the
361
+ stack. Advance YYPTR to a properly aligned location for the next
362
+ stack. */
363
+ # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
364
+ do \
365
+ { \
366
+ YYSIZE_T yynewbytes; \
367
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
368
+ Stack = &yyptr->Stack_alloc; \
369
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
370
+ yyptr += yynewbytes / sizeof (*yyptr); \
371
+ } \
372
+ while (0)
373
+
374
+ #endif
375
+
376
+ #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
377
+ /* Copy COUNT objects from SRC to DST. The source and destination do
378
+ not overlap. */
379
+ # ifndef YYCOPY
380
+ # if defined __GNUC__ && 1 < __GNUC__
381
+ # define YYCOPY(Dst, Src, Count) \
382
+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
383
+ # else
384
+ # define YYCOPY(Dst, Src, Count) \
385
+ do \
386
+ { \
387
+ YYSIZE_T yyi; \
388
+ for (yyi = 0; yyi < (Count); yyi++) \
389
+ (Dst)[yyi] = (Src)[yyi]; \
390
+ } \
391
+ while (0)
392
+ # endif
393
+ # endif
394
+ #endif /* !YYCOPY_NEEDED */
395
+
396
+ /* YYFINAL -- State number of the termination state. */
397
+ #define YYFINAL 3
398
+ /* YYLAST -- Last index in YYTABLE. */
399
+ #define YYLAST 26
400
+
401
+ /* YYNTOKENS -- Number of terminals. */
402
+ #define YYNTOKENS 17
403
+ /* YYNNTS -- Number of nonterminals. */
404
+ #define YYNNTS 9
405
+ /* YYNRULES -- Number of rules. */
406
+ #define YYNRULES 20
407
+ /* YYNSTATES -- Number of states. */
408
+ #define YYNSTATES 32
409
+
410
+ /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
411
+ by yylex, with out-of-bounds checking. */
412
+ #define YYUNDEFTOK 2
413
+ #define YYMAXUTOK 271
414
+
415
+ #define YYTRANSLATE(YYX) \
416
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
417
+
418
+ /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
419
+ as returned by yylex, without out-of-bounds checking. */
420
+ static const yytype_uint8 yytranslate[] =
421
+ {
422
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
423
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
424
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
425
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
426
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
427
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
428
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
429
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
430
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
431
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
432
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
433
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
434
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
435
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
436
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
437
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
438
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
439
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
440
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
441
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
442
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
443
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
444
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
445
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
446
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
447
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
448
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
449
+ 15, 16
450
+ };
451
+
452
+ #if YYDEBUG
453
+ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
454
+ static const yytype_uint8 yyrline[] =
455
+ {
456
+ 0, 37, 37, 50, 56, 67, 73, 84, 92, 100,
457
+ 108, 120, 126, 137, 148, 156, 168, 174, 183, 192,
458
+ 202
459
+ };
460
+ #endif
461
+
462
+ #if YYDEBUG || YYERROR_VERBOSE || 1
463
+ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
464
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
465
+ static const char *const yytname[] =
466
+ {
467
+ "$end", "error", "$undefined", "IDENTIFIER", "NUMBER", "STRING",
468
+ "COLON", "SEMICOLON", "LBRACK", "RBRACK", "PIPE", "HASH", "DOUBLE_HASH",
469
+ "KW_TOKEN", "KW_LEFT", "KW_RIGHT", "ACTIONS", "$accept", "grammar_file",
470
+ "optional_code", "token_list", "token", "grammar_rules", "grammar_rule",
471
+ "components", "sequence", YY_NULLPTR
472
+ };
473
+ #endif
474
+
475
+ # ifdef YYPRINT
476
+ /* YYTOKNUM[NUM] -- (External) token number corresponding to the
477
+ (internal) symbol number NUM (which must be that of a token). */
478
+ static const yytype_uint16 yytoknum[] =
479
+ {
480
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
481
+ 265, 266, 267, 268, 269, 270, 271
482
+ };
483
+ # endif
484
+
485
+ #define YYPACT_NINF -8
486
+
487
+ #define yypact_value_is_default(Yystate) \
488
+ (!!((Yystate) == (-8)))
489
+
490
+ #define YYTABLE_NINF -1
491
+
492
+ #define yytable_value_is_error(Yytable_value) \
493
+ 0
494
+
495
+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
496
+ STATE-NUM. */
497
+ static const yytype_int8 yypact[] =
498
+ {
499
+ -8, 11, -7, -8, -6, -8, 8, 12, 13, 14,
500
+ -2, -8, -8, -8, -8, 15, 2, -8, -8, -8,
501
+ -8, -4, -3, -8, -8, 6, -8, -8, -3, 16,
502
+ 17, -8
503
+ };
504
+
505
+ /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
506
+ Performed when YYTABLE does not specify something else to do. Zero
507
+ means the default is an error. */
508
+ static const yytype_uint8 yydefact[] =
509
+ {
510
+ 5, 0, 0, 1, 0, 11, 6, 0, 0, 0,
511
+ 3, 10, 7, 8, 9, 0, 0, 2, 12, 16,
512
+ 4, 0, 14, 13, 16, 18, 20, 17, 15, 0,
513
+ 0, 19
514
+ };
515
+
516
+ /* YYPGOTO[NTERM-NUM]. */
517
+ static const yytype_int8 yypgoto[] =
518
+ {
519
+ -8, -8, -8, -8, -8, -8, -8, -8, -1
520
+ };
521
+
522
+ /* YYDEFGOTO[NTERM-NUM]. */
523
+ static const yytype_int8 yydefgoto[] =
524
+ {
525
+ -1, 1, 17, 2, 6, 10, 18, 21, 22
526
+ };
527
+
528
+ /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
529
+ positive, shift that token. If negative, reduce the rule whose
530
+ number is the opposite. If YYTABLE_NINF, syntax error. */
531
+ static const yytype_uint8 yytable[] =
532
+ {
533
+ 25, 15, 26, 23, 4, 5, 24, 7, 8, 9,
534
+ 16, 3, 11, 27, 29, 12, 13, 14, 20, 30,
535
+ 0, 19, 0, 28, 0, 0, 31
536
+ };
537
+
538
+ static const yytype_int8 yycheck[] =
539
+ {
540
+ 3, 3, 5, 7, 11, 12, 10, 13, 14, 15,
541
+ 12, 0, 4, 16, 8, 3, 3, 3, 16, 3,
542
+ -1, 6, -1, 24, -1, -1, 9
543
+ };
544
+
545
+ /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
546
+ symbol of state STATE-NUM. */
547
+ static const yytype_uint8 yystos[] =
548
+ {
549
+ 0, 18, 20, 0, 11, 12, 21, 13, 14, 15,
550
+ 22, 4, 3, 3, 3, 3, 12, 19, 23, 6,
551
+ 16, 24, 25, 7, 10, 3, 5, 16, 25, 8,
552
+ 3, 9
553
+ };
554
+
555
+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
556
+ static const yytype_uint8 yyr1[] =
557
+ {
558
+ 0, 17, 18, 19, 19, 20, 20, 21, 21, 21,
559
+ 21, 22, 22, 23, 24, 24, 25, 25, 25, 25,
560
+ 25
561
+ };
562
+
563
+ /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
564
+ static const yytype_uint8 yyr2[] =
565
+ {
566
+ 0, 2, 4, 0, 2, 0, 2, 3, 3, 3,
567
+ 2, 0, 2, 4, 1, 3, 0, 2, 2, 5,
568
+ 2
569
+ };
570
+
571
+
572
+ #define yyerrok (yyerrstatus = 0)
573
+ #define yyclearin (yychar = YYEMPTY)
574
+ #define YYEMPTY (-2)
575
+ #define YYEOF 0
576
+
577
+ #define YYACCEPT goto yyacceptlab
578
+ #define YYABORT goto yyabortlab
579
+ #define YYERROR goto yyerrorlab
580
+
581
+
582
+ #define YYRECOVERING() (!!yyerrstatus)
583
+
584
+ #define YYBACKUP(Token, Value) \
585
+ do \
586
+ if (yychar == YYEMPTY) \
587
+ { \
588
+ yychar = (Token); \
589
+ yylval = (Value); \
590
+ YYPOPSTACK (yylen); \
591
+ yystate = *yyssp; \
592
+ goto yybackup; \
593
+ } \
594
+ else \
595
+ { \
596
+ yyerror (&yylloc, __actions, YY_("syntax error: cannot back up")); \
597
+ YYERROR; \
598
+ } \
599
+ while (0)
600
+
601
+ /* Error token number */
602
+ #define YYTERROR 1
603
+ #define YYERRCODE 256
604
+
605
+
606
+ /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
607
+ If N is 0, then set CURRENT to the empty location which ends
608
+ the previous symbol: RHS[0] (always defined). */
609
+
610
+ #ifndef YYLLOC_DEFAULT
611
+ # define YYLLOC_DEFAULT(Current, Rhs, N) \
612
+ do \
613
+ if (N) \
614
+ { \
615
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
616
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
617
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
618
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
619
+ } \
620
+ else \
621
+ { \
622
+ (Current).first_line = (Current).last_line = \
623
+ YYRHSLOC (Rhs, 0).last_line; \
624
+ (Current).first_column = (Current).last_column = \
625
+ YYRHSLOC (Rhs, 0).last_column; \
626
+ } \
627
+ while (0)
628
+ #endif
629
+
630
+ #define YYRHSLOC(Rhs, K) ((Rhs)[K])
631
+
632
+
633
+ /* Enable debugging if requested. */
634
+ #if YYDEBUG
635
+
636
+ # ifndef YYFPRINTF
637
+ # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
638
+ # define YYFPRINTF fprintf
639
+ # endif
640
+
641
+ # define YYDPRINTF(Args) \
642
+ do { \
643
+ if (yydebug) \
644
+ YYFPRINTF Args; \
645
+ } while (0)
646
+
647
+
648
+ /* YY_LOCATION_PRINT -- Print the location on the stream.
649
+ This macro was not mandated originally: define only if we know
650
+ we won't break user code: when these are the locations we know. */
651
+
652
+ #ifndef YY_LOCATION_PRINT
653
+ # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
654
+
655
+ /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
656
+
657
+ YY_ATTRIBUTE_UNUSED
658
+ static unsigned
659
+ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
660
+ {
661
+ unsigned res = 0;
662
+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
663
+ if (0 <= yylocp->first_line)
664
+ {
665
+ res += YYFPRINTF (yyo, "%d", yylocp->first_line);
666
+ if (0 <= yylocp->first_column)
667
+ res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
668
+ }
669
+ if (0 <= yylocp->last_line)
670
+ {
671
+ if (yylocp->first_line < yylocp->last_line)
672
+ {
673
+ res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
674
+ if (0 <= end_col)
675
+ res += YYFPRINTF (yyo, ".%d", end_col);
676
+ }
677
+ else if (0 <= end_col && yylocp->first_column < end_col)
678
+ res += YYFPRINTF (yyo, "-%d", end_col);
679
+ }
680
+ return res;
681
+ }
682
+
683
+ # define YY_LOCATION_PRINT(File, Loc) \
684
+ yy_location_print_ (File, &(Loc))
685
+
686
+ # else
687
+ # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
688
+ # endif
689
+ #endif
690
+
691
+
692
+ # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
693
+ do { \
694
+ if (yydebug) \
695
+ { \
696
+ YYFPRINTF (stderr, "%s ", Title); \
697
+ yy_symbol_print (stderr, \
698
+ Type, Value, Location, __actions); \
699
+ YYFPRINTF (stderr, "\n"); \
700
+ } \
701
+ } while (0)
702
+
703
+
704
+ /*----------------------------------------.
705
+ | Print this symbol's value on YYOUTPUT. |
706
+ `----------------------------------------*/
707
+
708
+ static void
709
+ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, VALUE __actions)
710
+ {
711
+ FILE *yyo = yyoutput;
712
+ YYUSE (yyo);
713
+ YYUSE (yylocationp);
714
+ YYUSE (__actions);
715
+ if (!yyvaluep)
716
+ return;
717
+ # ifdef YYPRINT
718
+ if (yytype < YYNTOKENS)
719
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
720
+ # endif
721
+ YYUSE (yytype);
722
+ }
723
+
724
+
725
+ /*--------------------------------.
726
+ | Print this symbol on YYOUTPUT. |
727
+ `--------------------------------*/
728
+
729
+ static void
730
+ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, VALUE __actions)
731
+ {
732
+ YYFPRINTF (yyoutput, "%s %s (",
733
+ yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
734
+
735
+ YY_LOCATION_PRINT (yyoutput, *yylocationp);
736
+ YYFPRINTF (yyoutput, ": ");
737
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, __actions);
738
+ YYFPRINTF (yyoutput, ")");
739
+ }
740
+
741
+ /*------------------------------------------------------------------.
742
+ | yy_stack_print -- Print the state stack from its BOTTOM up to its |
743
+ | TOP (included). |
744
+ `------------------------------------------------------------------*/
745
+
746
+ static void
747
+ yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
748
+ {
749
+ YYFPRINTF (stderr, "Stack now");
750
+ for (; yybottom <= yytop; yybottom++)
751
+ {
752
+ int yybot = *yybottom;
753
+ YYFPRINTF (stderr, " %d", yybot);
754
+ }
755
+ YYFPRINTF (stderr, "\n");
756
+ }
757
+
758
+ # define YY_STACK_PRINT(Bottom, Top) \
759
+ do { \
760
+ if (yydebug) \
761
+ yy_stack_print ((Bottom), (Top)); \
762
+ } while (0)
763
+
764
+
765
+ /*------------------------------------------------.
766
+ | Report that the YYRULE is going to be reduced. |
767
+ `------------------------------------------------*/
768
+
769
+ static void
770
+ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, VALUE __actions)
771
+ {
772
+ unsigned long int yylno = yyrline[yyrule];
773
+ int yynrhs = yyr2[yyrule];
774
+ int yyi;
775
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
776
+ yyrule - 1, yylno);
777
+ /* The symbols being reduced. */
778
+ for (yyi = 0; yyi < yynrhs; yyi++)
779
+ {
780
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
781
+ yy_symbol_print (stderr,
782
+ yystos[yyssp[yyi + 1 - yynrhs]],
783
+ &(yyvsp[(yyi + 1) - (yynrhs)])
784
+ , &(yylsp[(yyi + 1) - (yynrhs)]) , __actions);
785
+ YYFPRINTF (stderr, "\n");
786
+ }
787
+ }
788
+
789
+ # define YY_REDUCE_PRINT(Rule) \
790
+ do { \
791
+ if (yydebug) \
792
+ yy_reduce_print (yyssp, yyvsp, yylsp, Rule, __actions); \
793
+ } while (0)
794
+
795
+ /* Nonzero means print parse trace. It is left uninitialized so that
796
+ multiple parsers can coexist. */
797
+ int yydebug;
798
+ #else /* !YYDEBUG */
799
+ # define YYDPRINTF(Args)
800
+ # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
801
+ # define YY_STACK_PRINT(Bottom, Top)
802
+ # define YY_REDUCE_PRINT(Rule)
803
+ #endif /* !YYDEBUG */
804
+
805
+
806
+ /* YYINITDEPTH -- initial size of the parser's stacks. */
807
+ #ifndef YYINITDEPTH
808
+ # define YYINITDEPTH 200
809
+ #endif
810
+
811
+ /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
812
+ if the built-in stack extension method is used).
813
+
814
+ Do not make this value too large; the results are undefined if
815
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
816
+ evaluated with infinite-precision integer arithmetic. */
817
+
818
+ #ifndef YYMAXDEPTH
819
+ # define YYMAXDEPTH 10000
820
+ #endif
821
+
822
+
823
+ #if YYERROR_VERBOSE
824
+
825
+ # ifndef yystrlen
826
+ # if defined __GLIBC__ && defined _STRING_H
827
+ # define yystrlen strlen
828
+ # else
829
+ /* Return the length of YYSTR. */
830
+ static YYSIZE_T
831
+ yystrlen (const char *yystr)
832
+ {
833
+ YYSIZE_T yylen;
834
+ for (yylen = 0; yystr[yylen]; yylen++)
835
+ continue;
836
+ return yylen;
837
+ }
838
+ # endif
839
+ # endif
840
+
841
+ # ifndef yystpcpy
842
+ # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
843
+ # define yystpcpy stpcpy
844
+ # else
845
+ /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
846
+ YYDEST. */
847
+ static char *
848
+ yystpcpy (char *yydest, const char *yysrc)
849
+ {
850
+ char *yyd = yydest;
851
+ const char *yys = yysrc;
852
+
853
+ while ((*yyd++ = *yys++) != '\0')
854
+ continue;
855
+
856
+ return yyd - 1;
857
+ }
858
+ # endif
859
+ # endif
860
+
861
+ # ifndef yytnamerr
862
+ /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
863
+ quotes and backslashes, so that it's suitable for yyerror. The
864
+ heuristic is that double-quoting is unnecessary unless the string
865
+ contains an apostrophe, a comma, or backslash (other than
866
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
867
+ null, do not copy; instead, return the length of what the result
868
+ would have been. */
869
+ static YYSIZE_T
870
+ yytnamerr (char *yyres, const char *yystr)
871
+ {
872
+ if (*yystr == '"')
873
+ {
874
+ YYSIZE_T yyn = 0;
875
+ char const *yyp = yystr;
876
+
877
+ for (;;)
878
+ switch (*++yyp)
879
+ {
880
+ case '\'':
881
+ case ',':
882
+ goto do_not_strip_quotes;
883
+
884
+ case '\\':
885
+ if (*++yyp != '\\')
886
+ goto do_not_strip_quotes;
887
+ /* Fall through. */
888
+ default:
889
+ if (yyres)
890
+ yyres[yyn] = *yyp;
891
+ yyn++;
892
+ break;
893
+
894
+ case '"':
895
+ if (yyres)
896
+ yyres[yyn] = '\0';
897
+ return yyn;
898
+ }
899
+ do_not_strip_quotes: ;
900
+ }
901
+
902
+ if (! yyres)
903
+ return yystrlen (yystr);
904
+
905
+ return yystpcpy (yyres, yystr) - yyres;
906
+ }
907
+ # endif
908
+
909
+ /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
910
+ about the unexpected token YYTOKEN for the state stack whose top is
911
+ YYSSP.
912
+
913
+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
914
+ not large enough to hold the message. In that case, also set
915
+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the
916
+ required number of bytes is too large to store. */
917
+ static int
918
+ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
919
+ yytype_int16 *yyssp, int yytoken)
920
+ {
921
+ YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
922
+ YYSIZE_T yysize = yysize0;
923
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
924
+ /* Internationalized format string. */
925
+ const char *yyformat = YY_NULLPTR;
926
+ /* Arguments of yyformat. */
927
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
928
+ /* Number of reported tokens (one for the "unexpected", one per
929
+ "expected"). */
930
+ int yycount = 0;
931
+
932
+ /* There are many possibilities here to consider:
933
+ - If this state is a consistent state with a default action, then
934
+ the only way this function was invoked is if the default action
935
+ is an error action. In that case, don't check for expected
936
+ tokens because there are none.
937
+ - The only way there can be no lookahead present (in yychar) is if
938
+ this state is a consistent state with a default action. Thus,
939
+ detecting the absence of a lookahead is sufficient to determine
940
+ that there is no unexpected or expected token to report. In that
941
+ case, just report a simple "syntax error".
942
+ - Don't assume there isn't a lookahead just because this state is a
943
+ consistent state with a default action. There might have been a
944
+ previous inconsistent state, consistent state with a non-default
945
+ action, or user semantic action that manipulated yychar.
946
+ - Of course, the expected token list depends on states to have
947
+ correct lookahead information, and it depends on the parser not
948
+ to perform extra reductions after fetching a lookahead from the
949
+ scanner and before detecting a syntax error. Thus, state merging
950
+ (from LALR or IELR) and default reductions corrupt the expected
951
+ token list. However, the list is correct for canonical LR with
952
+ one exception: it will still contain any token that will not be
953
+ accepted due to an error action in a later state.
954
+ */
955
+ if (yytoken != YYEMPTY)
956
+ {
957
+ int yyn = yypact[*yyssp];
958
+ yyarg[yycount++] = yytname[yytoken];
959
+ if (!yypact_value_is_default (yyn))
960
+ {
961
+ /* Start YYX at -YYN if negative to avoid negative indexes in
962
+ YYCHECK. In other words, skip the first -YYN actions for
963
+ this state because they are default actions. */
964
+ int yyxbegin = yyn < 0 ? -yyn : 0;
965
+ /* Stay within bounds of both yycheck and yytname. */
966
+ int yychecklim = YYLAST - yyn + 1;
967
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
968
+ int yyx;
969
+
970
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
971
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
972
+ && !yytable_value_is_error (yytable[yyx + yyn]))
973
+ {
974
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
975
+ {
976
+ yycount = 1;
977
+ yysize = yysize0;
978
+ break;
979
+ }
980
+ yyarg[yycount++] = yytname[yyx];
981
+ {
982
+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
983
+ if (! (yysize <= yysize1
984
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
985
+ return 2;
986
+ yysize = yysize1;
987
+ }
988
+ }
989
+ }
990
+ }
991
+
992
+ switch (yycount)
993
+ {
994
+ # define YYCASE_(N, S) \
995
+ case N: \
996
+ yyformat = S; \
997
+ break
998
+ YYCASE_(0, YY_("syntax error"));
999
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
1000
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1001
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1002
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1003
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1004
+ # undef YYCASE_
1005
+ }
1006
+
1007
+ {
1008
+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1009
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1010
+ return 2;
1011
+ yysize = yysize1;
1012
+ }
1013
+
1014
+ if (*yymsg_alloc < yysize)
1015
+ {
1016
+ *yymsg_alloc = 2 * yysize;
1017
+ if (! (yysize <= *yymsg_alloc
1018
+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1019
+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1020
+ return 1;
1021
+ }
1022
+
1023
+ /* Avoid sprintf, as that infringes on the user's name space.
1024
+ Don't have undefined behavior even if the translation
1025
+ produced a string with the wrong number of "%s"s. */
1026
+ {
1027
+ char *yyp = *yymsg;
1028
+ int yyi = 0;
1029
+ while ((*yyp = *yyformat) != '\0')
1030
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1031
+ {
1032
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
1033
+ yyformat += 2;
1034
+ }
1035
+ else
1036
+ {
1037
+ yyp++;
1038
+ yyformat++;
1039
+ }
1040
+ }
1041
+ return 0;
1042
+ }
1043
+ #endif /* YYERROR_VERBOSE */
1044
+
1045
+ /*-----------------------------------------------.
1046
+ | Release the memory associated to this symbol. |
1047
+ `-----------------------------------------------*/
1048
+
1049
+ static void
1050
+ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, VALUE __actions)
1051
+ {
1052
+ YYUSE (yyvaluep);
1053
+ YYUSE (yylocationp);
1054
+ YYUSE (__actions);
1055
+ if (!yymsg)
1056
+ yymsg = "Deleting";
1057
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1058
+
1059
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1060
+ YYUSE (yytype);
1061
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
1062
+ }
1063
+
1064
+
1065
+
1066
+
1067
+ /*----------.
1068
+ | yyparse. |
1069
+ `----------*/
1070
+
1071
+ int
1072
+ yyparse (VALUE __actions)
1073
+ {
1074
+ /* The lookahead symbol. */
1075
+ int yychar;
1076
+
1077
+
1078
+ /* The semantic value of the lookahead symbol. */
1079
+ /* Default value used for initialization, for pacifying older GCCs
1080
+ or non-GCC compilers. */
1081
+ YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1082
+ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1083
+
1084
+ /* Location data for the lookahead symbol. */
1085
+ static YYLTYPE yyloc_default
1086
+ # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1087
+ = { 1, 1, 1, 1 }
1088
+ # endif
1089
+ ;
1090
+ YYLTYPE yylloc = yyloc_default;
1091
+
1092
+ /* Number of syntax errors so far. */
1093
+ int yynerrs;
1094
+
1095
+ int yystate;
1096
+ /* Number of tokens to shift before error messages enabled. */
1097
+ int yyerrstatus;
1098
+
1099
+ /* The stacks and their tools:
1100
+ 'yyss': related to states.
1101
+ 'yyvs': related to semantic values.
1102
+ 'yyls': related to locations.
1103
+
1104
+ Refer to the stacks through separate pointers, to allow yyoverflow
1105
+ to reallocate them elsewhere. */
1106
+
1107
+ /* The state stack. */
1108
+ yytype_int16 yyssa[YYINITDEPTH];
1109
+ yytype_int16 *yyss;
1110
+ yytype_int16 *yyssp;
1111
+
1112
+ /* The semantic value stack. */
1113
+ YYSTYPE yyvsa[YYINITDEPTH];
1114
+ YYSTYPE *yyvs;
1115
+ YYSTYPE *yyvsp;
1116
+
1117
+ /* The location stack. */
1118
+ YYLTYPE yylsa[YYINITDEPTH];
1119
+ YYLTYPE *yyls;
1120
+ YYLTYPE *yylsp;
1121
+
1122
+ /* The locations where the error started and ended. */
1123
+ YYLTYPE yyerror_range[3];
1124
+
1125
+ YYSIZE_T yystacksize;
1126
+
1127
+ int yyn;
1128
+ int yyresult;
1129
+ /* Lookahead token as an internal (translated) token number. */
1130
+ int yytoken = 0;
1131
+ /* The variables used to return semantic value and location from the
1132
+ action routines. */
1133
+ YYSTYPE yyval;
1134
+ YYLTYPE yyloc;
1135
+
1136
+ #if YYERROR_VERBOSE
1137
+ /* Buffer for error messages, and its allocated size. */
1138
+ char yymsgbuf[128];
1139
+ char *yymsg = yymsgbuf;
1140
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1141
+ #endif
1142
+
1143
+ #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1144
+
1145
+ /* The number of symbols on the RHS of the reduced rule.
1146
+ Keep to zero when no symbol should be popped. */
1147
+ int yylen = 0;
1148
+
1149
+ yyssp = yyss = yyssa;
1150
+ yyvsp = yyvs = yyvsa;
1151
+ yylsp = yyls = yylsa;
1152
+ yystacksize = YYINITDEPTH;
1153
+
1154
+ YYDPRINTF ((stderr, "Starting parse\n"));
1155
+
1156
+ yystate = 0;
1157
+ yyerrstatus = 0;
1158
+ yynerrs = 0;
1159
+ yychar = YYEMPTY; /* Cause a token to be read. */
1160
+ yylsp[0] = yylloc;
1161
+ goto yysetstate;
1162
+
1163
+ /*------------------------------------------------------------.
1164
+ | yynewstate -- Push a new state, which is found in yystate. |
1165
+ `------------------------------------------------------------*/
1166
+ yynewstate:
1167
+ /* In all cases, when you get here, the value and location stacks
1168
+ have just been pushed. So pushing a state here evens the stacks. */
1169
+ yyssp++;
1170
+
1171
+ yysetstate:
1172
+ *yyssp = yystate;
1173
+
1174
+ if (yyss + yystacksize - 1 <= yyssp)
1175
+ {
1176
+ /* Get the current used size of the three stacks, in elements. */
1177
+ YYSIZE_T yysize = yyssp - yyss + 1;
1178
+
1179
+ #ifdef yyoverflow
1180
+ {
1181
+ /* Give user a chance to reallocate the stack. Use copies of
1182
+ these so that the &'s don't force the real ones into
1183
+ memory. */
1184
+ YYSTYPE *yyvs1 = yyvs;
1185
+ yytype_int16 *yyss1 = yyss;
1186
+ YYLTYPE *yyls1 = yyls;
1187
+
1188
+ /* Each stack pointer address is followed by the size of the
1189
+ data in use in that stack, in bytes. This used to be a
1190
+ conditional around just the two extra args, but that might
1191
+ be undefined if yyoverflow is a macro. */
1192
+ yyoverflow (YY_("memory exhausted"),
1193
+ &yyss1, yysize * sizeof (*yyssp),
1194
+ &yyvs1, yysize * sizeof (*yyvsp),
1195
+ &yyls1, yysize * sizeof (*yylsp),
1196
+ &yystacksize);
1197
+
1198
+ yyls = yyls1;
1199
+ yyss = yyss1;
1200
+ yyvs = yyvs1;
1201
+ }
1202
+ #else /* no yyoverflow */
1203
+ # ifndef YYSTACK_RELOCATE
1204
+ goto yyexhaustedlab;
1205
+ # else
1206
+ /* Extend the stack our own way. */
1207
+ if (YYMAXDEPTH <= yystacksize)
1208
+ goto yyexhaustedlab;
1209
+ yystacksize *= 2;
1210
+ if (YYMAXDEPTH < yystacksize)
1211
+ yystacksize = YYMAXDEPTH;
1212
+
1213
+ {
1214
+ yytype_int16 *yyss1 = yyss;
1215
+ union yyalloc *yyptr =
1216
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1217
+ if (! yyptr)
1218
+ goto yyexhaustedlab;
1219
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
1220
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1221
+ YYSTACK_RELOCATE (yyls_alloc, yyls);
1222
+ # undef YYSTACK_RELOCATE
1223
+ if (yyss1 != yyssa)
1224
+ YYSTACK_FREE (yyss1);
1225
+ }
1226
+ # endif
1227
+ #endif /* no yyoverflow */
1228
+
1229
+ yyssp = yyss + yysize - 1;
1230
+ yyvsp = yyvs + yysize - 1;
1231
+ yylsp = yyls + yysize - 1;
1232
+
1233
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1234
+ (unsigned long int) yystacksize));
1235
+
1236
+ if (yyss + yystacksize - 1 <= yyssp)
1237
+ YYABORT;
1238
+ }
1239
+
1240
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1241
+
1242
+ if (yystate == YYFINAL)
1243
+ YYACCEPT;
1244
+
1245
+ goto yybackup;
1246
+
1247
+ /*-----------.
1248
+ | yybackup. |
1249
+ `-----------*/
1250
+ yybackup:
1251
+
1252
+ /* Do appropriate processing given the current state. Read a
1253
+ lookahead token if we need one and don't already have one. */
1254
+
1255
+ /* First try to decide what to do without reference to lookahead token. */
1256
+ yyn = yypact[yystate];
1257
+ if (yypact_value_is_default (yyn))
1258
+ goto yydefault;
1259
+
1260
+ /* Not known => get a lookahead token if don't already have one. */
1261
+
1262
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1263
+ if (yychar == YYEMPTY)
1264
+ {
1265
+ YYDPRINTF ((stderr, "Reading a token: "));
1266
+ yychar = yylex (&yylval, &yylloc, __actions);
1267
+ }
1268
+
1269
+ if (yychar <= YYEOF)
1270
+ {
1271
+ yychar = yytoken = YYEOF;
1272
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
1273
+ }
1274
+ else
1275
+ {
1276
+ yytoken = YYTRANSLATE (yychar);
1277
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1278
+ }
1279
+
1280
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
1281
+ detect an error, take that action. */
1282
+ yyn += yytoken;
1283
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1284
+ goto yydefault;
1285
+ yyn = yytable[yyn];
1286
+ if (yyn <= 0)
1287
+ {
1288
+ if (yytable_value_is_error (yyn))
1289
+ goto yyerrlab;
1290
+ yyn = -yyn;
1291
+ goto yyreduce;
1292
+ }
1293
+
1294
+ /* Count tokens shifted since error; after three, turn off error
1295
+ status. */
1296
+ if (yyerrstatus)
1297
+ yyerrstatus--;
1298
+
1299
+ /* Shift the lookahead token. */
1300
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1301
+
1302
+ /* Discard the shifted token. */
1303
+ yychar = YYEMPTY;
1304
+
1305
+ yystate = yyn;
1306
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1307
+ *++yyvsp = yylval;
1308
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
1309
+ *++yylsp = yylloc;
1310
+ goto yynewstate;
1311
+
1312
+
1313
+ /*-----------------------------------------------------------.
1314
+ | yydefault -- do the default action for the current state. |
1315
+ `-----------------------------------------------------------*/
1316
+ yydefault:
1317
+ yyn = yydefact[yystate];
1318
+ if (yyn == 0)
1319
+ goto yyerrlab;
1320
+ goto yyreduce;
1321
+
1322
+
1323
+ /*-----------------------------.
1324
+ | yyreduce -- Do a reduction. |
1325
+ `-----------------------------*/
1326
+ yyreduce:
1327
+ /* yyn is the number of a rule to reduce with. */
1328
+ yylen = yyr2[yyn];
1329
+
1330
+ /* If YYLEN is nonzero, implement the default value of the action:
1331
+ '$$ = $1'.
1332
+
1333
+ Otherwise, the following line sets YYVAL to garbage.
1334
+ This behavior is undocumented and Bison
1335
+ users should not rely upon it. Assigning to YYVAL
1336
+ unconditionally makes the parser a bit smaller, and it avoids a
1337
+ GCC warning that YYVAL may be used uninitialized. */
1338
+ yyval = yyvsp[1-yylen];
1339
+
1340
+ /* Default location. */
1341
+ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1342
+ YY_REDUCE_PRINT (yyn);
1343
+ switch (yyn)
1344
+ {
1345
+ case 2:
1346
+ #line 38 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1347
+ {
1348
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1349
+ rb_ivar_set(__actions, rb_intern("@tokens"), rb_ary_new3(2, INT2FIX((yylsp[-3]).first_line), INT2FIX((yylsp[-3]).first_column)));
1350
+ rb_ivar_set(__actions, rb_intern("@rules"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1351
+ rb_ivar_set(__actions, rb_intern("@code"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1352
+ (yyval) = rb_funcall(__actions, rb_intern("_0_grammar_file"), 3, (yyvsp[-3]), (yyvsp[-1]), (yyvsp[0]));
1353
+ }
1354
+ #line 1355 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1355
+ break;
1356
+
1357
+ case 3:
1358
+ #line 50 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1359
+ {
1360
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1361
+ (yyval) = rb_funcall(__actions, rb_intern("_0_optional_code"), 0);
1362
+ }
1363
+ #line 1364 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1364
+ break;
1365
+
1366
+ case 4:
1367
+ #line 57 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1368
+ {
1369
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1370
+ rb_ivar_set(__actions, rb_intern("@actions"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1371
+ (yyval) = rb_funcall(__actions, rb_intern("_1_optional_code"), 1, (yyvsp[0]));
1372
+ }
1373
+ #line 1374 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1374
+ break;
1375
+
1376
+ case 5:
1377
+ #line 67 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1378
+ {
1379
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1380
+ (yyval) = rb_funcall(__actions, rb_intern("_0_token_list"), 0);
1381
+ }
1382
+ #line 1383 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1383
+ break;
1384
+
1385
+ case 6:
1386
+ #line 74 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1387
+ {
1388
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1389
+ rb_ivar_set(__actions, rb_intern("@list"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1390
+ rb_ivar_set(__actions, rb_intern("@token"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1391
+ (yyval) = rb_funcall(__actions, rb_intern("_1_token_list"), 2, (yyvsp[-1]), (yyvsp[0]));
1392
+ }
1393
+ #line 1394 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1394
+ break;
1395
+
1396
+ case 7:
1397
+ #line 85 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1398
+ {
1399
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1400
+ rb_ivar_set(__actions, rb_intern("@name"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1401
+ (yyval) = rb_funcall(__actions, rb_intern("_0_token"), 1, (yyvsp[0]));
1402
+ }
1403
+ #line 1404 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1404
+ break;
1405
+
1406
+ case 8:
1407
+ #line 93 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1408
+ {
1409
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1410
+ rb_ivar_set(__actions, rb_intern("@name"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1411
+ (yyval) = rb_funcall(__actions, rb_intern("_1_token"), 1, (yyvsp[0]));
1412
+ }
1413
+ #line 1414 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1414
+ break;
1415
+
1416
+ case 9:
1417
+ #line 101 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1418
+ {
1419
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1420
+ rb_ivar_set(__actions, rb_intern("@name"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1421
+ (yyval) = rb_funcall(__actions, rb_intern("_2_token"), 1, (yyvsp[0]));
1422
+ }
1423
+ #line 1424 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1424
+ break;
1425
+
1426
+ case 10:
1427
+ #line 109 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1428
+ {
1429
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1430
+ rb_ivar_set(__actions, rb_intern("@token"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1431
+ rb_ivar_set(__actions, rb_intern("@num"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1432
+ (yyval) = rb_funcall(__actions, rb_intern("_3_token"), 2, (yyvsp[-1]), (yyvsp[0]));
1433
+ }
1434
+ #line 1435 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1435
+ break;
1436
+
1437
+ case 11:
1438
+ #line 120 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1439
+ {
1440
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1441
+ (yyval) = rb_funcall(__actions, rb_intern("_0_grammar_rules"), 0);
1442
+ }
1443
+ #line 1444 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1444
+ break;
1445
+
1446
+ case 12:
1447
+ #line 127 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1448
+ {
1449
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1450
+ rb_ivar_set(__actions, rb_intern("@list"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1451
+ rb_ivar_set(__actions, rb_intern("@rule"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1452
+ (yyval) = rb_funcall(__actions, rb_intern("_1_grammar_rules"), 2, (yyvsp[-1]), (yyvsp[0]));
1453
+ }
1454
+ #line 1455 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1455
+ break;
1456
+
1457
+ case 13:
1458
+ #line 138 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1459
+ {
1460
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1461
+ rb_ivar_set(__actions, rb_intern("@name"), rb_ary_new3(2, INT2FIX((yylsp[-3]).first_line), INT2FIX((yylsp[-3]).first_column)));
1462
+ rb_ivar_set(__actions, rb_intern("@components"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1463
+ (yyval) = rb_funcall(__actions, rb_intern("_0_grammar_rule"), 2, (yyvsp[-3]), (yyvsp[-1]));
1464
+ }
1465
+ #line 1466 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1466
+ break;
1467
+
1468
+ case 14:
1469
+ #line 149 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1470
+ {
1471
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1472
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1473
+ (yyval) = rb_funcall(__actions, rb_intern("_0_components"), 1, (yyvsp[0]));
1474
+ }
1475
+ #line 1476 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1476
+ break;
1477
+
1478
+ case 15:
1479
+ #line 157 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1480
+ {
1481
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1482
+ rb_ivar_set(__actions, rb_intern("@sequences"), rb_ary_new3(2, INT2FIX((yylsp[-2]).first_line), INT2FIX((yylsp[-2]).first_column)));
1483
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1484
+ (yyval) = rb_funcall(__actions, rb_intern("_1_components"), 2, (yyvsp[-2]), (yyvsp[0]));
1485
+ }
1486
+ #line 1487 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1487
+ break;
1488
+
1489
+ case 16:
1490
+ #line 168 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1491
+ {
1492
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1493
+ (yyval) = rb_funcall(__actions, rb_intern("_0_sequence"), 0);
1494
+ }
1495
+ #line 1496 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1496
+ break;
1497
+
1498
+ case 17:
1499
+ #line 175 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1500
+ {
1501
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1502
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1503
+ rb_ivar_set(__actions, rb_intern("@code"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1504
+ (yyval) = rb_funcall(__actions, rb_intern("_1_sequence"), 2, (yyvsp[-1]), (yyvsp[0]));
1505
+ }
1506
+ #line 1507 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1507
+ break;
1508
+
1509
+ case 18:
1510
+ #line 184 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1511
+ {
1512
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1513
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1514
+ rb_ivar_set(__actions, rb_intern("@follower"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1515
+ (yyval) = rb_funcall(__actions, rb_intern("_2_sequence"), 2, (yyvsp[-1]), (yyvsp[0]));
1516
+ }
1517
+ #line 1518 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1518
+ break;
1519
+
1520
+ case 19:
1521
+ #line 193 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1522
+ {
1523
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1524
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[-4]).first_line), INT2FIX((yylsp[-4]).first_column)));
1525
+ rb_ivar_set(__actions, rb_intern("@follower"), rb_ary_new3(2, INT2FIX((yylsp[-3]).first_line), INT2FIX((yylsp[-3]).first_column)));
1526
+ rb_ivar_set(__actions, rb_intern("@tag"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1527
+ (yyval) = rb_funcall(__actions, rb_intern("_3_sequence"), 3, (yyvsp[-4]), (yyvsp[-3]), (yyvsp[-1]));
1528
+ }
1529
+ #line 1530 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1530
+ break;
1531
+
1532
+ case 20:
1533
+ #line 203 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1661 */
1534
+ {
1535
+ rb_ivar_set(__actions, rb_intern("@_"), rb_ary_new3(2, INT2FIX((yyloc).first_line), INT2FIX((yyloc).first_column)));
1536
+ rb_ivar_set(__actions, rb_intern("@sequence"), rb_ary_new3(2, INT2FIX((yylsp[-1]).first_line), INT2FIX((yylsp[-1]).first_column)));
1537
+ rb_ivar_set(__actions, rb_intern("@follower"), rb_ary_new3(2, INT2FIX((yylsp[0]).first_line), INT2FIX((yylsp[0]).first_column)));
1538
+ (yyval) = rb_funcall(__actions, rb_intern("_4_sequence"), 2, (yyvsp[-1]), (yyvsp[0]));
1539
+ }
1540
+ #line 1541 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1541
+ break;
1542
+
1543
+
1544
+ #line 1545 "../../../../ext/bison_parser/bison_parser.c" /* yacc.c:1661 */
1545
+ default: break;
1546
+ }
1547
+ /* User semantic actions sometimes alter yychar, and that requires
1548
+ that yytoken be updated with the new translation. We take the
1549
+ approach of translating immediately before every use of yytoken.
1550
+ One alternative is translating here after every semantic action,
1551
+ but that translation would be missed if the semantic action invokes
1552
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1553
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1554
+ incorrect destructor might then be invoked immediately. In the
1555
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
1556
+ to an incorrect destructor call or verbose syntax error message
1557
+ before the lookahead is translated. */
1558
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1559
+
1560
+ YYPOPSTACK (yylen);
1561
+ yylen = 0;
1562
+ YY_STACK_PRINT (yyss, yyssp);
1563
+
1564
+ *++yyvsp = yyval;
1565
+ *++yylsp = yyloc;
1566
+
1567
+ /* Now 'shift' the result of the reduction. Determine what state
1568
+ that goes to, based on the state we popped back to and the rule
1569
+ number reduced by. */
1570
+
1571
+ yyn = yyr1[yyn];
1572
+
1573
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1574
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1575
+ yystate = yytable[yystate];
1576
+ else
1577
+ yystate = yydefgoto[yyn - YYNTOKENS];
1578
+
1579
+ goto yynewstate;
1580
+
1581
+
1582
+ /*--------------------------------------.
1583
+ | yyerrlab -- here on detecting error. |
1584
+ `--------------------------------------*/
1585
+ yyerrlab:
1586
+ /* Make sure we have latest lookahead translation. See comments at
1587
+ user semantic actions for why this is necessary. */
1588
+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1589
+
1590
+ /* If not already recovering from an error, report this error. */
1591
+ if (!yyerrstatus)
1592
+ {
1593
+ ++yynerrs;
1594
+ #if ! YYERROR_VERBOSE
1595
+ yyerror (&yylloc, __actions, YY_("syntax error"));
1596
+ #else
1597
+ # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1598
+ yyssp, yytoken)
1599
+ {
1600
+ char const *yymsgp = YY_("syntax error");
1601
+ int yysyntax_error_status;
1602
+ yysyntax_error_status = YYSYNTAX_ERROR;
1603
+ if (yysyntax_error_status == 0)
1604
+ yymsgp = yymsg;
1605
+ else if (yysyntax_error_status == 1)
1606
+ {
1607
+ if (yymsg != yymsgbuf)
1608
+ YYSTACK_FREE (yymsg);
1609
+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1610
+ if (!yymsg)
1611
+ {
1612
+ yymsg = yymsgbuf;
1613
+ yymsg_alloc = sizeof yymsgbuf;
1614
+ yysyntax_error_status = 2;
1615
+ }
1616
+ else
1617
+ {
1618
+ yysyntax_error_status = YYSYNTAX_ERROR;
1619
+ yymsgp = yymsg;
1620
+ }
1621
+ }
1622
+ yyerror (&yylloc, __actions, yymsgp);
1623
+ if (yysyntax_error_status == 2)
1624
+ goto yyexhaustedlab;
1625
+ }
1626
+ # undef YYSYNTAX_ERROR
1627
+ #endif
1628
+ }
1629
+
1630
+ yyerror_range[1] = yylloc;
1631
+
1632
+ if (yyerrstatus == 3)
1633
+ {
1634
+ /* If just tried and failed to reuse lookahead token after an
1635
+ error, discard it. */
1636
+
1637
+ if (yychar <= YYEOF)
1638
+ {
1639
+ /* Return failure if at end of input. */
1640
+ if (yychar == YYEOF)
1641
+ YYABORT;
1642
+ }
1643
+ else
1644
+ {
1645
+ yydestruct ("Error: discarding",
1646
+ yytoken, &yylval, &yylloc, __actions);
1647
+ yychar = YYEMPTY;
1648
+ }
1649
+ }
1650
+
1651
+ /* Else will try to reuse lookahead token after shifting the error
1652
+ token. */
1653
+ goto yyerrlab1;
1654
+
1655
+
1656
+ /*---------------------------------------------------.
1657
+ | yyerrorlab -- error raised explicitly by YYERROR. |
1658
+ `---------------------------------------------------*/
1659
+ yyerrorlab:
1660
+
1661
+ /* Pacify compilers like GCC when the user code never invokes
1662
+ YYERROR and the label yyerrorlab therefore never appears in user
1663
+ code. */
1664
+ if (/*CONSTCOND*/ 0)
1665
+ goto yyerrorlab;
1666
+
1667
+ yyerror_range[1] = yylsp[1-yylen];
1668
+ /* Do not reclaim the symbols of the rule whose action triggered
1669
+ this YYERROR. */
1670
+ YYPOPSTACK (yylen);
1671
+ yylen = 0;
1672
+ YY_STACK_PRINT (yyss, yyssp);
1673
+ yystate = *yyssp;
1674
+ goto yyerrlab1;
1675
+
1676
+
1677
+ /*-------------------------------------------------------------.
1678
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
1679
+ `-------------------------------------------------------------*/
1680
+ yyerrlab1:
1681
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
1682
+
1683
+ for (;;)
1684
+ {
1685
+ yyn = yypact[yystate];
1686
+ if (!yypact_value_is_default (yyn))
1687
+ {
1688
+ yyn += YYTERROR;
1689
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1690
+ {
1691
+ yyn = yytable[yyn];
1692
+ if (0 < yyn)
1693
+ break;
1694
+ }
1695
+ }
1696
+
1697
+ /* Pop the current state because it cannot handle the error token. */
1698
+ if (yyssp == yyss)
1699
+ YYABORT;
1700
+
1701
+ yyerror_range[1] = *yylsp;
1702
+ yydestruct ("Error: popping",
1703
+ yystos[yystate], yyvsp, yylsp, __actions);
1704
+ YYPOPSTACK (1);
1705
+ yystate = *yyssp;
1706
+ YY_STACK_PRINT (yyss, yyssp);
1707
+ }
1708
+
1709
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1710
+ *++yyvsp = yylval;
1711
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
1712
+
1713
+ yyerror_range[2] = yylloc;
1714
+ /* Using YYLLOC is tempting, but would change the location of
1715
+ the lookahead. YYLOC is available though. */
1716
+ YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
1717
+ *++yylsp = yyloc;
1718
+
1719
+ /* Shift the error token. */
1720
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1721
+
1722
+ yystate = yyn;
1723
+ goto yynewstate;
1724
+
1725
+
1726
+ /*-------------------------------------.
1727
+ | yyacceptlab -- YYACCEPT comes here. |
1728
+ `-------------------------------------*/
1729
+ yyacceptlab:
1730
+ yyresult = 0;
1731
+ goto yyreturn;
1732
+
1733
+ /*-----------------------------------.
1734
+ | yyabortlab -- YYABORT comes here. |
1735
+ `-----------------------------------*/
1736
+ yyabortlab:
1737
+ yyresult = 1;
1738
+ goto yyreturn;
1739
+
1740
+ #if !defined yyoverflow || YYERROR_VERBOSE
1741
+ /*-------------------------------------------------.
1742
+ | yyexhaustedlab -- memory exhaustion comes here. |
1743
+ `-------------------------------------------------*/
1744
+ yyexhaustedlab:
1745
+ yyerror (&yylloc, __actions, YY_("memory exhausted"));
1746
+ yyresult = 2;
1747
+ /* Fall through. */
1748
+ #endif
1749
+
1750
+ yyreturn:
1751
+ if (yychar != YYEMPTY)
1752
+ {
1753
+ /* Make sure we have latest lookahead translation. See comments at
1754
+ user semantic actions for why this is necessary. */
1755
+ yytoken = YYTRANSLATE (yychar);
1756
+ yydestruct ("Cleanup: discarding lookahead",
1757
+ yytoken, &yylval, &yylloc, __actions);
1758
+ }
1759
+ /* Do not reclaim the symbols of the rule whose action triggered
1760
+ this YYABORT or YYACCEPT. */
1761
+ YYPOPSTACK (yylen);
1762
+ YY_STACK_PRINT (yyss, yyssp);
1763
+ while (yyssp != yyss)
1764
+ {
1765
+ yydestruct ("Cleanup: popping",
1766
+ yystos[*yyssp], yyvsp, yylsp, __actions);
1767
+ YYPOPSTACK (1);
1768
+ }
1769
+ #ifndef yyoverflow
1770
+ if (yyss != yyssa)
1771
+ YYSTACK_FREE (yyss);
1772
+ #endif
1773
+ #if YYERROR_VERBOSE
1774
+ if (yymsg != yymsgbuf)
1775
+ YYSTACK_FREE (yymsg);
1776
+ #endif
1777
+ return yyresult;
1778
+ }
1779
+ #line 213 "../../../../ext/bison_parser/bison_parser.y" /* yacc.c:1906 */
1780
+
1781
+
1782
+ static VALUE cBisonParser;
1783
+ static VALUE cBisonParserTokens;
1784
+ static VALUE cBisonParserActions;
1785
+
1786
+ static VALUE bison_parser_parse(VALUE);
1787
+
1788
+ void Init_bison_parser(void) {
1789
+ cBisonParser = rb_define_class("BisonParser", rb_cObject);
1790
+ cBisonParserTokens = rb_define_module_under(cBisonParser, "Tokens");
1791
+ cBisonParserActions = rb_define_class_under(cBisonParser, "Actions", rb_cObject);
1792
+
1793
+ rb_define_const(cBisonParserTokens, "IDENTIFIER", INT2FIX(IDENTIFIER));
1794
+ rb_define_const(cBisonParserTokens, "NUMBER", INT2FIX(NUMBER));
1795
+ rb_define_const(cBisonParserTokens, "STRING", INT2FIX(STRING));
1796
+ rb_define_const(cBisonParserTokens, "COLON", INT2FIX(COLON));
1797
+ rb_define_const(cBisonParserTokens, "SEMICOLON", INT2FIX(SEMICOLON));
1798
+ rb_define_const(cBisonParserTokens, "LBRACK", INT2FIX(LBRACK));
1799
+ rb_define_const(cBisonParserTokens, "RBRACK", INT2FIX(RBRACK));
1800
+ rb_define_const(cBisonParserTokens, "PIPE", INT2FIX(PIPE));
1801
+ rb_define_const(cBisonParserTokens, "HASH", INT2FIX(HASH));
1802
+ rb_define_const(cBisonParserTokens, "DOUBLE_HASH", INT2FIX(DOUBLE_HASH));
1803
+ rb_define_const(cBisonParserTokens, "KW_TOKEN", INT2FIX(KW_TOKEN));
1804
+ rb_define_const(cBisonParserTokens, "KW_LEFT", INT2FIX(KW_LEFT));
1805
+ rb_define_const(cBisonParserTokens, "KW_RIGHT", INT2FIX(KW_RIGHT));
1806
+ rb_define_const(cBisonParserTokens, "ACTIONS", INT2FIX(ACTIONS));
1807
+
1808
+ rb_define_method(cBisonParser, "parse", bison_parser_parse, 0);
1809
+ }
1810
+
1811
+ VALUE bison_parser_parse(VALUE self) {
1812
+ VALUE actions = rb_funcall(cBisonParserActions, rb_intern("new"), 0);
1813
+ rb_funcall(actions, rb_intern("parser="), 1, self);
1814
+ if (yyparse(actions))
1815
+ return Qnil;
1816
+ return rb_funcall(actions, rb_intern("result"), 0);
1817
+ }
1818
+
1819
+ static void yyerror(YYLTYPE *loc, VALUE actions, const char *msg) {
1820
+ VALUE parser = rb_funcall(actions, rb_intern("parser"), 0);
1821
+ rb_funcall(parser, rb_intern("error"), 3,
1822
+ rb_str_new_cstr(msg),
1823
+ INT2FIX(loc->first_line),
1824
+ INT2FIX(loc->first_column));
1825
+ }
1826
+
1827
+ static int yylex(YYSTYPE *lval, YYLTYPE *lloc, VALUE actions) {
1828
+ int c;
1829
+ VALUE parser, value, vtok;
1830
+
1831
+ parser = rb_funcall(actions, rb_intern("parser"), 0);
1832
+
1833
+ rb_funcall(parser, rb_intern("lex_value="), 1, Qnil);
1834
+ rb_funcall(parser, rb_intern("token_row="), 1, INT2FIX(lloc->last_line));
1835
+ rb_funcall(parser, rb_intern("token_col="), 1, INT2FIX(lloc->last_column));
1836
+
1837
+ vtok = rb_funcall(parser, rb_intern("lex"), 0);
1838
+ value = rb_funcall(parser, rb_intern("lex_value"), 0);
1839
+
1840
+ lloc->first_line = FIX2INT(rb_funcall(parser, rb_intern("token_row"), 0));
1841
+ lloc->first_column = FIX2INT(rb_funcall(parser, rb_intern("token_col"), 0));
1842
+ lloc->last_line = FIX2INT(rb_funcall(parser, rb_intern("row"), 0));
1843
+ lloc->last_column = FIX2INT(rb_funcall(parser, rb_intern("col"), 0));
1844
+
1845
+ if (vtok == Qnil) {
1846
+ *lval = Qnil;
1847
+ return 0;
1848
+ }
1849
+
1850
+ if (vtok & 1) {
1851
+ *lval = value;
1852
+ return FIX2INT(vtok);
1853
+ }
1854
+
1855
+ if (RBASIC(vtok)->klass == rb_cString) {
1856
+ c = StringValueCStr(vtok)[0];
1857
+ *lval = rb_sprintf("%c", c);
1858
+ return c;
1859
+ }
1860
+
1861
+ return 0;
1862
+ }