1 /* A Bison parser, made by GNU Bison 3.7.  */
2 
3 /* Bison implementation for Yacc-like parsers in C
4 
5    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
6    Inc.
7 
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation, either version 3 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20 
21 /* As a special exception, you may create a larger work that contains
22    part or all of the Bison parser skeleton and distribute that work
23    under terms of your choice, so long as that work isn't itself a
24    parser generator using the skeleton or a modified version thereof
25    as a parser skeleton.  Alternatively, if you modify or redistribute
26    the parser skeleton itself, you may (at your option) remove this
27    special exception, which will cause the skeleton and the resulting
28    Bison output files to be licensed under the GNU General Public
29    License without this special exception.
30 
31    This special exception was added by the Free Software Foundation in
32    version 2.2 of Bison.  */
33 
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35    simplifying the original so-called "semantic" parser.  */
36 
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38    especially those whose name start with YY_ or yy_.  They are
39    private implementation details that can be changed or removed.  */
40 
41 /* All symbols defined below should begin with yy or YY, to avoid
42    infringing on user name space.  This should be done even for local
43    variables, as they might otherwise be expanded by user macros.
44    There are some unavoidable exceptions within include files to
45    define necessary library symbols; they are noted "INFRINGES ON
46    USER NAME SPACE" below.  */
47 
48 /* Identify Bison output.  */
49 #define YYBISON 1
50 
51 /* Bison version.  */
52 #define YYBISON_VERSION "3.7"
53 
54 /* Skeleton name.  */
55 #define YYSKELETON_NAME "yacc.c"
56 
57 /* Pure parsers.  */
58 #define YYPURE 0
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 
71 
72 #include <ctype.h>
73 #include <stdarg.h>
74 #include <stdio.h>
75 #include <stdlib.h>
76 #include <string.h>
77 #include <stdbool.h>
78 
79 #include "lkc.h"
80 #include "internal.h"
81 
82 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
83 
84 #define PRINTD		0x0001
85 #define DEBUG_PARSE	0x0002
86 
87 int cdebug = PRINTD;
88 
89 static void yyerror(const char *err);
90 static void zconfprint(const char *err, ...);
91 static void zconf_error(const char *err, ...);
92 static bool zconf_endtoken(const char *tokenname,
93 			   const char *expected_tokenname);
94 
95 struct symbol *symbol_hash[SYMBOL_HASHSIZE];
96 
97 struct menu *current_menu, *current_entry;
98 
99 
100 
101 # ifndef YY_CAST
102 #  ifdef __cplusplus
103 #   define YY_CAST(Type, Val) static_cast<Type> (Val)
104 #   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
105 #  else
106 #   define YY_CAST(Type, Val) ((Type) (Val))
107 #   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
108 #  endif
109 # endif
110 # ifndef YY_NULLPTR
111 #  if defined __cplusplus
112 #   if 201103L <= __cplusplus
113 #    define YY_NULLPTR nullptr
114 #   else
115 #    define YY_NULLPTR 0
116 #   endif
117 #  else
118 #   define YY_NULLPTR ((void*)0)
119 #  endif
120 # endif
121 
122 #include "parser.tab.h"
123 /* Symbol kind.  */
124 enum yysymbol_kind_t
125 {
126   YYSYMBOL_YYEMPTY = -2,
127   YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
128   YYSYMBOL_YYerror = 1,                    /* error  */
129   YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
130   YYSYMBOL_T_HELPTEXT = 3,                 /* T_HELPTEXT  */
131   YYSYMBOL_T_WORD = 4,                     /* T_WORD  */
132   YYSYMBOL_T_WORD_QUOTE = 5,               /* T_WORD_QUOTE  */
133   YYSYMBOL_T_BOOL = 6,                     /* T_BOOL  */
134   YYSYMBOL_T_CHOICE = 7,                   /* T_CHOICE  */
135   YYSYMBOL_T_CLOSE_PAREN = 8,              /* T_CLOSE_PAREN  */
136   YYSYMBOL_T_COLON_EQUAL = 9,              /* T_COLON_EQUAL  */
137   YYSYMBOL_T_COMMENT = 10,                 /* T_COMMENT  */
138   YYSYMBOL_T_CONFIG = 11,                  /* T_CONFIG  */
139   YYSYMBOL_T_DEFAULT = 12,                 /* T_DEFAULT  */
140   YYSYMBOL_T_DEF_BOOL = 13,                /* T_DEF_BOOL  */
141   YYSYMBOL_T_DEF_TRISTATE = 14,            /* T_DEF_TRISTATE  */
142   YYSYMBOL_T_DEPENDS = 15,                 /* T_DEPENDS  */
143   YYSYMBOL_T_ENDCHOICE = 16,               /* T_ENDCHOICE  */
144   YYSYMBOL_T_ENDIF = 17,                   /* T_ENDIF  */
145   YYSYMBOL_T_ENDMENU = 18,                 /* T_ENDMENU  */
146   YYSYMBOL_T_HELP = 19,                    /* T_HELP  */
147   YYSYMBOL_T_HEX = 20,                     /* T_HEX  */
148   YYSYMBOL_T_IF = 21,                      /* T_IF  */
149   YYSYMBOL_T_IMPLY = 22,                   /* T_IMPLY  */
150   YYSYMBOL_T_INT = 23,                     /* T_INT  */
151   YYSYMBOL_T_MAINMENU = 24,                /* T_MAINMENU  */
152   YYSYMBOL_T_MENU = 25,                    /* T_MENU  */
153   YYSYMBOL_T_MENUCONFIG = 26,              /* T_MENUCONFIG  */
154   YYSYMBOL_T_MODULES = 27,                 /* T_MODULES  */
155   YYSYMBOL_T_ON = 28,                      /* T_ON  */
156   YYSYMBOL_T_OPEN_PAREN = 29,              /* T_OPEN_PAREN  */
157   YYSYMBOL_T_OPTIONAL = 30,                /* T_OPTIONAL  */
158   YYSYMBOL_T_PLUS_EQUAL = 31,              /* T_PLUS_EQUAL  */
159   YYSYMBOL_T_PROMPT = 32,                  /* T_PROMPT  */
160   YYSYMBOL_T_RANGE = 33,                   /* T_RANGE  */
161   YYSYMBOL_T_SELECT = 34,                  /* T_SELECT  */
162   YYSYMBOL_T_SOURCE = 35,                  /* T_SOURCE  */
163   YYSYMBOL_T_STRING = 36,                  /* T_STRING  */
164   YYSYMBOL_T_TRISTATE = 37,                /* T_TRISTATE  */
165   YYSYMBOL_T_VISIBLE = 38,                 /* T_VISIBLE  */
166   YYSYMBOL_T_EOL = 39,                     /* T_EOL  */
167   YYSYMBOL_T_ASSIGN_VAL = 40,              /* T_ASSIGN_VAL  */
168   YYSYMBOL_T_OR = 41,                      /* T_OR  */
169   YYSYMBOL_T_AND = 42,                     /* T_AND  */
170   YYSYMBOL_T_EQUAL = 43,                   /* T_EQUAL  */
171   YYSYMBOL_T_UNEQUAL = 44,                 /* T_UNEQUAL  */
172   YYSYMBOL_T_LESS = 45,                    /* T_LESS  */
173   YYSYMBOL_T_LESS_EQUAL = 46,              /* T_LESS_EQUAL  */
174   YYSYMBOL_T_GREATER = 47,                 /* T_GREATER  */
175   YYSYMBOL_T_GREATER_EQUAL = 48,           /* T_GREATER_EQUAL  */
176   YYSYMBOL_T_NOT = 49,                     /* T_NOT  */
177   YYSYMBOL_YYACCEPT = 50,                  /* $accept  */
178   YYSYMBOL_input = 51,                     /* input  */
179   YYSYMBOL_mainmenu_stmt = 52,             /* mainmenu_stmt  */
180   YYSYMBOL_stmt_list = 53,                 /* stmt_list  */
181   YYSYMBOL_stmt_list_in_choice = 54,       /* stmt_list_in_choice  */
182   YYSYMBOL_config_entry_start = 55,        /* config_entry_start  */
183   YYSYMBOL_config_stmt = 56,               /* config_stmt  */
184   YYSYMBOL_menuconfig_entry_start = 57,    /* menuconfig_entry_start  */
185   YYSYMBOL_menuconfig_stmt = 58,           /* menuconfig_stmt  */
186   YYSYMBOL_config_option_list = 59,        /* config_option_list  */
187   YYSYMBOL_config_option = 60,             /* config_option  */
188   YYSYMBOL_choice = 61,                    /* choice  */
189   YYSYMBOL_choice_entry = 62,              /* choice_entry  */
190   YYSYMBOL_choice_end = 63,                /* choice_end  */
191   YYSYMBOL_choice_stmt = 64,               /* choice_stmt  */
192   YYSYMBOL_choice_option_list = 65,        /* choice_option_list  */
193   YYSYMBOL_choice_option = 66,             /* choice_option  */
194   YYSYMBOL_type = 67,                      /* type  */
195   YYSYMBOL_logic_type = 68,                /* logic_type  */
196   YYSYMBOL_default = 69,                   /* default  */
197   YYSYMBOL_if_entry = 70,                  /* if_entry  */
198   YYSYMBOL_if_end = 71,                    /* if_end  */
199   YYSYMBOL_if_stmt = 72,                   /* if_stmt  */
200   YYSYMBOL_if_stmt_in_choice = 73,         /* if_stmt_in_choice  */
201   YYSYMBOL_menu = 74,                      /* menu  */
202   YYSYMBOL_menu_entry = 75,                /* menu_entry  */
203   YYSYMBOL_menu_end = 76,                  /* menu_end  */
204   YYSYMBOL_menu_stmt = 77,                 /* menu_stmt  */
205   YYSYMBOL_menu_option_list = 78,          /* menu_option_list  */
206   YYSYMBOL_source_stmt = 79,               /* source_stmt  */
207   YYSYMBOL_comment = 80,                   /* comment  */
208   YYSYMBOL_comment_stmt = 81,              /* comment_stmt  */
209   YYSYMBOL_comment_option_list = 82,       /* comment_option_list  */
210   YYSYMBOL_help_start = 83,                /* help_start  */
211   YYSYMBOL_help = 84,                      /* help  */
212   YYSYMBOL_depends = 85,                   /* depends  */
213   YYSYMBOL_visible = 86,                   /* visible  */
214   YYSYMBOL_prompt_stmt_opt = 87,           /* prompt_stmt_opt  */
215   YYSYMBOL_end = 88,                       /* end  */
216   YYSYMBOL_if_expr = 89,                   /* if_expr  */
217   YYSYMBOL_expr = 90,                      /* expr  */
218   YYSYMBOL_nonconst_symbol = 91,           /* nonconst_symbol  */
219   YYSYMBOL_symbol = 92,                    /* symbol  */
220   YYSYMBOL_word_opt = 93,                  /* word_opt  */
221   YYSYMBOL_assignment_stmt = 94,           /* assignment_stmt  */
222   YYSYMBOL_assign_op = 95,                 /* assign_op  */
223   YYSYMBOL_assign_val = 96                 /* assign_val  */
224 };
225 typedef enum yysymbol_kind_t yysymbol_kind_t;
226 
227 
228 
229 
230 #ifdef short
231 # undef short
232 #endif
233 
234 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
235    <limits.h> and (if available) <stdint.h> are included
236    so that the code can choose integer types of a good width.  */
237 
238 #ifndef __PTRDIFF_MAX__
239 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
240 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
241 #  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
242 #  define YY_STDINT_H
243 # endif
244 #endif
245 
246 /* Narrow types that promote to a signed type and that can represent a
247    signed or unsigned integer of at least N bits.  In tables they can
248    save space and decrease cache pressure.  Promoting to a signed type
249    helps avoid bugs in integer arithmetic.  */
250 
251 #ifdef __INT_LEAST8_MAX__
252 typedef __INT_LEAST8_TYPE__ yytype_int8;
253 #elif defined YY_STDINT_H
254 typedef int_least8_t yytype_int8;
255 #else
256 typedef signed char yytype_int8;
257 #endif
258 
259 #ifdef __INT_LEAST16_MAX__
260 typedef __INT_LEAST16_TYPE__ yytype_int16;
261 #elif defined YY_STDINT_H
262 typedef int_least16_t yytype_int16;
263 #else
264 typedef short yytype_int16;
265 #endif
266 
267 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
268 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
269 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
270        && UINT_LEAST8_MAX <= INT_MAX)
271 typedef uint_least8_t yytype_uint8;
272 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
273 typedef unsigned char yytype_uint8;
274 #else
275 typedef short yytype_uint8;
276 #endif
277 
278 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
279 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
280 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
281        && UINT_LEAST16_MAX <= INT_MAX)
282 typedef uint_least16_t yytype_uint16;
283 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
284 typedef unsigned short yytype_uint16;
285 #else
286 typedef int yytype_uint16;
287 #endif
288 
289 #ifndef YYPTRDIFF_T
290 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
291 #  define YYPTRDIFF_T __PTRDIFF_TYPE__
292 #  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
293 # elif defined PTRDIFF_MAX
294 #  ifndef ptrdiff_t
295 #   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
296 #  endif
297 #  define YYPTRDIFF_T ptrdiff_t
298 #  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
299 # else
300 #  define YYPTRDIFF_T long
301 #  define YYPTRDIFF_MAXIMUM LONG_MAX
302 # endif
303 #endif
304 
305 #ifndef YYSIZE_T
306 # ifdef __SIZE_TYPE__
307 #  define YYSIZE_T __SIZE_TYPE__
308 # elif defined size_t
309 #  define YYSIZE_T size_t
310 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
311 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
312 #  define YYSIZE_T size_t
313 # else
314 #  define YYSIZE_T unsigned
315 # endif
316 #endif
317 
318 #define YYSIZE_MAXIMUM                                  \
319   YY_CAST (YYPTRDIFF_T,                                 \
320            (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
321             ? YYPTRDIFF_MAXIMUM                         \
322             : YY_CAST (YYSIZE_T, -1)))
323 
324 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
325 
326 
327 /* Stored state numbers (used for stacks). */
328 typedef yytype_uint8 yy_state_t;
329 
330 /* State numbers in computations.  */
331 typedef int yy_state_fast_t;
332 
333 #ifndef YY_
334 # if defined YYENABLE_NLS && YYENABLE_NLS
335 #  if ENABLE_NLS
336 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
337 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
338 #  endif
339 # endif
340 # ifndef YY_
341 #  define YY_(Msgid) Msgid
342 # endif
343 #endif
344 
345 
346 #ifndef YY_ATTRIBUTE_PURE
347 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
348 #  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
349 # else
350 #  define YY_ATTRIBUTE_PURE
351 # endif
352 #endif
353 
354 #ifndef YY_ATTRIBUTE_UNUSED
355 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
356 #  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
357 # else
358 #  define YY_ATTRIBUTE_UNUSED
359 # endif
360 #endif
361 
362 /* Suppress unused-variable warnings by "using" E.  */
363 #if ! defined lint || defined __GNUC__
364 # define YYUSE(E) ((void) (E))
365 #else
366 # define YYUSE(E) /* empty */
367 #endif
368 
369 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
370 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
371 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                            \
372     _Pragma ("GCC diagnostic push")                                     \
373     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
374     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
375 # define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
376     _Pragma ("GCC diagnostic pop")
377 #else
378 # define YY_INITIAL_VALUE(Value) Value
379 #endif
380 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
381 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
382 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
383 #endif
384 #ifndef YY_INITIAL_VALUE
385 # define YY_INITIAL_VALUE(Value) /* Nothing. */
386 #endif
387 
388 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
389 # define YY_IGNORE_USELESS_CAST_BEGIN                          \
390     _Pragma ("GCC diagnostic push")                            \
391     _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
392 # define YY_IGNORE_USELESS_CAST_END            \
393     _Pragma ("GCC diagnostic pop")
394 #endif
395 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
396 # define YY_IGNORE_USELESS_CAST_BEGIN
397 # define YY_IGNORE_USELESS_CAST_END
398 #endif
399 
400 
401 #define YY_ASSERT(E) ((void) (0 && (E)))
402 
403 #if !defined yyoverflow
404 
405 /* The parser invokes alloca or malloc; define the necessary symbols.  */
406 
407 # ifdef YYSTACK_USE_ALLOCA
408 #  if YYSTACK_USE_ALLOCA
409 #   ifdef __GNUC__
410 #    define YYSTACK_ALLOC __builtin_alloca
411 #   elif defined __BUILTIN_VA_ARG_INCR
412 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
413 #   elif defined _AIX
414 #    define YYSTACK_ALLOC __alloca
415 #   elif defined _MSC_VER
416 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
417 #    define alloca _alloca
418 #   else
419 #    define YYSTACK_ALLOC alloca
420 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
421 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
422       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
423 #     ifndef EXIT_SUCCESS
424 #      define EXIT_SUCCESS 0
425 #     endif
426 #    endif
427 #   endif
428 #  endif
429 # endif
430 
431 # ifdef YYSTACK_ALLOC
432    /* Pacify GCC's 'empty if-body' warning.  */
433 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
434 #  ifndef YYSTACK_ALLOC_MAXIMUM
435     /* The OS might guarantee only one guard page at the bottom of the stack,
436        and a page size can be as small as 4096 bytes.  So we cannot safely
437        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
438        to allow for a few compiler-allocated temporary stack slots.  */
439 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
440 #  endif
441 # else
442 #  define YYSTACK_ALLOC YYMALLOC
443 #  define YYSTACK_FREE YYFREE
444 #  ifndef YYSTACK_ALLOC_MAXIMUM
445 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
446 #  endif
447 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
448        && ! ((defined YYMALLOC || defined malloc) \
449              && (defined YYFREE || defined free)))
450 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
451 #   ifndef EXIT_SUCCESS
452 #    define EXIT_SUCCESS 0
453 #   endif
454 #  endif
455 #  ifndef YYMALLOC
456 #   define YYMALLOC malloc
457 #   if ! defined malloc && ! defined EXIT_SUCCESS
458 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
459 #   endif
460 #  endif
461 #  ifndef YYFREE
462 #   define YYFREE free
463 #   if ! defined free && ! defined EXIT_SUCCESS
464 void free (void *); /* INFRINGES ON USER NAME SPACE */
465 #   endif
466 #  endif
467 # endif
468 #endif /* !defined yyoverflow */
469 
470 #if (! defined yyoverflow \
471      && (! defined __cplusplus \
472          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
473 
474 /* A type that is properly aligned for any stack member.  */
475 union yyalloc
476 {
477   yy_state_t yyss_alloc;
478   YYSTYPE yyvs_alloc;
479 };
480 
481 /* The size of the maximum gap between one aligned stack and the next.  */
482 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
483 
484 /* The size of an array large to enough to hold all stacks, each with
485    N elements.  */
486 # define YYSTACK_BYTES(N) \
487      ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
488       + YYSTACK_GAP_MAXIMUM)
489 
490 # define YYCOPY_NEEDED 1
491 
492 /* Relocate STACK from its old location to the new one.  The
493    local variables YYSIZE and YYSTACKSIZE give the old and new number of
494    elements in the stack, and YYPTR gives the new location of the
495    stack.  Advance YYPTR to a properly aligned location for the next
496    stack.  */
497 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
498     do                                                                  \
499       {                                                                 \
500         YYPTRDIFF_T yynewbytes;                                         \
501         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
502         Stack = &yyptr->Stack_alloc;                                    \
503         yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
504         yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
505       }                                                                 \
506     while (0)
507 
508 #endif
509 
510 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
511 /* Copy COUNT objects from SRC to DST.  The source and destination do
512    not overlap.  */
513 # ifndef YYCOPY
514 #  if defined __GNUC__ && 1 < __GNUC__
515 #   define YYCOPY(Dst, Src, Count) \
516       __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
517 #  else
518 #   define YYCOPY(Dst, Src, Count)              \
519       do                                        \
520         {                                       \
521           YYPTRDIFF_T yyi;                      \
522           for (yyi = 0; yyi < (Count); yyi++)   \
523             (Dst)[yyi] = (Src)[yyi];            \
524         }                                       \
525       while (0)
526 #  endif
527 # endif
528 #endif /* !YYCOPY_NEEDED */
529 
530 /* YYFINAL -- State number of the termination state.  */
531 #define YYFINAL  6
532 /* YYLAST -- Last index in YYTABLE.  */
533 #define YYLAST   184
534 
535 /* YYNTOKENS -- Number of terminals.  */
536 #define YYNTOKENS  50
537 /* YYNNTS -- Number of nonterminals.  */
538 #define YYNNTS  47
539 /* YYNRULES -- Number of rules.  */
540 #define YYNRULES  105
541 /* YYNSTATES -- Number of states.  */
542 #define YYNSTATES  184
543 
544 /* YYMAXUTOK -- Last valid token kind.  */
545 #define YYMAXUTOK   304
546 
547 
548 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
549    as returned by yylex, with out-of-bounds checking.  */
550 #define YYTRANSLATE(YYX)                                \
551   (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
552    ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
553    : YYSYMBOL_YYUNDEF)
554 
555 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
556    as returned by yylex.  */
557 static const yytype_int8 yytranslate[] =
558 {
559        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
560        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
561        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
562        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
563        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
564        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
565        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
566        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
567        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
568        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
569        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
570        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
571        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
572        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
573        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
574        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
575        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
576        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
577        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
578        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
579        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
580        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
581        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
582        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
583        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
584        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
585        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
586       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
587       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
588       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
589       45,    46,    47,    48,    49
590 };
591 
592 #if YYDEBUG
593   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
594 static const yytype_int16 yyrline[] =
595 {
596        0,   109,   109,   109,   113,   118,   120,   121,   122,   123,
597      124,   125,   126,   127,   128,   129,   132,   134,   135,   136,
598      137,   142,   149,   154,   161,   170,   172,   173,   174,   177,
599      185,   191,   201,   207,   213,   219,   229,   239,   244,   252,
600      255,   257,   258,   259,   262,   268,   275,   281,   289,   290,
601      291,   292,   295,   296,   299,   300,   301,   305,   313,   321,
602      324,   329,   336,   341,   349,   352,   354,   355,   358,   367,
603      374,   377,   379,   384,   390,   408,   415,   422,   424,   429,
604      430,   431,   434,   435,   438,   439,   440,   441,   442,   443,
605      444,   445,   446,   447,   448,   452,   454,   455,   458,   459,
606      463,   466,   467,   468,   472,   473
607 };
608 #endif
609 
610 /** Accessing symbol of state STATE.  */
611 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
612 
613 #if YYDEBUG || 0
614 /* The user-facing name of the symbol whose (internal) number is
615    YYSYMBOL.  No bounds checking.  */
616 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
617 
618 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
619    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
620 static const char *const yytname[] =
621 {
622   "\"end of file\"", "error", "\"invalid token\"", "T_HELPTEXT", "T_WORD",
623   "T_WORD_QUOTE", "T_BOOL", "T_CHOICE", "T_CLOSE_PAREN", "T_COLON_EQUAL",
624   "T_COMMENT", "T_CONFIG", "T_DEFAULT", "T_DEF_BOOL", "T_DEF_TRISTATE",
625   "T_DEPENDS", "T_ENDCHOICE", "T_ENDIF", "T_ENDMENU", "T_HELP", "T_HEX",
626   "T_IF", "T_IMPLY", "T_INT", "T_MAINMENU", "T_MENU", "T_MENUCONFIG",
627   "T_MODULES", "T_ON", "T_OPEN_PAREN", "T_OPTIONAL", "T_PLUS_EQUAL",
628   "T_PROMPT", "T_RANGE", "T_SELECT", "T_SOURCE", "T_STRING", "T_TRISTATE",
629   "T_VISIBLE", "T_EOL", "T_ASSIGN_VAL", "T_OR", "T_AND", "T_EQUAL",
630   "T_UNEQUAL", "T_LESS", "T_LESS_EQUAL", "T_GREATER", "T_GREATER_EQUAL",
631   "T_NOT", "$accept", "input", "mainmenu_stmt", "stmt_list",
632   "stmt_list_in_choice", "config_entry_start", "config_stmt",
633   "menuconfig_entry_start", "menuconfig_stmt", "config_option_list",
634   "config_option", "choice", "choice_entry", "choice_end", "choice_stmt",
635   "choice_option_list", "choice_option", "type", "logic_type", "default",
636   "if_entry", "if_end", "if_stmt", "if_stmt_in_choice", "menu",
637   "menu_entry", "menu_end", "menu_stmt", "menu_option_list", "source_stmt",
638   "comment", "comment_stmt", "comment_option_list", "help_start", "help",
639   "depends", "visible", "prompt_stmt_opt", "end", "if_expr", "expr",
640   "nonconst_symbol", "symbol", "word_opt", "assignment_stmt", "assign_op",
641   "assign_val", YY_NULLPTR
642 };
643 
644 static const char *
yysymbol_name(yysymbol_kind_t yysymbol)645 yysymbol_name (yysymbol_kind_t yysymbol)
646 {
647   return yytname[yysymbol];
648 }
649 #endif
650 
651 #ifdef YYPRINT
652 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
653    (internal) symbol number NUM (which must be that of a token).  */
654 static const yytype_int16 yytoknum[] =
655 {
656        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
657      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
658      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
659      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
660      295,   296,   297,   298,   299,   300,   301,   302,   303,   304
661 };
662 #endif
663 
664 #define YYPACT_NINF (-65)
665 
666 #define yypact_value_is_default(Yyn) \
667   ((Yyn) == YYPACT_NINF)
668 
669 #define YYTABLE_NINF (-4)
670 
671 #define yytable_value_is_error(Yyn) \
672   0
673 
674   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
675      STATE-NUM.  */
676 static const yytype_int16 yypact[] =
677 {
678       -4,    29,    47,   -65,    17,     5,   -65,    49,     9,    14,
679       51,    56,    58,     2,    60,    58,    63,   -65,   -65,   -65,
680      -65,   -65,   -65,   -65,   -65,   -65,   -65,   -65,   -65,   -65,
681      -65,   -65,   -65,   -65,   -65,    34,   -65,   -65,   -65,    41,
682      -65,    38,    50,   -65,    52,   -65,     2,     2,    30,   -65,
683      135,    55,    57,    61,   108,   108,   131,   156,    91,    20,
684       91,    68,   -65,   -65,    67,   -65,   -65,   -65,    22,   -65,
685      -65,     2,     2,    28,    28,    28,    28,    28,    28,   -65,
686      -65,   -65,   -65,   -65,   -65,   -65,    62,    71,   -65,    58,
687      -65,    72,    83,    28,    58,   -65,   -65,   -65,    94,   -65,
688        2,   112,   -65,   -65,    58,    79,   114,   -65,    94,   -65,
689      -65,    85,    86,    90,    93,   -65,   -65,   -65,   -65,   -65,
690      -65,   -65,   -65,   113,   -65,   -65,   -65,   -65,   -65,   -65,
691      -65,    96,   -65,   -65,   -65,   -65,   -65,   -65,   -65,     2,
692      -65,   113,   -65,   113,    28,   113,   113,    97,    25,   -65,
693      113,   -65,   113,   100,   -65,   -65,   -65,   -65,   156,     2,
694      109,    37,   116,   120,   113,   121,   -65,   -65,   123,   125,
695      126,   -65,   -65,    44,   -65,   -65,   -65,   -65,   130,   -65,
696      -65,   -65,   -65,   -65
697 };
698 
699   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
700      Performed when YYTABLE does not specify something else to do.  Zero
701      means the default is an error.  */
702 static const yytype_int8 yydefact[] =
703 {
704        5,     0,     0,     5,     0,     0,     1,     0,     0,     0,
705       98,     0,     0,     0,     0,     0,     0,    25,     9,    25,
706       12,    40,    16,     7,     5,    10,    65,     5,    11,    13,
707       71,     8,     6,     4,    15,     0,   102,   103,   101,   104,
708       99,     0,     0,    95,     0,    97,     0,     0,     0,    96,
709       84,     0,     0,     0,    22,    24,    37,     0,     0,    62,
710        0,    70,    14,   105,     0,    36,    69,    21,     0,    92,
711       57,     0,     0,     0,     0,     0,     0,     0,     0,    61,
712       23,    68,    52,    54,    55,    56,     0,     0,    50,     0,
713       49,     0,     0,     0,     0,    51,    53,    26,    77,    48,
714        0,     0,    28,    27,     0,     0,     0,    41,    77,    43,
715       42,     0,     0,     0,     0,    18,    39,    16,    19,    17,
716       38,    59,    58,    82,    67,    66,    64,    63,    72,   100,
717       91,    93,    94,    89,    90,    85,    86,    87,    88,     0,
718       73,    82,    35,    82,     0,    82,    82,     0,    82,    74,
719       82,    46,    82,     0,    20,    80,    81,    79,     0,     0,
720        0,     0,     0,     0,    82,     0,    78,    29,     0,     0,
721        0,    45,    60,    83,    76,    75,    33,    30,     0,    32,
722       31,    47,    44,    34
723 };
724 
725   /* YYPGOTO[NTERM-NUM].  */
726 static const yytype_int16 yypgoto[] =
727 {
728      -65,   -65,   -65,    13,    16,   -65,   -55,   -65,   -65,   134,
729      -65,   -65,   -65,   -65,   -65,   -65,   -65,   -65,   115,   -65,
730      -54,    18,   -65,   -65,   -65,   -65,   -65,   -65,   -65,   -65,
731      -65,   -53,   -65,   -65,   119,   -20,   -65,    76,   -38,     6,
732      -46,    -7,   -64,   -65,   -65,   -65,   -65
733 };
734 
735   /* YYDEFGOTO[NTERM-NUM].  */
736 static const yytype_int16 yydefgoto[] =
737 {
738       -1,     2,     3,     4,    57,    17,    18,    19,    20,    54,
739       97,    21,    22,   116,    23,    56,   107,    98,    99,   100,
740       24,   121,    25,   118,    26,    27,   126,    28,    59,    29,
741       30,    31,    61,   101,   102,   103,   125,   147,   122,   160,
742       48,    49,    50,    41,    32,    39,    64
743 };
744 
745   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
746      positive, shift that token.  If negative, reduce the rule whose
747      number is the opposite.  If YYTABLE_NINF, syntax error.  */
748 static const yytype_int16 yytable[] =
749 {
750       68,    69,   115,   117,   119,    44,    43,    45,    52,   133,
751      134,   135,   136,   137,   138,    35,     7,    -3,     8,   120,
752        1,     9,   127,    36,    10,   131,   132,    11,    12,   144,
753      130,    46,    43,    45,     5,    86,   110,    58,    13,   124,
754       60,   128,    14,    15,    33,    37,   159,     6,    34,    -2,
755        8,    47,    16,     9,   148,    40,    10,    38,   123,    11,
756       12,    42,    43,    71,    72,    51,    71,    72,    53,    70,
757       13,    71,    72,    62,    14,    15,   175,    65,    71,    72,
758      164,    63,   141,    86,    16,    71,    72,   145,   143,    66,
759      139,    67,     8,   161,    79,     9,    80,   150,    10,   146,
760       81,    11,    12,   115,   117,   119,   129,   112,   113,   114,
761      140,   142,    13,   173,    82,   149,    14,    15,   151,   152,
762       83,    84,    85,    86,   154,   155,    16,    87,    88,   156,
763       89,    90,   157,   158,   159,    91,   167,    82,    72,   171,
764       92,    93,    94,   104,    95,    96,    86,   162,   174,   163,
765       87,   165,   166,    55,   168,   176,   169,   111,   170,   177,
766      179,   105,   180,   106,   181,   182,    11,    12,    96,   183,
767      178,   108,   112,   113,   114,   109,   172,    13,    73,    74,
768       75,    76,    77,    78,   153
769 };
770 
771 static const yytype_uint8 yycheck[] =
772 {
773       46,    47,    57,    57,    57,    12,     4,     5,    15,    73,
774       74,    75,    76,    77,    78,     1,     3,     0,     1,    57,
775       24,     4,    60,     9,     7,    71,    72,    10,    11,    93,
776        8,    29,     4,     5,     5,    15,    56,    24,    21,    59,
777       27,    61,    25,    26,    39,    31,    21,     0,    39,     0,
778        1,    49,    35,     4,   100,     4,     7,    43,    38,    10,
779       11,     5,     4,    41,    42,     5,    41,    42,     5,    39,
780       21,    41,    42,    39,    25,    26,    39,    39,    41,    42,
781      144,    40,    89,    15,    35,    41,    42,    94,     5,    39,
782       28,    39,     1,   139,    39,     4,    39,   104,     7,     5,
783       39,    10,    11,   158,   158,   158,    39,    16,    17,    18,
784       39,    39,    21,   159,     6,     3,    25,    26,    39,     5,
785       12,    13,    14,    15,    39,    39,    35,    19,    20,    39,
786       22,    23,    39,   117,    21,    27,    39,     6,    42,    39,
787       32,    33,    34,    12,    36,    37,    15,   141,    39,   143,
788       19,   145,   146,    19,   148,    39,   150,     1,   152,    39,
789       39,    30,    39,    32,    39,    39,    10,    11,    37,    39,
790      164,    56,    16,    17,    18,    56,   158,    21,    43,    44,
791       45,    46,    47,    48,   108
792 };
793 
794   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
795      symbol of state STATE-NUM.  */
796 static const yytype_int8 yystos[] =
797 {
798        0,    24,    51,    52,    53,     5,     0,    53,     1,     4,
799        7,    10,    11,    21,    25,    26,    35,    55,    56,    57,
800       58,    61,    62,    64,    70,    72,    74,    75,    77,    79,
801       80,    81,    94,    39,    39,     1,     9,    31,    43,    95,
802        4,    93,     5,     4,    91,     5,    29,    49,    90,    91,
803       92,     5,    91,     5,    59,    59,    65,    54,    53,    78,
804       53,    82,    39,    40,    96,    39,    39,    39,    90,    90,
805       39,    41,    42,    43,    44,    45,    46,    47,    48,    39,
806       39,    39,     6,    12,    13,    14,    15,    19,    20,    22,
807       23,    27,    32,    33,    34,    36,    37,    60,    67,    68,
808       69,    83,    84,    85,    12,    30,    32,    66,    68,    84,
809       85,     1,    16,    17,    18,    56,    63,    70,    73,    81,
810       88,    71,    88,    38,    85,    86,    76,    88,    85,    39,
811        8,    90,    90,    92,    92,    92,    92,    92,    92,    28,
812       39,    91,    39,     5,    92,    91,     5,    87,    90,     3,
813       91,    39,     5,    87,    39,    39,    39,    39,    54,    21,
814       89,    90,    89,    89,    92,    89,    89,    39,    89,    89,
815       89,    39,    71,    90,    39,    39,    39,    39,    89,    39,
816       39,    39,    39,    39
817 };
818 
819   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
820 static const yytype_int8 yyr1[] =
821 {
822        0,    50,    51,    51,    52,    53,    53,    53,    53,    53,
823       53,    53,    53,    53,    53,    53,    54,    54,    54,    54,
824       54,    55,    56,    57,    58,    59,    59,    59,    59,    60,
825       60,    60,    60,    60,    60,    60,    61,    62,    63,    64,
826       65,    65,    65,    65,    66,    66,    66,    66,    67,    67,
827       67,    67,    68,    68,    69,    69,    69,    70,    71,    72,
828       73,    74,    75,    76,    77,    78,    78,    78,    79,    80,
829       81,    82,    82,    83,    84,    85,    86,    87,    87,    88,
830       88,    88,    89,    89,    90,    90,    90,    90,    90,    90,
831       90,    90,    90,    90,    90,    91,    92,    92,    93,    93,
832       94,    95,    95,    95,    96,    96
833 };
834 
835   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
836 static const yytype_int8 yyr2[] =
837 {
838        0,     2,     2,     1,     3,     0,     2,     2,     2,     2,
839        2,     2,     2,     2,     4,     3,     0,     2,     2,     2,
840        3,     3,     2,     3,     2,     0,     2,     2,     2,     3,
841        4,     4,     4,     4,     5,     2,     3,     2,     1,     3,
842        0,     2,     2,     2,     4,     3,     2,     4,     1,     1,
843        1,     1,     1,     1,     1,     1,     1,     3,     1,     3,
844        3,     3,     2,     1,     3,     0,     2,     2,     3,     3,
845        2,     0,     2,     2,     2,     4,     3,     0,     2,     2,
846        2,     2,     0,     2,     1,     3,     3,     3,     3,     3,
847        3,     3,     2,     3,     3,     1,     1,     1,     0,     1,
848        4,     1,     1,     1,     0,     1
849 };
850 
851 
852 enum { YYENOMEM = -2 };
853 
854 #define yyerrok         (yyerrstatus = 0)
855 #define yyclearin       (yychar = YYEMPTY)
856 
857 #define YYACCEPT        goto yyacceptlab
858 #define YYABORT         goto yyabortlab
859 #define YYERROR         goto yyerrorlab
860 
861 
862 #define YYRECOVERING()  (!!yyerrstatus)
863 
864 #define YYBACKUP(Token, Value)                                    \
865   do                                                              \
866     if (yychar == YYEMPTY)                                        \
867       {                                                           \
868         yychar = (Token);                                         \
869         yylval = (Value);                                         \
870         YYPOPSTACK (yylen);                                       \
871         yystate = *yyssp;                                         \
872         goto yybackup;                                            \
873       }                                                           \
874     else                                                          \
875       {                                                           \
876         yyerror (YY_("syntax error: cannot back up")); \
877         YYERROR;                                                  \
878       }                                                           \
879   while (0)
880 
881 /* Backward compatibility with an undocumented macro.
882    Use YYerror or YYUNDEF. */
883 #define YYERRCODE YYUNDEF
884 
885 
886 /* Enable debugging if requested.  */
887 #if YYDEBUG
888 
889 # ifndef YYFPRINTF
890 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
891 #  define YYFPRINTF fprintf
892 # endif
893 
894 # define YYDPRINTF(Args)                        \
895 do {                                            \
896   if (yydebug)                                  \
897     YYFPRINTF Args;                             \
898 } while (0)
899 
900 /* This macro is provided for backward compatibility. */
901 # ifndef YY_LOCATION_PRINT
902 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
903 # endif
904 
905 
906 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
907 do {                                                                      \
908   if (yydebug)                                                            \
909     {                                                                     \
910       YYFPRINTF (stderr, "%s ", Title);                                   \
911       yy_symbol_print (stderr,                                            \
912                   Kind, Value); \
913       YYFPRINTF (stderr, "\n");                                           \
914     }                                                                     \
915 } while (0)
916 
917 
918 /*-----------------------------------.
919 | Print this symbol's value on YYO.  |
920 `-----------------------------------*/
921 
922 static void
yy_symbol_value_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)923 yy_symbol_value_print (FILE *yyo,
924                        yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
925 {
926   FILE *yyoutput = yyo;
927   YYUSE (yyoutput);
928   if (!yyvaluep)
929     return;
930 # ifdef YYPRINT
931   if (yykind < YYNTOKENS)
932     YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
933 # endif
934   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
935   YYUSE (yykind);
936   YY_IGNORE_MAYBE_UNINITIALIZED_END
937 }
938 
939 
940 /*---------------------------.
941 | Print this symbol on YYO.  |
942 `---------------------------*/
943 
944 static void
yy_symbol_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)945 yy_symbol_print (FILE *yyo,
946                  yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
947 {
948   YYFPRINTF (yyo, "%s %s (",
949              yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
950 
951   yy_symbol_value_print (yyo, yykind, yyvaluep);
952   YYFPRINTF (yyo, ")");
953 }
954 
955 /*------------------------------------------------------------------.
956 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
957 | TOP (included).                                                   |
958 `------------------------------------------------------------------*/
959 
960 static void
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)961 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
962 {
963   YYFPRINTF (stderr, "Stack now");
964   for (; yybottom <= yytop; yybottom++)
965     {
966       int yybot = *yybottom;
967       YYFPRINTF (stderr, " %d", yybot);
968     }
969   YYFPRINTF (stderr, "\n");
970 }
971 
972 # define YY_STACK_PRINT(Bottom, Top)                            \
973 do {                                                            \
974   if (yydebug)                                                  \
975     yy_stack_print ((Bottom), (Top));                           \
976 } while (0)
977 
978 
979 /*------------------------------------------------.
980 | Report that the YYRULE is going to be reduced.  |
981 `------------------------------------------------*/
982 
983 static void
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,int yyrule)984 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
985                  int yyrule)
986 {
987   int yylno = yyrline[yyrule];
988   int yynrhs = yyr2[yyrule];
989   int yyi;
990   YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
991              yyrule - 1, yylno);
992   /* The symbols being reduced.  */
993   for (yyi = 0; yyi < yynrhs; yyi++)
994     {
995       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
996       yy_symbol_print (stderr,
997                        YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
998                        &yyvsp[(yyi + 1) - (yynrhs)]);
999       YYFPRINTF (stderr, "\n");
1000     }
1001 }
1002 
1003 # define YY_REDUCE_PRINT(Rule)          \
1004 do {                                    \
1005   if (yydebug)                          \
1006     yy_reduce_print (yyssp, yyvsp, Rule); \
1007 } while (0)
1008 
1009 /* Nonzero means print parse trace.  It is left uninitialized so that
1010    multiple parsers can coexist.  */
1011 int yydebug;
1012 #else /* !YYDEBUG */
1013 # define YYDPRINTF(Args) ((void) 0)
1014 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1015 # define YY_STACK_PRINT(Bottom, Top)
1016 # define YY_REDUCE_PRINT(Rule)
1017 #endif /* !YYDEBUG */
1018 
1019 
1020 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1021 #ifndef YYINITDEPTH
1022 # define YYINITDEPTH 200
1023 #endif
1024 
1025 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1026    if the built-in stack extension method is used).
1027 
1028    Do not make this value too large; the results are undefined if
1029    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1030    evaluated with infinite-precision integer arithmetic.  */
1031 
1032 #ifndef YYMAXDEPTH
1033 # define YYMAXDEPTH 10000
1034 #endif
1035 
1036 
1037 
1038 
1039 
1040 
1041 /*-----------------------------------------------.
1042 | Release the memory associated to this symbol.  |
1043 `-----------------------------------------------*/
1044 
1045 static void
yydestruct(const char * yymsg,yysymbol_kind_t yykind,YYSTYPE * yyvaluep)1046 yydestruct (const char *yymsg,
1047             yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
1048 {
1049   YYUSE (yyvaluep);
1050   if (!yymsg)
1051     yymsg = "Deleting";
1052   YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1053 
1054   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1055   switch (yykind)
1056     {
1057     case YYSYMBOL_choice_entry: /* choice_entry  */
1058             {
1059 	fprintf(stderr, "%s:%d: missing end statement for this entry\n",
1060 		((*yyvaluep).menu)->file->name, ((*yyvaluep).menu)->lineno);
1061 	if (current_menu == ((*yyvaluep).menu))
1062 		menu_end_menu();
1063 }
1064         break;
1065 
1066     case YYSYMBOL_if_entry: /* if_entry  */
1067             {
1068 	fprintf(stderr, "%s:%d: missing end statement for this entry\n",
1069 		((*yyvaluep).menu)->file->name, ((*yyvaluep).menu)->lineno);
1070 	if (current_menu == ((*yyvaluep).menu))
1071 		menu_end_menu();
1072 }
1073         break;
1074 
1075     case YYSYMBOL_menu_entry: /* menu_entry  */
1076             {
1077 	fprintf(stderr, "%s:%d: missing end statement for this entry\n",
1078 		((*yyvaluep).menu)->file->name, ((*yyvaluep).menu)->lineno);
1079 	if (current_menu == ((*yyvaluep).menu))
1080 		menu_end_menu();
1081 }
1082         break;
1083 
1084       default:
1085         break;
1086     }
1087   YY_IGNORE_MAYBE_UNINITIALIZED_END
1088 }
1089 
1090 
1091 /* Lookahead token kind.  */
1092 int yychar;
1093 
1094 /* The semantic value of the lookahead symbol.  */
1095 YYSTYPE yylval;
1096 /* Number of syntax errors so far.  */
1097 int yynerrs;
1098 
1099 
1100 
1101 
1102 /*----------.
1103 | yyparse.  |
1104 `----------*/
1105 
1106 int
yyparse(void)1107 yyparse (void)
1108 {
1109     yy_state_fast_t yystate = 0;
1110     /* Number of tokens to shift before error messages enabled.  */
1111     int yyerrstatus = 0;
1112 
1113     /* Refer to the stacks through separate pointers, to allow yyoverflow
1114        to reallocate them elsewhere.  */
1115 
1116     /* Their size.  */
1117     YYPTRDIFF_T yystacksize = YYINITDEPTH;
1118 
1119     /* The state stack: array, bottom, top.  */
1120     yy_state_t yyssa[YYINITDEPTH];
1121     yy_state_t *yyss = yyssa;
1122     yy_state_t *yyssp = yyss;
1123 
1124     /* The semantic value stack: array, bottom, top.  */
1125     YYSTYPE yyvsa[YYINITDEPTH];
1126     YYSTYPE *yyvs = yyvsa;
1127     YYSTYPE *yyvsp = yyvs;
1128 
1129   int yyn;
1130   /* The return value of yyparse.  */
1131   int yyresult;
1132   /* Lookahead symbol kind.  */
1133   yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1134   /* The variables used to return semantic value and location from the
1135      action routines.  */
1136   YYSTYPE yyval;
1137 
1138 
1139 
1140 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1141 
1142   /* The number of symbols on the RHS of the reduced rule.
1143      Keep to zero when no symbol should be popped.  */
1144   int yylen = 0;
1145 
1146   YYDPRINTF ((stderr, "Starting parse\n"));
1147 
1148   yychar = YYEMPTY; /* Cause a token to be read.  */
1149   goto yysetstate;
1150 
1151 
1152 /*------------------------------------------------------------.
1153 | yynewstate -- push a new state, which is found in yystate.  |
1154 `------------------------------------------------------------*/
1155 yynewstate:
1156   /* In all cases, when you get here, the value and location stacks
1157      have just been pushed.  So pushing a state here evens the stacks.  */
1158   yyssp++;
1159 
1160 
1161 /*--------------------------------------------------------------------.
1162 | yysetstate -- set current state (the top of the stack) to yystate.  |
1163 `--------------------------------------------------------------------*/
1164 yysetstate:
1165   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1166   YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1167   YY_IGNORE_USELESS_CAST_BEGIN
1168   *yyssp = YY_CAST (yy_state_t, yystate);
1169   YY_IGNORE_USELESS_CAST_END
1170   YY_STACK_PRINT (yyss, yyssp);
1171 
1172   if (yyss + yystacksize - 1 <= yyssp)
1173 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1174     goto yyexhaustedlab;
1175 #else
1176     {
1177       /* Get the current used size of the three stacks, in elements.  */
1178       YYPTRDIFF_T yysize = yyssp - yyss + 1;
1179 
1180 # if defined yyoverflow
1181       {
1182         /* Give user a chance to reallocate the stack.  Use copies of
1183            these so that the &'s don't force the real ones into
1184            memory.  */
1185         yy_state_t *yyss1 = yyss;
1186         YYSTYPE *yyvs1 = yyvs;
1187 
1188         /* Each stack pointer address is followed by the size of the
1189            data in use in that stack, in bytes.  This used to be a
1190            conditional around just the two extra args, but that might
1191            be undefined if yyoverflow is a macro.  */
1192         yyoverflow (YY_("memory exhausted"),
1193                     &yyss1, yysize * YYSIZEOF (*yyssp),
1194                     &yyvs1, yysize * YYSIZEOF (*yyvsp),
1195                     &yystacksize);
1196         yyss = yyss1;
1197         yyvs = yyvs1;
1198       }
1199 # else /* defined YYSTACK_RELOCATE */
1200       /* Extend the stack our own way.  */
1201       if (YYMAXDEPTH <= yystacksize)
1202         goto yyexhaustedlab;
1203       yystacksize *= 2;
1204       if (YYMAXDEPTH < yystacksize)
1205         yystacksize = YYMAXDEPTH;
1206 
1207       {
1208         yy_state_t *yyss1 = yyss;
1209         union yyalloc *yyptr =
1210           YY_CAST (union yyalloc *,
1211                    YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1212         if (! yyptr)
1213           goto yyexhaustedlab;
1214         YYSTACK_RELOCATE (yyss_alloc, yyss);
1215         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1216 #  undef YYSTACK_RELOCATE
1217         if (yyss1 != yyssa)
1218           YYSTACK_FREE (yyss1);
1219       }
1220 # endif
1221 
1222       yyssp = yyss + yysize - 1;
1223       yyvsp = yyvs + yysize - 1;
1224 
1225       YY_IGNORE_USELESS_CAST_BEGIN
1226       YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1227                   YY_CAST (long, yystacksize)));
1228       YY_IGNORE_USELESS_CAST_END
1229 
1230       if (yyss + yystacksize - 1 <= yyssp)
1231         YYABORT;
1232     }
1233 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1234 
1235   if (yystate == YYFINAL)
1236     YYACCEPT;
1237 
1238   goto yybackup;
1239 
1240 
1241 /*-----------.
1242 | yybackup.  |
1243 `-----------*/
1244 yybackup:
1245   /* Do appropriate processing given the current state.  Read a
1246      lookahead token if we need one and don't already have one.  */
1247 
1248   /* First try to decide what to do without reference to lookahead token.  */
1249   yyn = yypact[yystate];
1250   if (yypact_value_is_default (yyn))
1251     goto yydefault;
1252 
1253   /* Not known => get a lookahead token if don't already have one.  */
1254 
1255   /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
1256   if (yychar == YYEMPTY)
1257     {
1258       YYDPRINTF ((stderr, "Reading a token\n"));
1259       yychar = yylex ();
1260     }
1261 
1262   if (yychar <= YYEOF)
1263     {
1264       yychar = YYEOF;
1265       yytoken = YYSYMBOL_YYEOF;
1266       YYDPRINTF ((stderr, "Now at end of input.\n"));
1267     }
1268   else if (yychar == YYerror)
1269     {
1270       /* The scanner already issued an error message, process directly
1271          to error recovery.  But do not keep the error token as
1272          lookahead, it is too special and may lead us to an endless
1273          loop in error recovery. */
1274       yychar = YYUNDEF;
1275       yytoken = YYSYMBOL_YYerror;
1276       goto yyerrlab1;
1277     }
1278   else
1279     {
1280       yytoken = YYTRANSLATE (yychar);
1281       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1282     }
1283 
1284   /* If the proper action on seeing token YYTOKEN is to reduce or to
1285      detect an error, take that action.  */
1286   yyn += yytoken;
1287   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1288     goto yydefault;
1289   yyn = yytable[yyn];
1290   if (yyn <= 0)
1291     {
1292       if (yytable_value_is_error (yyn))
1293         goto yyerrlab;
1294       yyn = -yyn;
1295       goto yyreduce;
1296     }
1297 
1298   /* Count tokens shifted since error; after three, turn off error
1299      status.  */
1300   if (yyerrstatus)
1301     yyerrstatus--;
1302 
1303   /* Shift the lookahead token.  */
1304   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1305   yystate = yyn;
1306   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1307   *++yyvsp = yylval;
1308   YY_IGNORE_MAYBE_UNINITIALIZED_END
1309 
1310   /* Discard the shifted token.  */
1311   yychar = YYEMPTY;
1312   goto yynewstate;
1313 
1314 
1315 /*-----------------------------------------------------------.
1316 | yydefault -- do the default action for the current state.  |
1317 `-----------------------------------------------------------*/
1318 yydefault:
1319   yyn = yydefact[yystate];
1320   if (yyn == 0)
1321     goto yyerrlab;
1322   goto yyreduce;
1323 
1324 
1325 /*-----------------------------.
1326 | yyreduce -- do a reduction.  |
1327 `-----------------------------*/
1328 yyreduce:
1329   /* yyn is the number of a rule to reduce with.  */
1330   yylen = yyr2[yyn];
1331 
1332   /* If YYLEN is nonzero, implement the default value of the action:
1333      '$$ = $1'.
1334 
1335      Otherwise, the following line sets YYVAL to garbage.
1336      This behavior is undocumented and Bison
1337      users should not rely upon it.  Assigning to YYVAL
1338      unconditionally makes the parser a bit smaller, and it avoids a
1339      GCC warning that YYVAL may be used uninitialized.  */
1340   yyval = yyvsp[1-yylen];
1341 
1342 
1343   YY_REDUCE_PRINT (yyn);
1344   switch (yyn)
1345     {
1346   case 4: /* mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL  */
1347 {
1348 	menu_add_prompt(P_MENU, (yyvsp[-1].string), NULL);
1349 }
1350     break;
1351 
1352   case 14: /* stmt_list: stmt_list T_WORD error T_EOL  */
1353                                         { zconf_error("unknown statement \"%s\"", (yyvsp[-2].string)); }
1354     break;
1355 
1356   case 15: /* stmt_list: stmt_list error T_EOL  */
1357                                         { zconf_error("invalid statement"); }
1358     break;
1359 
1360   case 20: /* stmt_list_in_choice: stmt_list_in_choice error T_EOL  */
1361                                                 { zconf_error("invalid statement"); }
1362     break;
1363 
1364   case 21: /* config_entry_start: T_CONFIG nonconst_symbol T_EOL  */
1365 {
1366 	(yyvsp[-1].symbol)->flags |= SYMBOL_OPTIONAL;
1367 	menu_add_entry((yyvsp[-1].symbol));
1368 	printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), (yyvsp[-1].symbol)->name);
1369 }
1370     break;
1371 
1372   case 22: /* config_stmt: config_entry_start config_option_list  */
1373 {
1374 	printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
1375 }
1376     break;
1377 
1378   case 23: /* menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL  */
1379 {
1380 	(yyvsp[-1].symbol)->flags |= SYMBOL_OPTIONAL;
1381 	menu_add_entry((yyvsp[-1].symbol));
1382 	printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), (yyvsp[-1].symbol)->name);
1383 }
1384     break;
1385 
1386   case 24: /* menuconfig_stmt: menuconfig_entry_start config_option_list  */
1387 {
1388 	if (current_entry->prompt)
1389 		current_entry->prompt->type = P_MENU;
1390 	else
1391 		zconfprint("warning: menuconfig statement without prompt");
1392 	printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
1393 }
1394     break;
1395 
1396   case 29: /* config_option: type prompt_stmt_opt T_EOL  */
1397 {
1398 	menu_set_type((yyvsp[-2].type));
1399 	printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
1400 		zconf_curname(), zconf_lineno(),
1401 		(yyvsp[-2].type));
1402 }
1403     break;
1404 
1405   case 30: /* config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL  */
1406 {
1407 	menu_add_prompt(P_PROMPT, (yyvsp[-2].string), (yyvsp[-1].expr));
1408 	printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
1409 }
1410     break;
1411 
1412   case 31: /* config_option: default expr if_expr T_EOL  */
1413 {
1414 	menu_add_expr(P_DEFAULT, (yyvsp[-2].expr), (yyvsp[-1].expr));
1415 	if ((yyvsp[-3].type) != S_UNKNOWN)
1416 		menu_set_type((yyvsp[-3].type));
1417 	printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
1418 		zconf_curname(), zconf_lineno(),
1419 		(yyvsp[-3].type));
1420 }
1421     break;
1422 
1423   case 32: /* config_option: T_SELECT nonconst_symbol if_expr T_EOL  */
1424 {
1425 	menu_add_symbol(P_SELECT, (yyvsp[-2].symbol), (yyvsp[-1].expr));
1426 	printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
1427 }
1428     break;
1429 
1430   case 33: /* config_option: T_IMPLY nonconst_symbol if_expr T_EOL  */
1431 {
1432 	menu_add_symbol(P_IMPLY, (yyvsp[-2].symbol), (yyvsp[-1].expr));
1433 	printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
1434 }
1435     break;
1436 
1437   case 34: /* config_option: T_RANGE symbol symbol if_expr T_EOL  */
1438 {
1439 	menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,(yyvsp[-3].symbol), (yyvsp[-2].symbol)), (yyvsp[-1].expr));
1440 	printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
1441 }
1442     break;
1443 
1444   case 35: /* config_option: T_MODULES T_EOL  */
1445 {
1446 	if (modules_sym)
1447 		zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
1448 			    current_entry->sym->name, modules_sym->name);
1449 	modules_sym = current_entry->sym;
1450 }
1451     break;
1452 
1453   case 36: /* choice: T_CHOICE word_opt T_EOL  */
1454 {
1455 	struct symbol *sym = sym_lookup((yyvsp[-1].string), SYMBOL_CHOICE);
1456 	sym->flags |= SYMBOL_NO_WRITE;
1457 	menu_add_entry(sym);
1458 	menu_add_expr(P_CHOICE, NULL, NULL);
1459 	free((yyvsp[-1].string));
1460 	printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
1461 }
1462     break;
1463 
1464   case 37: /* choice_entry: choice choice_option_list  */
1465 {
1466 	(yyval.menu) = menu_add_menu();
1467 }
1468     break;
1469 
1470   case 38: /* choice_end: end  */
1471 {
1472 	if (zconf_endtoken((yyvsp[0].string), "choice")) {
1473 		menu_end_menu();
1474 		printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
1475 	}
1476 }
1477     break;
1478 
1479   case 44: /* choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL  */
1480 {
1481 	menu_add_prompt(P_PROMPT, (yyvsp[-2].string), (yyvsp[-1].expr));
1482 	printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
1483 }
1484     break;
1485 
1486   case 45: /* choice_option: logic_type prompt_stmt_opt T_EOL  */
1487 {
1488 	menu_set_type((yyvsp[-2].type));
1489 	printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
1490 	       zconf_curname(), zconf_lineno(), (yyvsp[-2].type));
1491 }
1492     break;
1493 
1494   case 46: /* choice_option: T_OPTIONAL T_EOL  */
1495 {
1496 	current_entry->sym->flags |= SYMBOL_OPTIONAL;
1497 	printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
1498 }
1499     break;
1500 
1501   case 47: /* choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL  */
1502 {
1503 	menu_add_symbol(P_DEFAULT, (yyvsp[-2].symbol), (yyvsp[-1].expr));
1504 	printd(DEBUG_PARSE, "%s:%d:default\n",
1505 	       zconf_curname(), zconf_lineno());
1506 }
1507     break;
1508 
1509   case 49: /* type: T_INT  */
1510                                 { (yyval.type) = S_INT; }
1511     break;
1512 
1513   case 50: /* type: T_HEX  */
1514                                 { (yyval.type) = S_HEX; }
1515     break;
1516 
1517   case 51: /* type: T_STRING  */
1518                                 { (yyval.type) = S_STRING; }
1519     break;
1520 
1521   case 52: /* logic_type: T_BOOL  */
1522                                 { (yyval.type) = S_BOOLEAN; }
1523     break;
1524 
1525   case 53: /* logic_type: T_TRISTATE  */
1526                                 { (yyval.type) = S_TRISTATE; }
1527     break;
1528 
1529   case 54: /* default: T_DEFAULT  */
1530                                 { (yyval.type) = S_UNKNOWN; }
1531     break;
1532 
1533   case 55: /* default: T_DEF_BOOL  */
1534                                 { (yyval.type) = S_BOOLEAN; }
1535     break;
1536 
1537   case 56: /* default: T_DEF_TRISTATE  */
1538                                 { (yyval.type) = S_TRISTATE; }
1539     break;
1540 
1541   case 57: /* if_entry: T_IF expr T_EOL  */
1542 {
1543 	printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
1544 	menu_add_entry(NULL);
1545 	menu_add_dep((yyvsp[-1].expr));
1546 	(yyval.menu) = menu_add_menu();
1547 }
1548     break;
1549 
1550   case 58: /* if_end: end  */
1551 {
1552 	if (zconf_endtoken((yyvsp[0].string), "if")) {
1553 		menu_end_menu();
1554 		printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
1555 	}
1556 }
1557     break;
1558 
1559   case 61: /* menu: T_MENU T_WORD_QUOTE T_EOL  */
1560 {
1561 	menu_add_entry(NULL);
1562 	menu_add_prompt(P_MENU, (yyvsp[-1].string), NULL);
1563 	printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
1564 }
1565     break;
1566 
1567   case 62: /* menu_entry: menu menu_option_list  */
1568 {
1569 	(yyval.menu) = menu_add_menu();
1570 }
1571     break;
1572 
1573   case 63: /* menu_end: end  */
1574 {
1575 	if (zconf_endtoken((yyvsp[0].string), "menu")) {
1576 		menu_end_menu();
1577 		printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
1578 	}
1579 }
1580     break;
1581 
1582   case 68: /* source_stmt: T_SOURCE T_WORD_QUOTE T_EOL  */
1583 {
1584 	printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), (yyvsp[-1].string));
1585 	zconf_nextfile((yyvsp[-1].string));
1586 	free((yyvsp[-1].string));
1587 }
1588     break;
1589 
1590   case 69: /* comment: T_COMMENT T_WORD_QUOTE T_EOL  */
1591 {
1592 	menu_add_entry(NULL);
1593 	menu_add_prompt(P_COMMENT, (yyvsp[-1].string), NULL);
1594 	printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
1595 }
1596     break;
1597 
1598   case 73: /* help_start: T_HELP T_EOL  */
1599 {
1600 	printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
1601 	zconf_starthelp();
1602 }
1603     break;
1604 
1605   case 74: /* help: help_start T_HELPTEXT  */
1606 {
1607 	if (current_entry->help) {
1608 		free(current_entry->help);
1609 		zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
1610 			   current_entry->sym->name ?: "<choice>");
1611 	}
1612 
1613 	/* Is the help text empty or all whitespace? */
1614 	if ((yyvsp[0].string)[strspn((yyvsp[0].string), " \f\n\r\t\v")] == '\0')
1615 		zconfprint("warning: '%s' defined with blank help text",
1616 			   current_entry->sym->name ?: "<choice>");
1617 
1618 	current_entry->help = (yyvsp[0].string);
1619 }
1620     break;
1621 
1622   case 75: /* depends: T_DEPENDS T_ON expr T_EOL  */
1623 {
1624 	menu_add_dep((yyvsp[-1].expr));
1625 	printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
1626 }
1627     break;
1628 
1629   case 76: /* visible: T_VISIBLE if_expr T_EOL  */
1630 {
1631 	menu_add_visibility((yyvsp[-1].expr));
1632 }
1633     break;
1634 
1635   case 78: /* prompt_stmt_opt: T_WORD_QUOTE if_expr  */
1636 {
1637 	menu_add_prompt(P_PROMPT, (yyvsp[-1].string), (yyvsp[0].expr));
1638 }
1639     break;
1640 
1641   case 79: /* end: T_ENDMENU T_EOL  */
1642                                 { (yyval.string) = "menu"; }
1643     break;
1644 
1645   case 80: /* end: T_ENDCHOICE T_EOL  */
1646                                 { (yyval.string) = "choice"; }
1647     break;
1648 
1649   case 81: /* end: T_ENDIF T_EOL  */
1650                                 { (yyval.string) = "if"; }
1651     break;
1652 
1653   case 82: /* if_expr: %empty  */
1654                                         { (yyval.expr) = NULL; }
1655     break;
1656 
1657   case 83: /* if_expr: T_IF expr  */
1658                                         { (yyval.expr) = (yyvsp[0].expr); }
1659     break;
1660 
1661   case 84: /* expr: symbol  */
1662                                                 { (yyval.expr) = expr_alloc_symbol((yyvsp[0].symbol)); }
1663     break;
1664 
1665   case 85: /* expr: symbol T_LESS symbol  */
1666                                                 { (yyval.expr) = expr_alloc_comp(E_LTH, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1667     break;
1668 
1669   case 86: /* expr: symbol T_LESS_EQUAL symbol  */
1670                                                 { (yyval.expr) = expr_alloc_comp(E_LEQ, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1671     break;
1672 
1673   case 87: /* expr: symbol T_GREATER symbol  */
1674                                                 { (yyval.expr) = expr_alloc_comp(E_GTH, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1675     break;
1676 
1677   case 88: /* expr: symbol T_GREATER_EQUAL symbol  */
1678                                                 { (yyval.expr) = expr_alloc_comp(E_GEQ, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1679     break;
1680 
1681   case 89: /* expr: symbol T_EQUAL symbol  */
1682                                                 { (yyval.expr) = expr_alloc_comp(E_EQUAL, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1683     break;
1684 
1685   case 90: /* expr: symbol T_UNEQUAL symbol  */
1686                                                 { (yyval.expr) = expr_alloc_comp(E_UNEQUAL, (yyvsp[-2].symbol), (yyvsp[0].symbol)); }
1687     break;
1688 
1689   case 91: /* expr: T_OPEN_PAREN expr T_CLOSE_PAREN  */
1690                                                 { (yyval.expr) = (yyvsp[-1].expr); }
1691     break;
1692 
1693   case 92: /* expr: T_NOT expr  */
1694                                                 { (yyval.expr) = expr_alloc_one(E_NOT, (yyvsp[0].expr)); }
1695     break;
1696 
1697   case 93: /* expr: expr T_OR expr  */
1698                                                 { (yyval.expr) = expr_alloc_two(E_OR, (yyvsp[-2].expr), (yyvsp[0].expr)); }
1699     break;
1700 
1701   case 94: /* expr: expr T_AND expr  */
1702                                                 { (yyval.expr) = expr_alloc_two(E_AND, (yyvsp[-2].expr), (yyvsp[0].expr)); }
1703     break;
1704 
1705   case 95: /* nonconst_symbol: T_WORD  */
1706                         { (yyval.symbol) = sym_lookup((yyvsp[0].string), 0); free((yyvsp[0].string)); }
1707     break;
1708 
1709   case 97: /* symbol: T_WORD_QUOTE  */
1710                         { (yyval.symbol) = sym_lookup((yyvsp[0].string), SYMBOL_CONST); free((yyvsp[0].string)); }
1711     break;
1712 
1713   case 98: /* word_opt: %empty  */
1714                                         { (yyval.string) = NULL; }
1715     break;
1716 
1717   case 100: /* assignment_stmt: T_WORD assign_op assign_val T_EOL  */
1718                                                         { variable_add((yyvsp[-3].string), (yyvsp[-1].string), (yyvsp[-2].flavor)); free((yyvsp[-3].string)); free((yyvsp[-1].string)); }
1719     break;
1720 
1721   case 101: /* assign_op: T_EQUAL  */
1722                         { (yyval.flavor) = VAR_RECURSIVE; }
1723     break;
1724 
1725   case 102: /* assign_op: T_COLON_EQUAL  */
1726                         { (yyval.flavor) = VAR_SIMPLE; }
1727     break;
1728 
1729   case 103: /* assign_op: T_PLUS_EQUAL  */
1730                         { (yyval.flavor) = VAR_APPEND; }
1731     break;
1732 
1733   case 104: /* assign_val: %empty  */
1734                                 { (yyval.string) = xstrdup(""); }
1735     break;
1736 
1737 
1738 
1739       default: break;
1740     }
1741   /* User semantic actions sometimes alter yychar, and that requires
1742      that yytoken be updated with the new translation.  We take the
1743      approach of translating immediately before every use of yytoken.
1744      One alternative is translating here after every semantic action,
1745      but that translation would be missed if the semantic action invokes
1746      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1747      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1748      incorrect destructor might then be invoked immediately.  In the
1749      case of YYERROR or YYBACKUP, subsequent parser actions might lead
1750      to an incorrect destructor call or verbose syntax error message
1751      before the lookahead is translated.  */
1752   YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1753 
1754   YYPOPSTACK (yylen);
1755   yylen = 0;
1756 
1757   *++yyvsp = yyval;
1758 
1759   /* Now 'shift' the result of the reduction.  Determine what state
1760      that goes to, based on the state we popped back to and the rule
1761      number reduced by.  */
1762   {
1763     const int yylhs = yyr1[yyn] - YYNTOKENS;
1764     const int yyi = yypgoto[yylhs] + *yyssp;
1765     yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1766                ? yytable[yyi]
1767                : yydefgoto[yylhs]);
1768   }
1769 
1770   goto yynewstate;
1771 
1772 
1773 /*--------------------------------------.
1774 | yyerrlab -- here on detecting error.  |
1775 `--------------------------------------*/
1776 yyerrlab:
1777   /* Make sure we have latest lookahead translation.  See comments at
1778      user semantic actions for why this is necessary.  */
1779   yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1780   /* If not already recovering from an error, report this error.  */
1781   if (!yyerrstatus)
1782     {
1783       ++yynerrs;
1784       yyerror (YY_("syntax error"));
1785     }
1786 
1787   if (yyerrstatus == 3)
1788     {
1789       /* If just tried and failed to reuse lookahead token after an
1790          error, discard it.  */
1791 
1792       if (yychar <= YYEOF)
1793         {
1794           /* Return failure if at end of input.  */
1795           if (yychar == YYEOF)
1796             YYABORT;
1797         }
1798       else
1799         {
1800           yydestruct ("Error: discarding",
1801                       yytoken, &yylval);
1802           yychar = YYEMPTY;
1803         }
1804     }
1805 
1806   /* Else will try to reuse lookahead token after shifting the error
1807      token.  */
1808   goto yyerrlab1;
1809 
1810 
1811 /*---------------------------------------------------.
1812 | yyerrorlab -- error raised explicitly by YYERROR.  |
1813 `---------------------------------------------------*/
1814 yyerrorlab:
1815   /* Pacify compilers when the user code never invokes YYERROR and the
1816      label yyerrorlab therefore never appears in user code.  */
1817   if (0)
1818     YYERROR;
1819 
1820   /* Do not reclaim the symbols of the rule whose action triggered
1821      this YYERROR.  */
1822   YYPOPSTACK (yylen);
1823   yylen = 0;
1824   YY_STACK_PRINT (yyss, yyssp);
1825   yystate = *yyssp;
1826   goto yyerrlab1;
1827 
1828 
1829 /*-------------------------------------------------------------.
1830 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1831 `-------------------------------------------------------------*/
1832 yyerrlab1:
1833   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1834 
1835   /* Pop stack until we find a state that shifts the error token.  */
1836   for (;;)
1837     {
1838       yyn = yypact[yystate];
1839       if (!yypact_value_is_default (yyn))
1840         {
1841           yyn += YYSYMBOL_YYerror;
1842           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1843             {
1844               yyn = yytable[yyn];
1845               if (0 < yyn)
1846                 break;
1847             }
1848         }
1849 
1850       /* Pop the current state because it cannot handle the error token.  */
1851       if (yyssp == yyss)
1852         YYABORT;
1853 
1854 
1855       yydestruct ("Error: popping",
1856                   YY_ACCESSING_SYMBOL (yystate), yyvsp);
1857       YYPOPSTACK (1);
1858       yystate = *yyssp;
1859       YY_STACK_PRINT (yyss, yyssp);
1860     }
1861 
1862   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1863   *++yyvsp = yylval;
1864   YY_IGNORE_MAYBE_UNINITIALIZED_END
1865 
1866 
1867   /* Shift the error token.  */
1868   YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1869 
1870   yystate = yyn;
1871   goto yynewstate;
1872 
1873 
1874 /*-------------------------------------.
1875 | yyacceptlab -- YYACCEPT comes here.  |
1876 `-------------------------------------*/
1877 yyacceptlab:
1878   yyresult = 0;
1879   goto yyreturn;
1880 
1881 
1882 /*-----------------------------------.
1883 | yyabortlab -- YYABORT comes here.  |
1884 `-----------------------------------*/
1885 yyabortlab:
1886   yyresult = 1;
1887   goto yyreturn;
1888 
1889 
1890 #if !defined yyoverflow
1891 /*-------------------------------------------------.
1892 | yyexhaustedlab -- memory exhaustion comes here.  |
1893 `-------------------------------------------------*/
1894 yyexhaustedlab:
1895   yyerror (YY_("memory exhausted"));
1896   yyresult = 2;
1897   goto yyreturn;
1898 #endif
1899 
1900 
1901 /*-------------------------------------------------------.
1902 | yyreturn -- parsing is finished, clean up and return.  |
1903 `-------------------------------------------------------*/
1904 yyreturn:
1905   if (yychar != YYEMPTY)
1906     {
1907       /* Make sure we have latest lookahead translation.  See comments at
1908          user semantic actions for why this is necessary.  */
1909       yytoken = YYTRANSLATE (yychar);
1910       yydestruct ("Cleanup: discarding lookahead",
1911                   yytoken, &yylval);
1912     }
1913   /* Do not reclaim the symbols of the rule whose action triggered
1914      this YYABORT or YYACCEPT.  */
1915   YYPOPSTACK (yylen);
1916   YY_STACK_PRINT (yyss, yyssp);
1917   while (yyssp != yyss)
1918     {
1919       yydestruct ("Cleanup: popping",
1920                   YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
1921       YYPOPSTACK (1);
1922     }
1923 #ifndef yyoverflow
1924   if (yyss != yyssa)
1925     YYSTACK_FREE (yyss);
1926 #endif
1927 
1928   return yyresult;
1929 }
1930 
1931 
1932 
conf_parse(const char * name)1933 void conf_parse(const char *name)
1934 {
1935 	struct symbol *sym;
1936 	int i;
1937 
1938 	zconf_initscan(name);
1939 
1940 	_menu_init();
1941 
1942 	if (getenv("ZCONF_DEBUG"))
1943 		yydebug = 1;
1944 	yyparse();
1945 
1946 	/* Variables are expanded in the parse phase. We can free them here. */
1947 	variable_all_del();
1948 
1949 	if (yynerrs)
1950 		exit(1);
1951 	if (!modules_sym)
1952 		modules_sym = sym_find( "n" );
1953 
1954 	if (!menu_has_prompt(&rootmenu)) {
1955 		current_entry = &rootmenu;
1956 		menu_add_prompt(P_MENU, "Main menu", NULL);
1957 	}
1958 
1959 	menu_finalize(&rootmenu);
1960 	for_all_symbols(i, sym) {
1961 		if (sym_check_deps(sym))
1962 			yynerrs++;
1963 	}
1964 	if (yynerrs)
1965 		exit(1);
1966 	conf_set_changed(true);
1967 }
1968 
zconf_endtoken(const char * tokenname,const char * expected_tokenname)1969 static bool zconf_endtoken(const char *tokenname,
1970 			   const char *expected_tokenname)
1971 {
1972 	if (strcmp(tokenname, expected_tokenname)) {
1973 		zconf_error("unexpected '%s' within %s block",
1974 			    tokenname, expected_tokenname);
1975 		yynerrs++;
1976 		return false;
1977 	}
1978 	if (current_menu->file != current_file) {
1979 		zconf_error("'%s' in different file than '%s'",
1980 			    tokenname, expected_tokenname);
1981 		fprintf(stderr, "%s:%d: location of the '%s'\n",
1982 			current_menu->file->name, current_menu->lineno,
1983 			expected_tokenname);
1984 		yynerrs++;
1985 		return false;
1986 	}
1987 	return true;
1988 }
1989 
zconfprint(const char * err,...)1990 static void zconfprint(const char *err, ...)
1991 {
1992 	va_list ap;
1993 
1994 	fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
1995 	va_start(ap, err);
1996 	vfprintf(stderr, err, ap);
1997 	va_end(ap);
1998 	fprintf(stderr, "\n");
1999 }
2000 
zconf_error(const char * err,...)2001 static void zconf_error(const char *err, ...)
2002 {
2003 	va_list ap;
2004 
2005 	yynerrs++;
2006 	fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
2007 	va_start(ap, err);
2008 	vfprintf(stderr, err, ap);
2009 	va_end(ap);
2010 	fprintf(stderr, "\n");
2011 }
2012 
yyerror(const char * err)2013 static void yyerror(const char *err)
2014 {
2015 	fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
2016 }
2017 
print_quoted_string(FILE * out,const char * str)2018 static void print_quoted_string(FILE *out, const char *str)
2019 {
2020 	const char *p;
2021 	int len;
2022 
2023 	putc('"', out);
2024 	while ((p = strchr(str, '"'))) {
2025 		len = p - str;
2026 		if (len)
2027 			fprintf(out, "%.*s", len, str);
2028 		fputs("\\\"", out);
2029 		str = p + 1;
2030 	}
2031 	fputs(str, out);
2032 	putc('"', out);
2033 }
2034 
print_symbol(FILE * out,struct menu * menu)2035 static void print_symbol(FILE *out, struct menu *menu)
2036 {
2037 	struct symbol *sym = menu->sym;
2038 	struct property *prop;
2039 
2040 	if (sym_is_choice(sym))
2041 		fprintf(out, "\nchoice\n");
2042 	else
2043 		fprintf(out, "\nconfig %s\n", sym->name);
2044 	switch (sym->type) {
2045 	case S_BOOLEAN:
2046 		fputs("  bool\n", out);
2047 		break;
2048 	case S_TRISTATE:
2049 		fputs("  tristate\n", out);
2050 		break;
2051 	case S_STRING:
2052 		fputs("  string\n", out);
2053 		break;
2054 	case S_INT:
2055 		fputs("  integer\n", out);
2056 		break;
2057 	case S_HEX:
2058 		fputs("  hex\n", out);
2059 		break;
2060 	default:
2061 		fputs("  ???\n", out);
2062 		break;
2063 	}
2064 	for (prop = sym->prop; prop; prop = prop->next) {
2065 		if (prop->menu != menu)
2066 			continue;
2067 		switch (prop->type) {
2068 		case P_PROMPT:
2069 			fputs("  prompt ", out);
2070 			print_quoted_string(out, prop->text);
2071 			if (!expr_is_yes(prop->visible.expr)) {
2072 				fputs(" if ", out);
2073 				expr_fprint(prop->visible.expr, out);
2074 			}
2075 			fputc('\n', out);
2076 			break;
2077 		case P_DEFAULT:
2078 			fputs( "  default ", out);
2079 			expr_fprint(prop->expr, out);
2080 			if (!expr_is_yes(prop->visible.expr)) {
2081 				fputs(" if ", out);
2082 				expr_fprint(prop->visible.expr, out);
2083 			}
2084 			fputc('\n', out);
2085 			break;
2086 		case P_CHOICE:
2087 			fputs("  #choice value\n", out);
2088 			break;
2089 		case P_SELECT:
2090 			fputs( "  select ", out);
2091 			expr_fprint(prop->expr, out);
2092 			fputc('\n', out);
2093 			break;
2094 		case P_IMPLY:
2095 			fputs( "  imply ", out);
2096 			expr_fprint(prop->expr, out);
2097 			fputc('\n', out);
2098 			break;
2099 		case P_RANGE:
2100 			fputs( "  range ", out);
2101 			expr_fprint(prop->expr, out);
2102 			fputc('\n', out);
2103 			break;
2104 		case P_MENU:
2105 			fputs( "  menu ", out);
2106 			print_quoted_string(out, prop->text);
2107 			fputc('\n', out);
2108 			break;
2109 		case P_SYMBOL:
2110 			fputs( "  symbol ", out);
2111 			fprintf(out, "%s\n", prop->menu->sym->name);
2112 			break;
2113 		default:
2114 			fprintf(out, "  unknown prop %d!\n", prop->type);
2115 			break;
2116 		}
2117 	}
2118 	if (menu->help) {
2119 		int len = strlen(menu->help);
2120 		while (menu->help[--len] == '\n')
2121 			menu->help[len] = 0;
2122 		fprintf(out, "  help\n%s\n", menu->help);
2123 	}
2124 }
2125 
zconfdump(FILE * out)2126 void zconfdump(FILE *out)
2127 {
2128 	struct property *prop;
2129 	struct symbol *sym;
2130 	struct menu *menu;
2131 
2132 	menu = rootmenu.list;
2133 	while (menu) {
2134 		if ((sym = menu->sym))
2135 			print_symbol(out, menu);
2136 		else if ((prop = menu->prompt)) {
2137 			switch (prop->type) {
2138 			case P_COMMENT:
2139 				fputs("\ncomment ", out);
2140 				print_quoted_string(out, prop->text);
2141 				fputs("\n", out);
2142 				break;
2143 			case P_MENU:
2144 				fputs("\nmenu ", out);
2145 				print_quoted_string(out, prop->text);
2146 				fputs("\n", out);
2147 				break;
2148 			default:
2149 				;
2150 			}
2151 			if (!expr_is_yes(prop->visible.expr)) {
2152 				fputs("  depends ", out);
2153 				expr_fprint(prop->visible.expr, out);
2154 				fputc('\n', out);
2155 			}
2156 		}
2157 
2158 		if (menu->list)
2159 			menu = menu->list;
2160 		else if (menu->next)
2161 			menu = menu->next;
2162 		else while ((menu = menu->parent)) {
2163 			if (menu->prompt && menu->prompt->type == P_MENU)
2164 				fputs("\nendmenu\n", out);
2165 			if (menu->next) {
2166 				menu = menu->next;
2167 				break;
2168 			}
2169 		}
2170 	}
2171 }
2172