libevtr: alternative hash syntax and more fixes
[dragonfly.git] / lib / libevtr / ktrfmt.tab.c
1
2 /* A Bison parser, made by GNU Bison 2.4.1.  */
3
4 /* Skeleton implementation for Bison's Yacc-like parsers in C
5    
6       Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
7    Free Software Foundation, Inc.
8    
9    This program is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
22 /* As a special exception, you may create a larger work that contains
23    part or all of the Bison parser skeleton and distribute that work
24    under terms of your choice, so long as that work isn't itself a
25    parser generator using the skeleton or a modified version thereof
26    as a parser skeleton.  Alternatively, if you modify or redistribute
27    the parser skeleton itself, you may (at your option) remove this
28    special exception, which will cause the skeleton and the resulting
29    Bison output files to be licensed under the GNU General Public
30    License without this special exception.
31    
32    This special exception was added by the Free Software Foundation in
33    version 2.2 of Bison.  */
34
35 /* C LALR(1) parser skeleton written by Richard Stallman, by
36    simplifying the original so-called "semantic" parser.  */
37
38 /* All symbols defined below should begin with yy or YY, to avoid
39    infringing on user name space.  This should be done even for local
40    variables, as they might otherwise be expanded by user macros.
41    There are some unavoidable exceptions within include files to
42    define necessary library symbols; they are noted "INFRINGES ON
43    USER NAME SPACE" below.  */
44
45 /* Identify Bison output.  */
46 #define YYBISON 1
47
48 /* Bison version.  */
49 #define YYBISON_VERSION "2.4.1"
50
51 /* Skeleton name.  */
52 #define YYSKELETON_NAME "yacc.c"
53
54 /* Pure parsers.  */
55 #define YYPURE 1
56
57 /* Push parsers.  */
58 #define YYPUSH 0
59
60 /* Pull parsers.  */
61 #define YYPULL 1
62
63 /* Using locations.  */
64 #define YYLSP_NEEDED 0
65
66 /* Substitute the variable and function names.  */
67 #define yyparse         __ktrfmt_parse
68 #define yylex           __ktrfmt_lex
69 #define yyerror         __ktrfmt_error
70 #define yylval          __ktrfmt_lval
71 #define yychar          __ktrfmt_char
72 #define yydebug         __ktrfmt_debug
73 #define yynerrs         __ktrfmt_nerrs
74
75
76 /* Copy the first part of user declarations.  */
77
78 /* Line 189 of yacc.c  */
79 #line 1 "ktrfmt.y"
80
81
82 #include <assert.h>
83 #include <errno.h>
84 #include <stdarg.h>
85 #include <stdlib.h>
86 #include <string.h>
87
88 #include "evtr.h"
89 #include "tok.h"
90 #include "ktrfmt.tab.h"
91 #include "internal.h"
92
93 struct ktrfmt_parse_ctx {
94         struct symtab *symtab;
95         struct evtr_variable *var;
96         struct evtr_variable_value *val;
97         evtr_event_t ev;
98         char *errbuf;
99         size_t errbufsz;
100         int err;
101 };
102
103 int __ktrfmtlex(YYSTYPE *);
104 #define __ktrfmt_lex __ktrfmtlex
105
106 void __ktrfmt_error (struct ktrfmt_parse_ctx *, const char *);
107
108 static
109 void
110 do_parse_err(struct ktrfmt_parse_ctx *ctx, const char *fmt, ...)
111 {
112         va_list ap;
113
114         va_start(ap, fmt);
115         vsnprintf(ctx->errbuf, ctx->errbufsz, fmt, ap);
116         va_end(ap);
117         ctx->err = !0;
118 }
119
120 #define parse_err(fmt, ...)                     \
121         do {                                    \
122                 do_parse_err(ctx, fmt, ##__VA_ARGS__);  \
123                 YYABORT;                                \
124         } while (0)
125
126 static
127 struct evtr_variable *
128 evtr_var_new(const char *name)
129 {
130         struct evtr_variable *var;
131
132         var = calloc(1, sizeof(*var));
133         if (var) {
134                 if (!(var->name = strdup(name))) {
135                         free(var);
136                         return NULL;
137                 }
138                 var->val.type = EVTR_VAL_NIL;
139         }
140         return var;
141 }
142
143 /*
144  * XXX: should be reentrant
145  */
146 static
147 char *
148 uniq_varname(void)
149 {
150         static long serno;
151         static char buf[100];
152
153         serno++;
154         snprintf(buf, sizeof(buf), "@%ld", serno);
155         return &buf[0];
156 }
157
158 static
159 int
160 index_hash(struct ktrfmt_parse_ctx *ctx, const char *hashname,
161            evtr_variable_value_t val, evtr_var_t *_var)
162 {
163         evtr_var_t hsh, var;
164         uintptr_t ret, key;
165         hsh = symtab_find(ctx->symtab, hashname);
166         if (hsh->val.type == EVTR_VAL_NIL) {
167                 /* it's probably the first time we see this "variable" */
168                 printd(PARSE, "creating hash for %s\n", hsh->name);
169                 hsh->val.type = EVTR_VAL_HASH;
170                 hsh->val.hashtab = hash_new();
171         } else if (hsh->val.type != EVTR_VAL_HASH) {
172                 printd(PARSE, "trying to use type %d as hash\n", hsh->val.type);
173                 return !0;
174         }
175         if (val->type == EVTR_VAL_INT) {
176                 key = val->num;
177                 printd(PARSE, "looking up %s[%jd] in %p\n", hsh->name,
178                        val->num, hsh->val.hashtab);
179         } else if (val->type == EVTR_VAL_STR) {
180                 key = (uintptr_t)val->str;
181                 printd(PARSE, "looking up %s[\"%s\"] in %p\n", hsh->name,
182                        val->str, hsh->val.hashtab);
183         } else {
184                 do_parse_err(ctx, "trying to index hash '%s' with "
185                              "non-supported value", hashname);
186                 return !0;
187         }
188
189         if (hash_find(hsh->val.hashtab, key, &ret)) {
190                 printd(PARSE, "didn't find it\n");
191                 var = evtr_var_new(uniq_varname());
192                 if (var) {
193                         printd(PARSE, "inserting it as %s\n", var->name);
194                         if (!hash_insert(hsh->val.hashtab, key,
195                                          (uintptr_t)var)) {
196                                 do_parse_err(ctx, "can't insert temporary "
197                                         "variable into hash\n");
198                                 return !0;
199                         }
200                         symtab_insert(ctx->symtab, var->name, var);
201                 } else {
202                         do_parse_err(ctx, "out of memory");
203                 }
204         } else {
205                 var = (struct evtr_variable *)ret;
206         }
207         if (!var) {
208                 fprintf(stderr, "no var!\n");
209                 return !0;
210                 /* XXX */
211         }
212         *_var = var;
213         return 0;
214 }
215
216
217
218 /* Line 189 of yacc.c  */
219 #line 220 "ktrfmt.tab.c"
220
221 /* Enabling traces.  */
222 #ifndef YYDEBUG
223 # define YYDEBUG 1
224 #endif
225
226 /* Enabling verbose error messages.  */
227 #ifdef YYERROR_VERBOSE
228 # undef YYERROR_VERBOSE
229 # define YYERROR_VERBOSE 1
230 #else
231 # define YYERROR_VERBOSE 1
232 #endif
233
234 /* Enabling the token table.  */
235 #ifndef YYTOKEN_TABLE
236 # define YYTOKEN_TABLE 0
237 #endif
238
239
240 /* Tokens.  */
241 #ifndef YYTOKENTYPE
242 # define YYTOKENTYPE
243    /* Put the tokens into the symbol table, so that GDB and other debuggers
244       know about them.  */
245    enum yytokentype {
246      TOK_ID = 258,
247      TOK_INT = 259,
248      TOK_STR = 260,
249      TOK_EQ = 261,
250      TOK_LEFT_BRACK = 262,
251      TOK_RIGHT_BRACK = 263,
252      TOK_DOT = 264
253    };
254 #endif
255
256
257
258 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
259 typedef union YYSTYPE
260 {
261
262 /* Line 214 of yacc.c  */
263 #line 146 "ktrfmt.y"
264
265         struct token *tok;
266         struct evtr_variable *var;
267         struct evtr_variable_value *val;
268         void *na;
269
270
271
272 /* Line 214 of yacc.c  */
273 #line 274 "ktrfmt.tab.c"
274 } YYSTYPE;
275 # define YYSTYPE_IS_TRIVIAL 1
276 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
277 # define YYSTYPE_IS_DECLARED 1
278 #endif
279
280
281 /* Copy the second part of user declarations.  */
282
283
284 /* Line 264 of yacc.c  */
285 #line 286 "ktrfmt.tab.c"
286
287 #ifdef short
288 # undef short
289 #endif
290
291 #ifdef YYTYPE_UINT8
292 typedef YYTYPE_UINT8 yytype_uint8;
293 #else
294 typedef unsigned char yytype_uint8;
295 #endif
296
297 #ifdef YYTYPE_INT8
298 typedef YYTYPE_INT8 yytype_int8;
299 #elif (defined __STDC__ || defined __C99__FUNC__ \
300      || defined __cplusplus || defined _MSC_VER)
301 typedef signed char yytype_int8;
302 #else
303 typedef short int yytype_int8;
304 #endif
305
306 #ifdef YYTYPE_UINT16
307 typedef YYTYPE_UINT16 yytype_uint16;
308 #else
309 typedef unsigned short int yytype_uint16;
310 #endif
311
312 #ifdef YYTYPE_INT16
313 typedef YYTYPE_INT16 yytype_int16;
314 #else
315 typedef short int yytype_int16;
316 #endif
317
318 #ifndef YYSIZE_T
319 # ifdef __SIZE_TYPE__
320 #  define YYSIZE_T __SIZE_TYPE__
321 # elif defined size_t
322 #  define YYSIZE_T size_t
323 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
324      || defined __cplusplus || defined _MSC_VER)
325 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
326 #  define YYSIZE_T size_t
327 # else
328 #  define YYSIZE_T unsigned int
329 # endif
330 #endif
331
332 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
333
334 #ifndef YY_
335 # if YYENABLE_NLS
336 #  if ENABLE_NLS
337 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
338 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
339 #  endif
340 # endif
341 # ifndef YY_
342 #  define YY_(msgid) msgid
343 # endif
344 #endif
345
346 /* Suppress unused-variable warnings by "using" E.  */
347 #if ! defined lint || defined __GNUC__
348 # define YYUSE(e) ((void) (e))
349 #else
350 # define YYUSE(e) /* empty */
351 #endif
352
353 /* Identity function, used to suppress warnings about constant conditions.  */
354 #ifndef lint
355 # define YYID(n) (n)
356 #else
357 #if (defined __STDC__ || defined __C99__FUNC__ \
358      || defined __cplusplus || defined _MSC_VER)
359 static int
360 YYID (int yyi)
361 #else
362 static int
363 YYID (yyi)
364     int yyi;
365 #endif
366 {
367   return yyi;
368 }
369 #endif
370
371 #if ! defined yyoverflow || YYERROR_VERBOSE
372
373 /* The parser invokes alloca or malloc; define the necessary symbols.  */
374
375 # ifdef YYSTACK_USE_ALLOCA
376 #  if YYSTACK_USE_ALLOCA
377 #   ifdef __GNUC__
378 #    define YYSTACK_ALLOC __builtin_alloca
379 #   elif defined __BUILTIN_VA_ARG_INCR
380 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
381 #   elif defined _AIX
382 #    define YYSTACK_ALLOC __alloca
383 #   elif defined _MSC_VER
384 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
385 #    define alloca _alloca
386 #   else
387 #    define YYSTACK_ALLOC alloca
388 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
389      || defined __cplusplus || defined _MSC_VER)
390 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
391 #     ifndef _STDLIB_H
392 #      define _STDLIB_H 1
393 #     endif
394 #    endif
395 #   endif
396 #  endif
397 # endif
398
399 # ifdef YYSTACK_ALLOC
400    /* Pacify GCC's `empty if-body' warning.  */
401 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
402 #  ifndef YYSTACK_ALLOC_MAXIMUM
403     /* The OS might guarantee only one guard page at the bottom of the stack,
404        and a page size can be as small as 4096 bytes.  So we cannot safely
405        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
406        to allow for a few compiler-allocated temporary stack slots.  */
407 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
408 #  endif
409 # else
410 #  define YYSTACK_ALLOC YYMALLOC
411 #  define YYSTACK_FREE YYFREE
412 #  ifndef YYSTACK_ALLOC_MAXIMUM
413 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
414 #  endif
415 #  if (defined __cplusplus && ! defined _STDLIB_H \
416        && ! ((defined YYMALLOC || defined malloc) \
417              && (defined YYFREE || defined free)))
418 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
419 #   ifndef _STDLIB_H
420 #    define _STDLIB_H 1
421 #   endif
422 #  endif
423 #  ifndef YYMALLOC
424 #   define YYMALLOC malloc
425 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
426      || defined __cplusplus || defined _MSC_VER)
427 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
428 #   endif
429 #  endif
430 #  ifndef YYFREE
431 #   define YYFREE free
432 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
433      || defined __cplusplus || defined _MSC_VER)
434 void free (void *); /* INFRINGES ON USER NAME SPACE */
435 #   endif
436 #  endif
437 # endif
438 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
439
440
441 #if (! defined yyoverflow \
442      && (! defined __cplusplus \
443          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
444
445 /* A type that is properly aligned for any stack member.  */
446 union yyalloc
447 {
448   yytype_int16 yyss_alloc;
449   YYSTYPE yyvs_alloc;
450 };
451
452 /* The size of the maximum gap between one aligned stack and the next.  */
453 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
454
455 /* The size of an array large to enough to hold all stacks, each with
456    N elements.  */
457 # define YYSTACK_BYTES(N) \
458      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
459       + YYSTACK_GAP_MAXIMUM)
460
461 /* Copy COUNT objects from FROM to TO.  The source and destination do
462    not overlap.  */
463 # ifndef YYCOPY
464 #  if defined __GNUC__ && 1 < __GNUC__
465 #   define YYCOPY(To, From, Count) \
466       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
467 #  else
468 #   define YYCOPY(To, From, Count)              \
469       do                                        \
470         {                                       \
471           YYSIZE_T yyi;                         \
472           for (yyi = 0; yyi < (Count); yyi++)   \
473             (To)[yyi] = (From)[yyi];            \
474         }                                       \
475       while (YYID (0))
476 #  endif
477 # endif
478
479 /* Relocate STACK from its old location to the new one.  The
480    local variables YYSIZE and YYSTACKSIZE give the old and new number of
481    elements in the stack, and YYPTR gives the new location of the
482    stack.  Advance YYPTR to a properly aligned location for the next
483    stack.  */
484 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
485     do                                                                  \
486       {                                                                 \
487         YYSIZE_T yynewbytes;                                            \
488         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
489         Stack = &yyptr->Stack_alloc;                                    \
490         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
491         yyptr += yynewbytes / sizeof (*yyptr);                          \
492       }                                                                 \
493     while (YYID (0))
494
495 #endif
496
497 /* YYFINAL -- State number of the termination state.  */
498 #define YYFINAL  12
499 /* YYLAST -- Last index in YYTABLE.  */
500 #define YYLAST   14
501
502 /* YYNTOKENS -- Number of terminals.  */
503 #define YYNTOKENS  10
504 /* YYNNTS -- Number of nonterminals.  */
505 #define YYNNTS  9
506 /* YYNRULES -- Number of rules.  */
507 #define YYNRULES  14
508 /* YYNRULES -- Number of states.  */
509 #define YYNSTATES  20
510
511 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
512 #define YYUNDEFTOK  2
513 #define YYMAXUTOK   264
514
515 #define YYTRANSLATE(YYX)                                                \
516   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
517
518 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
519 static const yytype_uint8 yytranslate[] =
520 {
521        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
522        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
523        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
524        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
525        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
526        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
527        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
528        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
529        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
530        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
531        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
532        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
533        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
534        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
535        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
536        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
537        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
538        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
539        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
540        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
541        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
542        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
543        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
544        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
545        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
546        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
547        5,     6,     7,     8,     9
548 };
549
550 #if YYDEBUG
551 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
552    YYRHS.  */
553 static const yytype_uint8 yyprhs[] =
554 {
555        0,     0,     3,     5,     7,     9,    11,    13,    15,    17,
556       22,    26,    28,    30,    34
557 };
558
559 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
560 static const yytype_int8 yyrhs[] =
561 {
562       11,     0,    -1,    12,    -1,    16,    -1,    18,    -1,     4,
563       -1,     5,    -1,     3,    -1,    13,    -1,    15,     7,    15,
564        8,    -1,    15,     9,     3,    -1,    14,    -1,    15,    -1,
565       16,     6,    13,    -1,    17,    -1
566 };
567
568 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
569 static const yytype_uint16 yyrline[] =
570 {
571        0,   171,   171,   173,   176,   178,   192,   207,   225,   229,
572      236,   249,   253,   257,   265
573 };
574 #endif
575
576 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
577 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
578    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
579 static const char *const yytname[] =
580 {
581   "$end", "error", "$undefined", "TOK_ID", "TOK_INT", "TOK_STR", "TOK_EQ",
582   "TOK_LEFT_BRACK", "TOK_RIGHT_BRACK", "TOK_DOT", "$accept", "input",
583   "stmt", "constant", "primary_expr", "postfix_expr", "unary_expr",
584   "assign_expr", "expr", 0
585 };
586 #endif
587
588 # ifdef YYPRINT
589 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
590    token YYLEX-NUM.  */
591 static const yytype_uint16 yytoknum[] =
592 {
593        0,   256,   257,   258,   259,   260,   261,   262,   263,   264
594 };
595 # endif
596
597 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
598 static const yytype_uint8 yyr1[] =
599 {
600        0,    10,    11,    12,    12,    13,    13,    14,    14,    15,
601       15,    15,    16,    17,    18
602 };
603
604 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
605 static const yytype_uint8 yyr2[] =
606 {
607        0,     2,     1,     1,     1,     1,     1,     1,     1,     4,
608        3,     1,     1,     3,     1
609 };
610
611 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
612    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
613    means the default is an error.  */
614 static const yytype_uint8 yydefact[] =
615 {
616        0,     7,     5,     6,     0,     2,     8,    11,    12,     3,
617       14,     4,     1,     0,     0,     0,     0,    10,    13,     9
618 };
619
620 /* YYDEFGOTO[NTERM-NUM].  */
621 static const yytype_int8 yydefgoto[] =
622 {
623       -1,     4,     5,     6,     7,     8,     9,    10,    11
624 };
625
626 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
627    STATE-NUM.  */
628 #define YYPACT_NINF -5
629 static const yytype_int8 yypact[] =
630 {
631       -3,    -5,    -5,    -5,     7,    -5,    -5,    -5,    -1,     6,
632       -5,    -5,    -5,    -3,     8,     5,    -4,    -5,    -5,    -5
633 };
634
635 /* YYPGOTO[NTERM-NUM].  */
636 static const yytype_int8 yypgoto[] =
637 {
638       -5,    -5,    -5,    -2,    -5,     1,    -5,    -5,    -5
639 };
640
641 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
642    positive, shift that token.  If negative, reduce the rule which
643    number is the opposite.  If zero, do what YYDEFACT says.
644    If YYTABLE_NINF, syntax error.  */
645 #define YYTABLE_NINF -1
646 static const yytype_uint8 yytable[] =
647 {
648        1,     2,     3,    13,    19,    14,    13,    12,    14,     2,
649        3,    17,    15,    18,    16
650 };
651
652 static const yytype_uint8 yycheck[] =
653 {
654        3,     4,     5,     7,     8,     9,     7,     0,     9,     4,
655        5,     3,     6,    15,    13
656 };
657
658 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
659    symbol of state STATE-NUM.  */
660 static const yytype_uint8 yystos[] =
661 {
662        0,     3,     4,     5,    11,    12,    13,    14,    15,    16,
663       17,    18,     0,     7,     9,     6,    15,     3,    13,     8
664 };
665
666 #define yyerrok         (yyerrstatus = 0)
667 #define yyclearin       (yychar = YYEMPTY)
668 #define YYEMPTY         (-2)
669 #define YYEOF           0
670
671 #define YYACCEPT        goto yyacceptlab
672 #define YYABORT         goto yyabortlab
673 #define YYERROR         goto yyerrorlab
674
675
676 /* Like YYERROR except do call yyerror.  This remains here temporarily
677    to ease the transition to the new meaning of YYERROR, for GCC.
678    Once GCC version 2 has supplanted version 1, this can go.  */
679
680 #define YYFAIL          goto yyerrlab
681
682 #define YYRECOVERING()  (!!yyerrstatus)
683
684 #define YYBACKUP(Token, Value)                                  \
685 do                                                              \
686   if (yychar == YYEMPTY && yylen == 1)                          \
687     {                                                           \
688       yychar = (Token);                                         \
689       yylval = (Value);                                         \
690       yytoken = YYTRANSLATE (yychar);                           \
691       YYPOPSTACK (1);                                           \
692       goto yybackup;                                            \
693     }                                                           \
694   else                                                          \
695     {                                                           \
696       yyerror (ctx, YY_("syntax error: cannot back up")); \
697       YYERROR;                                                  \
698     }                                                           \
699 while (YYID (0))
700
701
702 #define YYTERROR        1
703 #define YYERRCODE       256
704
705
706 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
707    If N is 0, then set CURRENT to the empty location which ends
708    the previous symbol: RHS[0] (always defined).  */
709
710 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
711 #ifndef YYLLOC_DEFAULT
712 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
713     do                                                                  \
714       if (YYID (N))                                                    \
715         {                                                               \
716           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
717           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
718           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
719           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
720         }                                                               \
721       else                                                              \
722         {                                                               \
723           (Current).first_line   = (Current).last_line   =              \
724             YYRHSLOC (Rhs, 0).last_line;                                \
725           (Current).first_column = (Current).last_column =              \
726             YYRHSLOC (Rhs, 0).last_column;                              \
727         }                                                               \
728     while (YYID (0))
729 #endif
730
731
732 /* YY_LOCATION_PRINT -- Print the location on the stream.
733    This macro was not mandated originally: define only if we know
734    we won't break user code: when these are the locations we know.  */
735
736 #ifndef YY_LOCATION_PRINT
737 # if YYLTYPE_IS_TRIVIAL
738 #  define YY_LOCATION_PRINT(File, Loc)                  \
739      fprintf (File, "%d.%d-%d.%d",                      \
740               (Loc).first_line, (Loc).first_column,     \
741               (Loc).last_line,  (Loc).last_column)
742 # else
743 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
744 # endif
745 #endif
746
747
748 /* YYLEX -- calling `yylex' with the right arguments.  */
749
750 #ifdef YYLEX_PARAM
751 # define YYLEX yylex (&yylval, YYLEX_PARAM)
752 #else
753 # define YYLEX yylex (&yylval)
754 #endif
755
756 /* Enable debugging if requested.  */
757 #if YYDEBUG
758
759 # ifndef YYFPRINTF
760 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
761 #  define YYFPRINTF fprintf
762 # endif
763
764 # define YYDPRINTF(Args)                        \
765 do {                                            \
766   if (yydebug)                                  \
767     YYFPRINTF Args;                             \
768 } while (YYID (0))
769
770 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
771 do {                                                                      \
772   if (yydebug)                                                            \
773     {                                                                     \
774       YYFPRINTF (stderr, "%s ", Title);                                   \
775       yy_symbol_print (stderr,                                            \
776                   Type, Value, ctx); \
777       YYFPRINTF (stderr, "\n");                                           \
778     }                                                                     \
779 } while (YYID (0))
780
781
782 /*--------------------------------.
783 | Print this symbol on YYOUTPUT.  |
784 `--------------------------------*/
785
786 /*ARGSUSED*/
787 #if (defined __STDC__ || defined __C99__FUNC__ \
788      || defined __cplusplus || defined _MSC_VER)
789 static void
790 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct ktrfmt_parse_ctx *ctx)
791 #else
792 static void
793 yy_symbol_value_print (yyoutput, yytype, yyvaluep, ctx)
794     FILE *yyoutput;
795     int yytype;
796     YYSTYPE const * const yyvaluep;
797     struct ktrfmt_parse_ctx *ctx;
798 #endif
799 {
800   if (!yyvaluep)
801     return;
802   YYUSE (ctx);
803 # ifdef YYPRINT
804   if (yytype < YYNTOKENS)
805     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
806 # else
807   YYUSE (yyoutput);
808 # endif
809   switch (yytype)
810     {
811       default:
812         break;
813     }
814 }
815
816
817 /*--------------------------------.
818 | Print this symbol on YYOUTPUT.  |
819 `--------------------------------*/
820
821 #if (defined __STDC__ || defined __C99__FUNC__ \
822      || defined __cplusplus || defined _MSC_VER)
823 static void
824 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct ktrfmt_parse_ctx *ctx)
825 #else
826 static void
827 yy_symbol_print (yyoutput, yytype, yyvaluep, ctx)
828     FILE *yyoutput;
829     int yytype;
830     YYSTYPE const * const yyvaluep;
831     struct ktrfmt_parse_ctx *ctx;
832 #endif
833 {
834   if (yytype < YYNTOKENS)
835     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
836   else
837     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
838
839   yy_symbol_value_print (yyoutput, yytype, yyvaluep, ctx);
840   YYFPRINTF (yyoutput, ")");
841 }
842
843 /*------------------------------------------------------------------.
844 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
845 | TOP (included).                                                   |
846 `------------------------------------------------------------------*/
847
848 #if (defined __STDC__ || defined __C99__FUNC__ \
849      || defined __cplusplus || defined _MSC_VER)
850 static void
851 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
852 #else
853 static void
854 yy_stack_print (yybottom, yytop)
855     yytype_int16 *yybottom;
856     yytype_int16 *yytop;
857 #endif
858 {
859   YYFPRINTF (stderr, "Stack now");
860   for (; yybottom <= yytop; yybottom++)
861     {
862       int yybot = *yybottom;
863       YYFPRINTF (stderr, " %d", yybot);
864     }
865   YYFPRINTF (stderr, "\n");
866 }
867
868 # define YY_STACK_PRINT(Bottom, Top)                            \
869 do {                                                            \
870   if (yydebug)                                                  \
871     yy_stack_print ((Bottom), (Top));                           \
872 } while (YYID (0))
873
874
875 /*------------------------------------------------.
876 | Report that the YYRULE is going to be reduced.  |
877 `------------------------------------------------*/
878
879 #if (defined __STDC__ || defined __C99__FUNC__ \
880      || defined __cplusplus || defined _MSC_VER)
881 static void
882 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, struct ktrfmt_parse_ctx *ctx)
883 #else
884 static void
885 yy_reduce_print (yyvsp, yyrule, ctx)
886     YYSTYPE *yyvsp;
887     int yyrule;
888     struct ktrfmt_parse_ctx *ctx;
889 #endif
890 {
891   int yynrhs = yyr2[yyrule];
892   int yyi;
893   unsigned long int yylno = yyrline[yyrule];
894   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
895              yyrule - 1, yylno);
896   /* The symbols being reduced.  */
897   for (yyi = 0; yyi < yynrhs; yyi++)
898     {
899       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
900       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
901                        &(yyvsp[(yyi + 1) - (yynrhs)])
902                                        , ctx);
903       YYFPRINTF (stderr, "\n");
904     }
905 }
906
907 # define YY_REDUCE_PRINT(Rule)          \
908 do {                                    \
909   if (yydebug)                          \
910     yy_reduce_print (yyvsp, Rule, ctx); \
911 } while (YYID (0))
912
913 /* Nonzero means print parse trace.  It is left uninitialized so that
914    multiple parsers can coexist.  */
915 int yydebug;
916 #else /* !YYDEBUG */
917 # define YYDPRINTF(Args)
918 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
919 # define YY_STACK_PRINT(Bottom, Top)
920 # define YY_REDUCE_PRINT(Rule)
921 #endif /* !YYDEBUG */
922
923
924 /* YYINITDEPTH -- initial size of the parser's stacks.  */
925 #ifndef YYINITDEPTH
926 # define YYINITDEPTH 200
927 #endif
928
929 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
930    if the built-in stack extension method is used).
931
932    Do not make this value too large; the results are undefined if
933    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
934    evaluated with infinite-precision integer arithmetic.  */
935
936 #ifndef YYMAXDEPTH
937 # define YYMAXDEPTH 10000
938 #endif
939
940 \f
941
942 #if YYERROR_VERBOSE
943
944 # ifndef yystrlen
945 #  if defined __GLIBC__ && defined _STRING_H
946 #   define yystrlen strlen
947 #  else
948 /* Return the length of YYSTR.  */
949 #if (defined __STDC__ || defined __C99__FUNC__ \
950      || defined __cplusplus || defined _MSC_VER)
951 static YYSIZE_T
952 yystrlen (const char *yystr)
953 #else
954 static YYSIZE_T
955 yystrlen (yystr)
956     const char *yystr;
957 #endif
958 {
959   YYSIZE_T yylen;
960   for (yylen = 0; yystr[yylen]; yylen++)
961     continue;
962   return yylen;
963 }
964 #  endif
965 # endif
966
967 # ifndef yystpcpy
968 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
969 #   define yystpcpy stpcpy
970 #  else
971 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
972    YYDEST.  */
973 #if (defined __STDC__ || defined __C99__FUNC__ \
974      || defined __cplusplus || defined _MSC_VER)
975 static char *
976 yystpcpy (char *yydest, const char *yysrc)
977 #else
978 static char *
979 yystpcpy (yydest, yysrc)
980     char *yydest;
981     const char *yysrc;
982 #endif
983 {
984   char *yyd = yydest;
985   const char *yys = yysrc;
986
987   while ((*yyd++ = *yys++) != '\0')
988     continue;
989
990   return yyd - 1;
991 }
992 #  endif
993 # endif
994
995 # ifndef yytnamerr
996 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
997    quotes and backslashes, so that it's suitable for yyerror.  The
998    heuristic is that double-quoting is unnecessary unless the string
999    contains an apostrophe, a comma, or backslash (other than
1000    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1001    null, do not copy; instead, return the length of what the result
1002    would have been.  */
1003 static YYSIZE_T
1004 yytnamerr (char *yyres, const char *yystr)
1005 {
1006   if (*yystr == '"')
1007     {
1008       YYSIZE_T yyn = 0;
1009       char const *yyp = yystr;
1010
1011       for (;;)
1012         switch (*++yyp)
1013           {
1014           case '\'':
1015           case ',':
1016             goto do_not_strip_quotes;
1017
1018           case '\\':
1019             if (*++yyp != '\\')
1020               goto do_not_strip_quotes;
1021             /* Fall through.  */
1022           default:
1023             if (yyres)
1024               yyres[yyn] = *yyp;
1025             yyn++;
1026             break;
1027
1028           case '"':
1029             if (yyres)
1030               yyres[yyn] = '\0';
1031             return yyn;
1032           }
1033     do_not_strip_quotes: ;
1034     }
1035
1036   if (! yyres)
1037     return yystrlen (yystr);
1038
1039   return yystpcpy (yyres, yystr) - yyres;
1040 }
1041 # endif
1042
1043 /* Copy into YYRESULT an error message about the unexpected token
1044    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1045    including the terminating null byte.  If YYRESULT is null, do not
1046    copy anything; just return the number of bytes that would be
1047    copied.  As a special case, return 0 if an ordinary "syntax error"
1048    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1049    size calculation.  */
1050 static YYSIZE_T
1051 yysyntax_error (char *yyresult, int yystate, int yychar)
1052 {
1053   int yyn = yypact[yystate];
1054
1055   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1056     return 0;
1057   else
1058     {
1059       int yytype = YYTRANSLATE (yychar);
1060       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1061       YYSIZE_T yysize = yysize0;
1062       YYSIZE_T yysize1;
1063       int yysize_overflow = 0;
1064       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1065       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1066       int yyx;
1067
1068 # if 0
1069       /* This is so xgettext sees the translatable formats that are
1070          constructed on the fly.  */
1071       YY_("syntax error, unexpected %s");
1072       YY_("syntax error, unexpected %s, expecting %s");
1073       YY_("syntax error, unexpected %s, expecting %s or %s");
1074       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1075       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1076 # endif
1077       char *yyfmt;
1078       char const *yyf;
1079       static char const yyunexpected[] = "syntax error, unexpected %s";
1080       static char const yyexpecting[] = ", expecting %s";
1081       static char const yyor[] = " or %s";
1082       char yyformat[sizeof yyunexpected
1083                     + sizeof yyexpecting - 1
1084                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1085                        * (sizeof yyor - 1))];
1086       char const *yyprefix = yyexpecting;
1087
1088       /* Start YYX at -YYN if negative to avoid negative indexes in
1089          YYCHECK.  */
1090       int yyxbegin = yyn < 0 ? -yyn : 0;
1091
1092       /* Stay within bounds of both yycheck and yytname.  */
1093       int yychecklim = YYLAST - yyn + 1;
1094       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1095       int yycount = 1;
1096
1097       yyarg[0] = yytname[yytype];
1098       yyfmt = yystpcpy (yyformat, yyunexpected);
1099
1100       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1101         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1102           {
1103             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1104               {
1105                 yycount = 1;
1106                 yysize = yysize0;
1107                 yyformat[sizeof yyunexpected - 1] = '\0';
1108                 break;
1109               }
1110             yyarg[yycount++] = yytname[yyx];
1111             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1112             yysize_overflow |= (yysize1 < yysize);
1113             yysize = yysize1;
1114             yyfmt = yystpcpy (yyfmt, yyprefix);
1115             yyprefix = yyor;
1116           }
1117
1118       yyf = YY_(yyformat);
1119       yysize1 = yysize + yystrlen (yyf);
1120       yysize_overflow |= (yysize1 < yysize);
1121       yysize = yysize1;
1122
1123       if (yysize_overflow)
1124         return YYSIZE_MAXIMUM;
1125
1126       if (yyresult)
1127         {
1128           /* Avoid sprintf, as that infringes on the user's name space.
1129              Don't have undefined behavior even if the translation
1130              produced a string with the wrong number of "%s"s.  */
1131           char *yyp = yyresult;
1132           int yyi = 0;
1133           while ((*yyp = *yyf) != '\0')
1134             {
1135               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1136                 {
1137                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1138                   yyf += 2;
1139                 }
1140               else
1141                 {
1142                   yyp++;
1143                   yyf++;
1144                 }
1145             }
1146         }
1147       return yysize;
1148     }
1149 }
1150 #endif /* YYERROR_VERBOSE */
1151 \f
1152
1153 /*-----------------------------------------------.
1154 | Release the memory associated to this symbol.  |
1155 `-----------------------------------------------*/
1156
1157 /*ARGSUSED*/
1158 #if (defined __STDC__ || defined __C99__FUNC__ \
1159      || defined __cplusplus || defined _MSC_VER)
1160 static void
1161 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, struct ktrfmt_parse_ctx *ctx)
1162 #else
1163 static void
1164 yydestruct (yymsg, yytype, yyvaluep, ctx)
1165     const char *yymsg;
1166     int yytype;
1167     YYSTYPE *yyvaluep;
1168     struct ktrfmt_parse_ctx *ctx;
1169 #endif
1170 {
1171   YYUSE (yyvaluep);
1172   YYUSE (ctx);
1173
1174   if (!yymsg)
1175     yymsg = "Deleting";
1176   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1177
1178   switch (yytype)
1179     {
1180
1181       default:
1182         break;
1183     }
1184 }
1185
1186 /* Prevent warnings from -Wmissing-prototypes.  */
1187 #ifdef YYPARSE_PARAM
1188 #if defined __STDC__ || defined __cplusplus
1189 int yyparse (void *YYPARSE_PARAM);
1190 #else
1191 int yyparse ();
1192 #endif
1193 #else /* ! YYPARSE_PARAM */
1194 #if defined __STDC__ || defined __cplusplus
1195 int yyparse (struct ktrfmt_parse_ctx *ctx);
1196 #else
1197 int yyparse ();
1198 #endif
1199 #endif /* ! YYPARSE_PARAM */
1200
1201
1202
1203
1204
1205 /*-------------------------.
1206 | yyparse or yypush_parse.  |
1207 `-------------------------*/
1208
1209 #ifdef YYPARSE_PARAM
1210 #if (defined __STDC__ || defined __C99__FUNC__ \
1211      || defined __cplusplus || defined _MSC_VER)
1212 int
1213 yyparse (void *YYPARSE_PARAM)
1214 #else
1215 int
1216 yyparse (YYPARSE_PARAM)
1217     void *YYPARSE_PARAM;
1218 #endif
1219 #else /* ! YYPARSE_PARAM */
1220 #if (defined __STDC__ || defined __C99__FUNC__ \
1221      || defined __cplusplus || defined _MSC_VER)
1222 int
1223 yyparse (struct ktrfmt_parse_ctx *ctx)
1224 #else
1225 int
1226 yyparse (ctx)
1227     struct ktrfmt_parse_ctx *ctx;
1228 #endif
1229 #endif
1230 {
1231 /* The lookahead symbol.  */
1232 int yychar;
1233
1234 /* The semantic value of the lookahead symbol.  */
1235 YYSTYPE yylval;
1236
1237     /* Number of syntax errors so far.  */
1238     int yynerrs;
1239
1240     int yystate;
1241     /* Number of tokens to shift before error messages enabled.  */
1242     int yyerrstatus;
1243
1244     /* The stacks and their tools:
1245        `yyss': related to states.
1246        `yyvs': related to semantic values.
1247
1248        Refer to the stacks thru separate pointers, to allow yyoverflow
1249        to reallocate them elsewhere.  */
1250
1251     /* The state stack.  */
1252     yytype_int16 yyssa[YYINITDEPTH];
1253     yytype_int16 *yyss;
1254     yytype_int16 *yyssp;
1255
1256     /* The semantic value stack.  */
1257     YYSTYPE yyvsa[YYINITDEPTH];
1258     YYSTYPE *yyvs;
1259     YYSTYPE *yyvsp;
1260
1261     YYSIZE_T yystacksize;
1262
1263   int yyn;
1264   int yyresult;
1265   /* Lookahead token as an internal (translated) token number.  */
1266   int yytoken;
1267   /* The variables used to return semantic value and location from the
1268      action routines.  */
1269   YYSTYPE yyval;
1270
1271 #if YYERROR_VERBOSE
1272   /* Buffer for error messages, and its allocated size.  */
1273   char yymsgbuf[128];
1274   char *yymsg = yymsgbuf;
1275   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1276 #endif
1277
1278 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1279
1280   /* The number of symbols on the RHS of the reduced rule.
1281      Keep to zero when no symbol should be popped.  */
1282   int yylen = 0;
1283
1284   yytoken = 0;
1285   yyss = yyssa;
1286   yyvs = yyvsa;
1287   yystacksize = YYINITDEPTH;
1288
1289   YYDPRINTF ((stderr, "Starting parse\n"));
1290
1291   yystate = 0;
1292   yyerrstatus = 0;
1293   yynerrs = 0;
1294   yychar = YYEMPTY; /* Cause a token to be read.  */
1295
1296   /* Initialize stack pointers.
1297      Waste one element of value and location stack
1298      so that they stay on the same level as the state stack.
1299      The wasted elements are never initialized.  */
1300   yyssp = yyss;
1301   yyvsp = yyvs;
1302
1303   goto yysetstate;
1304
1305 /*------------------------------------------------------------.
1306 | yynewstate -- Push a new state, which is found in yystate.  |
1307 `------------------------------------------------------------*/
1308  yynewstate:
1309   /* In all cases, when you get here, the value and location stacks
1310      have just been pushed.  So pushing a state here evens the stacks.  */
1311   yyssp++;
1312
1313  yysetstate:
1314   *yyssp = yystate;
1315
1316   if (yyss + yystacksize - 1 <= yyssp)
1317     {
1318       /* Get the current used size of the three stacks, in elements.  */
1319       YYSIZE_T yysize = yyssp - yyss + 1;
1320
1321 #ifdef yyoverflow
1322       {
1323         /* Give user a chance to reallocate the stack.  Use copies of
1324            these so that the &'s don't force the real ones into
1325            memory.  */
1326         YYSTYPE *yyvs1 = yyvs;
1327         yytype_int16 *yyss1 = yyss;
1328
1329         /* Each stack pointer address is followed by the size of the
1330            data in use in that stack, in bytes.  This used to be a
1331            conditional around just the two extra args, but that might
1332            be undefined if yyoverflow is a macro.  */
1333         yyoverflow (YY_("memory exhausted"),
1334                     &yyss1, yysize * sizeof (*yyssp),
1335                     &yyvs1, yysize * sizeof (*yyvsp),
1336                     &yystacksize);
1337
1338         yyss = yyss1;
1339         yyvs = yyvs1;
1340       }
1341 #else /* no yyoverflow */
1342 # ifndef YYSTACK_RELOCATE
1343       goto yyexhaustedlab;
1344 # else
1345       /* Extend the stack our own way.  */
1346       if (YYMAXDEPTH <= yystacksize)
1347         goto yyexhaustedlab;
1348       yystacksize *= 2;
1349       if (YYMAXDEPTH < yystacksize)
1350         yystacksize = YYMAXDEPTH;
1351
1352       {
1353         yytype_int16 *yyss1 = yyss;
1354         union yyalloc *yyptr =
1355           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1356         if (! yyptr)
1357           goto yyexhaustedlab;
1358         YYSTACK_RELOCATE (yyss_alloc, yyss);
1359         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1360 #  undef YYSTACK_RELOCATE
1361         if (yyss1 != yyssa)
1362           YYSTACK_FREE (yyss1);
1363       }
1364 # endif
1365 #endif /* no yyoverflow */
1366
1367       yyssp = yyss + yysize - 1;
1368       yyvsp = yyvs + yysize - 1;
1369
1370       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1371                   (unsigned long int) yystacksize));
1372
1373       if (yyss + yystacksize - 1 <= yyssp)
1374         YYABORT;
1375     }
1376
1377   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1378
1379   if (yystate == YYFINAL)
1380     YYACCEPT;
1381
1382   goto yybackup;
1383
1384 /*-----------.
1385 | yybackup.  |
1386 `-----------*/
1387 yybackup:
1388
1389   /* Do appropriate processing given the current state.  Read a
1390      lookahead token if we need one and don't already have one.  */
1391
1392   /* First try to decide what to do without reference to lookahead token.  */
1393   yyn = yypact[yystate];
1394   if (yyn == YYPACT_NINF)
1395     goto yydefault;
1396
1397   /* Not known => get a lookahead token if don't already have one.  */
1398
1399   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1400   if (yychar == YYEMPTY)
1401     {
1402       YYDPRINTF ((stderr, "Reading a token: "));
1403       yychar = YYLEX;
1404     }
1405
1406   if (yychar <= YYEOF)
1407     {
1408       yychar = yytoken = YYEOF;
1409       YYDPRINTF ((stderr, "Now at end of input.\n"));
1410     }
1411   else
1412     {
1413       yytoken = YYTRANSLATE (yychar);
1414       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1415     }
1416
1417   /* If the proper action on seeing token YYTOKEN is to reduce or to
1418      detect an error, take that action.  */
1419   yyn += yytoken;
1420   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1421     goto yydefault;
1422   yyn = yytable[yyn];
1423   if (yyn <= 0)
1424     {
1425       if (yyn == 0 || yyn == YYTABLE_NINF)
1426         goto yyerrlab;
1427       yyn = -yyn;
1428       goto yyreduce;
1429     }
1430
1431   /* Count tokens shifted since error; after three, turn off error
1432      status.  */
1433   if (yyerrstatus)
1434     yyerrstatus--;
1435
1436   /* Shift the lookahead token.  */
1437   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1438
1439   /* Discard the shifted token.  */
1440   yychar = YYEMPTY;
1441
1442   yystate = yyn;
1443   *++yyvsp = yylval;
1444
1445   goto yynewstate;
1446
1447
1448 /*-----------------------------------------------------------.
1449 | yydefault -- do the default action for the current state.  |
1450 `-----------------------------------------------------------*/
1451 yydefault:
1452   yyn = yydefact[yystate];
1453   if (yyn == 0)
1454     goto yyerrlab;
1455   goto yyreduce;
1456
1457
1458 /*-----------------------------.
1459 | yyreduce -- Do a reduction.  |
1460 `-----------------------------*/
1461 yyreduce:
1462   /* yyn is the number of a rule to reduce with.  */
1463   yylen = yyr2[yyn];
1464
1465   /* If YYLEN is nonzero, implement the default value of the action:
1466      `$$ = $1'.
1467
1468      Otherwise, the following line sets YYVAL to garbage.
1469      This behavior is undocumented and Bison
1470      users should not rely upon it.  Assigning to YYVAL
1471      unconditionally makes the parser a bit smaller, and it avoids a
1472      GCC warning that YYVAL may be used uninitialized.  */
1473   yyval = yyvsp[1-yylen];
1474
1475
1476   YY_REDUCE_PRINT (yyn);
1477   switch (yyn)
1478     {
1479         case 3:
1480
1481 /* Line 1455 of yacc.c  */
1482 #line 173 "ktrfmt.y"
1483     {
1484         ctx->var = (yyvsp[(1) - (1)].var);
1485  ;}
1486     break;
1487
1488   case 5:
1489
1490 /* Line 1455 of yacc.c  */
1491 #line 178 "ktrfmt.y"
1492     {
1493         evtr_var_t var;
1494         if (!(yyvsp[(1) - (1)].tok)->str)
1495                 parse_err("out of memory");
1496         var = evtr_var_new(uniq_varname());
1497         var->val.type = EVTR_VAL_INT;
1498         errno = 0;
1499         var->val.num = strtoll((yyvsp[(1) - (1)].tok)->str, NULL, 0);
1500         if (errno) {
1501                 parse_err("Can't parse numeric constant '%s'", (yyvsp[(1) - (1)].tok)->str);
1502         }
1503         (yyval.var) = var;
1504         tok_free((yyvsp[(1) - (1)].tok));
1505         ;}
1506     break;
1507
1508   case 6:
1509
1510 /* Line 1455 of yacc.c  */
1511 #line 192 "ktrfmt.y"
1512     {
1513         evtr_var_t var;
1514         if (!(yyvsp[(1) - (1)].tok)->str)
1515                 parse_err("out of memory");
1516         var = evtr_var_new(uniq_varname());
1517         var->val.type = EVTR_VAL_STR;
1518         var->val.str = (yyvsp[(1) - (1)].tok)->str;
1519         if (!var->val.str) {
1520                 parse_err("out of memory");
1521         }
1522         (yyval.var) = var;
1523         tok_free((yyvsp[(1) - (1)].tok));
1524         ;}
1525     break;
1526
1527   case 7:
1528
1529 /* Line 1455 of yacc.c  */
1530 #line 207 "ktrfmt.y"
1531     {
1532         evtr_var_t var;
1533         if (!(yyvsp[(1) - (1)].tok)->str)
1534                 parse_err("out of memory");
1535         printd(PARSE, "TOK_ID\n");
1536         printd(PARSE, "tok: %p, str = %p\n", (yyvsp[(1) - (1)].tok), (yyvsp[(1) - (1)].tok)->str);
1537         var = symtab_find(ctx->symtab, (yyvsp[(1) - (1)].tok)->str);
1538         if (!var) {
1539                 if (!(var = evtr_var_new((yyvsp[(1) - (1)].tok)->str))) {
1540                         tok_free((yyvsp[(1) - (1)].tok));
1541                         parse_err("out of memory");
1542                 }
1543                 printd(PARSE, "creating var %s\n", (yyvsp[(1) - (1)].tok)->str);
1544                 symtab_insert(ctx->symtab, (yyvsp[(1) - (1)].tok)->str, var);
1545         }
1546         (yyval.var) = var;
1547         tok_free((yyvsp[(1) - (1)].tok));
1548  ;}
1549     break;
1550
1551   case 8:
1552
1553 /* Line 1455 of yacc.c  */
1554 #line 225 "ktrfmt.y"
1555     {
1556         (yyval.var) = (yyvsp[(1) - (1)].var);
1557   ;}
1558     break;
1559
1560   case 9:
1561
1562 /* Line 1455 of yacc.c  */
1563 #line 229 "ktrfmt.y"
1564     {
1565         evtr_var_t var;
1566
1567         if (index_hash(ctx, (yyvsp[(1) - (4)].var)->name, &(yyvsp[(3) - (4)].var)->val, &var))
1568                 YYABORT;
1569         (yyval.var) = var;
1570  ;}
1571     break;
1572
1573   case 10:
1574
1575 /* Line 1455 of yacc.c  */
1576 #line 236 "ktrfmt.y"
1577     {
1578         evtr_var_t var, tmp;
1579         if (!(yyvsp[(3) - (3)].tok)->str)
1580                 parse_err("out of memory");
1581         tmp = evtr_var_new(uniq_varname());
1582         tmp->val.type = EVTR_VAL_STR;
1583         tmp->val.str = (yyvsp[(3) - (3)].tok)->str;
1584
1585         if (index_hash(ctx, (yyvsp[(1) - (3)].var)->name, &tmp->val, &var))
1586                 YYABORT;
1587         tok_free((yyvsp[(3) - (3)].tok));
1588         (yyval.var) = var;
1589  ;}
1590     break;
1591
1592   case 11:
1593
1594 /* Line 1455 of yacc.c  */
1595 #line 249 "ktrfmt.y"
1596     {
1597         (yyval.var) = (yyvsp[(1) - (1)].var);
1598  ;}
1599     break;
1600
1601   case 12:
1602
1603 /* Line 1455 of yacc.c  */
1604 #line 253 "ktrfmt.y"
1605     {
1606         (yyval.var) = (yyvsp[(1) - (1)].var);
1607  ;}
1608     break;
1609
1610   case 13:
1611
1612 /* Line 1455 of yacc.c  */
1613 #line 257 "ktrfmt.y"
1614     {
1615         (yyvsp[(1) - (3)].var)->val = (yyvsp[(3) - (3)].var)->val;
1616         ctx->ev->type = EVTR_TYPE_STMT;
1617         ctx->ev->stmt.var = (yyvsp[(1) - (3)].var);
1618         ctx->ev->stmt.val = &(yyvsp[(3) - (3)].var)->val;
1619         ctx->ev->stmt.op = EVTR_OP_SET;
1620  ;}
1621     break;
1622
1623   case 14:
1624
1625 /* Line 1455 of yacc.c  */
1626 #line 265 "ktrfmt.y"
1627     {
1628         (yyval.na) = (yyvsp[(1) - (1)].na);
1629  ;}
1630     break;
1631
1632
1633
1634 /* Line 1455 of yacc.c  */
1635 #line 1636 "ktrfmt.tab.c"
1636       default: break;
1637     }
1638   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1639
1640   YYPOPSTACK (yylen);
1641   yylen = 0;
1642   YY_STACK_PRINT (yyss, yyssp);
1643
1644   *++yyvsp = yyval;
1645
1646   /* Now `shift' the result of the reduction.  Determine what state
1647      that goes to, based on the state we popped back to and the rule
1648      number reduced by.  */
1649
1650   yyn = yyr1[yyn];
1651
1652   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1653   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1654     yystate = yytable[yystate];
1655   else
1656     yystate = yydefgoto[yyn - YYNTOKENS];
1657
1658   goto yynewstate;
1659
1660
1661 /*------------------------------------.
1662 | yyerrlab -- here on detecting error |
1663 `------------------------------------*/
1664 yyerrlab:
1665   /* If not already recovering from an error, report this error.  */
1666   if (!yyerrstatus)
1667     {
1668       ++yynerrs;
1669 #if ! YYERROR_VERBOSE
1670       yyerror (ctx, YY_("syntax error"));
1671 #else
1672       {
1673         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1674         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1675           {
1676             YYSIZE_T yyalloc = 2 * yysize;
1677             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1678               yyalloc = YYSTACK_ALLOC_MAXIMUM;
1679             if (yymsg != yymsgbuf)
1680               YYSTACK_FREE (yymsg);
1681             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1682             if (yymsg)
1683               yymsg_alloc = yyalloc;
1684             else
1685               {
1686                 yymsg = yymsgbuf;
1687                 yymsg_alloc = sizeof yymsgbuf;
1688               }
1689           }
1690
1691         if (0 < yysize && yysize <= yymsg_alloc)
1692           {
1693             (void) yysyntax_error (yymsg, yystate, yychar);
1694             yyerror (ctx, yymsg);
1695           }
1696         else
1697           {
1698             yyerror (ctx, YY_("syntax error"));
1699             if (yysize != 0)
1700               goto yyexhaustedlab;
1701           }
1702       }
1703 #endif
1704     }
1705
1706
1707
1708   if (yyerrstatus == 3)
1709     {
1710       /* If just tried and failed to reuse lookahead token after an
1711          error, discard it.  */
1712
1713       if (yychar <= YYEOF)
1714         {
1715           /* Return failure if at end of input.  */
1716           if (yychar == YYEOF)
1717             YYABORT;
1718         }
1719       else
1720         {
1721           yydestruct ("Error: discarding",
1722                       yytoken, &yylval, ctx);
1723           yychar = YYEMPTY;
1724         }
1725     }
1726
1727   /* Else will try to reuse lookahead token after shifting the error
1728      token.  */
1729   goto yyerrlab1;
1730
1731
1732 /*---------------------------------------------------.
1733 | yyerrorlab -- error raised explicitly by YYERROR.  |
1734 `---------------------------------------------------*/
1735 yyerrorlab:
1736
1737   /* Pacify compilers like GCC when the user code never invokes
1738      YYERROR and the label yyerrorlab therefore never appears in user
1739      code.  */
1740   if (/*CONSTCOND*/ 0)
1741      goto yyerrorlab;
1742
1743   /* Do not reclaim the symbols of the rule which action triggered
1744      this YYERROR.  */
1745   YYPOPSTACK (yylen);
1746   yylen = 0;
1747   YY_STACK_PRINT (yyss, yyssp);
1748   yystate = *yyssp;
1749   goto yyerrlab1;
1750
1751
1752 /*-------------------------------------------------------------.
1753 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1754 `-------------------------------------------------------------*/
1755 yyerrlab1:
1756   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1757
1758   for (;;)
1759     {
1760       yyn = yypact[yystate];
1761       if (yyn != YYPACT_NINF)
1762         {
1763           yyn += YYTERROR;
1764           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1765             {
1766               yyn = yytable[yyn];
1767               if (0 < yyn)
1768                 break;
1769             }
1770         }
1771
1772       /* Pop the current state because it cannot handle the error token.  */
1773       if (yyssp == yyss)
1774         YYABORT;
1775
1776
1777       yydestruct ("Error: popping",
1778                   yystos[yystate], yyvsp, ctx);
1779       YYPOPSTACK (1);
1780       yystate = *yyssp;
1781       YY_STACK_PRINT (yyss, yyssp);
1782     }
1783
1784   *++yyvsp = yylval;
1785
1786
1787   /* Shift the error token.  */
1788   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1789
1790   yystate = yyn;
1791   goto yynewstate;
1792
1793
1794 /*-------------------------------------.
1795 | yyacceptlab -- YYACCEPT comes here.  |
1796 `-------------------------------------*/
1797 yyacceptlab:
1798   yyresult = 0;
1799   goto yyreturn;
1800
1801 /*-----------------------------------.
1802 | yyabortlab -- YYABORT comes here.  |
1803 `-----------------------------------*/
1804 yyabortlab:
1805   yyresult = 1;
1806   goto yyreturn;
1807
1808 #if !defined(yyoverflow) || YYERROR_VERBOSE
1809 /*-------------------------------------------------.
1810 | yyexhaustedlab -- memory exhaustion comes here.  |
1811 `-------------------------------------------------*/
1812 yyexhaustedlab:
1813   yyerror (ctx, YY_("memory exhausted"));
1814   yyresult = 2;
1815   /* Fall through.  */
1816 #endif
1817
1818 yyreturn:
1819   if (yychar != YYEMPTY)
1820      yydestruct ("Cleanup: discarding lookahead",
1821                  yytoken, &yylval, ctx);
1822   /* Do not reclaim the symbols of the rule which action triggered
1823      this YYABORT or YYACCEPT.  */
1824   YYPOPSTACK (yylen);
1825   YY_STACK_PRINT (yyss, yyssp);
1826   while (yyssp != yyss)
1827     {
1828       yydestruct ("Cleanup: popping",
1829                   yystos[*yyssp], yyvsp, ctx);
1830       YYPOPSTACK (1);
1831     }
1832 #ifndef yyoverflow
1833   if (yyss != yyssa)
1834     YYSTACK_FREE (yyss);
1835 #endif
1836 #if YYERROR_VERBOSE
1837   if (yymsg != yymsgbuf)
1838     YYSTACK_FREE (yymsg);
1839 #endif
1840   /* Make sure YYID is used.  */
1841   return YYID (yyresult);
1842 }
1843
1844
1845
1846 /* Line 1675 of yacc.c  */
1847 #line 270 "ktrfmt.y"
1848
1849
1850 void * __ktrfmt_scan_string(const char *);
1851 void __ktrfmt_delete_buffer(void *);
1852
1853 void
1854 __ktrfmt_error (struct ktrfmt_parse_ctx *ctx, const char *s)
1855 {
1856         do_parse_err(ctx, s);
1857 }
1858
1859 int
1860 parse_string(evtr_event_t ev, struct symtab *symtab, const char *str,
1861              char *errbuf, size_t errbufsz)
1862 {
1863         void *bufstate;
1864         int ret;
1865         struct ktrfmt_parse_ctx ctx;
1866
1867         printd(PARSE, "parsing \"%s\"\n", str);
1868         ctx.ev = ev;
1869         ctx.symtab = symtab;
1870         ctx.errbuf = errbuf;
1871         ctx.errbuf[0] = '\0';
1872         ctx.errbufsz = errbufsz;
1873         ctx.err = 0;
1874         bufstate = __ktrfmt_scan_string(str);
1875         ret = __ktrfmt_parse(&ctx);
1876         __ktrfmt_delete_buffer(bufstate);
1877
1878         return ret;
1879 }
1880
1881 int
1882 parse_var(const char *str, struct symtab *symtab, struct evtr_variable **var,
1883           char *errbuf, size_t errbufsz)
1884 {
1885         void *bufstate;
1886         int ret;
1887         struct ktrfmt_parse_ctx ctx;
1888
1889         printd(PARSE, "parsing \"%s\"\n", str);
1890         ctx.ev = NULL;
1891         ctx.symtab = symtab;
1892         ctx.var = NULL;
1893         ctx.errbuf = errbuf;
1894         ctx.errbuf[0] = '\0';
1895         ctx.errbufsz = errbufsz;
1896         ctx.err = 0;
1897         bufstate = __ktrfmt_scan_string(str);
1898         ret = __ktrfmt_parse(&ctx);
1899         __ktrfmt_delete_buffer(bufstate);
1900
1901         *var = ctx.var;
1902         return ret;
1903 }
1904