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