parse_y.c 48 KB

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