SphinxBase  5prealpha
jsgf_parser.c
1 /* A Bison parser, made by GNU Bison 3.7.4. */
2 
3 /* Bison implementation for Yacc-like parsers in C
4 
5  Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
6  Inc.
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 
21 /* As a special exception, you may create a larger work that contains
22  part or all of the Bison parser skeleton and distribute that work
23  under terms of your choice, so long as that work isn't itself a
24  parser generator using the skeleton or a modified version thereof
25  as a parser skeleton. Alternatively, if you modify or redistribute
26  the parser skeleton itself, you may (at your option) remove this
27  special exception, which will cause the skeleton and the resulting
28  Bison output files to be licensed under the GNU General Public
29  License without this special exception.
30 
31  This special exception was added by the Free Software Foundation in
32  version 2.2 of Bison. */
33 
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35  simplifying the original so-called "semantic" parser. */
36 
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38  especially those whose name start with YY_ or yy_. They are
39  private implementation details that can be changed or removed. */
40 
41 /* All symbols defined below should begin with yy or YY, to avoid
42  infringing on user name space. This should be done even for local
43  variables, as they might otherwise be expanded by user macros.
44  There are some unavoidable exceptions within include files to
45  define necessary library symbols; they are noted "INFRINGES ON
46  USER NAME SPACE" below. */
47 
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30704
50 
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.4"
53 
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56 
57 /* Pure parsers. */
58 #define YYPURE 1
59 
60 /* Push parsers. */
61 #define YYPUSH 0
62 
63 /* Pull parsers. */
64 #define YYPULL 1
65 
66 
67 
68 
69 /* First part of user prologue. */
70 #line 37 "jsgf_parser.y"
71 
72 #define YYERROR_VERBOSE
73 
74 #include <stdio.h>
75 #include <string.h>
76 
77 #include <sphinxbase/hash_table.h>
78 #include <sphinxbase/ckd_alloc.h>
79 #include <sphinxbase/err.h>
80 
81 #include "jsgf_internal.h"
82 #include "jsgf_parser.h"
83 #include "jsgf_scanner.h"
84 
85 /* Suppress warnings from generated code */
86 #if defined _MSC_VER
87 #pragma warning(disable: 4273)
88 #endif
89 
90 void yyerror(yyscan_t lex, jsgf_t *jsgf, const char *s);
91 
92 
93 #line 94 "jsgf_parser.c"
94 
95 # ifndef YY_CAST
96 # ifdef __cplusplus
97 # define YY_CAST(Type, Val) static_cast<Type> (Val)
98 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
99 # else
100 # define YY_CAST(Type, Val) ((Type) (Val))
101 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
102 # endif
103 # endif
104 # ifndef YY_NULLPTR
105 # if defined __cplusplus
106 # if 201103L <= __cplusplus
107 # define YY_NULLPTR nullptr
108 # else
109 # define YY_NULLPTR 0
110 # endif
111 # else
112 # define YY_NULLPTR ((void*)0)
113 # endif
114 # endif
115 
116 /* Use api.header.include to #include this header
117  instead of duplicating it here. */
118 #ifndef YY_YY_JSGF_PARSER_H_INCLUDED
119 # define YY_YY_JSGF_PARSER_H_INCLUDED
120 /* Debug traces. */
121 #ifndef YYDEBUG
122 # define YYDEBUG 0
123 #endif
124 #if YYDEBUG
125 extern int yydebug;
126 #endif
127 
128 /* Token kinds. */
129 #ifndef YYTOKENTYPE
130 # define YYTOKENTYPE
131  enum yytokentype
132  {
133  YYEMPTY = -2,
134  YYEOF = 0, /* "end of file" */
135  YYerror = 256, /* error */
136  YYUNDEF = 257, /* "invalid token" */
137  HEADER = 258, /* HEADER */
138  GRAMMAR = 259, /* GRAMMAR */
139  IMPORT = 260, /* IMPORT */
140  PUBLIC = 261, /* PUBLIC */
141  TOKEN = 262, /* TOKEN */
142  RULENAME = 263, /* RULENAME */
143  TAG = 264, /* TAG */
144  WEIGHT = 265 /* WEIGHT */
145  };
146  typedef enum yytokentype yytoken_kind_t;
147 #endif
148 /* Token kinds. */
149 #define YYEMPTY -2
150 #define YYEOF 0
151 #define YYerror 256
152 #define YYUNDEF 257
153 #define HEADER 258
154 #define GRAMMAR 259
155 #define IMPORT 260
156 #define PUBLIC 261
157 #define TOKEN 262
158 #define RULENAME 263
159 #define TAG 264
160 #define WEIGHT 265
161 
162 /* Value type. */
163 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
164 union YYSTYPE
165 {
166 #line 65 "jsgf_parser.y"
167 
168  char *name;
169  float weight;
170  jsgf_rule_t *rule;
171  jsgf_rhs_t *rhs;
172  jsgf_atom_t *atom;
173 
174 #line 175 "jsgf_parser.c"
175 
176 };
177 typedef union YYSTYPE YYSTYPE;
178 # define YYSTYPE_IS_TRIVIAL 1
179 # define YYSTYPE_IS_DECLARED 1
180 #endif
181 
182 
183 
184 int yyparse (void* yyscanner, jsgf_t *jsgf);
185 
186 #endif /* !YY_YY_JSGF_PARSER_H_INCLUDED */
187 /* Symbol kind. */
188 enum yysymbol_kind_t
189 {
190  YYSYMBOL_YYEMPTY = -2,
191  YYSYMBOL_YYEOF = 0, /* "end of file" */
192  YYSYMBOL_YYerror = 1, /* error */
193  YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
194  YYSYMBOL_HEADER = 3, /* HEADER */
195  YYSYMBOL_GRAMMAR = 4, /* GRAMMAR */
196  YYSYMBOL_IMPORT = 5, /* IMPORT */
197  YYSYMBOL_PUBLIC = 6, /* PUBLIC */
198  YYSYMBOL_TOKEN = 7, /* TOKEN */
199  YYSYMBOL_RULENAME = 8, /* RULENAME */
200  YYSYMBOL_TAG = 9, /* TAG */
201  YYSYMBOL_WEIGHT = 10, /* WEIGHT */
202  YYSYMBOL_11_ = 11, /* ';' */
203  YYSYMBOL_12_ = 12, /* '=' */
204  YYSYMBOL_13_ = 13, /* '|' */
205  YYSYMBOL_14_ = 14, /* '(' */
206  YYSYMBOL_15_ = 15, /* ')' */
207  YYSYMBOL_16_ = 16, /* '[' */
208  YYSYMBOL_17_ = 17, /* ']' */
209  YYSYMBOL_18_ = 18, /* '*' */
210  YYSYMBOL_19_ = 19, /* '+' */
211  YYSYMBOL_YYACCEPT = 20, /* $accept */
212  YYSYMBOL_grammar = 21, /* grammar */
213  YYSYMBOL_header = 22, /* header */
214  YYSYMBOL_jsgf_header = 23, /* jsgf_header */
215  YYSYMBOL_grammar_header = 24, /* grammar_header */
216  YYSYMBOL_import_header = 25, /* import_header */
217  YYSYMBOL_import_statement = 26, /* import_statement */
218  YYSYMBOL_rule_list = 27, /* rule_list */
219  YYSYMBOL_rule = 28, /* rule */
220  YYSYMBOL_alternate_list = 29, /* alternate_list */
221  YYSYMBOL_rule_expansion = 30, /* rule_expansion */
222  YYSYMBOL_tagged_rule_item = 31, /* tagged_rule_item */
223  YYSYMBOL_rule_item = 32, /* rule_item */
224  YYSYMBOL_rule_group = 33, /* rule_group */
225  YYSYMBOL_rule_optional = 34, /* rule_optional */
226  YYSYMBOL_rule_atom = 35 /* rule_atom */
227 };
228 typedef enum yysymbol_kind_t yysymbol_kind_t;
229 
230 
231 
232 
233 #ifdef short
234 # undef short
235 #endif
236 
237 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
238  <limits.h> and (if available) <stdint.h> are included
239  so that the code can choose integer types of a good width. */
240 
241 #ifndef __PTRDIFF_MAX__
242 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
243 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
244 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
245 # define YY_STDINT_H
246 # endif
247 #endif
248 
249 /* Narrow types that promote to a signed type and that can represent a
250  signed or unsigned integer of at least N bits. In tables they can
251  save space and decrease cache pressure. Promoting to a signed type
252  helps avoid bugs in integer arithmetic. */
253 
254 #ifdef __INT_LEAST8_MAX__
255 typedef __INT_LEAST8_TYPE__ yytype_int8;
256 #elif defined YY_STDINT_H
257 typedef int_least8_t yytype_int8;
258 #else
259 typedef signed char yytype_int8;
260 #endif
261 
262 #ifdef __INT_LEAST16_MAX__
263 typedef __INT_LEAST16_TYPE__ yytype_int16;
264 #elif defined YY_STDINT_H
265 typedef int_least16_t yytype_int16;
266 #else
267 typedef short yytype_int16;
268 #endif
269 
270 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
271 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
272 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
273  && UINT_LEAST8_MAX <= INT_MAX)
274 typedef uint_least8_t yytype_uint8;
275 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
276 typedef unsigned char yytype_uint8;
277 #else
278 typedef short yytype_uint8;
279 #endif
280 
281 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
282 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
283 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
284  && UINT_LEAST16_MAX <= INT_MAX)
285 typedef uint_least16_t yytype_uint16;
286 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
287 typedef unsigned short yytype_uint16;
288 #else
289 typedef int yytype_uint16;
290 #endif
291 
292 #ifndef YYPTRDIFF_T
293 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
294 # define YYPTRDIFF_T __PTRDIFF_TYPE__
295 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
296 # elif defined PTRDIFF_MAX
297 # ifndef ptrdiff_t
298 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
299 # endif
300 # define YYPTRDIFF_T ptrdiff_t
301 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
302 # else
303 # define YYPTRDIFF_T long
304 # define YYPTRDIFF_MAXIMUM LONG_MAX
305 # endif
306 #endif
307 
308 #ifndef YYSIZE_T
309 # ifdef __SIZE_TYPE__
310 # define YYSIZE_T __SIZE_TYPE__
311 # elif defined size_t
312 # define YYSIZE_T size_t
313 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
314 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
315 # define YYSIZE_T size_t
316 # else
317 # define YYSIZE_T unsigned
318 # endif
319 #endif
320 
321 #define YYSIZE_MAXIMUM \
322  YY_CAST (YYPTRDIFF_T, \
323  (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
324  ? YYPTRDIFF_MAXIMUM \
325  : YY_CAST (YYSIZE_T, -1)))
326 
327 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
328 
329 
330 /* Stored state numbers (used for stacks). */
331 typedef yytype_int8 yy_state_t;
332 
333 /* State numbers in computations. */
334 typedef int yy_state_fast_t;
335 
336 #ifndef YY_
337 # if defined YYENABLE_NLS && YYENABLE_NLS
338 # if ENABLE_NLS
339 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
340 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
341 # endif
342 # endif
343 # ifndef YY_
344 # define YY_(Msgid) Msgid
345 # endif
346 #endif
347 
348 
349 #ifndef YY_ATTRIBUTE_PURE
350 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
351 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
352 # else
353 # define YY_ATTRIBUTE_PURE
354 # endif
355 #endif
356 
357 #ifndef YY_ATTRIBUTE_UNUSED
358 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
359 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
360 # else
361 # define YY_ATTRIBUTE_UNUSED
362 # endif
363 #endif
364 
365 /* Suppress unused-variable warnings by "using" E. */
366 #if ! defined lint || defined __GNUC__
367 # define YYUSE(E) ((void) (E))
368 #else
369 # define YYUSE(E) /* empty */
370 #endif
371 
372 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
373 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
374 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
375  _Pragma ("GCC diagnostic push") \
376  _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
377  _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
378 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
379  _Pragma ("GCC diagnostic pop")
380 #else
381 # define YY_INITIAL_VALUE(Value) Value
382 #endif
383 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
384 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
385 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
386 #endif
387 #ifndef YY_INITIAL_VALUE
388 # define YY_INITIAL_VALUE(Value) /* Nothing. */
389 #endif
390 
391 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
392 # define YY_IGNORE_USELESS_CAST_BEGIN \
393  _Pragma ("GCC diagnostic push") \
394  _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
395 # define YY_IGNORE_USELESS_CAST_END \
396  _Pragma ("GCC diagnostic pop")
397 #endif
398 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
399 # define YY_IGNORE_USELESS_CAST_BEGIN
400 # define YY_IGNORE_USELESS_CAST_END
401 #endif
402 
403 
404 #define YY_ASSERT(E) ((void) (0 && (E)))
405 
406 #if !defined yyoverflow
407 
408 /* The parser invokes alloca or malloc; define the necessary symbols. */
409 
410 # ifdef YYSTACK_USE_ALLOCA
411 # if YYSTACK_USE_ALLOCA
412 # ifdef __GNUC__
413 # define YYSTACK_ALLOC __builtin_alloca
414 # elif defined __BUILTIN_VA_ARG_INCR
415 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
416 # elif defined _AIX
417 # define YYSTACK_ALLOC __alloca
418 # elif defined _MSC_VER
419 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
420 # define alloca _alloca
421 # else
422 # define YYSTACK_ALLOC alloca
423 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
424 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
425  /* Use EXIT_SUCCESS as a witness for stdlib.h. */
426 # ifndef EXIT_SUCCESS
427 # define EXIT_SUCCESS 0
428 # endif
429 # endif
430 # endif
431 # endif
432 # endif
433 
434 # ifdef YYSTACK_ALLOC
435  /* Pacify GCC's 'empty if-body' warning. */
436 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
437 # ifndef YYSTACK_ALLOC_MAXIMUM
438  /* The OS might guarantee only one guard page at the bottom of the stack,
439  and a page size can be as small as 4096 bytes. So we cannot safely
440  invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
441  to allow for a few compiler-allocated temporary stack slots. */
442 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
443 # endif
444 # else
445 # define YYSTACK_ALLOC YYMALLOC
446 # define YYSTACK_FREE YYFREE
447 # ifndef YYSTACK_ALLOC_MAXIMUM
448 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
449 # endif
450 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
451  && ! ((defined YYMALLOC || defined malloc) \
452  && (defined YYFREE || defined free)))
453 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
454 # ifndef EXIT_SUCCESS
455 # define EXIT_SUCCESS 0
456 # endif
457 # endif
458 # ifndef YYMALLOC
459 # define YYMALLOC malloc
460 # if ! defined malloc && ! defined EXIT_SUCCESS
461 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
462 # endif
463 # endif
464 # ifndef YYFREE
465 # define YYFREE free
466 # if ! defined free && ! defined EXIT_SUCCESS
467 void free (void *); /* INFRINGES ON USER NAME SPACE */
468 # endif
469 # endif
470 # endif
471 #endif /* !defined yyoverflow */
472 
473 #if (! defined yyoverflow \
474  && (! defined __cplusplus \
475  || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
476 
477 /* A type that is properly aligned for any stack member. */
478 union yyalloc
479 {
480  yy_state_t yyss_alloc;
481  YYSTYPE yyvs_alloc;
482 };
483 
484 /* The size of the maximum gap between one aligned stack and the next. */
485 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
486 
487 /* The size of an array large to enough to hold all stacks, each with
488  N elements. */
489 # define YYSTACK_BYTES(N) \
490  ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
491  + YYSTACK_GAP_MAXIMUM)
492 
493 # define YYCOPY_NEEDED 1
494 
495 /* Relocate STACK from its old location to the new one. The
496  local variables YYSIZE and YYSTACKSIZE give the old and new number of
497  elements in the stack, and YYPTR gives the new location of the
498  stack. Advance YYPTR to a properly aligned location for the next
499  stack. */
500 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
501  do \
502  { \
503  YYPTRDIFF_T yynewbytes; \
504  YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
505  Stack = &yyptr->Stack_alloc; \
506  yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
507  yyptr += yynewbytes / YYSIZEOF (*yyptr); \
508  } \
509  while (0)
510 
511 #endif
512 
513 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
514 /* Copy COUNT objects from SRC to DST. The source and destination do
515  not overlap. */
516 # ifndef YYCOPY
517 # if defined __GNUC__ && 1 < __GNUC__
518 # define YYCOPY(Dst, Src, Count) \
519  __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
520 # else
521 # define YYCOPY(Dst, Src, Count) \
522  do \
523  { \
524  YYPTRDIFF_T yyi; \
525  for (yyi = 0; yyi < (Count); yyi++) \
526  (Dst)[yyi] = (Src)[yyi]; \
527  } \
528  while (0)
529 # endif
530 # endif
531 #endif /* !YYCOPY_NEEDED */
532 
533 /* YYFINAL -- State number of the termination state. */
534 #define YYFINAL 7
535 /* YYLAST -- Last index in YYTABLE. */
536 #define YYLAST 54
537 
538 /* YYNTOKENS -- Number of terminals. */
539 #define YYNTOKENS 20
540 /* YYNNTS -- Number of nonterminals. */
541 #define YYNNTS 16
542 /* YYNRULES -- Number of rules. */
543 #define YYNRULES 33
544 /* YYNSTATES -- Number of states. */
545 #define YYNSTATES 58
546 
547 /* YYMAXUTOK -- Last valid token kind. */
548 #define YYMAXUTOK 265
549 
550 
551 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
552  as returned by yylex, with out-of-bounds checking. */
553 #define YYTRANSLATE(YYX) \
554  (0 <= (YYX) && (YYX) <= YYMAXUTOK \
555  ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
556  : YYSYMBOL_YYUNDEF)
557 
558 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
559  as returned by yylex. */
560 static const yytype_int8 yytranslate[] =
561 {
562  0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566  14, 15, 18, 19, 2, 2, 2, 2, 2, 2,
567  2, 2, 2, 2, 2, 2, 2, 2, 2, 11,
568  2, 12, 2, 2, 2, 2, 2, 2, 2, 2,
569  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
570  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571  2, 16, 2, 17, 2, 2, 2, 2, 2, 2,
572  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574  2, 2, 2, 2, 13, 2, 2, 2, 2, 2,
575  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
587  2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
588  5, 6, 7, 8, 9, 10
589 };
590 
591 #if YYDEBUG
592  /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
593 static const yytype_uint8 yyrline[] =
594 {
595  0, 82, 82, 83, 84, 87, 90, 91, 92, 93,
596  97, 100, 101, 104, 107, 108, 111, 112, 115, 116,
597  121, 123, 127, 128, 132, 133, 136, 139, 142, 143,
598  144, 145, 146, 147
599 };
600 #endif
601 
603 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
604 
605 #if YYDEBUG || 0
606 /* The user-facing name of the symbol whose (internal) number is
607  YYSYMBOL. No bounds checking. */
608 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
609 
610 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
611  First, the terminals, then, starting at YYNTOKENS, nonterminals. */
612 static const char *const yytname[] =
613 {
614  "\"end of file\"", "error", "\"invalid token\"", "HEADER", "GRAMMAR",
615  "IMPORT", "PUBLIC", "TOKEN", "RULENAME", "TAG", "WEIGHT", "';'", "'='",
616  "'|'", "'('", "')'", "'['", "']'", "'*'", "'+'", "$accept", "grammar",
617  "header", "jsgf_header", "grammar_header", "import_header",
618  "import_statement", "rule_list", "rule", "alternate_list",
619  "rule_expansion", "tagged_rule_item", "rule_item", "rule_group",
620  "rule_optional", "rule_atom", YY_NULLPTR
621 };
622 
623 static const char *
624 yysymbol_name (yysymbol_kind_t yysymbol)
625 {
626  return yytname[yysymbol];
627 }
628 #endif
629 
630 #ifdef YYPRINT
631 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
632  (internal) symbol number NUM (which must be that of a token). */
633 static const yytype_int16 yytoknum[] =
634 {
635  0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
636  265, 59, 61, 124, 40, 41, 91, 93, 42, 43
637 };
638 #endif
639 
640 #define YYPACT_NINF (-37)
641 
642 #define yypact_value_is_default(Yyn) \
643  ((Yyn) == YYPACT_NINF)
644 
645 #define YYTABLE_NINF (-1)
646 
647 #define yytable_value_is_error(Yyn) \
648  0
649 
650  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
651  STATE-NUM. */
652 static const yytype_int8 yypact[] =
653 {
654  -1, -2, 36, 22, 35, 8, -37, -37, 32, 33,
655  30, 22, -37, 17, -37, 37, -37, 13, -37, 34,
656  31, -4, -37, 17, -37, 38, 39, -37, -37, -4,
657  -37, -37, 0, -4, -4, 18, -4, 42, -37, -37,
658  -37, 19, -37, -37, 21, 19, 20, 9, -37, -4,
659  42, -37, -37, -37, -37, -37, -37, -4
660 };
661 
662  /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
663  Performed when YYTABLE does not specify something else to do. Zero
664  means the default is an error. */
665 static const yytype_int8 yydefact[] =
666 {
667  0, 0, 0, 2, 0, 0, 6, 1, 0, 0,
668  0, 0, 11, 3, 14, 0, 5, 0, 7, 0,
669  0, 0, 12, 4, 15, 0, 0, 8, 13, 0,
670  28, 29, 0, 0, 0, 0, 18, 20, 22, 30,
671  31, 24, 10, 9, 0, 25, 0, 0, 16, 0,
672  21, 23, 32, 33, 17, 26, 27, 19
673 };
674 
675  /* YYPGOTO[NTERM-NUM]. */
676 static const yytype_int8 yypgoto[] =
677 {
678  -37, -37, -37, -37, -37, -37, 41, 43, -12, -16,
679  -3, -36, -37, -37, -37, 15
680 };
681 
682  /* YYDEFGOTO[NTERM-NUM]. */
683 static const yytype_int8 yydefgoto[] =
684 {
685  -1, 2, 3, 4, 16, 11, 12, 13, 14, 35,
686  36, 37, 38, 39, 40, 41
687 };
688 
689  /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
690  positive, shift that token. If negative, reduce the rule whose
691  number is the opposite. If YYTABLE_NINF, syntax error. */
692 static const yytype_int8 yytable[] =
693 {
694  50, 24, 1, 30, 31, 5, 32, 30, 31, 6,
695  33, 24, 34, 44, 33, 17, 34, 46, 47, 18,
696  26, 50, 49, 9, 27, 10, 56, 8, 9, 48,
697  10, 49, 54, 49, 49, 55, 7, 52, 53, 15,
698  19, 20, 21, 29, 25, 28, 57, 45, 0, 42,
699  43, 51, 22, 0, 23
700 };
701 
702 static const yytype_int8 yycheck[] =
703 {
704  36, 13, 3, 7, 8, 7, 10, 7, 8, 11,
705  14, 23, 16, 29, 14, 7, 16, 33, 34, 11,
706  7, 57, 13, 6, 11, 8, 17, 5, 6, 11,
707  8, 13, 11, 13, 13, 15, 0, 18, 19, 4,
708  8, 8, 12, 12, 7, 11, 49, 32, -1, 11,
709  11, 9, 11, -1, 11
710 };
711 
712  /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
713  symbol of state STATE-NUM. */
714 static const yytype_int8 yystos[] =
715 {
716  0, 3, 21, 22, 23, 7, 11, 0, 5, 6,
717  8, 25, 26, 27, 28, 4, 24, 7, 11, 8,
718  8, 12, 26, 27, 28, 7, 7, 11, 11, 12,
719  7, 8, 10, 14, 16, 29, 30, 31, 32, 33,
720  34, 35, 11, 11, 29, 35, 29, 29, 11, 13,
721  31, 9, 18, 19, 11, 15, 17, 30
722 };
723 
724  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
725 static const yytype_int8 yyr1[] =
726 {
727  0, 20, 21, 21, 21, 22, 23, 23, 23, 23,
728  24, 25, 25, 26, 27, 27, 28, 28, 29, 29,
729  30, 30, 31, 31, 32, 32, 33, 34, 35, 35,
730  35, 35, 35, 35
731 };
732 
733  /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
734 static const yytype_int8 yyr2[] =
735 {
736  0, 2, 1, 2, 3, 2, 2, 3, 4, 5,
737  3, 1, 2, 3, 1, 2, 4, 5, 1, 3,
738  1, 2, 1, 2, 1, 2, 3, 3, 1, 1,
739  1, 1, 2, 2
740 };
741 
742 
743 enum { YYENOMEM = -2 };
744 
745 #define yyerrok (yyerrstatus = 0)
746 #define yyclearin (yychar = YYEMPTY)
747 
748 #define YYACCEPT goto yyacceptlab
749 #define YYABORT goto yyabortlab
750 #define YYERROR goto yyerrorlab
751 
752 
753 #define YYRECOVERING() (!!yyerrstatus)
754 
755 #define YYBACKUP(Token, Value) \
756  do \
757  if (yychar == YYEMPTY) \
758  { \
759  yychar = (Token); \
760  yylval = (Value); \
761  YYPOPSTACK (yylen); \
762  yystate = *yyssp; \
763  goto yybackup; \
764  } \
765  else \
766  { \
767  yyerror (yyscanner, jsgf, YY_("syntax error: cannot back up")); \
768  YYERROR; \
769  } \
770  while (0)
771 
772 /* Backward compatibility with an undocumented macro.
773  Use YYerror or YYUNDEF. */
774 #define YYERRCODE YYUNDEF
775 
776 
777 /* Enable debugging if requested. */
778 #if YYDEBUG
779 
780 # ifndef YYFPRINTF
781 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
782 # define YYFPRINTF fprintf
783 # endif
784 
785 # define YYDPRINTF(Args) \
786 do { \
787  if (yydebug) \
788  YYFPRINTF Args; \
789 } while (0)
790 
791 /* This macro is provided for backward compatibility. */
792 # ifndef YY_LOCATION_PRINT
793 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
794 # endif
795 
796 
797 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
798 do { \
799  if (yydebug) \
800  { \
801  YYFPRINTF (stderr, "%s ", Title); \
802  yy_symbol_print (stderr, \
803  Kind, Value, yyscanner, jsgf); \
804  YYFPRINTF (stderr, "\n"); \
805  } \
806 } while (0)
807 
808 
809 /*-----------------------------------.
810 | Print this symbol's value on YYO. |
811 `-----------------------------------*/
812 
813 static void
814 yy_symbol_value_print (FILE *yyo,
815  yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, void* yyscanner, jsgf_t *jsgf)
816 {
817  FILE *yyoutput = yyo;
818  YYUSE (yyoutput);
819  YYUSE (yyscanner);
820  YYUSE (jsgf);
821  if (!yyvaluep)
822  return;
823 # ifdef YYPRINT
824  if (yykind < YYNTOKENS)
825  YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
826 # endif
827  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
828  YYUSE (yykind);
829  YY_IGNORE_MAYBE_UNINITIALIZED_END
830 }
831 
832 
833 /*---------------------------.
834 | Print this symbol on YYO. |
835 `---------------------------*/
836 
837 static void
838 yy_symbol_print (FILE *yyo,
839  yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, void* yyscanner, jsgf_t *jsgf)
840 {
841  YYFPRINTF (yyo, "%s %s (",
842  yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
843 
844  yy_symbol_value_print (yyo, yykind, yyvaluep, yyscanner, jsgf);
845  YYFPRINTF (yyo, ")");
846 }
847 
848 /*------------------------------------------------------------------.
849 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
850 | TOP (included). |
851 `------------------------------------------------------------------*/
852 
853 static void
854 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
855 {
856  YYFPRINTF (stderr, "Stack now");
857  for (; yybottom <= yytop; yybottom++)
858  {
859  int yybot = *yybottom;
860  YYFPRINTF (stderr, " %d", yybot);
861  }
862  YYFPRINTF (stderr, "\n");
863 }
864 
865 # define YY_STACK_PRINT(Bottom, Top) \
866 do { \
867  if (yydebug) \
868  yy_stack_print ((Bottom), (Top)); \
869 } while (0)
870 
871 
872 /*------------------------------------------------.
873 | Report that the YYRULE is going to be reduced. |
874 `------------------------------------------------*/
875 
876 static void
877 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
878  int yyrule, void* yyscanner, jsgf_t *jsgf)
879 {
880  int yylno = yyrline[yyrule];
881  int yynrhs = yyr2[yyrule];
882  int yyi;
883  YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
884  yyrule - 1, yylno);
885  /* The symbols being reduced. */
886  for (yyi = 0; yyi < yynrhs; yyi++)
887  {
888  YYFPRINTF (stderr, " $%d = ", yyi + 1);
889  yy_symbol_print (stderr,
890  YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
891  &yyvsp[(yyi + 1) - (yynrhs)], yyscanner, jsgf);
892  YYFPRINTF (stderr, "\n");
893  }
894 }
895 
896 # define YY_REDUCE_PRINT(Rule) \
897 do { \
898  if (yydebug) \
899  yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, jsgf); \
900 } while (0)
901 
902 /* Nonzero means print parse trace. It is left uninitialized so that
903  multiple parsers can coexist. */
904 int yydebug;
905 #else /* !YYDEBUG */
906 # define YYDPRINTF(Args) ((void) 0)
907 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
908 # define YY_STACK_PRINT(Bottom, Top)
909 # define YY_REDUCE_PRINT(Rule)
910 #endif /* !YYDEBUG */
911 
912 
913 /* YYINITDEPTH -- initial size of the parser's stacks. */
914 #ifndef YYINITDEPTH
915 # define YYINITDEPTH 200
916 #endif
917 
918 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
919  if the built-in stack extension method is used).
920 
921  Do not make this value too large; the results are undefined if
922  YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
923  evaluated with infinite-precision integer arithmetic. */
924 
925 #ifndef YYMAXDEPTH
926 # define YYMAXDEPTH 10000
927 #endif
928 
929 
930 
931 
932 
933 
934 /*-----------------------------------------------.
935 | Release the memory associated to this symbol. |
936 `-----------------------------------------------*/
937 
938 static void
939 yydestruct (const char *yymsg,
940  yysymbol_kind_t yykind, YYSTYPE *yyvaluep, void* yyscanner, jsgf_t *jsgf)
941 {
942  YYUSE (yyvaluep);
943  YYUSE (yyscanner);
944  YYUSE (jsgf);
945  if (!yymsg)
946  yymsg = "Deleting";
947  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
948 
949  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
950  YYUSE (yykind);
951  YY_IGNORE_MAYBE_UNINITIALIZED_END
952 }
953 
954 
955 
956 
957 
958 
959 /*----------.
960 | yyparse. |
961 `----------*/
962 
963 int
964 yyparse (void* yyscanner, jsgf_t *jsgf)
965 {
966 /* Lookahead token kind. */
967 int yychar;
968 
969 
970 /* The semantic value of the lookahead symbol. */
971 /* Default value used for initialization, for pacifying older GCCs
972  or non-GCC compilers. */
973 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
974 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
975 
976  /* Number of syntax errors so far. */
977  int yynerrs = 0;
978 
979  yy_state_fast_t yystate = 0;
980  /* Number of tokens to shift before error messages enabled. */
981  int yyerrstatus = 0;
982 
983  /* Refer to the stacks through separate pointers, to allow yyoverflow
984  to reallocate them elsewhere. */
985 
986  /* Their size. */
987  YYPTRDIFF_T yystacksize = YYINITDEPTH;
988 
989  /* The state stack: array, bottom, top. */
990  yy_state_t yyssa[YYINITDEPTH];
991  yy_state_t *yyss = yyssa;
992  yy_state_t *yyssp = yyss;
993 
994  /* The semantic value stack: array, bottom, top. */
995  YYSTYPE yyvsa[YYINITDEPTH];
996  YYSTYPE *yyvs = yyvsa;
997  YYSTYPE *yyvsp = yyvs;
998 
999  int yyn;
1000  /* The return value of yyparse. */
1001  int yyresult;
1002  /* Lookahead symbol kind. */
1003  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1004  /* The variables used to return semantic value and location from the
1005  action routines. */
1006  YYSTYPE yyval;
1007 
1008 
1009 
1010 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1011 
1012  /* The number of symbols on the RHS of the reduced rule.
1013  Keep to zero when no symbol should be popped. */
1014  int yylen = 0;
1015 
1016  YYDPRINTF ((stderr, "Starting parse\n"));
1017 
1018  yychar = YYEMPTY; /* Cause a token to be read. */
1019  goto yysetstate;
1020 
1021 
1022 /*------------------------------------------------------------.
1023 | yynewstate -- push a new state, which is found in yystate. |
1024 `------------------------------------------------------------*/
1025 yynewstate:
1026  /* In all cases, when you get here, the value and location stacks
1027  have just been pushed. So pushing a state here evens the stacks. */
1028  yyssp++;
1029 
1030 
1031 /*--------------------------------------------------------------------.
1032 | yysetstate -- set current state (the top of the stack) to yystate. |
1033 `--------------------------------------------------------------------*/
1034 yysetstate:
1035  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1036  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1037  YY_IGNORE_USELESS_CAST_BEGIN
1038  *yyssp = YY_CAST (yy_state_t, yystate);
1039  YY_IGNORE_USELESS_CAST_END
1040  YY_STACK_PRINT (yyss, yyssp);
1041 
1042  if (yyss + yystacksize - 1 <= yyssp)
1043 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1044  goto yyexhaustedlab;
1045 #else
1046  {
1047  /* Get the current used size of the three stacks, in elements. */
1048  YYPTRDIFF_T yysize = yyssp - yyss + 1;
1049 
1050 # if defined yyoverflow
1051  {
1052  /* Give user a chance to reallocate the stack. Use copies of
1053  these so that the &'s don't force the real ones into
1054  memory. */
1055  yy_state_t *yyss1 = yyss;
1056  YYSTYPE *yyvs1 = yyvs;
1057 
1058  /* Each stack pointer address is followed by the size of the
1059  data in use in that stack, in bytes. This used to be a
1060  conditional around just the two extra args, but that might
1061  be undefined if yyoverflow is a macro. */
1062  yyoverflow (YY_("memory exhausted"),
1063  &yyss1, yysize * YYSIZEOF (*yyssp),
1064  &yyvs1, yysize * YYSIZEOF (*yyvsp),
1065  &yystacksize);
1066  yyss = yyss1;
1067  yyvs = yyvs1;
1068  }
1069 # else /* defined YYSTACK_RELOCATE */
1070  /* Extend the stack our own way. */
1071  if (YYMAXDEPTH <= yystacksize)
1072  goto yyexhaustedlab;
1073  yystacksize *= 2;
1074  if (YYMAXDEPTH < yystacksize)
1075  yystacksize = YYMAXDEPTH;
1076 
1077  {
1078  yy_state_t *yyss1 = yyss;
1079  union yyalloc *yyptr =
1080  YY_CAST (union yyalloc *,
1081  YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1082  if (! yyptr)
1083  goto yyexhaustedlab;
1084  YYSTACK_RELOCATE (yyss_alloc, yyss);
1085  YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1086 # undef YYSTACK_RELOCATE
1087  if (yyss1 != yyssa)
1088  YYSTACK_FREE (yyss1);
1089  }
1090 # endif
1091 
1092  yyssp = yyss + yysize - 1;
1093  yyvsp = yyvs + yysize - 1;
1094 
1095  YY_IGNORE_USELESS_CAST_BEGIN
1096  YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1097  YY_CAST (long, yystacksize)));
1098  YY_IGNORE_USELESS_CAST_END
1099 
1100  if (yyss + yystacksize - 1 <= yyssp)
1101  YYABORT;
1102  }
1103 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1104 
1105  if (yystate == YYFINAL)
1106  YYACCEPT;
1107 
1108  goto yybackup;
1109 
1110 
1111 /*-----------.
1112 | yybackup. |
1113 `-----------*/
1114 yybackup:
1115  /* Do appropriate processing given the current state. Read a
1116  lookahead token if we need one and don't already have one. */
1117 
1118  /* First try to decide what to do without reference to lookahead token. */
1119  yyn = yypact[yystate];
1120  if (yypact_value_is_default (yyn))
1121  goto yydefault;
1122 
1123  /* Not known => get a lookahead token if don't already have one. */
1124 
1125  /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1126  if (yychar == YYEMPTY)
1127  {
1128  YYDPRINTF ((stderr, "Reading a token\n"));
1129  yychar = yylex (&yylval, yyscanner);
1130  }
1131 
1132  if (yychar <= YYEOF)
1133  {
1134  yychar = YYEOF;
1135  yytoken = YYSYMBOL_YYEOF;
1136  YYDPRINTF ((stderr, "Now at end of input.\n"));
1137  }
1138  else if (yychar == YYerror)
1139  {
1140  /* The scanner already issued an error message, process directly
1141  to error recovery. But do not keep the error token as
1142  lookahead, it is too special and may lead us to an endless
1143  loop in error recovery. */
1144  yychar = YYUNDEF;
1145  yytoken = YYSYMBOL_YYerror;
1146  goto yyerrlab1;
1147  }
1148  else
1149  {
1150  yytoken = YYTRANSLATE (yychar);
1151  YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1152  }
1153 
1154  /* If the proper action on seeing token YYTOKEN is to reduce or to
1155  detect an error, take that action. */
1156  yyn += yytoken;
1157  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1158  goto yydefault;
1159  yyn = yytable[yyn];
1160  if (yyn <= 0)
1161  {
1162  if (yytable_value_is_error (yyn))
1163  goto yyerrlab;
1164  yyn = -yyn;
1165  goto yyreduce;
1166  }
1167 
1168  /* Count tokens shifted since error; after three, turn off error
1169  status. */
1170  if (yyerrstatus)
1171  yyerrstatus--;
1172 
1173  /* Shift the lookahead token. */
1174  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1175  yystate = yyn;
1176  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1177  *++yyvsp = yylval;
1178  YY_IGNORE_MAYBE_UNINITIALIZED_END
1179 
1180  /* Discard the shifted token. */
1181  yychar = YYEMPTY;
1182  goto yynewstate;
1183 
1184 
1185 /*-----------------------------------------------------------.
1186 | yydefault -- do the default action for the current state. |
1187 `-----------------------------------------------------------*/
1188 yydefault:
1189  yyn = yydefact[yystate];
1190  if (yyn == 0)
1191  goto yyerrlab;
1192  goto yyreduce;
1193 
1194 
1195 /*-----------------------------.
1196 | yyreduce -- do a reduction. |
1197 `-----------------------------*/
1198 yyreduce:
1199  /* yyn is the number of a rule to reduce with. */
1200  yylen = yyr2[yyn];
1201 
1202  /* If YYLEN is nonzero, implement the default value of the action:
1203  '$$ = $1'.
1204 
1205  Otherwise, the following line sets YYVAL to garbage.
1206  This behavior is undocumented and Bison
1207  users should not rely upon it. Assigning to YYVAL
1208  unconditionally makes the parser a bit smaller, and it avoids a
1209  GCC warning that YYVAL may be used uninitialized. */
1210  yyval = yyvsp[1-yylen];
1211 
1212 
1213  YY_REDUCE_PRINT (yyn);
1214  switch (yyn)
1215  {
1216  case 5: /* header: jsgf_header grammar_header */
1217 #line 87 "jsgf_parser.y"
1218  { jsgf->name = (yyvsp[0].name); }
1219 #line 1220 "jsgf_parser.c"
1220  break;
1221 
1222  case 7: /* jsgf_header: HEADER TOKEN ';' */
1223 #line 91 "jsgf_parser.y"
1224  { jsgf->version = (yyvsp[-1].name); }
1225 #line 1226 "jsgf_parser.c"
1226  break;
1227 
1228  case 8: /* jsgf_header: HEADER TOKEN TOKEN ';' */
1229 #line 92 "jsgf_parser.y"
1230  { jsgf->version = (yyvsp[-2].name); jsgf->charset = (yyvsp[-1].name); }
1231 #line 1232 "jsgf_parser.c"
1232  break;
1233 
1234  case 9: /* jsgf_header: HEADER TOKEN TOKEN TOKEN ';' */
1235 #line 93 "jsgf_parser.y"
1236  { jsgf->version = (yyvsp[-3].name); jsgf->charset = (yyvsp[-2].name);
1237  jsgf->locale = (yyvsp[-1].name); }
1238 #line 1239 "jsgf_parser.c"
1239  break;
1240 
1241  case 10: /* grammar_header: GRAMMAR TOKEN ';' */
1242 #line 97 "jsgf_parser.y"
1243  { (yyval.name) = (yyvsp[-1].name); }
1244 #line 1245 "jsgf_parser.c"
1245  break;
1246 
1247  case 13: /* import_statement: IMPORT RULENAME ';' */
1248 #line 104 "jsgf_parser.y"
1249  { jsgf_import_rule(jsgf, (yyvsp[-1].name)); ckd_free((yyvsp[-1].name)); }
1250 #line 1251 "jsgf_parser.c"
1251  break;
1252 
1253  case 16: /* rule: RULENAME '=' alternate_list ';' */
1254 #line 111 "jsgf_parser.y"
1255  { jsgf_define_rule(jsgf, (yyvsp[-3].name), (yyvsp[-1].rhs), 0); ckd_free((yyvsp[-3].name)); }
1256 #line 1257 "jsgf_parser.c"
1257  break;
1258 
1259  case 17: /* rule: PUBLIC RULENAME '=' alternate_list ';' */
1260 #line 112 "jsgf_parser.y"
1261  { jsgf_define_rule(jsgf, (yyvsp[-3].name), (yyvsp[-1].rhs), 1); ckd_free((yyvsp[-3].name)); }
1262 #line 1263 "jsgf_parser.c"
1263  break;
1264 
1265  case 18: /* alternate_list: rule_expansion */
1266 #line 115 "jsgf_parser.y"
1267  { (yyval.rhs) = (yyvsp[0].rhs); (yyval.rhs)->atoms = glist_reverse((yyval.rhs)->atoms); }
1268 #line 1269 "jsgf_parser.c"
1269  break;
1270 
1271  case 19: /* alternate_list: alternate_list '|' rule_expansion */
1272 #line 116 "jsgf_parser.y"
1273  { (yyval.rhs) = (yyvsp[0].rhs);
1274  (yyval.rhs)->atoms = glist_reverse((yyval.rhs)->atoms);
1275  (yyval.rhs)->alt = (yyvsp[-2].rhs); }
1276 #line 1277 "jsgf_parser.c"
1277  break;
1278 
1279  case 20: /* rule_expansion: tagged_rule_item */
1280 #line 121 "jsgf_parser.y"
1281  { (yyval.rhs) = ckd_calloc(1, sizeof(*(yyval.rhs)));
1282  (yyval.rhs)->atoms = glist_add_ptr((yyval.rhs)->atoms, (yyvsp[0].atom)); }
1283 #line 1284 "jsgf_parser.c"
1284  break;
1285 
1286  case 21: /* rule_expansion: rule_expansion tagged_rule_item */
1287 #line 123 "jsgf_parser.y"
1288  { (yyval.rhs) = (yyvsp[-1].rhs);
1289  (yyval.rhs)->atoms = glist_add_ptr((yyval.rhs)->atoms, (yyvsp[0].atom)); }
1290 #line 1291 "jsgf_parser.c"
1291  break;
1292 
1293  case 23: /* tagged_rule_item: tagged_rule_item TAG */
1294 #line 128 "jsgf_parser.y"
1295  { (yyval.atom) = (yyvsp[-1].atom);
1296  (yyval.atom)->tags = glist_add_ptr((yyval.atom)->tags, (yyvsp[0].name)); }
1297 #line 1298 "jsgf_parser.c"
1298  break;
1299 
1300  case 25: /* rule_item: WEIGHT rule_atom */
1301 #line 133 "jsgf_parser.y"
1302  { (yyval.atom) = (yyvsp[0].atom); (yyval.atom)->weight = (yyvsp[-1].weight); }
1303 #line 1304 "jsgf_parser.c"
1304  break;
1305 
1306  case 26: /* rule_group: '(' alternate_list ')' */
1307 #line 136 "jsgf_parser.y"
1308  { (yyval.rule) = jsgf_define_rule(jsgf, NULL, (yyvsp[-1].rhs), 0); }
1309 #line 1310 "jsgf_parser.c"
1310  break;
1311 
1312  case 27: /* rule_optional: '[' alternate_list ']' */
1313 #line 139 "jsgf_parser.y"
1314  { (yyval.rule) = jsgf_optional_new(jsgf, (yyvsp[-1].rhs)); }
1315 #line 1316 "jsgf_parser.c"
1316  break;
1317 
1318  case 28: /* rule_atom: TOKEN */
1319 #line 142 "jsgf_parser.y"
1320  { (yyval.atom) = jsgf_atom_new((yyvsp[0].name), 1.0); ckd_free((yyvsp[0].name)); }
1321 #line 1322 "jsgf_parser.c"
1322  break;
1323 
1324  case 29: /* rule_atom: RULENAME */
1325 #line 143 "jsgf_parser.y"
1326  { (yyval.atom) = jsgf_atom_new((yyvsp[0].name), 1.0); ckd_free((yyvsp[0].name)); }
1327 #line 1328 "jsgf_parser.c"
1328  break;
1329 
1330  case 30: /* rule_atom: rule_group */
1331 #line 144 "jsgf_parser.y"
1332  { (yyval.atom) = jsgf_atom_new((yyvsp[0].rule)->name, 1.0); }
1333 #line 1334 "jsgf_parser.c"
1334  break;
1335 
1336  case 31: /* rule_atom: rule_optional */
1337 #line 145 "jsgf_parser.y"
1338  { (yyval.atom) = jsgf_atom_new((yyvsp[0].rule)->name, 1.0); }
1339 #line 1340 "jsgf_parser.c"
1340  break;
1341 
1342  case 32: /* rule_atom: rule_atom '*' */
1343 #line 146 "jsgf_parser.y"
1344  { (yyval.atom) = jsgf_kleene_new(jsgf, (yyvsp[-1].atom), 0); }
1345 #line 1346 "jsgf_parser.c"
1346  break;
1347 
1348  case 33: /* rule_atom: rule_atom '+' */
1349 #line 147 "jsgf_parser.y"
1350  { (yyval.atom) = jsgf_kleene_new(jsgf, (yyvsp[-1].atom), 1); }
1351 #line 1352 "jsgf_parser.c"
1352  break;
1353 
1354 
1355 #line 1356 "jsgf_parser.c"
1356 
1357  default: break;
1358  }
1359  /* User semantic actions sometimes alter yychar, and that requires
1360  that yytoken be updated with the new translation. We take the
1361  approach of translating immediately before every use of yytoken.
1362  One alternative is translating here after every semantic action,
1363  but that translation would be missed if the semantic action invokes
1364  YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1365  if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1366  incorrect destructor might then be invoked immediately. In the
1367  case of YYERROR or YYBACKUP, subsequent parser actions might lead
1368  to an incorrect destructor call or verbose syntax error message
1369  before the lookahead is translated. */
1370  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1371 
1372  YYPOPSTACK (yylen);
1373  yylen = 0;
1374 
1375  *++yyvsp = yyval;
1376 
1377  /* Now 'shift' the result of the reduction. Determine what state
1378  that goes to, based on the state we popped back to and the rule
1379  number reduced by. */
1380  {
1381  const int yylhs = yyr1[yyn] - YYNTOKENS;
1382  const int yyi = yypgoto[yylhs] + *yyssp;
1383  yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1384  ? yytable[yyi]
1385  : yydefgoto[yylhs]);
1386  }
1387 
1388  goto yynewstate;
1389 
1390 
1391 /*--------------------------------------.
1392 | yyerrlab -- here on detecting error. |
1393 `--------------------------------------*/
1394 yyerrlab:
1395  /* Make sure we have latest lookahead translation. See comments at
1396  user semantic actions for why this is necessary. */
1397  yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1398  /* If not already recovering from an error, report this error. */
1399  if (!yyerrstatus)
1400  {
1401  ++yynerrs;
1402  yyerror (yyscanner, jsgf, YY_("syntax error"));
1403  }
1404 
1405  if (yyerrstatus == 3)
1406  {
1407  /* If just tried and failed to reuse lookahead token after an
1408  error, discard it. */
1409 
1410  if (yychar <= YYEOF)
1411  {
1412  /* Return failure if at end of input. */
1413  if (yychar == YYEOF)
1414  YYABORT;
1415  }
1416  else
1417  {
1418  yydestruct ("Error: discarding",
1419  yytoken, &yylval, yyscanner, jsgf);
1420  yychar = YYEMPTY;
1421  }
1422  }
1423 
1424  /* Else will try to reuse lookahead token after shifting the error
1425  token. */
1426  goto yyerrlab1;
1427 
1428 
1429 /*---------------------------------------------------.
1430 | yyerrorlab -- error raised explicitly by YYERROR. |
1431 `---------------------------------------------------*/
1432 yyerrorlab:
1433  /* Pacify compilers when the user code never invokes YYERROR and the
1434  label yyerrorlab therefore never appears in user code. */
1435  if (0)
1436  YYERROR;
1437 
1438  /* Do not reclaim the symbols of the rule whose action triggered
1439  this YYERROR. */
1440  YYPOPSTACK (yylen);
1441  yylen = 0;
1442  YY_STACK_PRINT (yyss, yyssp);
1443  yystate = *yyssp;
1444  goto yyerrlab1;
1445 
1446 
1447 /*-------------------------------------------------------------.
1448 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1449 `-------------------------------------------------------------*/
1450 yyerrlab1:
1451  yyerrstatus = 3; /* Each real token shifted decrements this. */
1452 
1453  /* Pop stack until we find a state that shifts the error token. */
1454  for (;;)
1455  {
1456  yyn = yypact[yystate];
1457  if (!yypact_value_is_default (yyn))
1458  {
1459  yyn += YYSYMBOL_YYerror;
1460  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1461  {
1462  yyn = yytable[yyn];
1463  if (0 < yyn)
1464  break;
1465  }
1466  }
1467 
1468  /* Pop the current state because it cannot handle the error token. */
1469  if (yyssp == yyss)
1470  YYABORT;
1471 
1472 
1473  yydestruct ("Error: popping",
1474  YY_ACCESSING_SYMBOL (yystate), yyvsp, yyscanner, jsgf);
1475  YYPOPSTACK (1);
1476  yystate = *yyssp;
1477  YY_STACK_PRINT (yyss, yyssp);
1478  }
1479 
1480  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1481  *++yyvsp = yylval;
1482  YY_IGNORE_MAYBE_UNINITIALIZED_END
1483 
1484 
1485  /* Shift the error token. */
1486  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1487 
1488  yystate = yyn;
1489  goto yynewstate;
1490 
1491 
1492 /*-------------------------------------.
1493 | yyacceptlab -- YYACCEPT comes here. |
1494 `-------------------------------------*/
1495 yyacceptlab:
1496  yyresult = 0;
1497  goto yyreturn;
1498 
1499 
1500 /*-----------------------------------.
1501 | yyabortlab -- YYABORT comes here. |
1502 `-----------------------------------*/
1503 yyabortlab:
1504  yyresult = 1;
1505  goto yyreturn;
1506 
1507 
1508 #if !defined yyoverflow
1509 /*-------------------------------------------------.
1510 | yyexhaustedlab -- memory exhaustion comes here. |
1511 `-------------------------------------------------*/
1512 yyexhaustedlab:
1513  yyerror (yyscanner, jsgf, YY_("memory exhausted"));
1514  yyresult = 2;
1515  goto yyreturn;
1516 #endif
1517 
1518 
1519 /*-------------------------------------------------------.
1520 | yyreturn -- parsing is finished, clean up and return. |
1521 `-------------------------------------------------------*/
1522 yyreturn:
1523  if (yychar != YYEMPTY)
1524  {
1525  /* Make sure we have latest lookahead translation. See comments at
1526  user semantic actions for why this is necessary. */
1527  yytoken = YYTRANSLATE (yychar);
1528  yydestruct ("Cleanup: discarding lookahead",
1529  yytoken, &yylval, yyscanner, jsgf);
1530  }
1531  /* Do not reclaim the symbols of the rule whose action triggered
1532  this YYABORT or YYACCEPT. */
1533  YYPOPSTACK (yylen);
1534  YY_STACK_PRINT (yyss, yyssp);
1535  while (yyssp != yyss)
1536  {
1537  yydestruct ("Cleanup: popping",
1538  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yyscanner, jsgf);
1539  YYPOPSTACK (1);
1540  }
1541 #ifndef yyoverflow
1542  if (yyss != yyssa)
1543  YYSTACK_FREE (yyss);
1544 #endif
1545 
1546  return yyresult;
1547 }
1548 
1549 #line 150 "jsgf_parser.y"
1550 
1551 
1552 void
1553 yyerror(yyscan_t lex, jsgf_t *jsgf, const char *s)
1554 {
1555  E_ERROR("%s at line %d current token '%s'\n", s, yyget_lineno(lex), yyget_text(lex));
1556 }
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
Definition: ckd_alloc.c:244
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
Definition: ckd_alloc.h:248
Implementation of logging routines.
#define E_ERROR(...)
Print error message to error log.
Definition: err.h:104
SPHINXBASE_EXPORT glist_t glist_reverse(glist_t g)
Reverse the order of the given glist.
Definition: glist.c:169
SPHINXBASE_EXPORT glist_t glist_add_ptr(glist_t g, void *ptr)
Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...
Definition: glist.c:74
Hash table implementation.
Internal definitions for JSGF grammar compiler.
char * locale
JSGF locale (default C)
Definition: jsgf_internal.h:78
char * name
Grammar name.
Definition: jsgf_internal.h:79
char * charset
JSGF charset (default UTF-8)
Definition: jsgf_internal.h:77
char * version
JSGF version (from header)
Definition: jsgf_internal.h:76