You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2385 line
53KB

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