1 /* A Bison parser, made by GNU Bison 3.0.4.  */
2 
3 /* Bison implementation for Yacc-like parsers in C
4 
5    Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29 
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32 
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35 
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42 
43 /* Identify Bison output.  */
44 #define YYBISON 1
45 
46 /* Bison version.  */
47 #define YYBISON_VERSION "3.0.4"
48 
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51 
52 /* Pure parsers.  */
53 #define YYPURE 0
54 
55 /* Push parsers.  */
56 #define YYPUSH 0
57 
58 /* Pull parsers.  */
59 #define YYPULL 1
60 
61 
62 
63 
64 /* Copy the first part of user declarations.  */
65 
66 
67 /*
68  *  R : A Computer Language for Statistical Data Analysis
69  *  Copyright (C) 1995, 1996, 1997  Robert Gentleman and Ross Ihaka
70  *  Copyright (C) 1997--2019  The R Core Team
71  *
72  *  This program is free software; you can redistribute it and/or modify
73  *  it under the terms of the GNU General Public License as published by
74  *  the Free Software Foundation; either version 2 of the License, or
75  *  (at your option) any later version.
76  *
77  *  This program is distributed in the hope that it will be useful,
78  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
79  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
80  *  GNU General Public License for more details.
81  *
82  *  You should have received a copy of the GNU General Public License
83  *  along with this program; if not, a copy is available at
84  *  https://www.R-project.org/Licenses/
85  */
86 
87 #ifdef HAVE_CONFIG_H
88 #include <config.h>
89 #endif
90 
91 #define R_USE_SIGNALS 1
92 #include <Defn.h>
93 #include <Parse.h>
94 #define STRICT_R_HEADERS
95 #include <R_ext/RS.h>           /* for R_chk_* allocation */
96 #include <ctype.h>
97 #include <Rmath.h> /* for imax2(.),..*/
98 #undef _
99 #ifdef ENABLE_NLS
100 #include <libintl.h>
101 #define _(String) dgettext ("tools", String)
102 #else
103 #define _(String) (String)
104 #endif
105 
106 /* bison creates a non-static symbol yylloc (and other) in both gramLatex.o
107    and gramRd.o, so remap */
108 
109 #define yylloc yyllocR
110 #undef yynerrs /* from Defn.h */
111 #define yynerrs yynerrsR
112 #undef yychar /* from Defn.h */
113 #define yychar yycharR
114 #undef yylval /* from Defn.h */
115 #define yylval yylvalR
116 
117 #define DEBUGVALS 0		/* 1 causes detailed internal state output to R console */
118 #define DEBUGMODE 0		/* 1 causes Bison output of parse state, to stdout or stderr */
119 
120 static Rboolean wCalls = TRUE;
121 static Rboolean warnDups = FALSE;
122 
123 #define YYERROR_VERBOSE 1
124 
125 static void yyerror(const char *);
126 static int yylex();
127 static int yyparse(void);
128 
129 #define yyconst const
130 
131 typedef struct yyltype
132 {
133   int first_line;
134   int first_column;
135   int first_byte;
136 
137   int last_line;
138   int last_column;
139   int last_byte;
140 } yyltype;
141 
142 # define YYLTYPE yyltype
143 # define YYLLOC_DEFAULT(Current, Rhs, N)				\
144     do									\
145 	if (N)								\
146 	{								\
147 	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
148 	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
149 	  (Current).first_byte   = YYRHSLOC (Rhs, 1).first_byte;	\
150 	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
151 	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
152 	  (Current).last_byte    = YYRHSLOC (Rhs, N).last_byte;		\
153 	}								\
154       else								\
155 	{								\
156 	  (Current).first_line   = (Current).last_line   =		\
157 	    YYRHSLOC (Rhs, 0).last_line;				\
158 	  (Current).first_column = (Current).last_column =		\
159 	    YYRHSLOC (Rhs, 0).last_column;				\
160 	  (Current).first_byte   = (Current).last_byte =		\
161 	    YYRHSLOC (Rhs, 0).last_byte;				\
162 	}								\
163     while (0)
164 
165 /* Useful defines so editors don't get confused ... */
166 
167 #define LBRACE	'{'
168 #define RBRACE	'}'
169 
170 /* Functions used in the parsing process */
171 
172 static void	GrowList(SEXP, SEXP);
173 static int	KeywordLookup(const char *);
174 static SEXP	UserMacroLookup(const char *);
175 static SEXP	InstallKeywords();
176 static SEXP	NewList(void);
177 static SEXP     makeSrcref(YYLTYPE *, SEXP);
178 static int	xxgetc();
179 static int	xxungetc(int);
180 
181 /* Flags used to mark need for postprocessing in the dynamicFlag attribute */
182 
183 #define STATIC 0
184 #define HAS_IFDEF 1
185 #define HAS_SEXPR 2
186 
187 /* Internal lexer / parser state variables */
188 
189 static char const yyunknown[] = "unknown macro"; /* our message, not bison's */
190 
191 
192 typedef struct ParseState ParseState;
193 struct ParseState {
194     int xxinRString, xxQuoteLine, xxQuoteCol;
195     int	xxinEqn;
196     int	xxNewlineInString;
197     int	xxlineno, xxbyteno, xxcolno;
198     int	xxmode, xxitemType, xxbraceDepth;  /* context for lexer */
199     int	xxDebugTokens;  /* non-zero causes debug output to R console */
200     const char* xxBasename;     /* basename of file for error messages */
201     SEXP	Value;
202     int	xxinitvalue;
203     SEXP	xxMacroList;/* A hashed environment containing all the standard and user-defined macro names */
204     SEXP mset; /* Precious mset for protecting parser semantic values */
205     ParseState *prevState;
206 };
207 
208 static Rboolean busy = FALSE;
209 static ParseState parseState;
210 
211 #define PRESERVE_SV(x) R_PreserveInMSet((x), parseState.mset)
212 #define RELEASE_SV(x)  R_ReleaseFromMSet((x), parseState.mset)
213 
214 #define RLIKE 1		/* Includes R strings; xxinRString holds the opening quote char, or 0 outside a string */
215 #define LATEXLIKE 2
216 #define VERBATIM 3
217 #define INOPTION 4
218 #define COMMENTMODE 5   /* only used in deparsing */
219 #define UNKNOWNMODE 6   /* ditto */
220 
221 static SEXP     SrcFile;  /* parse_Rd will *always* supply a srcfile */
222 
223 /* Routines used to build the parse tree */
224 
225 static SEXP	xxpushMode(int, int, int);
226 static void	xxpopMode(SEXP);
227 static SEXP	xxnewlist(SEXP);
228 static SEXP	xxnewlist2(SEXP, SEXP);
229 static SEXP	xxnewlist3(SEXP, SEXP, SEXP);
230 static SEXP	xxnewlist4(SEXP, SEXP, SEXP, SEXP);
231 static SEXP	xxnewlist5(SEXP, SEXP, SEXP, SEXP, SEXP);
232 static SEXP	xxnewlist6(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
233 static SEXP	xxnewlist7(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
234 static SEXP	xxnewlist8(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
235 static SEXP	xxnewlist9(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
236 
237 static SEXP	xxlist(SEXP, SEXP);
238 static SEXP	xxmarkup(SEXP, SEXP, int, YYLTYPE *);
239 static SEXP	xxmarkup2(SEXP, SEXP, SEXP, int, int, YYLTYPE *);
240 static SEXP	xxmarkup3(SEXP, SEXP, SEXP, SEXP, int, YYLTYPE *);
241 static SEXP	xxOptionmarkup(SEXP, SEXP, SEXP, int, YYLTYPE *);
242 static SEXP	xxtag(SEXP, int, YYLTYPE *);
243 static void	xxsavevalue(SEXP, YYLTYPE *);
244 static void	xxWarnNewline();
245 static SEXP	xxnewcommand(SEXP, SEXP, SEXP, YYLTYPE *);
246 static SEXP	xxusermacro(SEXP, SEXP, YYLTYPE *);
247 static int	mkMarkup(int);
248 static int      mkIfdef(int);
249 static int	mkCode(int);
250 static int	mkText(int);
251 static int	mkVerb(int);
252 static int 	mkComment(int);
253 
254 static SEXP R_RdTagSymbol = NULL;
255 static SEXP R_RdOptionSymbol = NULL;
256 static SEXP R_DefinitionSymbol = NULL;
257 static SEXP R_DynamicFlagSymbol = NULL;
258 static SEXP R_MacroSymbol = NULL;
259 
260 #define YYSTYPE		SEXP
261 
262 
263 
264 
265 # ifndef YY_NULLPTR
266 #  if defined __cplusplus && 201103L <= __cplusplus
267 #   define YY_NULLPTR nullptr
268 #  else
269 #   define YY_NULLPTR 0
270 #  endif
271 # endif
272 
273 /* Enabling verbose error messages.  */
274 #ifdef YYERROR_VERBOSE
275 # undef YYERROR_VERBOSE
276 # define YYERROR_VERBOSE 1
277 #else
278 # define YYERROR_VERBOSE 0
279 #endif
280 
281 
282 /* Debug traces.  */
283 #ifndef YYDEBUG
284 # define YYDEBUG 0
285 #endif
286 #if YYDEBUG
287 extern int yydebug;
288 #endif
289 
290 /* Token type.  */
291 #ifndef YYTOKENTYPE
292 # define YYTOKENTYPE
293   enum yytokentype
294   {
295     END_OF_INPUT = 258,
296     ERROR = 259,
297     SECTIONHEADER = 260,
298     RSECTIONHEADER = 261,
299     VSECTIONHEADER = 262,
300     SECTIONHEADER2 = 263,
301     RCODEMACRO = 264,
302     SEXPR = 265,
303     RDOPTS = 266,
304     LATEXMACRO = 267,
305     VERBMACRO = 268,
306     OPTMACRO = 269,
307     ESCAPE = 270,
308     LISTSECTION = 271,
309     ITEMIZE = 272,
310     DESCRIPTION = 273,
311     NOITEM = 274,
312     LATEXMACRO2 = 275,
313     VERBMACRO2 = 276,
314     VERBLATEX = 277,
315     LATEXMACRO3 = 278,
316     NEWCOMMAND = 279,
317     USERMACRO = 280,
318     USERMACRO1 = 281,
319     USERMACRO2 = 282,
320     USERMACRO3 = 283,
321     USERMACRO4 = 284,
322     USERMACRO5 = 285,
323     USERMACRO6 = 286,
324     USERMACRO7 = 287,
325     USERMACRO8 = 288,
326     USERMACRO9 = 289,
327     IFDEF = 290,
328     ENDIF = 291,
329     TEXT = 292,
330     RCODE = 293,
331     VERB = 294,
332     COMMENT = 295,
333     UNKNOWN = 296,
334     STARTFILE = 297,
335     STARTFRAGMENT = 298
336   };
337 #endif
338 /* Tokens.  */
339 #define END_OF_INPUT 258
340 #define ERROR 259
341 #define SECTIONHEADER 260
342 #define RSECTIONHEADER 261
343 #define VSECTIONHEADER 262
344 #define SECTIONHEADER2 263
345 #define RCODEMACRO 264
346 #define SEXPR 265
347 #define RDOPTS 266
348 #define LATEXMACRO 267
349 #define VERBMACRO 268
350 #define OPTMACRO 269
351 #define ESCAPE 270
352 #define LISTSECTION 271
353 #define ITEMIZE 272
354 #define DESCRIPTION 273
355 #define NOITEM 274
356 #define LATEXMACRO2 275
357 #define VERBMACRO2 276
358 #define VERBLATEX 277
359 #define LATEXMACRO3 278
360 #define NEWCOMMAND 279
361 #define USERMACRO 280
362 #define USERMACRO1 281
363 #define USERMACRO2 282
364 #define USERMACRO3 283
365 #define USERMACRO4 284
366 #define USERMACRO5 285
367 #define USERMACRO6 286
368 #define USERMACRO7 287
369 #define USERMACRO8 288
370 #define USERMACRO9 289
371 #define IFDEF 290
372 #define ENDIF 291
373 #define TEXT 292
374 #define RCODE 293
375 #define VERB 294
376 #define COMMENT 295
377 #define UNKNOWN 296
378 #define STARTFILE 297
379 #define STARTFRAGMENT 298
380 
381 /* Value type.  */
382 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
383 typedef int YYSTYPE;
384 # define YYSTYPE_IS_TRIVIAL 1
385 # define YYSTYPE_IS_DECLARED 1
386 #endif
387 
388 /* Location type.  */
389 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
390 typedef struct YYLTYPE YYLTYPE;
391 struct YYLTYPE
392 {
393   int first_line;
394   int first_column;
395   int last_line;
396   int last_column;
397 };
398 # define YYLTYPE_IS_DECLARED 1
399 # define YYLTYPE_IS_TRIVIAL 1
400 #endif
401 
402 
403 extern YYSTYPE yylval;
404 extern YYLTYPE yylloc;
405 int yyparse (void);
406 
407 
408 
409 /* Copy the second part of user declarations.  */
410 
411 
412 
413 #ifdef short
414 # undef short
415 #endif
416 
417 #ifdef YYTYPE_UINT8
418 typedef YYTYPE_UINT8 yytype_uint8;
419 #else
420 typedef unsigned char yytype_uint8;
421 #endif
422 
423 #ifdef YYTYPE_INT8
424 typedef YYTYPE_INT8 yytype_int8;
425 #else
426 typedef signed char yytype_int8;
427 #endif
428 
429 #ifdef YYTYPE_UINT16
430 typedef YYTYPE_UINT16 yytype_uint16;
431 #else
432 typedef unsigned short int yytype_uint16;
433 #endif
434 
435 #ifdef YYTYPE_INT16
436 typedef YYTYPE_INT16 yytype_int16;
437 #else
438 typedef short int yytype_int16;
439 #endif
440 
441 #ifndef YYSIZE_T
442 # ifdef __SIZE_TYPE__
443 #  define YYSIZE_T __SIZE_TYPE__
444 # elif defined size_t
445 #  define YYSIZE_T size_t
446 # elif ! defined YYSIZE_T
447 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
448 #  define YYSIZE_T size_t
449 # else
450 #  define YYSIZE_T unsigned int
451 # endif
452 #endif
453 
454 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
455 
456 #ifndef YY_
457 # if defined YYENABLE_NLS && YYENABLE_NLS
458 #  if ENABLE_NLS
459 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
460 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
461 #  endif
462 # endif
463 # ifndef YY_
464 #  define YY_(Msgid) Msgid
465 # endif
466 #endif
467 
468 #ifndef YY_ATTRIBUTE
469 # if (defined __GNUC__                                               \
470       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
471      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
472 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
473 # else
474 #  define YY_ATTRIBUTE(Spec) /* empty */
475 # endif
476 #endif
477 
478 #ifndef YY_ATTRIBUTE_PURE
479 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
480 #endif
481 
482 #ifndef YY_ATTRIBUTE_UNUSED
483 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
484 #endif
485 
486 #if !defined _Noreturn \
487      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
488 # if defined _MSC_VER && 1200 <= _MSC_VER
489 #  define _Noreturn __declspec (noreturn)
490 # else
491 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
492 # endif
493 #endif
494 
495 /* Suppress unused-variable warnings by "using" E.  */
496 #if ! defined lint || defined __GNUC__
497 # define YYUSE(E) ((void) (E))
498 #else
499 # define YYUSE(E) /* empty */
500 #endif
501 
502 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
503 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
504 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
505     _Pragma ("GCC diagnostic push") \
506     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
507     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
508 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
509     _Pragma ("GCC diagnostic pop")
510 #else
511 # define YY_INITIAL_VALUE(Value) Value
512 #endif
513 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
514 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
515 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
516 #endif
517 #ifndef YY_INITIAL_VALUE
518 # define YY_INITIAL_VALUE(Value) /* Nothing. */
519 #endif
520 
521 
522 #if ! defined yyoverflow || YYERROR_VERBOSE
523 
524 /* The parser invokes alloca or malloc; define the necessary symbols.  */
525 
526 # ifdef YYSTACK_USE_ALLOCA
527 #  if YYSTACK_USE_ALLOCA
528 #   ifdef __GNUC__
529 #    define YYSTACK_ALLOC __builtin_alloca
530 #   elif defined __BUILTIN_VA_ARG_INCR
531 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
532 #   elif defined _AIX
533 #    define YYSTACK_ALLOC __alloca
534 #   elif defined _MSC_VER
535 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
536 #    define alloca _alloca
537 #   else
538 #    define YYSTACK_ALLOC alloca
539 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
540 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
541       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
542 #     ifndef EXIT_SUCCESS
543 #      define EXIT_SUCCESS 0
544 #     endif
545 #    endif
546 #   endif
547 #  endif
548 # endif
549 
550 # ifdef YYSTACK_ALLOC
551    /* Pacify GCC's 'empty if-body' warning.  */
552 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
553 #  ifndef YYSTACK_ALLOC_MAXIMUM
554     /* The OS might guarantee only one guard page at the bottom of the stack,
555        and a page size can be as small as 4096 bytes.  So we cannot safely
556        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
557        to allow for a few compiler-allocated temporary stack slots.  */
558 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
559 #  endif
560 # else
561 #  define YYSTACK_ALLOC YYMALLOC
562 #  define YYSTACK_FREE YYFREE
563 #  ifndef YYSTACK_ALLOC_MAXIMUM
564 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
565 #  endif
566 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
567        && ! ((defined YYMALLOC || defined malloc) \
568              && (defined YYFREE || defined free)))
569 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
570 #   ifndef EXIT_SUCCESS
571 #    define EXIT_SUCCESS 0
572 #   endif
573 #  endif
574 #  ifndef YYMALLOC
575 #   define YYMALLOC malloc
576 #   if ! defined malloc && ! defined EXIT_SUCCESS
577 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
578 #   endif
579 #  endif
580 #  ifndef YYFREE
581 #   define YYFREE free
582 #   if ! defined free && ! defined EXIT_SUCCESS
583 void free (void *); /* INFRINGES ON USER NAME SPACE */
584 #   endif
585 #  endif
586 # endif
587 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
588 
589 
590 #if (! defined yyoverflow \
591      && (! defined __cplusplus \
592          || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
593              && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
594 
595 /* A type that is properly aligned for any stack member.  */
596 union yyalloc
597 {
598   yytype_int16 yyss_alloc;
599   YYSTYPE yyvs_alloc;
600   YYLTYPE yyls_alloc;
601 };
602 
603 /* The size of the maximum gap between one aligned stack and the next.  */
604 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
605 
606 /* The size of an array large to enough to hold all stacks, each with
607    N elements.  */
608 # define YYSTACK_BYTES(N) \
609      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
610       + 2 * YYSTACK_GAP_MAXIMUM)
611 
612 # define YYCOPY_NEEDED 1
613 
614 /* Relocate STACK from its old location to the new one.  The
615    local variables YYSIZE and YYSTACKSIZE give the old and new number of
616    elements in the stack, and YYPTR gives the new location of the
617    stack.  Advance YYPTR to a properly aligned location for the next
618    stack.  */
619 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
620     do                                                                  \
621       {                                                                 \
622         YYSIZE_T yynewbytes;                                            \
623         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
624         Stack = &yyptr->Stack_alloc;                                    \
625         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
626         yyptr += yynewbytes / sizeof (*yyptr);                          \
627       }                                                                 \
628     while (0)
629 
630 #endif
631 
632 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
633 /* Copy COUNT objects from SRC to DST.  The source and destination do
634    not overlap.  */
635 # ifndef YYCOPY
636 #  if defined __GNUC__ && 1 < __GNUC__
637 #   define YYCOPY(Dst, Src, Count) \
638       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
639 #  else
640 #   define YYCOPY(Dst, Src, Count)              \
641       do                                        \
642         {                                       \
643           YYSIZE_T yyi;                         \
644           for (yyi = 0; yyi < (Count); yyi++)   \
645             (Dst)[yyi] = (Src)[yyi];            \
646         }                                       \
647       while (0)
648 #  endif
649 # endif
650 #endif /* !YYCOPY_NEEDED */
651 
652 /* YYFINAL -- State number of the termination state.  */
653 #define YYFINAL  33
654 /* YYLAST -- Last index in YYTABLE.  */
655 #define YYLAST   832
656 
657 /* YYNTOKENS -- Number of terminals.  */
658 #define YYNTOKENS  48
659 /* YYNNTS -- Number of nonterminals.  */
660 #define YYNNTS  31
661 /* YYNRULES -- Number of rules.  */
662 #define YYNRULES  89
663 /* YYNSTATES -- Number of states.  */
664 #define YYNSTATES  194
665 
666 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
667    by yylex, with out-of-bounds checking.  */
668 #define YYUNDEFTOK  2
669 #define YYMAXUTOK   298
670 
671 #define YYTRANSLATE(YYX)                                                \
672   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
673 
674 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
675    as returned by yylex, without out-of-bounds checking.  */
676 static const yytype_uint8 yytranslate[] =
677 {
678        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
679        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
680        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
681        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
682        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
683        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
684        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
685        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
686        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
687        2,    46,     2,    47,     2,     2,     2,     2,     2,     2,
688        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
689        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
690        2,     2,     2,    44,     2,    45,     2,     2,     2,     2,
691        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
692        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
693        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
694        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
695        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
696        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
697        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
698        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
699        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
700        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
701        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
702        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
703        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
704        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
705       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
706       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
707       35,    36,    37,    38,    39,    40,    41,    42,    43
708 };
709 
710 #if YYDEBUG
711   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
712 static const yytype_uint16 yyrline[] =
713 {
714        0,   230,   230,   231,   232,   235,   238,   241,   242,   244,
715      245,   246,   247,   248,   249,   250,   251,   252,   253,   254,
716      255,   256,   257,   259,   260,   262,   263,   264,   265,   266,
717      267,   268,   269,   270,   272,   273,   274,   275,   276,   277,
718      278,   279,   280,   281,   282,   283,   284,   285,   286,   287,
719      288,   290,   291,   292,   293,   295,   297,   299,   301,   303,
720      306,   309,   314,   316,   317,   326,   328,   330,   334,   335,
721      337,   339,   343,   344,   346,   349,   351,   353,   355,   357,
722      359,   361,   363,   365,   367,   368,   369,   370,   371,   373
723 };
724 #endif
725 
726 #if YYDEBUG || YYERROR_VERBOSE || 0
727 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
728    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
729 static const char *const yytname[] =
730 {
731   "$end", "error", "$undefined", "END_OF_INPUT", "ERROR", "SECTIONHEADER",
732   "RSECTIONHEADER", "VSECTIONHEADER", "SECTIONHEADER2", "RCODEMACRO",
733   "SEXPR", "RDOPTS", "LATEXMACRO", "VERBMACRO", "OPTMACRO", "ESCAPE",
734   "LISTSECTION", "ITEMIZE", "DESCRIPTION", "NOITEM", "LATEXMACRO2",
735   "VERBMACRO2", "VERBLATEX", "LATEXMACRO3", "NEWCOMMAND", "USERMACRO",
736   "USERMACRO1", "USERMACRO2", "USERMACRO3", "USERMACRO4", "USERMACRO5",
737   "USERMACRO6", "USERMACRO7", "USERMACRO8", "USERMACRO9", "IFDEF", "ENDIF",
738   "TEXT", "RCODE", "VERB", "COMMENT", "UNKNOWN", "STARTFILE",
739   "STARTFRAGMENT", "'{'", "'}'", "'['", "']'", "$accept", "Init",
740   "RdFragment", "RdFile", "SectionList", "Section", "ArgItems", "Item",
741   "Markup", "UserMacro", "LatexArg", "LatexArg2", "Item0Arg", "Item2Arg",
742   "RLikeArg", "RLikeArg2", "VerbatimArg", "VerbatimArg1", "VerbatimArg2",
743   "IfDefTarget", "goLatexLike", "goRLike", "goRLike2", "goOption",
744   "goVerbatim", "goVerbatim1", "goVerbatim2", "goItem0", "goItem2", "Arg",
745   "Option", YY_NULLPTR
746 };
747 #endif
748 
749 # ifdef YYPRINT
750 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
751    (internal) symbol number NUM (which must be that of a token).  */
752 static const yytype_uint16 yytoknum[] =
753 {
754        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
755      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
756      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
757      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
758      295,   296,   297,   298,   123,   125,    91,    93
759 };
760 # endif
761 
762 #define YYPACT_NINF -94
763 
764 #define yypact_value_is_default(Yystate) \
765   (!!((Yystate) == (-94)))
766 
767 #define YYTABLE_NINF -50
768 
769 #define yytable_value_is_error(Yytable_value) \
770   0
771 
772   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
773      STATE-NUM.  */
774 static const yytype_int16 yypact[] =
775 {
776       28,   -94,   792,   -94,    20,   792,   -94,   -94,   -94,   -94,
777      -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
778      -94,   -94,   -94,   -94,   -94,   -94,   -94,    29,   718,   -94,
779      -94,    34,   638,   -94,   -94,   -94,   -19,   -94,   -19,   -94,
780      -19,   -94,   -30,   -94,   -94,   -19,   -94,   -19,   -94,   -94,
781      -94,   -94,   -94,   -94,   -94,   -94,   -94,   792,    -6,   -94,
782      -94,   -94,   638,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
783      -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
784      -94,   265,   556,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
785      -94,   -22,   -94,   638,   -94,     2,   -94,   -94,   -94,   -94,
786      -94,   -94,   -94,   -94,   -94,   -94,   -94,   755,   -94,   -94,
787      -94,   -30,   -94,   -94,     1,   -94,   -19,   -94,   -94,     4,
788      -94,   -94,   638,   306,   -94,   347,   -94,   -94,   -94,   388,
789        7,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   680,
790      -94,   -94,     2,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
791      -94,   597,   -94,   224,   -94,   -94,   429,   -94,   -94,   -94,
792      -94,   -94,   -94,   -94,   -94,   -94,   470,   -94,   179,   -94,
793      -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   511,
794      -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,   -94,
795      -94,   -94,   -94,   -94
796 };
797 
798   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
799      Performed when YYTABLE does not specify something else to do.  Zero
800      means the default is an error.  */
801 static const yytype_uint8 yydefact[] =
802 {
803        0,     4,     0,    75,     0,     0,    75,    76,    79,    75,
804       78,    79,    83,    80,    52,    79,    79,    79,    79,    79,
805       79,    79,    79,    79,    75,    20,    19,     0,     0,     7,
806       21,     0,     0,     1,    22,    12,     0,    11,     0,     9,
807        0,    75,     0,    10,    13,     0,    79,     0,    53,    79,
808       79,    79,    79,    79,    79,    79,    79,     0,     0,     2,
809        8,     3,     0,    76,    78,    75,    79,    78,    47,    82,
810       83,    75,    80,    79,    75,    75,    25,    26,    27,    28,
811       29,     0,     0,    23,    31,    32,    30,    62,    67,    70,
812       14,     0,    77,     0,    17,     0,    66,    51,    71,    54,
813       79,    79,    79,    79,    79,    79,    79,     0,    74,    33,
814       41,     0,    34,    44,    75,    37,     0,    38,    75,    45,
815       75,    75,     0,     0,    85,     0,    24,    64,    63,     0,
816        0,    18,    55,    79,    79,    79,    79,    79,    79,     0,
817       15,    42,     0,    39,    75,    65,    35,    81,    46,    50,
818       75,     0,    87,     0,    84,    69,     0,    89,    56,    79,
819       79,    79,    79,    79,    43,    40,     0,    36,     0,    48,
820       88,    86,    68,    57,    79,    79,    79,    79,    73,     0,
821       58,    79,    79,    79,    72,    79,    79,    79,    59,    79,
822       79,    60,    79,    61
823 };
824 
825   /* YYPGOTO[NTERM-NUM].  */
826 static const yytype_int8 yypgoto[] =
827 {
828      -94,   -94,   -94,   -94,     3,    -2,   -64,   -10,   -94,    22,
829       -8,   -43,   -94,    -9,    -4,   -93,   -11,    -5,   -94,    -7,
830       10,   -94,   -94,   -31,   -94,   -94,   -94,   -94,   -94,   -17,
831      -58
832 };
833 
834   /* YYDEFGOTO[NTERM-NUM].  */
835 static const yytype_int16 yydefgoto[] =
836 {
837       -1,     4,    31,    27,    28,    29,    82,    83,    84,    85,
838       35,    90,   115,    44,    37,    94,    39,    46,   148,    57,
839       36,    38,   129,    42,    40,    47,   166,   116,    45,    86,
840       95
841 };
842 
843   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
844      positive, shift that token.  If negative, reduce the rule whose
845      number is the opposite.  If YYTABLE_NINF, syntax error.  */
846 static const yytype_int16 yytable[] =
847 {
848       43,    41,   131,    34,    48,    49,    50,    51,    52,    53,
849       54,    55,    56,    32,    92,   127,    93,   125,   141,    87,
850       33,    88,    81,    89,    30,    81,    60,    30,    96,     1,
851       98,   108,    59,   111,    58,    97,   114,    61,    99,   100,
852      101,   102,   103,   104,   105,   106,    92,    93,   147,   164,
853       30,    91,   109,   142,   157,   113,   144,   112,   151,   110,
854      107,   117,   120,   118,     0,   156,   121,   119,   122,     0,
855        2,     3,   126,     0,   128,   146,     0,   149,   150,    30,
856        0,     0,     0,   130,     0,    58,     0,     0,     0,   132,
857      133,   134,   135,   136,   137,   138,     0,     0,     0,   145,
858        0,     0,   179,     0,     0,    60,   143,   167,     0,     0,
859        0,     0,     0,   109,     0,   126,     0,     0,     0,     0,
860        0,     0,   158,   159,   160,   161,   162,   163,    91,    30,
861       91,    91,     0,     0,     0,     0,   165,    34,     0,     0,
862        0,   126,     0,   109,     0,     0,   126,     0,   173,   174,
863      175,   176,   177,     0,     0,     0,     0,     0,   109,     0,
864       91,    30,     0,   180,   181,   182,   183,     0,     0,   126,
865      185,   186,   187,     0,   188,   189,   190,     0,   191,   192,
866       62,   193,   -49,     0,     0,     0,     0,     0,    63,    64,
867        0,    65,    66,    67,    68,     0,    69,    70,     0,    71,
868       72,    73,    74,    13,    14,    15,    16,    17,    18,    19,
869       20,    21,    22,    23,    75,   -49,    76,    77,    78,    79,
870       80,     0,     0,    81,   -49,    62,   -49,   170,     0,     0,
871        0,     0,     0,    63,    64,     0,    65,    66,    67,    68,
872        0,    69,    70,     0,    71,    72,    73,    74,    13,    14,
873       15,    16,    17,    18,    19,    20,    21,    22,    23,    75,
874        0,    76,    77,    78,    79,    80,   123,     0,    81,   171,
875        0,     0,     0,     0,    63,    64,     0,    65,    66,    67,
876       68,     0,    69,    70,     0,    71,    72,    73,    74,    13,
877       14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
878       75,     0,    76,    77,    78,    79,    80,    62,     0,    81,
879      124,     0,     0,     0,     0,    63,    64,     0,    65,    66,
880       67,    68,     0,    69,    70,     0,    71,    72,    73,    74,
881       13,    14,    15,    16,    17,    18,    19,    20,    21,    22,
882       23,    75,     0,    76,    77,    78,    79,    80,   153,     0,
883       81,   152,     0,     0,     0,     0,    63,    64,     0,    65,
884       66,    67,    68,     0,    69,    70,     0,    71,    72,    73,
885       74,    13,    14,    15,    16,    17,    18,    19,    20,    21,
886       22,    23,    75,     0,    76,    77,    78,    79,    80,    62,
887        0,    81,   154,     0,     0,     0,     0,    63,    64,     0,
888       65,    66,    67,    68,     0,    69,    70,     0,    71,    72,
889       73,    74,    13,    14,    15,    16,    17,    18,    19,    20,
890       21,    22,    23,    75,     0,    76,    77,    78,    79,    80,
891       62,     0,    81,   155,     0,     0,     0,     0,    63,    64,
892        0,    65,    66,    67,    68,     0,    69,    70,     0,    71,
893       72,    73,    74,    13,    14,    15,    16,    17,    18,    19,
894       20,    21,    22,    23,    75,     0,    76,    77,    78,    79,
895       80,    62,     0,    81,   172,     0,     0,     0,     0,    63,
896       64,     0,    65,    66,    67,    68,     0,    69,    70,     0,
897       71,    72,    73,    74,    13,    14,    15,    16,    17,    18,
898       19,    20,    21,    22,    23,    75,     0,    76,    77,    78,
899       79,    80,    62,     0,    81,   178,     0,     0,     0,     0,
900       63,    64,     0,    65,    66,    67,    68,     0,    69,    70,
901        0,    71,    72,    73,    74,    13,    14,    15,    16,    17,
902       18,    19,    20,    21,    22,    23,    75,     0,    76,    77,
903       78,    79,    80,     0,     0,    81,   184,    62,     0,    -5,
904        0,     0,     0,     0,     0,    63,    64,     0,    65,    66,
905       67,    68,     0,    69,    70,     0,    71,    72,    73,    74,
906       13,    14,    15,    16,    17,    18,    19,    20,    21,    22,
907       23,    75,     0,    76,    77,    78,    79,    80,   168,     0,
908       81,     0,     0,     0,     0,     0,    63,    64,     0,    65,
909       66,    67,    68,     0,    69,    70,     0,    71,    72,    73,
910       74,    13,    14,    15,    16,    17,    18,    19,    20,    21,
911       22,    23,    75,   169,    76,    77,    78,    79,    80,    62,
912        0,    81,     0,     0,     0,     0,     0,    63,    64,     0,
913       65,    66,    67,    68,     0,    69,    70,     0,    71,    72,
914       73,    74,    13,    14,    15,    16,    17,    18,    19,    20,
915       21,    22,    23,    75,     0,    76,    77,    78,    79,    80,
916        0,     5,    81,   -16,     0,     6,     7,     8,     9,     0,
917       10,    11,     0,     0,     0,     0,    12,     0,     0,     0,
918        0,     0,     0,     0,    13,    14,    15,    16,    17,    18,
919       19,    20,    21,    22,    23,    24,   -16,    25,     0,     5,
920       26,    -6,     0,     6,     7,     8,     9,     0,    10,    11,
921        0,     0,     0,     0,    12,     0,     0,     0,     0,     0,
922        0,     0,    13,    14,    15,    16,    17,    18,    19,    20,
923       21,    22,    23,    24,     0,    25,   139,     0,    26,     0,
924        6,     7,     8,     9,     0,    10,    11,     0,     0,     0,
925        0,    12,     0,     0,     0,     0,     0,     0,     0,    13,
926       14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
927       24,   140,    25,     5,     0,    26,     0,     6,     7,     8,
928        9,     0,    10,    11,     0,     0,     0,     0,    12,     0,
929        0,     0,     0,     0,     0,     0,    13,    14,    15,    16,
930       17,    18,    19,    20,    21,    22,    23,    24,     0,    25,
931        0,     0,    26
932 };
933 
934 static const yytype_int16 yycheck[] =
935 {
936       11,     9,    95,     5,    15,    16,    17,    18,    19,    20,
937       21,    22,    23,     3,    44,    37,    46,    81,   111,    36,
938        0,    38,    44,    40,     2,    44,    28,     5,    45,     1,
939       47,    37,     3,    64,    24,    46,    67,     3,    49,    50,
940       51,    52,    53,    54,    55,    56,    44,    46,    44,   142,
941       28,    41,    62,   111,    47,    66,   114,    65,   122,    63,
942       57,    70,    73,    71,    -1,   129,    74,    72,    75,    -1,
943       42,    43,    82,    -1,    91,   118,    -1,   120,   121,    57,
944       -1,    -1,    -1,    93,    -1,    75,    -1,    -1,    -1,   100,
945      101,   102,   103,   104,   105,   106,    -1,    -1,    -1,   116,
946       -1,    -1,   166,    -1,    -1,   107,   114,   150,    -1,    -1,
947       -1,    -1,    -1,   123,    -1,   125,    -1,    -1,    -1,    -1,
948       -1,    -1,   133,   134,   135,   136,   137,   138,   118,   107,
949      120,   121,    -1,    -1,    -1,    -1,   144,   139,    -1,    -1,
950       -1,   151,    -1,   153,    -1,    -1,   156,    -1,   159,   160,
951      161,   162,   163,    -1,    -1,    -1,    -1,    -1,   168,    -1,
952      150,   139,    -1,   174,   175,   176,   177,    -1,    -1,   179,
953      181,   182,   183,    -1,   185,   186,   187,    -1,   189,   190,
954        1,   192,     3,    -1,    -1,    -1,    -1,    -1,     9,    10,
955       -1,    12,    13,    14,    15,    -1,    17,    18,    -1,    20,
956       21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
957       31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
958       41,    -1,    -1,    44,    45,     1,    47,     3,    -1,    -1,
959       -1,    -1,    -1,     9,    10,    -1,    12,    13,    14,    15,
960       -1,    17,    18,    -1,    20,    21,    22,    23,    24,    25,
961       26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
962       -1,    37,    38,    39,    40,    41,     1,    -1,    44,    45,
963       -1,    -1,    -1,    -1,     9,    10,    -1,    12,    13,    14,
964       15,    -1,    17,    18,    -1,    20,    21,    22,    23,    24,
965       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
966       35,    -1,    37,    38,    39,    40,    41,     1,    -1,    44,
967       45,    -1,    -1,    -1,    -1,     9,    10,    -1,    12,    13,
968       14,    15,    -1,    17,    18,    -1,    20,    21,    22,    23,
969       24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
970       34,    35,    -1,    37,    38,    39,    40,    41,     1,    -1,
971       44,    45,    -1,    -1,    -1,    -1,     9,    10,    -1,    12,
972       13,    14,    15,    -1,    17,    18,    -1,    20,    21,    22,
973       23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
974       33,    34,    35,    -1,    37,    38,    39,    40,    41,     1,
975       -1,    44,    45,    -1,    -1,    -1,    -1,     9,    10,    -1,
976       12,    13,    14,    15,    -1,    17,    18,    -1,    20,    21,
977       22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
978       32,    33,    34,    35,    -1,    37,    38,    39,    40,    41,
979        1,    -1,    44,    45,    -1,    -1,    -1,    -1,     9,    10,
980       -1,    12,    13,    14,    15,    -1,    17,    18,    -1,    20,
981       21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
982       31,    32,    33,    34,    35,    -1,    37,    38,    39,    40,
983       41,     1,    -1,    44,    45,    -1,    -1,    -1,    -1,     9,
984       10,    -1,    12,    13,    14,    15,    -1,    17,    18,    -1,
985       20,    21,    22,    23,    24,    25,    26,    27,    28,    29,
986       30,    31,    32,    33,    34,    35,    -1,    37,    38,    39,
987       40,    41,     1,    -1,    44,    45,    -1,    -1,    -1,    -1,
988        9,    10,    -1,    12,    13,    14,    15,    -1,    17,    18,
989       -1,    20,    21,    22,    23,    24,    25,    26,    27,    28,
990       29,    30,    31,    32,    33,    34,    35,    -1,    37,    38,
991       39,    40,    41,    -1,    -1,    44,    45,     1,    -1,     3,
992       -1,    -1,    -1,    -1,    -1,     9,    10,    -1,    12,    13,
993       14,    15,    -1,    17,    18,    -1,    20,    21,    22,    23,
994       24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
995       34,    35,    -1,    37,    38,    39,    40,    41,     1,    -1,
996       44,    -1,    -1,    -1,    -1,    -1,     9,    10,    -1,    12,
997       13,    14,    15,    -1,    17,    18,    -1,    20,    21,    22,
998       23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
999       33,    34,    35,    36,    37,    38,    39,    40,    41,     1,
1000       -1,    44,    -1,    -1,    -1,    -1,    -1,     9,    10,    -1,
1001       12,    13,    14,    15,    -1,    17,    18,    -1,    20,    21,
1002       22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
1003       32,    33,    34,    35,    -1,    37,    38,    39,    40,    41,
1004       -1,     1,    44,     3,    -1,     5,     6,     7,     8,    -1,
1005       10,    11,    -1,    -1,    -1,    -1,    16,    -1,    -1,    -1,
1006       -1,    -1,    -1,    -1,    24,    25,    26,    27,    28,    29,
1007       30,    31,    32,    33,    34,    35,    36,    37,    -1,     1,
1008       40,     3,    -1,     5,     6,     7,     8,    -1,    10,    11,
1009       -1,    -1,    -1,    -1,    16,    -1,    -1,    -1,    -1,    -1,
1010       -1,    -1,    24,    25,    26,    27,    28,    29,    30,    31,
1011       32,    33,    34,    35,    -1,    37,     1,    -1,    40,    -1,
1012        5,     6,     7,     8,    -1,    10,    11,    -1,    -1,    -1,
1013       -1,    16,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    24,
1014       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
1015       35,    36,    37,     1,    -1,    40,    -1,     5,     6,     7,
1016        8,    -1,    10,    11,    -1,    -1,    -1,    -1,    16,    -1,
1017       -1,    -1,    -1,    -1,    -1,    -1,    24,    25,    26,    27,
1018       28,    29,    30,    31,    32,    33,    34,    35,    -1,    37,
1019       -1,    -1,    40
1020 };
1021 
1022   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1023      symbol of state STATE-NUM.  */
1024 static const yytype_uint8 yystos[] =
1025 {
1026        0,     1,    42,    43,    49,     1,     5,     6,     7,     8,
1027       10,    11,    16,    24,    25,    26,    27,    28,    29,    30,
1028       31,    32,    33,    34,    35,    37,    40,    51,    52,    53,
1029       57,    50,    68,     0,    53,    58,    68,    62,    69,    64,
1030       72,    58,    71,    64,    61,    76,    65,    73,    64,    64,
1031       64,    64,    64,    64,    64,    64,    64,    67,    68,     3,
1032       53,     3,     1,     9,    10,    12,    13,    14,    15,    17,
1033       18,    20,    21,    22,    23,    35,    37,    38,    39,    40,
1034       41,    44,    54,    55,    56,    57,    77,    77,    77,    77,
1035       59,    68,    44,    46,    63,    78,    77,    64,    77,    64,
1036       64,    64,    64,    64,    64,    64,    64,    52,    37,    55,
1037       62,    71,    58,    64,    71,    60,    75,    61,    58,    65,
1038       64,    58,    67,     1,    45,    54,    55,    37,    77,    70,
1039       55,    63,    64,    64,    64,    64,    64,    64,    64,     1,
1040       36,    63,    78,    58,    78,    77,    59,    44,    66,    59,
1041       59,    54,    45,     1,    45,    45,    54,    47,    64,    64,
1042       64,    64,    64,    64,    63,    58,    74,    59,     1,    36,
1043        3,    45,    45,    64,    64,    64,    64,    64,    45,    54,
1044       64,    64,    64,    64,    45,    64,    64,    64,    64,    64,
1045       64,    64,    64,    64
1046 };
1047 
1048   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
1049 static const yytype_uint8 yyr1[] =
1050 {
1051        0,    48,    49,    49,    49,    50,    51,    52,    52,    53,
1052       53,    53,    53,    53,    53,    53,    53,    53,    53,    53,
1053       53,    53,    53,    54,    54,    55,    55,    55,    55,    55,
1054       55,    55,    55,    55,    56,    56,    56,    56,    56,    56,
1055       56,    56,    56,    56,    56,    56,    56,    56,    56,    56,
1056       56,    57,    57,    57,    57,    57,    57,    57,    57,    57,
1057       57,    57,    58,    59,    59,    60,    61,    62,    63,    63,
1058       64,    65,    66,    66,    67,    68,    69,    70,    71,    72,
1059       73,    74,    75,    76,    77,    77,    77,    77,    77,    78
1060 };
1061 
1062   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
1063 static const yytype_uint8 yyr2[] =
1064 {
1065        0,     2,     3,     3,     1,     2,     1,     1,     2,     2,
1066        2,     2,     2,     2,     3,     4,     4,     3,     4,     1,
1067        1,     1,     2,     1,     2,     1,     1,     1,     1,     1,
1068        1,     1,     1,     2,     2,     3,     4,     2,     2,     3,
1069        4,     2,     3,     4,     2,     2,     3,     1,     4,     4,
1070        3,     3,     1,     2,     3,     4,     5,     6,     7,     9,
1071       10,    11,     2,     2,     2,     2,     2,     2,     4,     3,
1072        2,     2,     4,     3,     2,     0,     0,     0,     0,     0,
1073        0,     0,     0,     0,     3,     2,     4,     3,     4,     3
1074 };
1075 
1076 
1077 #define yyerrok         (yyerrstatus = 0)
1078 #define yyclearin       (yychar = YYEMPTY)
1079 #define YYEMPTY         (-2)
1080 #define YYEOF           0
1081 
1082 #define YYACCEPT        goto yyacceptlab
1083 #define YYABORT         goto yyabortlab
1084 #define YYERROR         goto yyerrorlab
1085 
1086 
1087 #define YYRECOVERING()  (!!yyerrstatus)
1088 
1089 #define YYBACKUP(Token, Value)                                  \
1090 do                                                              \
1091   if (yychar == YYEMPTY)                                        \
1092     {                                                           \
1093       yychar = (Token);                                         \
1094       yylval = (Value);                                         \
1095       YYPOPSTACK (yylen);                                       \
1096       yystate = *yyssp;                                         \
1097       goto yybackup;                                            \
1098     }                                                           \
1099   else                                                          \
1100     {                                                           \
1101       yyerror (YY_("syntax error: cannot back up")); \
1102       YYERROR;                                                  \
1103     }                                                           \
1104 while (0)
1105 
1106 /* Error token number */
1107 #define YYTERROR        1
1108 #define YYERRCODE       256
1109 
1110 
1111 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1112    If N is 0, then set CURRENT to the empty location which ends
1113    the previous symbol: RHS[0] (always defined).  */
1114 
1115 #ifndef YYLLOC_DEFAULT
1116 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
1117     do                                                                  \
1118       if (N)                                                            \
1119         {                                                               \
1120           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
1121           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
1122           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
1123           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
1124         }                                                               \
1125       else                                                              \
1126         {                                                               \
1127           (Current).first_line   = (Current).last_line   =              \
1128             YYRHSLOC (Rhs, 0).last_line;                                \
1129           (Current).first_column = (Current).last_column =              \
1130             YYRHSLOC (Rhs, 0).last_column;                              \
1131         }                                                               \
1132     while (0)
1133 #endif
1134 
1135 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1136 
1137 
1138 /* Enable debugging if requested.  */
1139 #if YYDEBUG
1140 
1141 # ifndef YYFPRINTF
1142 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1143 #  define YYFPRINTF fprintf
1144 # endif
1145 
1146 # define YYDPRINTF(Args)                        \
1147 do {                                            \
1148   if (yydebug)                                  \
1149     YYFPRINTF Args;                             \
1150 } while (0)
1151 
1152 
1153 /* YY_LOCATION_PRINT -- Print the location on the stream.
1154    This macro was not mandated originally: define only if we know
1155    we won't break user code: when these are the locations we know.  */
1156 
1157 #ifndef YY_LOCATION_PRINT
1158 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1159 
1160 /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
1161 
1162 YY_ATTRIBUTE_UNUSED
1163 static unsigned
yy_location_print_(FILE * yyo,YYLTYPE const * const yylocp)1164 yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
1165 {
1166   unsigned res = 0;
1167   int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
1168   if (0 <= yylocp->first_line)
1169     {
1170       res += YYFPRINTF (yyo, "%d", yylocp->first_line);
1171       if (0 <= yylocp->first_column)
1172         res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
1173     }
1174   if (0 <= yylocp->last_line)
1175     {
1176       if (yylocp->first_line < yylocp->last_line)
1177         {
1178           res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
1179           if (0 <= end_col)
1180             res += YYFPRINTF (yyo, ".%d", end_col);
1181         }
1182       else if (0 <= end_col && yylocp->first_column < end_col)
1183         res += YYFPRINTF (yyo, "-%d", end_col);
1184     }
1185   return res;
1186  }
1187 
1188 #  define YY_LOCATION_PRINT(File, Loc)          \
1189   yy_location_print_ (File, &(Loc))
1190 
1191 # else
1192 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1193 # endif
1194 #endif
1195 
1196 
1197 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1198 do {                                                                      \
1199   if (yydebug)                                                            \
1200     {                                                                     \
1201       YYFPRINTF (stderr, "%s ", Title);                                   \
1202       yy_symbol_print (stderr,                                            \
1203                   Type, Value, Location); \
1204       YYFPRINTF (stderr, "\n");                                           \
1205     }                                                                     \
1206 } while (0)
1207 
1208 
1209 /*----------------------------------------.
1210 | Print this symbol's value on YYOUTPUT.  |
1211 `----------------------------------------*/
1212 
1213 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)1214 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1215 {
1216   FILE *yyo = yyoutput;
1217   YYUSE (yyo);
1218   YYUSE (yylocationp);
1219   if (!yyvaluep)
1220     return;
1221 # ifdef YYPRINT
1222   if (yytype < YYNTOKENS)
1223     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1224 # endif
1225   YYUSE (yytype);
1226 }
1227 
1228 
1229 /*--------------------------------.
1230 | Print this symbol on YYOUTPUT.  |
1231 `--------------------------------*/
1232 
1233 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)1234 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1235 {
1236   YYFPRINTF (yyoutput, "%s %s (",
1237              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1238 
1239   YY_LOCATION_PRINT (yyoutput, *yylocationp);
1240   YYFPRINTF (yyoutput, ": ");
1241   yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1242   YYFPRINTF (yyoutput, ")");
1243 }
1244 
1245 /*------------------------------------------------------------------.
1246 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1247 | TOP (included).                                                   |
1248 `------------------------------------------------------------------*/
1249 
1250 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)1251 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1252 {
1253   YYFPRINTF (stderr, "Stack now");
1254   for (; yybottom <= yytop; yybottom++)
1255     {
1256       int yybot = *yybottom;
1257       YYFPRINTF (stderr, " %d", yybot);
1258     }
1259   YYFPRINTF (stderr, "\n");
1260 }
1261 
1262 # define YY_STACK_PRINT(Bottom, Top)                            \
1263 do {                                                            \
1264   if (yydebug)                                                  \
1265     yy_stack_print ((Bottom), (Top));                           \
1266 } while (0)
1267 
1268 
1269 /*------------------------------------------------.
1270 | Report that the YYRULE is going to be reduced.  |
1271 `------------------------------------------------*/
1272 
1273 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,YYLTYPE * yylsp,int yyrule)1274 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1275 {
1276   unsigned long int yylno = yyrline[yyrule];
1277   int yynrhs = yyr2[yyrule];
1278   int yyi;
1279   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1280              yyrule - 1, yylno);
1281   /* The symbols being reduced.  */
1282   for (yyi = 0; yyi < yynrhs; yyi++)
1283     {
1284       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1285       yy_symbol_print (stderr,
1286                        yystos[yyssp[yyi + 1 - yynrhs]],
1287                        &(yyvsp[(yyi + 1) - (yynrhs)])
1288                        , &(yylsp[(yyi + 1) - (yynrhs)])                       );
1289       YYFPRINTF (stderr, "\n");
1290     }
1291 }
1292 
1293 # define YY_REDUCE_PRINT(Rule)          \
1294 do {                                    \
1295   if (yydebug)                          \
1296     yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
1297 } while (0)
1298 
1299 /* Nonzero means print parse trace.  It is left uninitialized so that
1300    multiple parsers can coexist.  */
1301 int yydebug;
1302 #else /* !YYDEBUG */
1303 # define YYDPRINTF(Args)
1304 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1305 # define YY_STACK_PRINT(Bottom, Top)
1306 # define YY_REDUCE_PRINT(Rule)
1307 #endif /* !YYDEBUG */
1308 
1309 
1310 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1311 #ifndef YYINITDEPTH
1312 # define YYINITDEPTH 200
1313 #endif
1314 
1315 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1316    if the built-in stack extension method is used).
1317 
1318    Do not make this value too large; the results are undefined if
1319    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1320    evaluated with infinite-precision integer arithmetic.  */
1321 
1322 #ifndef YYMAXDEPTH
1323 # define YYMAXDEPTH 10000
1324 #endif
1325 
1326 
1327 #if YYERROR_VERBOSE
1328 
1329 # ifndef yystrlen
1330 #  if defined __GLIBC__ && defined _STRING_H
1331 #   define yystrlen strlen
1332 #  else
1333 /* Return the length of YYSTR.  */
1334 static YYSIZE_T
yystrlen(const char * yystr)1335 yystrlen (const char *yystr)
1336 {
1337   YYSIZE_T yylen;
1338   for (yylen = 0; yystr[yylen]; yylen++)
1339     continue;
1340   return yylen;
1341 }
1342 #  endif
1343 # endif
1344 
1345 # ifndef yystpcpy
1346 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1347 #   define yystpcpy stpcpy
1348 #  else
1349 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1350    YYDEST.  */
1351 static char *
yystpcpy(char * yydest,const char * yysrc)1352 yystpcpy (char *yydest, const char *yysrc)
1353 {
1354   char *yyd = yydest;
1355   const char *yys = yysrc;
1356 
1357   while ((*yyd++ = *yys++) != '\0')
1358     continue;
1359 
1360   return yyd - 1;
1361 }
1362 #  endif
1363 # endif
1364 
1365 # ifndef yytnamerr
1366 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1367    quotes and backslashes, so that it's suitable for yyerror.  The
1368    heuristic is that double-quoting is unnecessary unless the string
1369    contains an apostrophe, a comma, or backslash (other than
1370    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1371    null, do not copy; instead, return the length of what the result
1372    would have been.  */
1373 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1374 yytnamerr (char *yyres, const char *yystr)
1375 {
1376   if (*yystr == '"')
1377     {
1378       YYSIZE_T yyn = 0;
1379       char const *yyp = yystr;
1380 
1381       for (;;)
1382         switch (*++yyp)
1383           {
1384           case '\'':
1385           case ',':
1386             goto do_not_strip_quotes;
1387 
1388           case '\\':
1389             if (*++yyp != '\\')
1390               goto do_not_strip_quotes;
1391             /* Fall through.  */
1392           default:
1393             if (yyres)
1394               yyres[yyn] = *yyp;
1395             yyn++;
1396             break;
1397 
1398           case '"':
1399             if (yyres)
1400               yyres[yyn] = '\0';
1401             return yyn;
1402           }
1403     do_not_strip_quotes: ;
1404     }
1405 
1406   if (! yyres)
1407     return yystrlen (yystr);
1408 
1409   return yystpcpy (yyres, yystr) - yyres;
1410 }
1411 # endif
1412 
1413 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1414    about the unexpected token YYTOKEN for the state stack whose top is
1415    YYSSP.
1416 
1417    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1418    not large enough to hold the message.  In that case, also set
1419    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1420    required number of bytes is too large to store.  */
1421 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1422 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1423                 yytype_int16 *yyssp, int yytoken)
1424 {
1425   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1426   YYSIZE_T yysize = yysize0;
1427   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1428   /* Internationalized format string. */
1429   const char *yyformat = YY_NULLPTR;
1430   /* Arguments of yyformat. */
1431   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1432   /* Number of reported tokens (one for the "unexpected", one per
1433      "expected"). */
1434   int yycount = 0;
1435 
1436   /* There are many possibilities here to consider:
1437      - If this state is a consistent state with a default action, then
1438        the only way this function was invoked is if the default action
1439        is an error action.  In that case, don't check for expected
1440        tokens because there are none.
1441      - The only way there can be no lookahead present (in yychar) is if
1442        this state is a consistent state with a default action.  Thus,
1443        detecting the absence of a lookahead is sufficient to determine
1444        that there is no unexpected or expected token to report.  In that
1445        case, just report a simple "syntax error".
1446      - Don't assume there isn't a lookahead just because this state is a
1447        consistent state with a default action.  There might have been a
1448        previous inconsistent state, consistent state with a non-default
1449        action, or user semantic action that manipulated yychar.
1450      - Of course, the expected token list depends on states to have
1451        correct lookahead information, and it depends on the parser not
1452        to perform extra reductions after fetching a lookahead from the
1453        scanner and before detecting a syntax error.  Thus, state merging
1454        (from LALR or IELR) and default reductions corrupt the expected
1455        token list.  However, the list is correct for canonical LR with
1456        one exception: it will still contain any token that will not be
1457        accepted due to an error action in a later state.
1458   */
1459   if (yytoken != YYEMPTY)
1460     {
1461       int yyn = yypact[*yyssp];
1462       yyarg[yycount++] = yytname[yytoken];
1463       if (!yypact_value_is_default (yyn))
1464         {
1465           /* Start YYX at -YYN if negative to avoid negative indexes in
1466              YYCHECK.  In other words, skip the first -YYN actions for
1467              this state because they are default actions.  */
1468           int yyxbegin = yyn < 0 ? -yyn : 0;
1469           /* Stay within bounds of both yycheck and yytname.  */
1470           int yychecklim = YYLAST - yyn + 1;
1471           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1472           int yyx;
1473 
1474           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1475             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1476                 && !yytable_value_is_error (yytable[yyx + yyn]))
1477               {
1478                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1479                   {
1480                     yycount = 1;
1481                     yysize = yysize0;
1482                     break;
1483                   }
1484                 yyarg[yycount++] = yytname[yyx];
1485                 {
1486                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1487                   if (! (yysize <= yysize1
1488                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1489                     return 2;
1490                   yysize = yysize1;
1491                 }
1492               }
1493         }
1494     }
1495 
1496   switch (yycount)
1497     {
1498 # define YYCASE_(N, S)                      \
1499       case N:                               \
1500         yyformat = S;                       \
1501       break
1502       YYCASE_(0, YY_("syntax error"));
1503       YYCASE_(1, YY_("syntax error, unexpected %s"));
1504       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1505       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1506       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1507       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1508 # undef YYCASE_
1509     }
1510 
1511   {
1512     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1513     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1514       return 2;
1515     yysize = yysize1;
1516   }
1517 
1518   if (*yymsg_alloc < yysize)
1519     {
1520       *yymsg_alloc = 2 * yysize;
1521       if (! (yysize <= *yymsg_alloc
1522              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1523         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1524       return 1;
1525     }
1526 
1527   /* Avoid sprintf, as that infringes on the user's name space.
1528      Don't have undefined behavior even if the translation
1529      produced a string with the wrong number of "%s"s.  */
1530   {
1531     char *yyp = *yymsg;
1532     int yyi = 0;
1533     while ((*yyp = *yyformat) != '\0')
1534       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1535         {
1536           yyp += yytnamerr (yyp, yyarg[yyi++]);
1537           yyformat += 2;
1538         }
1539       else
1540         {
1541           yyp++;
1542           yyformat++;
1543         }
1544   }
1545   return 0;
1546 }
1547 #endif /* YYERROR_VERBOSE */
1548 
1549 /*-----------------------------------------------.
1550 | Release the memory associated to this symbol.  |
1551 `-----------------------------------------------*/
1552 
1553 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp)1554 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1555 {
1556   YYUSE (yyvaluep);
1557   YYUSE (yylocationp);
1558   if (!yymsg)
1559     yymsg = "Deleting";
1560   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1561 
1562   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1563   switch (yytype)
1564     {
1565           case 5: /* SECTIONHEADER  */
1566 
1567       { RELEASE_SV(((*yyvaluep))); }
1568 
1569         break;
1570 
1571     case 6: /* RSECTIONHEADER  */
1572 
1573       { RELEASE_SV(((*yyvaluep))); }
1574 
1575         break;
1576 
1577     case 7: /* VSECTIONHEADER  */
1578 
1579       { RELEASE_SV(((*yyvaluep))); }
1580 
1581         break;
1582 
1583     case 8: /* SECTIONHEADER2  */
1584 
1585       { RELEASE_SV(((*yyvaluep))); }
1586 
1587         break;
1588 
1589     case 9: /* RCODEMACRO  */
1590 
1591       { RELEASE_SV(((*yyvaluep))); }
1592 
1593         break;
1594 
1595     case 10: /* SEXPR  */
1596 
1597       { RELEASE_SV(((*yyvaluep))); }
1598 
1599         break;
1600 
1601     case 12: /* LATEXMACRO  */
1602 
1603       { RELEASE_SV(((*yyvaluep))); }
1604 
1605         break;
1606 
1607     case 13: /* VERBMACRO  */
1608 
1609       { RELEASE_SV(((*yyvaluep))); }
1610 
1611         break;
1612 
1613     case 14: /* OPTMACRO  */
1614 
1615       { RELEASE_SV(((*yyvaluep))); }
1616 
1617         break;
1618 
1619     case 15: /* ESCAPE  */
1620 
1621       { RELEASE_SV(((*yyvaluep))); }
1622 
1623         break;
1624 
1625     case 16: /* LISTSECTION  */
1626 
1627       { RELEASE_SV(((*yyvaluep))); }
1628 
1629         break;
1630 
1631     case 17: /* ITEMIZE  */
1632 
1633       { RELEASE_SV(((*yyvaluep))); }
1634 
1635         break;
1636 
1637     case 18: /* DESCRIPTION  */
1638 
1639       { RELEASE_SV(((*yyvaluep))); }
1640 
1641         break;
1642 
1643     case 19: /* NOITEM  */
1644 
1645       { RELEASE_SV(((*yyvaluep))); }
1646 
1647         break;
1648 
1649     case 20: /* LATEXMACRO2  */
1650 
1651       { RELEASE_SV(((*yyvaluep))); }
1652 
1653         break;
1654 
1655     case 21: /* VERBMACRO2  */
1656 
1657       { RELEASE_SV(((*yyvaluep))); }
1658 
1659         break;
1660 
1661     case 22: /* VERBLATEX  */
1662 
1663       { RELEASE_SV(((*yyvaluep))); }
1664 
1665         break;
1666 
1667     case 23: /* LATEXMACRO3  */
1668 
1669       { RELEASE_SV(((*yyvaluep))); }
1670 
1671         break;
1672 
1673     case 24: /* NEWCOMMAND  */
1674 
1675       { RELEASE_SV(((*yyvaluep))); }
1676 
1677         break;
1678 
1679     case 25: /* USERMACRO  */
1680 
1681       { RELEASE_SV(((*yyvaluep))); }
1682 
1683         break;
1684 
1685     case 26: /* USERMACRO1  */
1686 
1687       { RELEASE_SV(((*yyvaluep))); }
1688 
1689         break;
1690 
1691     case 27: /* USERMACRO2  */
1692 
1693       { RELEASE_SV(((*yyvaluep))); }
1694 
1695         break;
1696 
1697     case 28: /* USERMACRO3  */
1698 
1699       { RELEASE_SV(((*yyvaluep))); }
1700 
1701         break;
1702 
1703     case 29: /* USERMACRO4  */
1704 
1705       { RELEASE_SV(((*yyvaluep))); }
1706 
1707         break;
1708 
1709     case 30: /* USERMACRO5  */
1710 
1711       { RELEASE_SV(((*yyvaluep))); }
1712 
1713         break;
1714 
1715     case 31: /* USERMACRO6  */
1716 
1717       { RELEASE_SV(((*yyvaluep))); }
1718 
1719         break;
1720 
1721     case 32: /* USERMACRO7  */
1722 
1723       { RELEASE_SV(((*yyvaluep))); }
1724 
1725         break;
1726 
1727     case 33: /* USERMACRO8  */
1728 
1729       { RELEASE_SV(((*yyvaluep))); }
1730 
1731         break;
1732 
1733     case 34: /* USERMACRO9  */
1734 
1735       { RELEASE_SV(((*yyvaluep))); }
1736 
1737         break;
1738 
1739     case 35: /* IFDEF  */
1740 
1741       { RELEASE_SV(((*yyvaluep))); }
1742 
1743         break;
1744 
1745     case 36: /* ENDIF  */
1746 
1747       { RELEASE_SV(((*yyvaluep))); }
1748 
1749         break;
1750 
1751     case 37: /* TEXT  */
1752 
1753       { RELEASE_SV(((*yyvaluep))); }
1754 
1755         break;
1756 
1757     case 38: /* RCODE  */
1758 
1759       { RELEASE_SV(((*yyvaluep))); }
1760 
1761         break;
1762 
1763     case 39: /* VERB  */
1764 
1765       { RELEASE_SV(((*yyvaluep))); }
1766 
1767         break;
1768 
1769     case 40: /* COMMENT  */
1770 
1771       { RELEASE_SV(((*yyvaluep))); }
1772 
1773         break;
1774 
1775     case 41: /* UNKNOWN  */
1776 
1777       { RELEASE_SV(((*yyvaluep))); }
1778 
1779         break;
1780 
1781     case 42: /* STARTFILE  */
1782 
1783       { RELEASE_SV(((*yyvaluep))); }
1784 
1785         break;
1786 
1787     case 43: /* STARTFRAGMENT  */
1788 
1789       { RELEASE_SV(((*yyvaluep))); }
1790 
1791         break;
1792 
1793     case 54: /* ArgItems  */
1794 
1795       { RELEASE_SV(((*yyvaluep))); }
1796 
1797         break;
1798 
1799     case 58: /* LatexArg  */
1800 
1801       { RELEASE_SV(((*yyvaluep))); }
1802 
1803         break;
1804 
1805     case 63: /* RLikeArg2  */
1806 
1807       { RELEASE_SV(((*yyvaluep))); }
1808 
1809         break;
1810 
1811     case 65: /* VerbatimArg1  */
1812 
1813       { RELEASE_SV(((*yyvaluep))); }
1814 
1815         break;
1816 
1817     case 66: /* VerbatimArg2  */
1818 
1819       { RELEASE_SV(((*yyvaluep))); }
1820 
1821         break;
1822 
1823     case 67: /* IfDefTarget  */
1824 
1825       { RELEASE_SV(((*yyvaluep))); }
1826 
1827         break;
1828 
1829     case 68: /* goLatexLike  */
1830 
1831       { RELEASE_SV(((*yyvaluep))); }
1832 
1833         break;
1834 
1835     case 69: /* goRLike  */
1836 
1837       { RELEASE_SV(((*yyvaluep))); }
1838 
1839         break;
1840 
1841     case 70: /* goRLike2  */
1842 
1843       { RELEASE_SV(((*yyvaluep))); }
1844 
1845         break;
1846 
1847     case 71: /* goOption  */
1848 
1849       { RELEASE_SV(((*yyvaluep))); }
1850 
1851         break;
1852 
1853     case 72: /* goVerbatim  */
1854 
1855       { RELEASE_SV(((*yyvaluep))); }
1856 
1857         break;
1858 
1859     case 73: /* goVerbatim1  */
1860 
1861       { RELEASE_SV(((*yyvaluep))); }
1862 
1863         break;
1864 
1865     case 74: /* goVerbatim2  */
1866 
1867       { RELEASE_SV(((*yyvaluep))); }
1868 
1869         break;
1870 
1871     case 75: /* goItem0  */
1872 
1873       { RELEASE_SV(((*yyvaluep))); }
1874 
1875         break;
1876 
1877     case 76: /* goItem2  */
1878 
1879       { RELEASE_SV(((*yyvaluep))); }
1880 
1881         break;
1882 
1883     case 78: /* Option  */
1884 
1885       { RELEASE_SV(((*yyvaluep))); }
1886 
1887         break;
1888 
1889 
1890       default:
1891         break;
1892     }
1893   YY_IGNORE_MAYBE_UNINITIALIZED_END
1894 }
1895 
1896 
1897 
1898 
1899 /* The lookahead symbol.  */
1900 int yychar;
1901 
1902 /* The semantic value of the lookahead symbol.  */
1903 YYSTYPE yylval;
1904 /* Location data for the lookahead symbol.  */
1905 YYLTYPE yylloc
1906 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1907   = { 1, 1, 1, 1 }
1908 # endif
1909 ;
1910 /* Number of syntax errors so far.  */
1911 int yynerrs;
1912 
1913 
1914 /*----------.
1915 | yyparse.  |
1916 `----------*/
1917 
1918 int
yyparse(void)1919 yyparse (void)
1920 {
1921     int yystate;
1922     /* Number of tokens to shift before error messages enabled.  */
1923     int yyerrstatus;
1924 
1925     /* The stacks and their tools:
1926        'yyss': related to states.
1927        'yyvs': related to semantic values.
1928        'yyls': related to locations.
1929 
1930        Refer to the stacks through separate pointers, to allow yyoverflow
1931        to reallocate them elsewhere.  */
1932 
1933     /* The state stack.  */
1934     yytype_int16 yyssa[YYINITDEPTH];
1935     yytype_int16 *yyss;
1936     yytype_int16 *yyssp;
1937 
1938     /* The semantic value stack.  */
1939     YYSTYPE yyvsa[YYINITDEPTH];
1940     YYSTYPE *yyvs;
1941     YYSTYPE *yyvsp;
1942 
1943     /* The location stack.  */
1944     YYLTYPE yylsa[YYINITDEPTH];
1945     YYLTYPE *yyls;
1946     YYLTYPE *yylsp;
1947 
1948     /* The locations where the error started and ended.  */
1949     YYLTYPE yyerror_range[3];
1950 
1951     YYSIZE_T yystacksize;
1952 
1953   int yyn;
1954   int yyresult;
1955   /* Lookahead token as an internal (translated) token number.  */
1956   int yytoken = 0;
1957   /* The variables used to return semantic value and location from the
1958      action routines.  */
1959   YYSTYPE yyval;
1960   YYLTYPE yyloc;
1961 
1962 #if YYERROR_VERBOSE
1963   /* Buffer for error messages, and its allocated size.  */
1964   char yymsgbuf[128];
1965   char *yymsg = yymsgbuf;
1966   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1967 #endif
1968 
1969 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1970 
1971   /* The number of symbols on the RHS of the reduced rule.
1972      Keep to zero when no symbol should be popped.  */
1973   int yylen = 0;
1974 
1975   yyssp = yyss = yyssa;
1976   yyvsp = yyvs = yyvsa;
1977   yylsp = yyls = yylsa;
1978   yystacksize = YYINITDEPTH;
1979 
1980   YYDPRINTF ((stderr, "Starting parse\n"));
1981 
1982   yystate = 0;
1983   yyerrstatus = 0;
1984   yynerrs = 0;
1985   yychar = YYEMPTY; /* Cause a token to be read.  */
1986   yylsp[0] = yylloc;
1987   goto yysetstate;
1988 
1989 /*------------------------------------------------------------.
1990 | yynewstate -- Push a new state, which is found in yystate.  |
1991 `------------------------------------------------------------*/
1992  yynewstate:
1993   /* In all cases, when you get here, the value and location stacks
1994      have just been pushed.  So pushing a state here evens the stacks.  */
1995   yyssp++;
1996 
1997  yysetstate:
1998   *yyssp = yystate;
1999 
2000   if (yyss + yystacksize - 1 <= yyssp)
2001     {
2002       /* Get the current used size of the three stacks, in elements.  */
2003       YYSIZE_T yysize = yyssp - yyss + 1;
2004 
2005 #ifdef yyoverflow
2006       {
2007         /* Give user a chance to reallocate the stack.  Use copies of
2008            these so that the &'s don't force the real ones into
2009            memory.  */
2010         YYSTYPE *yyvs1 = yyvs;
2011         yytype_int16 *yyss1 = yyss;
2012         YYLTYPE *yyls1 = yyls;
2013 
2014         /* Each stack pointer address is followed by the size of the
2015            data in use in that stack, in bytes.  This used to be a
2016            conditional around just the two extra args, but that might
2017            be undefined if yyoverflow is a macro.  */
2018         yyoverflow (YY_("memory exhausted"),
2019                     &yyss1, yysize * sizeof (*yyssp),
2020                     &yyvs1, yysize * sizeof (*yyvsp),
2021                     &yyls1, yysize * sizeof (*yylsp),
2022                     &yystacksize);
2023 
2024         yyls = yyls1;
2025         yyss = yyss1;
2026         yyvs = yyvs1;
2027       }
2028 #else /* no yyoverflow */
2029 # ifndef YYSTACK_RELOCATE
2030       goto yyexhaustedlab;
2031 # else
2032       /* Extend the stack our own way.  */
2033       if (YYMAXDEPTH <= yystacksize)
2034         goto yyexhaustedlab;
2035       yystacksize *= 2;
2036       if (YYMAXDEPTH < yystacksize)
2037         yystacksize = YYMAXDEPTH;
2038 
2039       {
2040         yytype_int16 *yyss1 = yyss;
2041         union yyalloc *yyptr =
2042           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
2043         if (! yyptr)
2044           goto yyexhaustedlab;
2045         YYSTACK_RELOCATE (yyss_alloc, yyss);
2046         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
2047         YYSTACK_RELOCATE (yyls_alloc, yyls);
2048 #  undef YYSTACK_RELOCATE
2049         if (yyss1 != yyssa)
2050           YYSTACK_FREE (yyss1);
2051       }
2052 # endif
2053 #endif /* no yyoverflow */
2054 
2055       yyssp = yyss + yysize - 1;
2056       yyvsp = yyvs + yysize - 1;
2057       yylsp = yyls + yysize - 1;
2058 
2059       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
2060                   (unsigned long int) yystacksize));
2061 
2062       if (yyss + yystacksize - 1 <= yyssp)
2063         YYABORT;
2064     }
2065 
2066   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2067 
2068   if (yystate == YYFINAL)
2069     YYACCEPT;
2070 
2071   goto yybackup;
2072 
2073 /*-----------.
2074 | yybackup.  |
2075 `-----------*/
2076 yybackup:
2077 
2078   /* Do appropriate processing given the current state.  Read a
2079      lookahead token if we need one and don't already have one.  */
2080 
2081   /* First try to decide what to do without reference to lookahead token.  */
2082   yyn = yypact[yystate];
2083   if (yypact_value_is_default (yyn))
2084     goto yydefault;
2085 
2086   /* Not known => get a lookahead token if don't already have one.  */
2087 
2088   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
2089   if (yychar == YYEMPTY)
2090     {
2091       YYDPRINTF ((stderr, "Reading a token: "));
2092       yychar = yylex ();
2093     }
2094 
2095   if (yychar <= YYEOF)
2096     {
2097       yychar = yytoken = YYEOF;
2098       YYDPRINTF ((stderr, "Now at end of input.\n"));
2099     }
2100   else
2101     {
2102       yytoken = YYTRANSLATE (yychar);
2103       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2104     }
2105 
2106   /* If the proper action on seeing token YYTOKEN is to reduce or to
2107      detect an error, take that action.  */
2108   yyn += yytoken;
2109   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2110     goto yydefault;
2111   yyn = yytable[yyn];
2112   if (yyn <= 0)
2113     {
2114       if (yytable_value_is_error (yyn))
2115         goto yyerrlab;
2116       yyn = -yyn;
2117       goto yyreduce;
2118     }
2119 
2120   /* Count tokens shifted since error; after three, turn off error
2121      status.  */
2122   if (yyerrstatus)
2123     yyerrstatus--;
2124 
2125   /* Shift the lookahead token.  */
2126   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2127 
2128   /* Discard the shifted token.  */
2129   yychar = YYEMPTY;
2130 
2131   yystate = yyn;
2132   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2133   *++yyvsp = yylval;
2134   YY_IGNORE_MAYBE_UNINITIALIZED_END
2135   *++yylsp = yylloc;
2136   goto yynewstate;
2137 
2138 
2139 /*-----------------------------------------------------------.
2140 | yydefault -- do the default action for the current state.  |
2141 `-----------------------------------------------------------*/
2142 yydefault:
2143   yyn = yydefact[yystate];
2144   if (yyn == 0)
2145     goto yyerrlab;
2146   goto yyreduce;
2147 
2148 
2149 /*-----------------------------.
2150 | yyreduce -- Do a reduction.  |
2151 `-----------------------------*/
2152 yyreduce:
2153   /* yyn is the number of a rule to reduce with.  */
2154   yylen = yyr2[yyn];
2155 
2156   /* If YYLEN is nonzero, implement the default value of the action:
2157      '$$ = $1'.
2158 
2159      Otherwise, the following line sets YYVAL to garbage.
2160      This behavior is undocumented and Bison
2161      users should not rely upon it.  Assigning to YYVAL
2162      unconditionally makes the parser a bit smaller, and it avoids a
2163      GCC warning that YYVAL may be used uninitialized.  */
2164   yyval = yyvsp[1-yylen];
2165 
2166   /* Default location.  */
2167   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
2168   YY_REDUCE_PRINT (yyn);
2169   switch (yyn)
2170     {
2171         case 2:
2172 
2173     { xxsavevalue((yyvsp[-1]), &(yyloc)); RELEASE_SV((yyvsp[-2])); YYACCEPT; }
2174 
2175     break;
2176 
2177   case 3:
2178 
2179     { xxsavevalue((yyvsp[-1]), &(yyloc)); RELEASE_SV((yyvsp[-2])); YYACCEPT; }
2180 
2181     break;
2182 
2183   case 4:
2184 
2185     { PRESERVE_SV(parseState.Value = R_NilValue);  YYABORT; }
2186 
2187     break;
2188 
2189   case 5:
2190 
2191     { (yyval) = (yyvsp[0]); RELEASE_SV((yyvsp[-1])); }
2192 
2193     break;
2194 
2195   case 6:
2196 
2197     { (yyval) = (yyvsp[0]); }
2198 
2199     break;
2200 
2201   case 7:
2202 
2203     { (yyval) = xxnewlist((yyvsp[0])); }
2204 
2205     break;
2206 
2207   case 8:
2208 
2209     { (yyval) = xxlist((yyvsp[-1]), (yyvsp[0])); }
2210 
2211     break;
2212 
2213   case 9:
2214 
2215     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2216 
2217     break;
2218 
2219   case 10:
2220 
2221     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), HAS_SEXPR, &(yyloc)); }
2222 
2223     break;
2224 
2225   case 11:
2226 
2227     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2228 
2229     break;
2230 
2231   case 12:
2232 
2233     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2234 
2235     break;
2236 
2237   case 13:
2238 
2239     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2240 
2241     break;
2242 
2243   case 14:
2244 
2245     { (yyval) = xxmarkup2((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), 2, STATIC, &(yyloc)); }
2246 
2247     break;
2248 
2249   case 15:
2250 
2251     { (yyval) = xxmarkup2((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), 2, HAS_IFDEF, &(yyloc)); RELEASE_SV((yyvsp[0])); }
2252 
2253     break;
2254 
2255   case 16:
2256 
2257     { (yyval) = xxmarkup2((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), 2, HAS_IFDEF, &(yyloc)); }
2258 
2259     break;
2260 
2261   case 17:
2262 
2263     { (yyval) = xxmarkup((yyvsp[-2]), (yyvsp[0]), HAS_SEXPR, &(yyloc)); xxpopMode((yyvsp[-1])); }
2264 
2265     break;
2266 
2267   case 18:
2268 
2269     { (yyval) = xxOptionmarkup((yyvsp[-3]), (yyvsp[-1]), (yyvsp[0]), HAS_SEXPR, &(yyloc)); xxpopMode((yyvsp[-2])); }
2270 
2271     break;
2272 
2273   case 19:
2274 
2275     { (yyval) = xxtag((yyvsp[0]), COMMENT, &(yyloc)); }
2276 
2277     break;
2278 
2279   case 20:
2280 
2281     { (yyval) = xxtag((yyvsp[0]), TEXT, &(yyloc)); }
2282 
2283     break;
2284 
2285   case 21:
2286 
2287     { (yyval) = (yyvsp[0]); }
2288 
2289     break;
2290 
2291   case 22:
2292 
2293     { (yyval) = (yyvsp[0]); }
2294 
2295     break;
2296 
2297   case 23:
2298 
2299     { (yyval) = xxnewlist((yyvsp[0])); }
2300 
2301     break;
2302 
2303   case 24:
2304 
2305     { (yyval) = xxlist((yyvsp[-1]), (yyvsp[0])); }
2306 
2307     break;
2308 
2309   case 25:
2310 
2311     { (yyval) = xxtag((yyvsp[0]), TEXT, &(yyloc)); }
2312 
2313     break;
2314 
2315   case 26:
2316 
2317     { (yyval) = xxtag((yyvsp[0]), RCODE, &(yyloc)); }
2318 
2319     break;
2320 
2321   case 27:
2322 
2323     { (yyval) = xxtag((yyvsp[0]), VERB, &(yyloc)); }
2324 
2325     break;
2326 
2327   case 28:
2328 
2329     { (yyval) = xxtag((yyvsp[0]), COMMENT, &(yyloc)); }
2330 
2331     break;
2332 
2333   case 29:
2334 
2335     { (yyval) = xxtag((yyvsp[0]), UNKNOWN, &(yyloc)); yyerror(yyunknown); }
2336 
2337     break;
2338 
2339   case 30:
2340 
2341     { (yyval) = xxmarkup(R_NilValue, (yyvsp[0]), STATIC, &(yyloc)); }
2342 
2343     break;
2344 
2345   case 31:
2346 
2347     { (yyval) = (yyvsp[0]); }
2348 
2349     break;
2350 
2351   case 32:
2352 
2353     { (yyval) = (yyvsp[0]); }
2354 
2355     break;
2356 
2357   case 33:
2358 
2359     { (yyval) = (yyvsp[0]); }
2360 
2361     break;
2362 
2363   case 34:
2364 
2365     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2366 
2367     break;
2368 
2369   case 35:
2370 
2371     { (yyval) = xxmarkup2((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), 2, STATIC, &(yyloc)); }
2372 
2373     break;
2374 
2375   case 36:
2376 
2377     { (yyval) = xxmarkup3((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2378 
2379     break;
2380 
2381   case 37:
2382 
2383     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2384 
2385     break;
2386 
2387   case 38:
2388 
2389     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2390 
2391     break;
2392 
2393   case 39:
2394 
2395     { (yyval) = xxmarkup((yyvsp[-2]), (yyvsp[0]), STATIC, &(yyloc)); xxpopMode((yyvsp[-1])); }
2396 
2397     break;
2398 
2399   case 40:
2400 
2401     { (yyval) = xxOptionmarkup((yyvsp[-3]), (yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); xxpopMode((yyvsp[-2])); }
2402 
2403     break;
2404 
2405   case 41:
2406 
2407     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2408 
2409     break;
2410 
2411   case 42:
2412 
2413     { (yyval) = xxmarkup((yyvsp[-2]), (yyvsp[0]), HAS_SEXPR, &(yyloc)); xxpopMode((yyvsp[-1])); }
2414 
2415     break;
2416 
2417   case 43:
2418 
2419     { (yyval) = xxOptionmarkup((yyvsp[-3]), (yyvsp[-1]), (yyvsp[0]), HAS_SEXPR, &(yyloc)); xxpopMode((yyvsp[-2])); }
2420 
2421     break;
2422 
2423   case 44:
2424 
2425     { (yyval) = xxmarkup((yyvsp[-1]), (yyvsp[0]), STATIC, &(yyloc)); }
2426 
2427     break;
2428 
2429   case 45:
2430 
2431     { (yyval) = xxmarkup2((yyvsp[-1]), (yyvsp[0]), R_NilValue, 1, STATIC, &(yyloc)); }
2432 
2433     break;
2434 
2435   case 46:
2436 
2437     { (yyval) = xxmarkup2((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), 2, STATIC, &(yyloc)); }
2438 
2439     break;
2440 
2441   case 47:
2442 
2443     { (yyval) = xxmarkup((yyvsp[0]), R_NilValue, STATIC, &(yyloc)); }
2444 
2445     break;
2446 
2447   case 48:
2448 
2449     { (yyval) = xxmarkup2((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), 2, HAS_IFDEF, &(yyloc)); RELEASE_SV((yyvsp[0])); }
2450 
2451     break;
2452 
2453   case 49:
2454 
2455     { (yyval) = xxmarkup2((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), 2, HAS_IFDEF, &(yyloc)); }
2456 
2457     break;
2458 
2459   case 50:
2460 
2461     { (yyval) = xxmarkup2((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), 2, STATIC, &(yyloc)); }
2462 
2463     break;
2464 
2465   case 51:
2466 
2467     { (yyval) = xxnewcommand((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), &(yyloc)); }
2468 
2469     break;
2470 
2471   case 52:
2472 
2473     { (yyval) = xxusermacro((yyvsp[0]), xxnewlist(NULL), &(yyloc)); }
2474 
2475     break;
2476 
2477   case 53:
2478 
2479     { (yyval) = xxusermacro((yyvsp[-1]), xxnewlist((yyvsp[0])), &(yyloc)); }
2480 
2481     break;
2482 
2483   case 54:
2484 
2485     { (yyval) = xxusermacro((yyvsp[-2]), xxnewlist2((yyvsp[-1]), (yyvsp[0])), &(yyloc)); }
2486 
2487     break;
2488 
2489   case 55:
2490 
2491     { (yyval) = xxusermacro((yyvsp[-3]), xxnewlist3((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])), &(yyloc)); }
2492 
2493     break;
2494 
2495   case 56:
2496 
2497     { (yyval) = xxusermacro((yyvsp[-4]), xxnewlist4((yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])), &(yyloc)); }
2498 
2499     break;
2500 
2501   case 57:
2502 
2503     { (yyval) = xxusermacro((yyvsp[-5]), xxnewlist5((yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])), &(yyloc)); }
2504 
2505     break;
2506 
2507   case 58:
2508 
2509     { (yyval) = xxusermacro((yyvsp[-6]), xxnewlist6((yyvsp[-5]), (yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])), &(yyloc)); }
2510 
2511     break;
2512 
2513   case 59:
2514 
2515     { (yyval) = xxusermacro((yyvsp[-8]), xxnewlist7((yyvsp[-7]), (yyvsp[-6]), (yyvsp[-5]), (yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1])), &(yyloc)); }
2516 
2517     break;
2518 
2519   case 60:
2520 
2521     { (yyval) = xxusermacro((yyvsp[-9]), xxnewlist8((yyvsp[-8]), (yyvsp[-7]), (yyvsp[-6]), (yyvsp[-5]), (yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1])), &(yyloc)); }
2522 
2523     break;
2524 
2525   case 61:
2526 
2527     { (yyval) = xxusermacro((yyvsp[-10]), xxnewlist9((yyvsp[-9]), (yyvsp[-8]), (yyvsp[-7]), (yyvsp[-6]), (yyvsp[-5]), (yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1])), &(yyloc)); }
2528 
2529     break;
2530 
2531   case 62:
2532 
2533     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2534 
2535     break;
2536 
2537   case 63:
2538 
2539     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2540 
2541     break;
2542 
2543   case 64:
2544 
2545     { xxpopMode((yyvsp[-1])); (yyval) = xxnewlist((yyvsp[0]));
2546      						  if(wCalls)
2547     	    					      warning(_("bad markup (extra space?) at %s:%d:%d"),
2548     	    					            parseState.xxBasename, (yylsp[0]).first_line, (yylsp[0]).first_column);
2549      						  else
2550     	    					      warningcall(R_NilValue, _("bad markup (extra space?) at %s:%d:%d"),
2551     	    					            parseState.xxBasename, (yylsp[0]).first_line, (yylsp[0]).first_column);
2552 						}
2553 
2554     break;
2555 
2556   case 65:
2557 
2558     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2559 
2560     break;
2561 
2562   case 66:
2563 
2564     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2565 
2566     break;
2567 
2568   case 67:
2569 
2570     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2571 
2572     break;
2573 
2574   case 68:
2575 
2576     { xxpopMode((yyvsp[-2])); (yyval) = (yyvsp[-1]); }
2577 
2578     break;
2579 
2580   case 69:
2581 
2582     { xxpopMode((yyvsp[-1])); (yyval) = xxnewlist(NULL); }
2583 
2584     break;
2585 
2586   case 70:
2587 
2588     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2589 
2590     break;
2591 
2592   case 71:
2593 
2594     { xxpopMode((yyvsp[-1])); (yyval) = (yyvsp[0]); }
2595 
2596     break;
2597 
2598   case 72:
2599 
2600     { xxpopMode((yyvsp[-2])); (yyval) = (yyvsp[-1]); }
2601 
2602     break;
2603 
2604   case 73:
2605 
2606     { xxpopMode((yyvsp[-1])); (yyval) = xxnewlist(NULL); }
2607 
2608     break;
2609 
2610   case 74:
2611 
2612     { xxpopMode((yyvsp[-1])); (yyval) = xxnewlist(xxtag((yyvsp[0]), TEXT, &(yyloc))); }
2613 
2614     break;
2615 
2616   case 75:
2617 
2618     { (yyval) = xxpushMode(LATEXLIKE, UNKNOWN, FALSE); }
2619 
2620     break;
2621 
2622   case 76:
2623 
2624     { (yyval) = xxpushMode(RLIKE, UNKNOWN, FALSE); }
2625 
2626     break;
2627 
2628   case 77:
2629 
2630     { parseState.xxbraceDepth--; (yyval) = xxpushMode(RLIKE, UNKNOWN, FALSE); parseState.xxbraceDepth++; }
2631 
2632     break;
2633 
2634   case 78:
2635 
2636     { (yyval) = xxpushMode(INOPTION, UNKNOWN, FALSE); }
2637 
2638     break;
2639 
2640   case 79:
2641 
2642     { (yyval) = xxpushMode(VERBATIM, UNKNOWN, FALSE); }
2643 
2644     break;
2645 
2646   case 80:
2647 
2648     { (yyval) = xxpushMode(VERBATIM, UNKNOWN, TRUE); }
2649 
2650     break;
2651 
2652   case 81:
2653 
2654     { parseState.xxbraceDepth--; (yyval) = xxpushMode(VERBATIM, UNKNOWN, FALSE); parseState.xxbraceDepth++; }
2655 
2656     break;
2657 
2658   case 82:
2659 
2660     { (yyval) = xxpushMode(LATEXLIKE, ESCAPE, FALSE); }
2661 
2662     break;
2663 
2664   case 83:
2665 
2666     { (yyval) = xxpushMode(LATEXLIKE, LATEXMACRO2, FALSE); }
2667 
2668     break;
2669 
2670   case 84:
2671 
2672     { (yyval) = (yyvsp[-1]); }
2673 
2674     break;
2675 
2676   case 85:
2677 
2678     { (yyval) = xxnewlist(NULL); }
2679 
2680     break;
2681 
2682   case 86:
2683 
2684     { (yyval) = (yyvsp[-2]); }
2685 
2686     break;
2687 
2688   case 87:
2689 
2690     { (yyval) = xxnewlist(NULL); }
2691 
2692     break;
2693 
2694   case 88:
2695 
2696     { (yyval) = (yyvsp[-2]); }
2697 
2698     break;
2699 
2700   case 89:
2701 
2702     { (yyval) = (yyvsp[-1]); }
2703 
2704     break;
2705 
2706 
2707 
2708       default: break;
2709     }
2710   /* User semantic actions sometimes alter yychar, and that requires
2711      that yytoken be updated with the new translation.  We take the
2712      approach of translating immediately before every use of yytoken.
2713      One alternative is translating here after every semantic action,
2714      but that translation would be missed if the semantic action invokes
2715      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2716      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
2717      incorrect destructor might then be invoked immediately.  In the
2718      case of YYERROR or YYBACKUP, subsequent parser actions might lead
2719      to an incorrect destructor call or verbose syntax error message
2720      before the lookahead is translated.  */
2721   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2722 
2723   YYPOPSTACK (yylen);
2724   yylen = 0;
2725   YY_STACK_PRINT (yyss, yyssp);
2726 
2727   *++yyvsp = yyval;
2728   *++yylsp = yyloc;
2729 
2730   /* Now 'shift' the result of the reduction.  Determine what state
2731      that goes to, based on the state we popped back to and the rule
2732      number reduced by.  */
2733 
2734   yyn = yyr1[yyn];
2735 
2736   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2737   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2738     yystate = yytable[yystate];
2739   else
2740     yystate = yydefgoto[yyn - YYNTOKENS];
2741 
2742   goto yynewstate;
2743 
2744 
2745 /*--------------------------------------.
2746 | yyerrlab -- here on detecting error.  |
2747 `--------------------------------------*/
2748 yyerrlab:
2749   /* Make sure we have latest lookahead translation.  See comments at
2750      user semantic actions for why this is necessary.  */
2751   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2752 
2753   /* If not already recovering from an error, report this error.  */
2754   if (!yyerrstatus)
2755     {
2756       ++yynerrs;
2757 #if ! YYERROR_VERBOSE
2758       yyerror (YY_("syntax error"));
2759 #else
2760 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2761                                         yyssp, yytoken)
2762       {
2763         char const *yymsgp = YY_("syntax error");
2764         int yysyntax_error_status;
2765         yysyntax_error_status = YYSYNTAX_ERROR;
2766         if (yysyntax_error_status == 0)
2767           yymsgp = yymsg;
2768         else if (yysyntax_error_status == 1)
2769           {
2770             if (yymsg != yymsgbuf)
2771               YYSTACK_FREE (yymsg);
2772             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2773             if (!yymsg)
2774               {
2775                 yymsg = yymsgbuf;
2776                 yymsg_alloc = sizeof yymsgbuf;
2777                 yysyntax_error_status = 2;
2778               }
2779             else
2780               {
2781                 yysyntax_error_status = YYSYNTAX_ERROR;
2782                 yymsgp = yymsg;
2783               }
2784           }
2785         yyerror (yymsgp);
2786         if (yysyntax_error_status == 2)
2787           goto yyexhaustedlab;
2788       }
2789 # undef YYSYNTAX_ERROR
2790 #endif
2791     }
2792 
2793   yyerror_range[1] = yylloc;
2794 
2795   if (yyerrstatus == 3)
2796     {
2797       /* If just tried and failed to reuse lookahead token after an
2798          error, discard it.  */
2799 
2800       if (yychar <= YYEOF)
2801         {
2802           /* Return failure if at end of input.  */
2803           if (yychar == YYEOF)
2804             YYABORT;
2805         }
2806       else
2807         {
2808           yydestruct ("Error: discarding",
2809                       yytoken, &yylval, &yylloc);
2810           yychar = YYEMPTY;
2811         }
2812     }
2813 
2814   /* Else will try to reuse lookahead token after shifting the error
2815      token.  */
2816   goto yyerrlab1;
2817 
2818 
2819 /*---------------------------------------------------.
2820 | yyerrorlab -- error raised explicitly by YYERROR.  |
2821 `---------------------------------------------------*/
2822 yyerrorlab:
2823 
2824   /* Pacify compilers like GCC when the user code never invokes
2825      YYERROR and the label yyerrorlab therefore never appears in user
2826      code.  */
2827   if (/*CONSTCOND*/ 0)
2828      goto yyerrorlab;
2829 
2830   yyerror_range[1] = yylsp[1-yylen];
2831   /* Do not reclaim the symbols of the rule whose action triggered
2832      this YYERROR.  */
2833   YYPOPSTACK (yylen);
2834   yylen = 0;
2835   YY_STACK_PRINT (yyss, yyssp);
2836   yystate = *yyssp;
2837   goto yyerrlab1;
2838 
2839 
2840 /*-------------------------------------------------------------.
2841 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2842 `-------------------------------------------------------------*/
2843 yyerrlab1:
2844   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2845 
2846   for (;;)
2847     {
2848       yyn = yypact[yystate];
2849       if (!yypact_value_is_default (yyn))
2850         {
2851           yyn += YYTERROR;
2852           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2853             {
2854               yyn = yytable[yyn];
2855               if (0 < yyn)
2856                 break;
2857             }
2858         }
2859 
2860       /* Pop the current state because it cannot handle the error token.  */
2861       if (yyssp == yyss)
2862         YYABORT;
2863 
2864       yyerror_range[1] = *yylsp;
2865       yydestruct ("Error: popping",
2866                   yystos[yystate], yyvsp, yylsp);
2867       YYPOPSTACK (1);
2868       yystate = *yyssp;
2869       YY_STACK_PRINT (yyss, yyssp);
2870     }
2871 
2872   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2873   *++yyvsp = yylval;
2874   YY_IGNORE_MAYBE_UNINITIALIZED_END
2875 
2876   yyerror_range[2] = yylloc;
2877   /* Using YYLLOC is tempting, but would change the location of
2878      the lookahead.  YYLOC is available though.  */
2879   YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
2880   *++yylsp = yyloc;
2881 
2882   /* Shift the error token.  */
2883   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2884 
2885   yystate = yyn;
2886   goto yynewstate;
2887 
2888 
2889 /*-------------------------------------.
2890 | yyacceptlab -- YYACCEPT comes here.  |
2891 `-------------------------------------*/
2892 yyacceptlab:
2893   yyresult = 0;
2894   goto yyreturn;
2895 
2896 /*-----------------------------------.
2897 | yyabortlab -- YYABORT comes here.  |
2898 `-----------------------------------*/
2899 yyabortlab:
2900   yyresult = 1;
2901   goto yyreturn;
2902 
2903 #if !defined yyoverflow || YYERROR_VERBOSE
2904 /*-------------------------------------------------.
2905 | yyexhaustedlab -- memory exhaustion comes here.  |
2906 `-------------------------------------------------*/
2907 yyexhaustedlab:
2908   yyerror (YY_("memory exhausted"));
2909   yyresult = 2;
2910   /* Fall through.  */
2911 #endif
2912 
2913 yyreturn:
2914   if (yychar != YYEMPTY)
2915     {
2916       /* Make sure we have latest lookahead translation.  See comments at
2917          user semantic actions for why this is necessary.  */
2918       yytoken = YYTRANSLATE (yychar);
2919       yydestruct ("Cleanup: discarding lookahead",
2920                   yytoken, &yylval, &yylloc);
2921     }
2922   /* Do not reclaim the symbols of the rule whose action triggered
2923      this YYABORT or YYACCEPT.  */
2924   YYPOPSTACK (yylen);
2925   YY_STACK_PRINT (yyss, yyssp);
2926   while (yyssp != yyss)
2927     {
2928       yydestruct ("Cleanup: popping",
2929                   yystos[*yyssp], yyvsp, yylsp);
2930       YYPOPSTACK (1);
2931     }
2932 #ifndef yyoverflow
2933   if (yyss != yyssa)
2934     YYSTACK_FREE (yyss);
2935 #endif
2936 #if YYERROR_VERBOSE
2937   if (yymsg != yymsgbuf)
2938     YYSTACK_FREE (yymsg);
2939 #endif
2940   return yyresult;
2941 }
2942 
2943 
2944 
xxpushMode(int newmode,int newitem,int neweqn)2945 static SEXP xxpushMode(int newmode, int newitem, int neweqn)
2946 {
2947     SEXP ans;
2948 
2949     PRESERVE_SV(ans = allocVector(INTSXP, 7));
2950     INTEGER(ans)[0] = parseState.xxmode;		/* Lexer mode */
2951     INTEGER(ans)[1] = parseState.xxitemType;	/* What is \item? */
2952     INTEGER(ans)[2] = parseState.xxbraceDepth;	/* Brace depth used in RCODE and VERBATIM */
2953     INTEGER(ans)[3] = parseState.xxinRString;      /* Quote char that started a string */
2954     INTEGER(ans)[4] = parseState.xxQuoteLine;      /* Where the quote was */
2955     INTEGER(ans)[5] = parseState.xxQuoteCol;       /*           "         */
2956     INTEGER(ans)[6] = parseState.xxinEqn;          /* In the first arg to \eqn or \deqn:  no escapes */
2957 
2958 #if DEBUGMODE
2959     Rprintf("xxpushMode(%d, %s) pushes %d, %s, %d\n", newmode, yytname[YYTRANSLATE(newitem)],
2960     						parseState.xxmode, yytname[YYTRANSLATE(parseState.xxitemType)], parseState.xxbraceDepth);
2961 #endif
2962     parseState.xxmode = newmode;
2963     parseState.xxitemType = newitem;
2964     parseState.xxbraceDepth = 0;
2965     parseState.xxinRString = 0;
2966     parseState.xxinEqn = neweqn;
2967 
2968     return ans;
2969 }
2970 
xxpopMode(SEXP oldmode)2971 static void xxpopMode(SEXP oldmode)
2972 {
2973 #if DEBUGVALS
2974     Rprintf("xxpopMode(%d, %s, %d) replaces %d, %s, %d\n", INTEGER(oldmode)[0], yytname[YYTRANSLATE(INTEGER(oldmode)[1])], INTEGER(oldmode)[2],
2975     					parseState.xxmode, yytname[YYTRANSLATE(parseState.xxitemType)], parseState.xxbraceDepth);
2976 #endif
2977     parseState.xxmode = INTEGER(oldmode)[0];
2978     parseState.xxitemType = INTEGER(oldmode)[1];
2979     parseState.xxbraceDepth = INTEGER(oldmode)[2];
2980     parseState.xxinRString = INTEGER(oldmode)[3];
2981     parseState.xxQuoteLine = INTEGER(oldmode)[4];
2982     parseState.xxQuoteCol  = INTEGER(oldmode)[5];
2983     parseState.xxinEqn	= INTEGER(oldmode)[6];
2984 
2985     RELEASE_SV(oldmode);
2986 }
2987 
getDynamicFlag(SEXP item)2988 static int getDynamicFlag(SEXP item)
2989 {
2990     SEXP flag = getAttrib(item, R_DynamicFlagSymbol);
2991     if (isNull(flag)) return 0;
2992     else return INTEGER(flag)[0];
2993 }
2994 
setDynamicFlag(SEXP item,int flag)2995 static void setDynamicFlag(SEXP item, int flag)
2996 {
2997     if (flag)
2998 	setAttrib(item, R_DynamicFlagSymbol, ScalarInteger(flag));
2999 }
3000 
xxnewlist(SEXP item)3001 static SEXP xxnewlist(SEXP item)
3002 {
3003     SEXP ans;
3004 #if DEBUGVALS
3005     Rprintf("xxnewlist(item=%p)", item);
3006 #endif
3007     PRESERVE_SV(ans = NewList());
3008     if (item) {
3009     	int flag = getDynamicFlag(item);
3010 	GrowList(ans, item);
3011     	setDynamicFlag(ans, flag);
3012 	RELEASE_SV(item);
3013     }
3014 #if DEBUGVALS
3015     Rprintf(" result: %p is length %d\n", ans, length(ans));
3016 #endif
3017     return ans;
3018 }
3019 
xxnewlist2(SEXP item1,SEXP item2)3020 static SEXP xxnewlist2(SEXP item1, SEXP item2)
3021 {
3022     return xxlist(xxnewlist(item1), item2);
3023 }
3024 
xxnewlist3(SEXP item1,SEXP item2,SEXP item3)3025 static SEXP xxnewlist3(SEXP item1, SEXP item2, SEXP item3)
3026 {
3027     return xxlist(xxnewlist2(item1, item2), item3);
3028 }
3029 
xxnewlist4(SEXP item1,SEXP item2,SEXP item3,SEXP item4)3030 static SEXP xxnewlist4(SEXP item1, SEXP item2, SEXP item3, SEXP item4)
3031 {
3032     return xxlist(xxnewlist3(item1, item2, item3), item4);
3033 }
3034 
xxnewlist5(SEXP item1,SEXP item2,SEXP item3,SEXP item4,SEXP item5)3035 static SEXP xxnewlist5(SEXP item1, SEXP item2, SEXP item3, SEXP item4, SEXP item5)
3036 {
3037     return xxlist(xxnewlist4(item1, item2, item3, item4), item5);
3038 }
3039 
xxnewlist6(SEXP item1,SEXP item2,SEXP item3,SEXP item4,SEXP item5,SEXP item6)3040 static SEXP xxnewlist6(SEXP item1, SEXP item2, SEXP item3, SEXP item4, SEXP item5,
3041 		       SEXP item6)
3042 {
3043     return xxlist(xxnewlist5(item1, item2, item3, item4, item5), item6);
3044 }
3045 
xxnewlist7(SEXP item1,SEXP item2,SEXP item3,SEXP item4,SEXP item5,SEXP item6,SEXP item7)3046 static SEXP xxnewlist7(SEXP item1, SEXP item2, SEXP item3, SEXP item4, SEXP item5,
3047 		       SEXP item6, SEXP item7)
3048 {
3049     return xxlist(xxnewlist6(item1, item2, item3, item4, item5, item6), item7);
3050 }
3051 
xxnewlist8(SEXP item1,SEXP item2,SEXP item3,SEXP item4,SEXP item5,SEXP item6,SEXP item7,SEXP item8)3052 static SEXP xxnewlist8(SEXP item1, SEXP item2, SEXP item3, SEXP item4, SEXP item5,
3053 		       SEXP item6, SEXP item7, SEXP item8)
3054 {
3055     return xxlist(xxnewlist7(item1, item2, item3, item4, item5, item6, item7), item8);
3056 }
3057 
xxnewlist9(SEXP item1,SEXP item2,SEXP item3,SEXP item4,SEXP item5,SEXP item6,SEXP item7,SEXP item8,SEXP item9)3058 static SEXP xxnewlist9(SEXP item1, SEXP item2, SEXP item3, SEXP item4, SEXP item5,
3059 		       SEXP item6, SEXP item7, SEXP item8, SEXP item9)
3060 {
3061     return xxlist(xxnewlist8(item1, item2, item3, item4, item5, item6, item7, item8),
3062                   item9);
3063 }
3064 
xxlist(SEXP list,SEXP item)3065 static SEXP xxlist(SEXP list, SEXP item)
3066 {
3067     int flag = getDynamicFlag(list) | getDynamicFlag(item);
3068 #if DEBUGVALS
3069     Rprintf("xxlist(list=%p, item=%p)", list, item);
3070 #endif
3071     GrowList(list, item);
3072     RELEASE_SV(item);
3073     setDynamicFlag(list, flag);
3074 #if DEBUGVALS
3075     Rprintf(" result: %p is length %d\n", list, length(list));
3076 #endif
3077     return list;
3078 }
3079 
xxmarkup(SEXP header,SEXP body,int flag,YYLTYPE * lloc)3080 static SEXP xxmarkup(SEXP header, SEXP body, int flag, YYLTYPE *lloc)
3081 {
3082     SEXP ans;
3083 #if DEBUGVALS
3084     Rprintf("xxmarkup(header=%p, body=%p)", header, body);
3085 #endif
3086     if (isNull(body))
3087         PRESERVE_SV(ans = allocVector(VECSXP, 0));
3088     else {
3089         flag |= getDynamicFlag(body);
3090 	PRESERVE_SV(ans = PairToVectorList(CDR(body)));
3091 	RELEASE_SV(body);
3092     }
3093     if (isNull(header))
3094 	setAttrib(ans, R_RdTagSymbol, mkString("LIST"));
3095     else {
3096 	setAttrib(ans, R_RdTagSymbol, header);
3097 	RELEASE_SV(header);
3098     }
3099     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3100     setDynamicFlag(ans, flag);
3101 #if DEBUGVALS
3102     Rprintf(" result: %p\n", ans);
3103 #endif
3104     return ans;
3105 }
3106 
xxnewcommand(SEXP cmd,SEXP name,SEXP defn,YYLTYPE * lloc)3107 static SEXP xxnewcommand(SEXP cmd, SEXP name, SEXP defn, YYLTYPE *lloc)
3108 {
3109     SEXP ans, prev, thename, thedefn;
3110     char buffer[128];
3111     const char *c;
3112     int maxarg = 0;
3113 #if DEBUGVALS
3114     Rprintf("xxnewcommand(cmd=%p, name=%p, defn=%p)", cmd, name, defn);
3115 #endif
3116     thename = CADR(name);
3117     thedefn = CADR(defn);
3118     if (TYPEOF(thedefn) == STRSXP)
3119     	PROTECT(thedefn = mkString(CHAR(STRING_ELT(thedefn,0))));
3120     else
3121     	PROTECT(thedefn = mkString(""));
3122     if (warnDups) {
3123 	prev = findVar(installTrChar(STRING_ELT(thename, 0)), parseState.xxMacroList);
3124     	if (prev != R_UnboundValue && strcmp(CHAR(STRING_ELT(cmd,0)), "\\renewcommand")) {
3125 	    snprintf(buffer, sizeof(buffer), _("Macro '%s' previously defined."),
3126                  CHAR(STRING_ELT(thename, 0)));
3127             yyerror(buffer);
3128         }
3129     }
3130     for (c = CHAR(STRING_ELT(thedefn, 0)); *c; c++) {
3131     	if (*c == '#' && isdigit(*(c+1)))
3132     	    maxarg = imax2(maxarg, *(c+1) - '0');
3133     }
3134     if (maxarg > 4) {
3135     	snprintf(buffer, sizeof(buffer), _("At most 4 arguments are allowed for user defined macros."));
3136 	yyerror(buffer);
3137     }
3138     PROTECT(ans = ScalarInteger(USERMACRO + maxarg));
3139     setAttrib(ans, R_RdTagSymbol, cmd);
3140     setAttrib(ans, R_DefinitionSymbol, thedefn);
3141     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3142     defineVar(installTrChar(STRING_ELT(thename, 0)), ans, parseState.xxMacroList);
3143     UNPROTECT(2); /* thedefn, ans */
3144 
3145     PRESERVE_SV(ans);
3146     RELEASE_SV(cmd);
3147     RELEASE_SV(name);
3148     RELEASE_SV(defn);
3149     return ans;
3150 }
3151 
3152 #define START_MACRO -2
3153 #define END_MACRO -3
3154 
isComment(SEXP elt)3155 static Rboolean isComment(SEXP elt)
3156 {
3157     SEXP a = getAttrib(elt, R_RdTagSymbol);
3158     return isString(a) && LENGTH(a) == 1 &&
3159            !strcmp(CHAR(STRING_ELT(a, 0)), "COMMENT");
3160 }
3161 
xxusermacro(SEXP macro,SEXP args,YYLTYPE * lloc)3162 static SEXP xxusermacro(SEXP macro, SEXP args, YYLTYPE *lloc)
3163 {
3164     SEXP ans, value, nextarg;
3165     int i,len;
3166     const char *c, *start ;
3167 
3168 #if DEBUGVALS
3169     Rprintf("xxusermacro(macro=%p, args=%p)", macro, args);
3170 #endif
3171     len = length(args)-1;
3172     PRESERVE_SV(ans = allocVector(STRSXP, len + 1));
3173     value = UserMacroLookup(CHAR(STRING_ELT(macro,0)));
3174     if (TYPEOF(value) == STRSXP)
3175     	SET_STRING_ELT(ans, 0, STRING_ELT(value, 0));
3176     else
3177     	error(_("No macro definition for '%s'."), CHAR(STRING_ELT(macro,0)));
3178 
3179     for (i = 0, nextarg=args; i < len; i++, nextarg = CDR(nextarg)) {
3180 	if (isNull(CDR(CADR(nextarg)))) {
3181 	    /* This happens for an empty argument {} and for invocation
3182 	       of a macro with zero parameters. In that case, the ""
3183 	       element of ans is not needed but does no harm. */
3184 	    SET_STRING_ELT(ans, i+1, mkChar(""));
3185 	    continue;
3186 	}
3187 	if (isNull(CDR(CDR(CADR(nextarg))))) {
3188 	    /* The common case: argument without newline nor comment.
3189 	       (when the length is 1, there can be no comment) */
3190 	    SEXP s = CADR(CADR(nextarg));
3191 	    if (TYPEOF(s) == STRSXP && LENGTH(s) == 1)
3192 		SET_STRING_ELT(ans, i+1, STRING_ELT(s, 0));
3193 	    else
3194 		error("internal error: invalid argument to xxusermacro");
3195 	    continue;
3196 	}
3197 
3198 	/* An argument with a newline or comment or both. Exclude comments and
3199 	   concatenate VERBs from different lines (newline characters are
3200 	   in the VERBs already. */
3201 	const void *vmax = vmaxget();
3202 	SEXP si;
3203 	size_t ilen = 0;
3204 	for(si = CDR(CADR(nextarg)); si != R_NilValue; si = CDR(si)) {
3205 	    SEXP stri = CAR(si);
3206 	    if (TYPEOF(stri) == STRSXP && LENGTH(stri) == 1) {
3207 		if (!isComment(stri))
3208 		    ilen += LENGTH(STRING_ELT(stri, 0));
3209 	    } else
3210 		error("internal error: invalid argument to xxusermacro");
3211 	}
3212 
3213 	char *str = (char *)R_alloc(ilen + 1, sizeof(char));
3214 	size_t offset = 0;
3215 	for(si = CDR(CADR(nextarg)); si != R_NilValue; si = CDR(si)) {
3216 	    SEXP stri = CAR(si);
3217 	    if (!isComment(stri)) {
3218 		int nc = LENGTH(STRING_ELT(stri, 0));
3219 		memcpy(str + offset, CHAR(STRING_ELT(stri, 0)), nc);
3220 		offset += nc;
3221 	    }
3222 	}
3223 	str[offset] = '\0';
3224 	SET_STRING_ELT(ans, i+1, mkChar(str));
3225         vmaxset(vmax);
3226     }
3227     RELEASE_SV(args);
3228 
3229     /* Now push the expanded macro onto the input stream, in reverse order */
3230     xxungetc(END_MACRO);
3231     start = CHAR(STRING_ELT(ans, 0));
3232     for (c = start + strlen(start); c > start; c--) {
3233     	if (c > start + 1 && *(c-2) == '#' && isdigit(*(c-1))) {
3234     	    int which = *(c-1) - '0';
3235 	    if (which >= len + 1)
3236 		/* currently this won't happen, because the parser gets
3237 		   confused whenever there is invalid number of {} arguments
3238 		   to a user macro */
3239 		error(_("Not enough arguments passed to user macro '%s'"),
3240 		        CHAR(STRING_ELT(macro,0)));
3241     	    const char *arg = CHAR(STRING_ELT(ans, which));
3242     	    for (size_t ii = strlen(arg); ii > 0; ii--) xxungetc(arg[ii-1]);
3243     	    c--;
3244 	} else
3245     	    xxungetc(*(c-1));
3246     }
3247     xxungetc(START_MACRO);
3248 
3249     setAttrib(ans, R_RdTagSymbol, mkString("USERMACRO"));
3250     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3251     setAttrib(ans, R_MacroSymbol, macro);
3252     RELEASE_SV(macro);
3253 #if DEBUGVALS
3254     Rprintf(" result: %p\n", ans);
3255 #endif
3256     return ans;
3257 }
3258 
xxOptionmarkup(SEXP header,SEXP option,SEXP body,int flag,YYLTYPE * lloc)3259 static SEXP xxOptionmarkup(SEXP header, SEXP option, SEXP body, int flag, YYLTYPE *lloc)
3260 {
3261     SEXP ans;
3262 #if DEBUGVALS
3263     Rprintf("xxOptionmarkup(header=%p, option=%p, body=%p)", header, option, body);
3264 #endif
3265     flag |= getDynamicFlag(body);
3266     PRESERVE_SV(ans = PairToVectorList(CDR(body)));
3267     RELEASE_SV(body);
3268     setAttrib(ans, R_RdTagSymbol, header);
3269     RELEASE_SV(header);
3270     flag |= getDynamicFlag(option);
3271     setAttrib(ans, R_RdOptionSymbol, option);
3272     RELEASE_SV(option);
3273     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3274     setDynamicFlag(ans, flag);
3275 #if DEBUGVALS
3276     Rprintf(" result: %p\n", ans);
3277 #endif
3278     return ans;
3279 }
3280 
xxmarkup2(SEXP header,SEXP body1,SEXP body2,int argcount,int flag,YYLTYPE * lloc)3281 static SEXP xxmarkup2(SEXP header, SEXP body1, SEXP body2, int argcount, int flag, YYLTYPE *lloc)
3282 {
3283     SEXP ans;
3284 #if DEBUGVALS
3285     Rprintf("xxmarkup2(header=%p, body1=%p, body2=%p)", header, body1, body2);
3286 #endif
3287 
3288     PRESERVE_SV(ans = allocVector(VECSXP, argcount));
3289     if (!isNull(body1)) {
3290     	int flag1 = getDynamicFlag(body1);
3291     	SET_VECTOR_ELT(ans, 0, PairToVectorList(CDR(body1)));
3292 	RELEASE_SV(body1);
3293     	setDynamicFlag(VECTOR_ELT(ans, 0), flag1);
3294     	flag |= flag1;
3295     }
3296     if (!isNull(body2)) {
3297     	int flag2;
3298 	if (argcount < 2) error("internal error: inconsistent argument count");
3299 	flag2 = getDynamicFlag(body2);
3300     	SET_VECTOR_ELT(ans, 1, PairToVectorList(CDR(body2)));
3301 	RELEASE_SV(body2);
3302     	setDynamicFlag(VECTOR_ELT(ans, 1), flag2);
3303     	flag |= flag2;
3304     }
3305     setAttrib(ans, R_RdTagSymbol, header);
3306     RELEASE_SV(header);
3307     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3308     setDynamicFlag(ans, flag);
3309 #if DEBUGVALS
3310     Rprintf(" result: %p\n", ans);
3311 #endif
3312     return ans;
3313 }
3314 
xxmarkup3(SEXP header,SEXP body1,SEXP body2,SEXP body3,int flag,YYLTYPE * lloc)3315 static SEXP xxmarkup3(SEXP header, SEXP body1, SEXP body2, SEXP body3, int flag, YYLTYPE *lloc)
3316 {
3317     SEXP ans;
3318 #if DEBUGVALS
3319     Rprintf("xxmarkup2(header=%p, body1=%p, body2=%p, body3=%p)", header, body1, body2, body3);
3320 #endif
3321 
3322     PRESERVE_SV(ans = allocVector(VECSXP, 3));
3323     if (!isNull(body1)) {
3324     	int flag1 = getDynamicFlag(body1);
3325     	SET_VECTOR_ELT(ans, 0, PairToVectorList(CDR(body1)));
3326 	RELEASE_SV(body1);
3327     	setDynamicFlag(VECTOR_ELT(ans, 0), flag1);
3328     	flag |= flag1;
3329     }
3330     if (!isNull(body2)) {
3331     	int flag2;
3332 	flag2 = getDynamicFlag(body2);
3333     	SET_VECTOR_ELT(ans, 1, PairToVectorList(CDR(body2)));
3334 	RELEASE_SV(body2);
3335     	setDynamicFlag(VECTOR_ELT(ans, 1), flag2);
3336     	flag |= flag2;
3337     }
3338     if (!isNull(body3)) {
3339     	int flag3;
3340 	flag3 = getDynamicFlag(body3);
3341     	SET_VECTOR_ELT(ans, 2, PairToVectorList(CDR(body3)));
3342 	RELEASE_SV(body3);
3343     	setDynamicFlag(VECTOR_ELT(ans, 2), flag3);
3344     	flag |= flag3;
3345     }
3346     setAttrib(ans, R_RdTagSymbol, header);
3347     RELEASE_SV(header);
3348     setAttrib(ans, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3349     setDynamicFlag(ans, flag);
3350 #if DEBUGVALS
3351     Rprintf(" result: %p\n", ans);
3352 #endif
3353     return ans;
3354 }
3355 
xxsavevalue(SEXP Rd,YYLTYPE * lloc)3356 static void xxsavevalue(SEXP Rd, YYLTYPE *lloc)
3357 {
3358     int flag = getDynamicFlag(Rd);
3359     PRESERVE_SV(parseState.Value = PairToVectorList(CDR(Rd)));
3360     if (!isNull(parseState.Value)) {
3361     	setAttrib(parseState.Value, R_ClassSymbol, mkString("Rd"));
3362     	setAttrib(parseState.Value, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3363     	setDynamicFlag(parseState.Value, flag);
3364     }
3365     RELEASE_SV(Rd);
3366 }
3367 
xxtag(SEXP item,int type,YYLTYPE * lloc)3368 static SEXP xxtag(SEXP item, int type, YYLTYPE *lloc)
3369 {
3370     setAttrib(item, R_RdTagSymbol, mkString(yytname[YYTRANSLATE(type)]));
3371     setAttrib(item, R_SrcrefSymbol, makeSrcref(lloc, SrcFile));
3372     return item;
3373 }
3374 
xxWarnNewline()3375 static void xxWarnNewline()
3376 {
3377     if (parseState.xxNewlineInString) {
3378 	if(wCalls)
3379 	    warning(_("newline within quoted string at %s:%d"),
3380 		    parseState.xxBasename, parseState.xxNewlineInString);
3381 	else
3382 	    warningcall(R_NilValue,
3383 			_("newline within quoted string at %s:%d"),
3384 			parseState.xxBasename, parseState.xxNewlineInString);
3385     }
3386 }
3387 
3388 
3389 /*----------------------------------------------------------------------------*/
3390 
3391 
3392 static int (*ptr_getc)(void);
3393 
3394 /* Private pushback, since file ungetc only guarantees one byte.
3395    We need arbitrarily large size, since this is how macros are expanded. */
3396 
3397 #define PUSH_BACK(c) do {                  \
3398 	if (npush >= pushsize - 1) {             \
3399 	    int *old = pushbase;              \
3400             pushsize *= 2;                    \
3401 	    pushbase = malloc(pushsize*sizeof(int));         \
3402 	    if(!pushbase) error(_("unable to allocate buffer for long macro at line %d"), parseState.xxlineno);\
3403 	    memmove(pushbase, old, npush*sizeof(int));        \
3404 	    if(old != pushback) free(old); }	    \
3405 	pushbase[npush++] = (c);                        \
3406 } while(0)
3407 
3408 
3409 
3410 #define PUSHBACK_BUFSIZE 32
3411 
3412 static int pushback[PUSHBACK_BUFSIZE];
3413 static int *pushbase;
3414 static unsigned int npush, pushsize;
3415 static int macrolevel;
3416 static int prevpos = 0;
3417 static int prevlines[PUSHBACK_BUFSIZE];
3418 static int prevcols[PUSHBACK_BUFSIZE];
3419 static int prevbytes[PUSHBACK_BUFSIZE];
3420 
3421 
xxgetc(void)3422 static int xxgetc(void)
3423 {
3424     int c, oldpos;
3425 
3426     do {
3427     	if(npush) {
3428     	    c = pushbase[--npush];
3429     	    if (c == START_MACRO) {
3430     	    	macrolevel++;
3431     	    	if (macrolevel > 1000)
3432     	    	    error(_("macros nested too deeply: infinite recursion?"));
3433     	    } else if (c == END_MACRO) macrolevel--;
3434     	} else  c = ptr_getc();
3435     } while (c == START_MACRO || c == END_MACRO);
3436 
3437     if (!macrolevel) {
3438 	oldpos = prevpos;
3439 	prevpos = (prevpos + 1) % PUSHBACK_BUFSIZE;
3440 	prevbytes[prevpos] = parseState.xxbyteno;
3441 	prevlines[prevpos] = parseState.xxlineno;
3442 	/* We only advance the column for the 1st byte in UTF-8, so handle later bytes specially */
3443 	if (0x80 <= (unsigned char)c && (unsigned char)c <= 0xBF) {
3444 	    parseState.xxcolno--;
3445 	    prevcols[prevpos] = prevcols[oldpos];
3446 	} else
3447 	    prevcols[prevpos] = parseState.xxcolno;
3448 
3449 	if (c == EOF) return R_EOF;
3450 
3451 	R_ParseContextLast = (R_ParseContextLast + 1) % PARSE_CONTEXT_SIZE;
3452 	R_ParseContext[R_ParseContextLast] = (char) c;
3453 
3454 	if (c == '\n') {
3455 	    parseState.xxlineno += 1;
3456 	    parseState.xxcolno = 1;
3457 	    parseState.xxbyteno = 1;
3458 	} else {
3459 	    parseState.xxcolno++;
3460 	    parseState.xxbyteno++;
3461 	}
3462 
3463 	if (c == '\t') parseState.xxcolno = ((parseState.xxcolno + 6) & ~7) + 1;
3464 
3465 	R_ParseContextLine = parseState.xxlineno;
3466     }
3467     /* Rprintf("get %c\n", c); */
3468     return c;
3469 }
3470 
xxungetc(int c)3471 static int xxungetc(int c)
3472 {
3473     /* this assumes that c was the result of xxgetc; if not, some edits will be needed */
3474     if (c == END_MACRO) macrolevel++;
3475     if (!macrolevel) {
3476     	parseState.xxlineno = prevlines[prevpos];
3477     	parseState.xxbyteno = prevbytes[prevpos];
3478     	parseState.xxcolno  = prevcols[prevpos];
3479     	prevpos = (prevpos + PUSHBACK_BUFSIZE - 1) % PUSHBACK_BUFSIZE;
3480 
3481     	R_ParseContextLine = parseState.xxlineno;
3482 
3483     	R_ParseContext[R_ParseContextLast] = '\0';
3484     	/* macOS requires us to keep this non-negative */
3485     	R_ParseContextLast = (R_ParseContextLast + PARSE_CONTEXT_SIZE - 1)
3486 		% PARSE_CONTEXT_SIZE;
3487     }
3488     if (c == START_MACRO) macrolevel--;
3489     PUSH_BACK(c);
3490     /* Rprintf("unget %c;", c); */
3491     return c;
3492 }
3493 
makeSrcref(YYLTYPE * lloc,SEXP srcfile)3494 static SEXP makeSrcref(YYLTYPE *lloc, SEXP srcfile)
3495 {
3496     SEXP val;
3497 
3498     PROTECT(val = allocVector(INTSXP, 6));
3499     INTEGER(val)[0] = lloc->first_line;
3500     INTEGER(val)[1] = lloc->first_byte;
3501     INTEGER(val)[2] = lloc->last_line;
3502     INTEGER(val)[3] = lloc->last_byte;
3503     INTEGER(val)[4] = lloc->first_column;
3504     INTEGER(val)[5] = lloc->last_column;
3505     setAttrib(val, R_SrcfileSymbol, srcfile);
3506     setAttrib(val, R_ClassSymbol, mkString("srcref"));
3507     UNPROTECT(1); /* val */
3508     return val;
3509 }
3510 
mkString2(const char * s,size_t len)3511 static SEXP mkString2(const char *s, size_t len)
3512 {
3513     SEXP t;
3514     cetype_t enc = CE_UTF8;
3515 
3516     PROTECT(t = allocVector(STRSXP, 1));
3517     SET_STRING_ELT(t, 0, mkCharLenCE(s, (int) len, enc));
3518     UNPROTECT(1); /* t */
3519     return t;
3520 }
3521 
3522 
3523 /* Stretchy List Structures : Lists are created and grown using a special */
3524 /* dotted pair.  The CAR of the list points to the last cons-cell in the */
3525 /* list and the CDR points to the first.  The list can be extracted from */
3526 /* the pair by taking its CDR, while the CAR gives fast access to the end */
3527 /* of the list. */
3528 
3529 
3530 /* Create a stretchy-list dotted pair */
3531 
NewList(void)3532 static SEXP NewList(void)
3533 {
3534     SEXP s = CONS(R_NilValue, R_NilValue);
3535     SETCAR(s, s);
3536     return s;
3537 }
3538 
3539 /* Add a new element at the end of a stretchy list */
3540 
GrowList(SEXP l,SEXP s)3541 static void GrowList(SEXP l, SEXP s)
3542 {
3543     SEXP tmp;
3544     tmp = CONS(s, R_NilValue);
3545     SETCDR(CAR(l), tmp);
3546     SETCAR(l, tmp);
3547 }
3548 
3549 /*--------------------------------------------------------------------------*/
3550 
InitSymbols(void)3551 static void InitSymbols(void)
3552 {
3553     if (!R_RdTagSymbol)
3554 	R_RdTagSymbol = install("Rd_tag");
3555     if (!R_RdOptionSymbol)
3556 	R_RdOptionSymbol = install("Rd_option");
3557     if (!R_DefinitionSymbol)
3558 	R_DefinitionSymbol = install("definition");
3559     if (!R_DynamicFlagSymbol)
3560 	R_DynamicFlagSymbol = install("dynamicFlag");
3561     if (!R_MacroSymbol)
3562 	R_MacroSymbol = install("macro");
3563 }
3564 
ParseRd(ParseStatus * status,SEXP srcfile,Rboolean fragment,SEXP macros)3565 static SEXP ParseRd(ParseStatus *status, SEXP srcfile, Rboolean fragment, SEXP macros)
3566 {
3567     Rboolean keepmacros = !isLogical(macros) || asLogical(macros);
3568 
3569     InitSymbols();
3570     R_ParseContextLast = 0;
3571     R_ParseContext[0] = '\0';
3572 
3573     parseState.xxlineno = 1;
3574     parseState.xxcolno = 1;
3575     parseState.xxbyteno = 1;
3576 
3577     SrcFile = srcfile;
3578 
3579     npush = 0;
3580     pushbase = pushback;
3581     pushsize = PUSHBACK_BUFSIZE;
3582     macrolevel = 0;
3583 
3584     parseState.xxmode = LATEXLIKE;
3585     parseState.xxitemType = UNKNOWN;
3586     parseState.xxbraceDepth = 0;
3587     parseState.xxinRString = 0;
3588     parseState.xxNewlineInString = 0;
3589     parseState.xxinEqn = 0;
3590     if (fragment) parseState.xxinitvalue = STARTFRAGMENT;
3591     else	  parseState.xxinitvalue = STARTFILE;
3592 
3593     if (!isEnvironment(macros))
3594 	macros = InstallKeywords();
3595 
3596     PROTECT(macros);
3597     PROTECT(parseState.xxMacroList = R_NewHashedEnv(macros, ScalarInteger(0)));
3598     PROTECT(parseState.mset = R_NewPreciousMSet(50));
3599 
3600     parseState.Value = R_NilValue;
3601 
3602     if (yyparse()) *status = PARSE_ERROR;
3603     else *status = PARSE_OK;
3604 
3605     if (keepmacros && !isNull(parseState.Value))
3606 	setAttrib(parseState.Value, install("macros"), parseState.xxMacroList);
3607 
3608 #if DEBUGVALS
3609     Rprintf("ParseRd result: %p\n", parseState.Value);
3610 #endif
3611     RELEASE_SV(parseState.Value);
3612     UNPROTECT(3); /* macros, parseState.xxMacroList, parseState.mset */
3613 
3614     if (pushbase != pushback) free(pushbase);
3615 
3616     return parseState.Value;
3617 }
3618 
3619 #include "Rconnections.h"
3620 static Rconnection con_parse;
3621 
3622 /* need to handle incomplete last line */
con_getc(void)3623 static int con_getc(void)
3624 {
3625     int c;
3626     static int last=-1000;
3627 
3628     c = Rconn_fgetc(con_parse);
3629     if (c == EOF && last != '\n') c = '\n';
3630     return (last = c);
3631 }
3632 
3633 static
R_ParseRd(Rconnection con,ParseStatus * status,SEXP srcfile,Rboolean fragment,SEXP macros)3634 SEXP R_ParseRd(Rconnection con, ParseStatus *status, SEXP srcfile, Rboolean fragment, SEXP macros)
3635 {
3636     con_parse = con;
3637     ptr_getc = con_getc;
3638     return ParseRd(status, srcfile, fragment, macros);
3639 }
3640 
3641 /*----------------------------------------------------------------------------
3642  *
3643  *  The Lexical Analyzer:
3644  *
3645  *  Basic lexical analysis is performed by the following
3646  *  routines.
3647  *
3648  *  The function yylex() scans the input, breaking it into
3649  *  tokens which are then passed to the parser.
3650  *
3651  */
3652 
3653 
3654 /* Special Symbols */
3655 /* Section and R code headers */
3656 
3657 struct {
3658     char *name;
3659     int token;
3660 }
3661 
3662 /* When adding keywords here, make sure all the handlers
3663    are also modified:  checkRd, Rd2HTML, Rd2latex, Rd2txt, any other new ones... */
3664 
3665 static keywords[] = {
3666     /* These sections contain Latex-like text */
3667 
3668     { "\\author",  SECTIONHEADER },
3669     { "\\concept", SECTIONHEADER },
3670     { "\\description",SECTIONHEADER },
3671     { "\\details", SECTIONHEADER },
3672     { "\\docType", SECTIONHEADER },
3673 
3674     { "\\encoding",SECTIONHEADER },
3675     { "\\format",  SECTIONHEADER },
3676     { "\\keyword", SECTIONHEADER },
3677     { "\\note",    SECTIONHEADER },
3678     { "\\references", SECTIONHEADER },
3679 
3680     { "\\section", SECTIONHEADER2 },
3681     { "\\seealso", SECTIONHEADER },
3682     { "\\source",  SECTIONHEADER },
3683     { "\\title",   SECTIONHEADER },
3684 
3685     /* These sections contain R-like text */
3686 
3687     { "\\examples",RSECTIONHEADER },
3688     { "\\usage",   RSECTIONHEADER },
3689 
3690     /* These sections contain verbatim text */
3691 
3692     { "\\alias",   VSECTIONHEADER },
3693     { "\\name",    VSECTIONHEADER },
3694     { "\\synopsis",VSECTIONHEADER },
3695     { "\\Rdversion",VSECTIONHEADER },
3696 
3697     /* These macros take no arguments.  One character non-alpha escapes get the
3698        same token value */
3699 
3700     { "\\cr",      ESCAPE },
3701     { "\\dots",    ESCAPE },
3702     { "\\ldots",   ESCAPE },
3703     { "\\R",       ESCAPE },
3704     { "\\tab",     ESCAPE },
3705 
3706     /* These macros take one LaTeX-like argument. */
3707 
3708     { "\\acronym", LATEXMACRO },
3709     { "\\bold",    LATEXMACRO },
3710     { "\\cite",    LATEXMACRO },
3711     { "\\command", LATEXMACRO },
3712     { "\\dfn",     LATEXMACRO },
3713     { "\\dQuote",  LATEXMACRO },
3714     { "\\email",   LATEXMACRO },
3715 
3716     { "\\emph",    LATEXMACRO },
3717     { "\\file",    LATEXMACRO },
3718     { "\\linkS4class", LATEXMACRO },
3719     { "\\pkg",	   LATEXMACRO },
3720     { "\\sQuote",  LATEXMACRO },
3721 
3722     { "\\strong",  LATEXMACRO },
3723 
3724     { "\\var",     LATEXMACRO },
3725 
3726     /* These are like SECTIONHEADER/LATEXMACRO, but they change the interpretation of \item */
3727 
3728     { "\\arguments",LISTSECTION },
3729     { "\\value",   LISTSECTION },
3730 
3731     { "\\describe",DESCRIPTION },
3732     { "\\enumerate",ITEMIZE },
3733     { "\\itemize", ITEMIZE },
3734 
3735     { "\\item",    NOITEM }, /* will change to UNKNOWN, ESCAPE, or LATEXMACRO2 depending on context */
3736 
3737     /* These macros take two LaTeX-like arguments. */
3738 
3739     { "\\enc",     LATEXMACRO2 },
3740     { "\\if",      LATEXMACRO2 },
3741     { "\\method",  LATEXMACRO2 },
3742     { "\\S3method",LATEXMACRO2 },
3743     { "\\S4method",LATEXMACRO2 },
3744     { "\\tabular", LATEXMACRO2 },
3745     { "\\subsection", LATEXMACRO2 },
3746 
3747     /* This macro takes one verbatim and one LaTeX-like argument. */
3748 
3749     { "\\href",    VERBLATEX },
3750 
3751     /* This macro takes three LaTeX-like arguments. */
3752 
3753     { "\\ifelse",  LATEXMACRO3 },
3754 
3755     /* These macros take one optional bracketed option and always take
3756        one LaTeX-like argument */
3757 
3758     { "\\link",    OPTMACRO },
3759 
3760     /* These markup macros require an R-like text argument */
3761 
3762     { "\\code",    RCODEMACRO },
3763     { "\\dontshow",RCODEMACRO },
3764     { "\\donttest",RCODEMACRO },
3765     { "\\testonly",RCODEMACRO },
3766 
3767     /* This macro takes one optional bracketed option and one R-like argument */
3768 
3769     { "\\Sexpr",   SEXPR },
3770 
3771     /* This is just like a VSECTIONHEADER, but it needs SEXPR processing */
3772 
3773     { "\\RdOpts",   RDOPTS },
3774 
3775     /* These macros take one verbatim arg and ignore everything except braces */
3776 
3777     { "\\dontrun", VERBMACRO }, /* at least for now */
3778     { "\\env",     VERBMACRO },
3779     { "\\kbd", 	   VERBMACRO },
3780     { "\\option",  VERBMACRO },
3781     { "\\out",     VERBMACRO },
3782     { "\\preformatted", VERBMACRO },
3783 
3784     { "\\samp",    VERBMACRO },
3785     { "\\special", RCODEMACRO },
3786     { "\\url",     VERBMACRO },
3787     { "\\verb",    VERBMACRO },
3788 
3789     /* These ones take one or two verbatim args */
3790 
3791     { "\\eqn",     VERBMACRO2 },
3792     { "\\deqn",    VERBMACRO2 },
3793     { "\\figure",  VERBMACRO2 },
3794 
3795     /* We parse IFDEF/IFNDEF as markup, not as a separate preprocessor step */
3796 
3797     { "#ifdef",    IFDEF },
3798     { "#ifndef",   IFDEF },
3799     { "#endif",    ENDIF },
3800 
3801     /* These allow user defined macros */
3802     { "\\newcommand", NEWCOMMAND },
3803     { "\\renewcommand", NEWCOMMAND },
3804 
3805     { 0,	   0	      }
3806     /* All other markup macros are rejected. */
3807 };
3808 
3809 /* Record the longest # directive here */
3810 #define DIRECTIVE_LEN 7
3811 
InstallKeywords()3812 static SEXP InstallKeywords()
3813 {
3814     int i, num;
3815     SEXP result, name, val;
3816     num = sizeof(keywords)/sizeof(keywords[0]);
3817     PROTECT(result = R_NewHashedEnv(R_EmptyEnv, ScalarInteger(num)));
3818     for (i = 0; keywords[i].name; i++) {
3819         name = install(keywords[i].name);
3820         PROTECT(val = ScalarInteger(keywords[i].token));
3821     	defineVar(name, val, result);
3822 	UNPROTECT(1); /* val */
3823     }
3824     UNPROTECT(1); /* result */
3825     return result;
3826 }
3827 
KeywordLookup(const char * s)3828 static int KeywordLookup(const char *s)
3829 {
3830     SEXP rec = findVar(install(s), parseState.xxMacroList);
3831     if (rec == R_UnboundValue) return UNKNOWN;
3832     else return INTEGER(rec)[0];
3833 }
3834 
UserMacroLookup(const char * s)3835 static SEXP UserMacroLookup(const char *s)
3836 {
3837     SEXP rec = findVar(install(s), parseState.xxMacroList);
3838     if (rec == R_UnboundValue) error(_("Unable to find macro %s"), s);
3839     PROTECT(rec);
3840     SEXP res = getAttrib(rec, R_DefinitionSymbol);
3841     UNPROTECT(1); /* rec */
3842     return res;
3843 }
3844 
yyerror(const char * s)3845 static void yyerror(const char *s)
3846 {
3847     static const char *const yytname_translations[] =
3848     {
3849     /* the left column are strings coming from bison, the right
3850        column are translations for users.
3851        The first YYENGLISH from the right column are English to be translated,
3852        the rest are to be copied literally.  The #if 0 block below allows xgettext
3853        to see these.
3854     */
3855 #define YYENGLISH 17
3856 	"$undefined",	"input",
3857 	"SECTIONHEADER","section header",
3858 	"RSECTIONHEADER","section header",
3859 	"VSECTIONHEADER","section header",
3860 	"LISTSECTION",	"section header",
3861 
3862 	"LATEXMACRO",	"macro",
3863 	"LATEXMACRO2",  "macro",
3864 	"LATEXMACRO3",  "macro",
3865 	"RCODEMACRO",	"macro",
3866 	"VERBMACRO",    "macro",
3867 	"VERBMACRO2",	"macro",
3868 
3869 	"ESCAPE",	"macro",
3870 	"ITEMIZE",	"macro",
3871 	"IFDEF",	"conditional",
3872 	"SECTIONHEADER2","section header",
3873 	"OPTMACRO",	"macro",
3874 
3875 	"DESCRIPTION",	"macro",
3876 	"VERB",		"VERBATIM TEXT",
3877 	0,		0
3878     };
3879     static char const yyunexpected[] = "syntax error, unexpected ";
3880     static char const yyexpecting[] = ", expecting ";
3881     static char const yyshortunexpected[] = "unexpected %s";
3882     static char const yylongunexpected[] = "unexpected %s '%s'";
3883     char *expecting;
3884     char ParseErrorMsg[PARSE_ERROR_SIZE];
3885     SEXP filename;
3886     char ParseErrorFilename[PARSE_ERROR_SIZE];
3887 
3888     xxWarnNewline();	/* post newline warning if necessary */
3889 
3890     /*
3891     R_ParseError     = yylloc.first_line;
3892     R_ParseErrorCol  = yylloc.first_column;
3893     R_ParseErrorFile = SrcFile;
3894     */
3895 
3896     if (!strncmp(s, yyunexpected, sizeof yyunexpected -1)) {
3897 	int i, translated = FALSE;
3898     	/* Edit the error message */
3899     	expecting = strstr(s + sizeof yyunexpected -1, yyexpecting);
3900     	if (expecting) *expecting = '\0';
3901     	for (i = 0; yytname_translations[i]; i += 2) {
3902     	    if (!strcmp(s + sizeof yyunexpected - 1, yytname_translations[i])) {
3903     	    	if (yychar < 256)
3904     	    	    snprintf(ParseErrorMsg, PARSE_ERROR_SIZE,
3905 			     _(yyshortunexpected),
3906 			     i/2 < YYENGLISH ? _(yytname_translations[i+1])
3907 			     : yytname_translations[i+1]);
3908     	    	else
3909     	    	    snprintf(ParseErrorMsg, PARSE_ERROR_SIZE,
3910 			     _(yylongunexpected),
3911 			     i/2 < YYENGLISH ? _(yytname_translations[i+1])
3912 			     : yytname_translations[i+1],
3913 			     CHAR(STRING_ELT(yylval, 0)));
3914     	    	translated = TRUE;
3915     	    	break;
3916     	    }
3917     	}
3918     	if (!translated) {
3919     	    if (yychar < 256)
3920     		snprintf(ParseErrorMsg, PARSE_ERROR_SIZE, _(yyshortunexpected),
3921 			s + sizeof yyunexpected - 1);
3922     	    else
3923     	    	snprintf(ParseErrorMsg, PARSE_ERROR_SIZE, _(yylongunexpected),
3924 			 s + sizeof yyunexpected - 1, CHAR(STRING_ELT(yylval, 0)));
3925 	}
3926     	if (expecting) {
3927  	    translated = FALSE;
3928     	    for (i = 0; yytname_translations[i]; i += 2) {
3929     	    	if (!strcmp(expecting + sizeof yyexpecting - 1, yytname_translations[i])) {
3930     	    	    strcat(ParseErrorMsg, _(yyexpecting));
3931     	    	    strcat(ParseErrorMsg, i/2 < YYENGLISH ? _(yytname_translations[i+1])
3932     	    	                    : yytname_translations[i+1]);
3933     	    	    translated = TRUE;
3934 		    break;
3935 		}
3936 	    }
3937 	    if (!translated) {
3938 	    	strcat(ParseErrorMsg, _(yyexpecting));
3939 	    	strcat(ParseErrorMsg, expecting + sizeof yyexpecting - 1);
3940 	    }
3941 	}
3942     } else if (!strncmp(s, yyunknown, sizeof yyunknown-1)) {
3943     	snprintf(ParseErrorMsg, PARSE_ERROR_SIZE,
3944 		"%s '%s'", s, CHAR(STRING_ELT(yylval, 0)));
3945     } else {
3946     	snprintf(ParseErrorMsg, PARSE_ERROR_SIZE, "%s", s);
3947     }
3948     filename = findVar(install("filename"), SrcFile);
3949     if (isString(filename) && LENGTH(filename))
3950     	strncpy(ParseErrorFilename, CHAR(STRING_ELT(filename, 0)), PARSE_ERROR_SIZE - 1);
3951     else
3952         ParseErrorFilename[0] = '\0';
3953     if (wCalls) {
3954 	if (yylloc.first_line != yylloc.last_line)
3955 	    warning("%s:%d-%d: %s",
3956 		    ParseErrorFilename, yylloc.first_line, yylloc.last_line, ParseErrorMsg);
3957 	else
3958 	    warning("%s:%d: %s",
3959 		    ParseErrorFilename, yylloc.first_line, ParseErrorMsg);
3960     } else {
3961 	if (yylloc.first_line != yylloc.last_line)
3962 	    warningcall(R_NilValue, "%s:%d-%d: %s",
3963 		    ParseErrorFilename, yylloc.first_line, yylloc.last_line, ParseErrorMsg);
3964 	else
3965 	    warningcall(R_NilValue, "%s:%d: %s",
3966 			ParseErrorFilename, yylloc.first_line, ParseErrorMsg);
3967     }
3968 }
3969 
3970 #define TEXT_PUSH(c) do {                  \
3971 	size_t nc = bp - stext;       \
3972 	if (nc >= nstext - 1) {             \
3973 	    char *old = stext;              \
3974             nstext *= 2;                    \
3975 	    stext = malloc(nstext);         \
3976 	    if(!stext) error(_("unable to allocate buffer for long string at line %d"), parseState.xxlineno);\
3977 	    memmove(stext, old, nc);        \
3978 	    if(old != st0) free(old);	    \
3979 	    bp = stext+nc; }		    \
3980 	*bp++ = ((char) c);		    \
3981 } while(0)
3982 
setfirstloc(void)3983 static void setfirstloc(void)
3984 {
3985     yylloc.first_line = parseState.xxlineno;
3986     yylloc.first_column = parseState.xxcolno;
3987     yylloc.first_byte = parseState.xxbyteno;
3988 }
3989 
setlastloc(void)3990 static void setlastloc(void)
3991 {
3992     yylloc.last_line = prevlines[prevpos];
3993     yylloc.last_column = prevcols[prevpos];
3994     yylloc.last_byte = prevbytes[prevpos];
3995 }
3996 
3997 /* Split the input stream into tokens. */
3998 /* This is the lowest of the parsing levels. */
3999 
token(void)4000 static int token(void)
4001 {
4002     int c, lookahead;
4003     int outsideLiteral = parseState.xxmode == LATEXLIKE || parseState.xxmode == INOPTION || parseState.xxbraceDepth == 0;
4004 
4005     if (parseState.xxinitvalue) {
4006         yylloc.first_line = 0;
4007         yylloc.first_column = 0;
4008         yylloc.first_byte = 0;
4009         yylloc.last_line = 0;
4010         yylloc.last_column = 0;
4011         yylloc.last_byte = 0;
4012 	PRESERVE_SV(yylval = mkString(""));
4013         c = parseState.xxinitvalue;
4014     	parseState.xxinitvalue = 0;
4015     	return(c);
4016     }
4017 
4018     setfirstloc();
4019     c = xxgetc();
4020 
4021     switch (c) {
4022     	case '%': if (!parseState.xxinEqn) return mkComment(c);
4023     	    break;
4024 	case '\\':
4025 	    if (!parseState.xxinEqn) {
4026 		lookahead = xxungetc(xxgetc());
4027 		if (isalpha(lookahead) && parseState.xxmode != VERBATIM
4028 		    /* In R strings, only link or var is allowed as markup */
4029 		    && (lookahead == 'l' || lookahead == 'v' || !parseState.xxinRString))
4030 		    return mkMarkup(c);
4031 	    }
4032 	    break;
4033         case R_EOF:
4034             if (parseState.xxinRString) {
4035        		xxWarnNewline();
4036        		error(_("Unexpected end of input (in %c quoted string opened at %s:%d:%d)"),
4037  			parseState.xxinRString, parseState.xxBasename, parseState.xxQuoteLine, parseState.xxQuoteCol);
4038     	    }
4039     	    return END_OF_INPUT;
4040     	case '#':
4041     	    if (!parseState.xxinEqn && yylloc.first_column == 1) return mkIfdef(c);
4042     	    break;
4043     	case LBRACE:
4044     	    if (!parseState.xxinRString) {
4045     	    	parseState.xxbraceDepth++;
4046     	    	if (outsideLiteral) return c;
4047     	    }
4048     	    break;
4049     	case RBRACE:
4050     	    if (!parseState.xxinRString) {
4051     	    	parseState.xxbraceDepth--;
4052     	    	if (outsideLiteral || parseState.xxbraceDepth == 0) return c;
4053     	    }
4054     	    break;
4055     	case '[':
4056     	case ']':
4057     	    if (parseState.xxmode == INOPTION ) return c;
4058     	    break;
4059     }
4060 
4061     switch (parseState.xxmode) {
4062 	case RLIKE:     return mkCode(c);
4063 	case INOPTION:
4064 	case LATEXLIKE: return mkText(c);
4065 	case VERBATIM:  return mkVerb(c);
4066     }
4067 
4068     return ERROR; /* We shouldn't get here. */
4069 }
4070 
4071 #define INITBUFSIZE 128
4072 
mkText(int c)4073 static int mkText(int c)
4074 {
4075     char st0[INITBUFSIZE];
4076     unsigned int nstext = INITBUFSIZE;
4077     char *stext = st0, *bp = st0, lookahead;
4078 
4079     while(1) {
4080     	switch (c) {
4081     	case '\\':
4082     	    lookahead = (char) xxgetc();
4083     	    if (lookahead == LBRACE || lookahead == RBRACE ||
4084     	        lookahead == '%' || lookahead == '\\') {
4085     	    	c = lookahead;
4086     	    	break;
4087     	    }
4088     	    xxungetc(lookahead);
4089     	    if (isalpha(lookahead)) goto stop;
4090     	case ']':
4091     	    if (parseState.xxmode == INOPTION) goto stop;
4092             break;
4093     	case '%':
4094     	case LBRACE:
4095     	case RBRACE:
4096     	case R_EOF:
4097     	    goto stop;
4098     	}
4099     	TEXT_PUSH(c);
4100     	if (c == '\n') goto stop;
4101     	c = xxgetc();
4102     };
4103 stop:
4104     if (c != '\n') xxungetc(c); /* newline causes a break, but we keep it */
4105     PRESERVE_SV(yylval = mkString2(stext, bp - stext));
4106     if(stext != st0) free(stext);
4107     return TEXT;
4108 }
4109 
mkComment(int c)4110 static int mkComment(int c)
4111 {
4112     char st0[INITBUFSIZE];
4113     unsigned int nstext = INITBUFSIZE;
4114     char *stext = st0, *bp = st0;
4115 
4116     do TEXT_PUSH(c);
4117     while ((c = xxgetc()) != '\n' && c != R_EOF);
4118 
4119     xxungetc(c);
4120 
4121     PRESERVE_SV(yylval = mkString2(stext, bp - stext));
4122     if(stext != st0) free(stext);
4123     return COMMENT;
4124 }
4125 
4126 #define EAT_DASHES(n_var) do {				\
4127 	for (c = xxgetc(); c == '-'; c = xxgetc()) {	\
4128 	    n_var++;					\
4129 	    TEXT_PUSH(c);				\
4130 	}						\
4131     } while (0)
4132 
4133 #define EAT_CHARS_TO_DELIM_OR_EOF(delim) do {	\
4134 	while (c != delim && c != R_EOF) {	\
4135 	    TEXT_PUSH(c);			\
4136 	    c = xxgetc();			\
4137 	}					\
4138     } while (0)
4139 
closingRawStringDelim(int c)4140 static int closingRawStringDelim(int c)
4141 {
4142     switch(c) {
4143     case '(': return ')';
4144     case '{': return '}';
4145     case '[': return ']';
4146     case '|': return '|';
4147     default:  return 0;
4148     }
4149 }
4150 
mkCode(int c)4151 static int mkCode(int c)
4152 {
4153     char st0[INITBUFSIZE];
4154     unsigned int nstext = INITBUFSIZE;
4155     char *stext = st0, *bp = st0;
4156 
4157     /* Avoid double counting initial braces */
4158     if (c == LBRACE && !parseState.xxinRString) parseState.xxbraceDepth--;
4159     if (c == RBRACE && !parseState.xxinRString) parseState.xxbraceDepth++;
4160 
4161     while(1) {
4162 	/* handle a raw string */
4163 	if (parseState.xxinRString == 0 && (c == 'r' || c == 'R')) {
4164     	    int lookahead = xxgetc();
4165 	    if (lookahead == '"' || lookahead == '\'') {
4166 		TEXT_PUSH(c);
4167 		int quote = lookahead;
4168 		parseState.xxinRString = quote;
4169     	    	parseState.xxQuoteLine = parseState.xxlineno;
4170     	    	parseState.xxQuoteCol  = parseState.xxcolno;
4171 		TEXT_PUSH(quote);
4172 		int ndash = 0;
4173 		EAT_DASHES(ndash);
4174 		int delim = closingRawStringDelim(c);
4175 		if (delim != 0) {
4176 		    int done = FALSE;
4177 		    do {
4178 			EAT_CHARS_TO_DELIM_OR_EOF(delim);
4179 			if (c == delim) {
4180 			    TEXT_PUSH(c);
4181 			    int nndash = 0;
4182 			    EAT_DASHES(nndash);
4183 			    if (nndash == ndash && c == quote)
4184 				done = TRUE; // close quote is handled below
4185 			}
4186 			else done = TRUE; // EOF; move on
4187 		    } while (! done);
4188 		}
4189 	    }
4190 	    else xxungetc(lookahead);
4191 	}
4192 
4193 	int escaped = 0;
4194     	if (c == '\\') {
4195     	    int lookahead = xxgetc();
4196     	    if (lookahead == '\\' || lookahead == '%') {
4197     	         c = lookahead;
4198     	         escaped = 1;
4199     	    } else xxungetc(lookahead);
4200     	}
4201     	if ((!escaped && c == '%') || c == R_EOF) break;
4202     	if (parseState.xxinRString) {
4203     	    /* This stuff is messy, because there are two levels of escaping:
4204     	       The Rd escaping and the R code string escaping. */
4205     	    if (c == '\\') {
4206     		int lookahead = xxgetc();
4207     		if (lookahead == '\\') { /* This must be the 3rd backslash */
4208     		    lookahead = xxgetc();
4209     		    if (lookahead == parseState.xxinRString || lookahead == '\\') {
4210     	    	    	TEXT_PUSH(c);
4211     	    	    	c = lookahead;
4212     	    	    	escaped = 1;
4213     	    	    } else {
4214     	    	    	xxungetc(lookahead); /* put back the 4th char */
4215     	    	    	xxungetc('\\');	     /* and the 3rd */
4216     	    	    }
4217     	    	} else if (lookahead == parseState.xxinRString) { /* There could be one or two before this */
4218     	    	    TEXT_PUSH(c);
4219     	    	    c = lookahead;
4220     	    	    escaped = 1;
4221     	    	} else if (!escaped && (lookahead == 'l' || lookahead == 'v')) {
4222     	    	    /* assume \link or \var; this breaks vertical tab, but does anyone ever use that? */
4223     	    	    xxungetc(lookahead);
4224     	    	    break;
4225     	    	} else xxungetc(lookahead);
4226     	    }
4227     	    if (!escaped && c == parseState.xxinRString)
4228     	    	parseState.xxinRString = 0;
4229     	} else {
4230     	    if (c == '#') {
4231     	    	do {
4232     	    	    int escaped = 0;
4233     	    	    TEXT_PUSH(c);
4234     	    	    c = xxgetc();
4235     	    	    if (c == '\\') {
4236 		        int lookahead = xxgetc();
4237 		        if (lookahead == '\\' || lookahead == '%' || lookahead == LBRACE || lookahead == RBRACE) {
4238 		            c = lookahead;
4239 		            escaped = 1;
4240 		        } else xxungetc(lookahead);
4241     		    }
4242     	    	    if (c == LBRACE && !escaped) parseState.xxbraceDepth++;
4243     	    	    else if (c == RBRACE && !escaped) parseState.xxbraceDepth--;
4244     	    	} while (c != '\n' && c != R_EOF && parseState.xxbraceDepth > 0);
4245     	    	if (c == RBRACE && !escaped) parseState.xxbraceDepth++; /* avoid double counting */
4246     	    }
4247     	    if (c == '\'' || c == '"' || c == '`') {
4248     	    	parseState.xxinRString = c;
4249     	    	parseState.xxQuoteLine = parseState.xxlineno;
4250     	    	parseState.xxQuoteCol  = parseState.xxcolno;
4251     	    } else if (c == '\\' && !escaped) {
4252     	    	int lookahead = xxgetc();
4253     	    	if (lookahead == LBRACE || lookahead == RBRACE) {
4254 		    c = lookahead;
4255 		} else if (isalpha(lookahead)) {
4256     	    	    xxungetc(lookahead);
4257     	    	    c = '\\';
4258     	    	    break;
4259     	    	} else {
4260     	    	    TEXT_PUSH('\\');
4261     	    	    c = lookahead;
4262     	    	}
4263     	    } else if (c == LBRACE) {
4264     	    	parseState.xxbraceDepth++;
4265     	    } else if (c == RBRACE) {
4266     	    	if (parseState.xxbraceDepth == 1) break;
4267     	    	else parseState.xxbraceDepth--;
4268     	    } else if (c == R_EOF) break;
4269     	}
4270     	TEXT_PUSH(c);
4271     	if (c == '\n') {
4272     	    if (parseState.xxinRString && !parseState.xxNewlineInString)
4273     	    	parseState.xxNewlineInString = parseState.xxlineno-1;
4274     	    break;
4275     	}
4276     	c = xxgetc();
4277     }
4278     if (c != '\n') xxungetc(c);
4279     PRESERVE_SV(yylval = mkString2(stext, bp - stext));
4280     if(stext != st0) free(stext);
4281     return RCODE;
4282 }
4283 
mkMarkup(int c)4284 static int mkMarkup(int c)
4285 {
4286     char st0[INITBUFSIZE];
4287     unsigned int nstext = INITBUFSIZE;
4288     char *stext = st0, *bp = st0;
4289     int retval = 0, attempt = 0;
4290 
4291     TEXT_PUSH(c);
4292     while (isalnum((c = xxgetc()))) TEXT_PUSH(c);
4293 
4294     while (attempt++ < 2) {
4295     	/* character escapes are processed as text, not markup */
4296     	if (bp == stext+1) {
4297     	    TEXT_PUSH(c);
4298     	    TEXT_PUSH('\0');
4299     	    retval = TEXT;
4300     	    c = xxgetc();
4301     	    break;
4302     	} else {
4303     	    TEXT_PUSH('\0');
4304     	    retval = KeywordLookup(stext);
4305     	    if (retval == UNKNOWN && attempt == 1) { /* try again, non-digits only */
4306     	    	bp--; 				     /* pop the \0 */
4307     	        while (isdigit(*(bp-1))) {
4308             	    xxungetc(c);
4309     	            c = *(--bp);                     /* pop the last letter into c */
4310             	}
4311             } else {
4312             	if (retval == NOITEM)
4313     	    	    retval = parseState.xxitemType;
4314     	    	break;
4315     	    }
4316         }
4317     }
4318     PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1));
4319     if(stext != st0) free(stext);
4320     xxungetc(c);
4321     return retval;
4322 }
4323 
mkIfdef(int c)4324 static int mkIfdef(int c)
4325 {
4326     char st0[INITBUFSIZE];
4327     unsigned int nstext = INITBUFSIZE;
4328     char *stext = st0, *bp = st0;
4329     int retval;
4330 
4331     TEXT_PUSH(c);
4332     while (isalpha((c = xxgetc())) && bp - stext <= DIRECTIVE_LEN) TEXT_PUSH(c);
4333     TEXT_PUSH('\0');
4334     xxungetc(c);
4335 
4336     retval = KeywordLookup(stext);
4337     PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1));
4338 
4339     switch (retval) {
4340     case ENDIF:  /* eat chars to the end of the line */
4341     	do { c = xxgetc(); }
4342     	while (c != '\n' && c != R_EOF);
4343     	break;
4344     case UNKNOWN:
4345 	RELEASE_SV(yylval);
4346     	bp--; bp--;
4347     	for (; bp > stext; bp--)
4348     	    xxungetc(*bp);
4349     	switch (parseState.xxmode) {
4350     	case RLIKE:
4351     	    retval = mkCode(*bp);
4352     	    break;
4353     	case INOPTION:
4354     	case LATEXLIKE:
4355     	    retval = mkText(*bp);
4356     	    break;
4357     	case VERBATIM:
4358     	    retval = mkVerb(*bp);
4359     	    break;
4360 	}
4361 	break;
4362     }
4363     if(stext != st0) free(stext);
4364     return retval;
4365 }
4366 
mkVerb(int c)4367 static int mkVerb(int c)
4368 {
4369     char st0[INITBUFSIZE];
4370     unsigned int nstext = INITBUFSIZE;
4371     char *stext = st0, *bp = st0;
4372 
4373     /* Avoid double counting initial braces */
4374     if (c == LBRACE) parseState.xxbraceDepth--;
4375     if (c == RBRACE) parseState.xxbraceDepth++;
4376 
4377     while(1) {
4378     	int escaped = 0;
4379         if (c == '\\') {
4380             int lookahead = xxgetc();
4381             if (lookahead == '\\' || lookahead == '%' || lookahead == LBRACE || lookahead == RBRACE) {
4382 		escaped = 1;
4383 		if (parseState.xxinEqn) TEXT_PUSH(c);
4384 		c = lookahead;
4385 	    } else xxungetc(lookahead);
4386         }
4387         if (c == R_EOF) break;
4388         if (!escaped) {
4389     	    if (c == '%' && !parseState.xxinEqn) break;
4390 	    else if (c == LBRACE) parseState.xxbraceDepth++;
4391     	    else if (c == RBRACE) {
4392 	    	if (parseState.xxbraceDepth == 1) break;
4393 	    	else parseState.xxbraceDepth--;
4394 	    }
4395 	}
4396     	TEXT_PUSH(c);
4397     	if (c == '\n') break;
4398     	c = xxgetc();
4399     };
4400     if (c != '\n') xxungetc(c);
4401     PRESERVE_SV(yylval = mkString2(stext, bp - stext));
4402     if(stext != st0) free(stext);
4403     return VERB;
4404 }
4405 
yylex(void)4406 static int yylex(void)
4407 {
4408     int tok = token();
4409 
4410     if (parseState.xxDebugTokens) {
4411         Rprintf("%d:%d: %s", yylloc.first_line, yylloc.first_column, yytname[YYTRANSLATE(tok)]);
4412     	if (parseState.xxinRString) Rprintf("(in %c%c)", parseState.xxinRString, parseState.xxinRString);
4413     	if (tok > 255 && tok != END_OF_INPUT)
4414     	    Rprintf(": %s", CHAR(STRING_ELT(yylval, 0)));
4415 	Rprintf("\n");
4416     }
4417     setlastloc();
4418     return tok;
4419 }
4420 
con_cleanup(void * data)4421 static void con_cleanup(void *data)
4422 {
4423     Rconnection con = data;
4424     if(con->isopen) con->close(con);
4425 }
4426 
PutState(ParseState * state)4427 static void PutState(ParseState *state) {
4428     state->xxinRString = parseState.xxinRString;
4429     state->xxQuoteLine = parseState.xxQuoteLine;
4430     state->xxQuoteCol = parseState.xxQuoteCol;
4431     state->xxinEqn = parseState.xxinEqn;
4432     state->xxNewlineInString = parseState.xxNewlineInString;
4433     state->xxlineno = parseState.xxlineno;
4434     state->xxbyteno = parseState.xxbyteno;
4435     state->xxcolno = parseState.xxcolno;
4436     state->xxmode = parseState.xxmode;
4437     state->xxitemType = parseState.xxitemType;
4438     state->xxbraceDepth = parseState.xxbraceDepth;
4439     state->xxDebugTokens = parseState.xxDebugTokens;
4440     state->xxBasename = parseState.xxBasename;
4441     state->Value = parseState.Value;
4442     state->xxinitvalue = parseState.xxinitvalue;
4443     state->xxMacroList = parseState.xxMacroList;
4444     state->prevState = parseState.prevState;
4445 }
4446 
UseState(ParseState * state)4447 static void UseState(ParseState *state) {
4448     parseState.xxinRString = state->xxinRString;
4449     parseState.xxQuoteLine = state->xxQuoteLine;
4450     parseState.xxQuoteCol = state->xxQuoteCol;
4451     parseState.xxinEqn = state->xxinEqn;
4452     parseState.xxNewlineInString = state->xxNewlineInString;
4453     parseState.xxlineno = state->xxlineno;
4454     parseState.xxbyteno = state->xxbyteno;
4455     parseState.xxcolno = state->xxcolno;
4456     parseState.xxmode = state->xxmode;
4457     parseState.xxitemType = state->xxitemType;
4458     parseState.xxbraceDepth = state->xxbraceDepth;
4459     parseState.xxDebugTokens = state->xxDebugTokens;
4460     parseState.xxBasename = state->xxBasename;
4461     parseState.Value = state->Value;
4462     parseState.xxinitvalue = state->xxinitvalue;
4463     parseState.xxMacroList = state->xxMacroList;
4464     parseState.prevState = state->prevState;
4465 }
4466 
PushState()4467 static void PushState() {
4468     if (busy) {
4469     	ParseState *prev = malloc(sizeof(ParseState));
4470 	if (prev == NULL) error("unable to allocate in PushState");
4471     	PutState(prev);
4472     	parseState.prevState = prev;
4473     } else
4474         parseState.prevState = NULL;
4475     busy = TRUE;
4476 }
4477 
PopState()4478 static void PopState() {
4479     if (parseState.prevState) {
4480     	ParseState *prev = parseState.prevState;
4481     	UseState(prev);
4482     	free(prev);
4483     } else
4484     	busy = FALSE;
4485 }
4486 
4487 /* "do_parseRd"
4488 
4489  .External2(C_parseRd,file, srcfile, encoding, verbose, basename, warningCalls, macros, warndups)
4490  If there is text then that is read and the other arguments are ignored.
4491 */
4492 
parseRd(SEXP call,SEXP op,SEXP args,SEXP env)4493 SEXP parseRd(SEXP call, SEXP op, SEXP args, SEXP env)
4494 {
4495     args = CDR(args);
4496 
4497     SEXP s = R_NilValue, source;
4498     Rconnection con;
4499     Rboolean wasopen, fragment;
4500     int ifile, wcall;
4501     ParseStatus status;
4502     RCNTXT cntxt;
4503     SEXP macros;
4504 
4505 #if DEBUGMODE
4506     yydebug = 1;
4507 #endif
4508 
4509     R_ParseError = 0;
4510     R_ParseErrorMsg[0] = '\0';
4511 
4512     PushState();
4513 
4514     ifile = asInteger(CAR(args));                       args = CDR(args);
4515 
4516     con = getConnection(ifile);
4517     wasopen = con->isopen;
4518     source = CAR(args);					args = CDR(args);
4519     /* encoding is unused */
4520     args = CDR(args);
4521     if(!isLogical(CAR(args)) || LENGTH(CAR(args)) != 1)
4522     	error(_("invalid '%s' value"), "verbose");
4523     parseState.xxDebugTokens = asInteger(CAR(args));		args = CDR(args);
4524     parseState.xxBasename = CHAR(STRING_ELT(CAR(args), 0));	args = CDR(args);
4525     fragment = asLogical(CAR(args));				args = CDR(args);
4526     wcall = asLogical(CAR(args));				args = CDR(args);
4527     if (wcall == NA_LOGICAL)
4528     	error(_("invalid '%s' value"), "warningCalls");
4529     wCalls = wcall;
4530     macros = CAR(args);						args = CDR(args);
4531     warnDups = asLogical(CAR(args));
4532 
4533     if (ifile >= 3) {/* file != "" */
4534 	if(!wasopen) {
4535 	    if(!con->open(con)) error(_("cannot open the connection"));
4536 	    /* Set up a context which will close the connection on error */
4537 	    begincontext(&cntxt, CTXT_CCODE, R_NilValue, R_BaseEnv, R_BaseEnv,
4538 			 R_NilValue, R_NilValue);
4539 	    cntxt.cend = &con_cleanup;
4540 	    cntxt.cenddata = con;
4541 	}
4542 	if(!con->canread) error(_("cannot read from this connection"));
4543 	s = R_ParseRd(con, &status, source, fragment, macros);
4544 	if(!wasopen) endcontext(&cntxt);
4545 	PopState();
4546 	if (status != PARSE_OK) parseError(call, R_ParseError);
4547     }
4548     else {
4549       PopState();
4550       error(_("invalid Rd file"));
4551     }
4552     return s;
4553 }
4554 
4555 /* "do_deparseRd"
4556 
4557  .External2(C_deparseRd, element, state)
4558 */
4559 
deparseRd(SEXP e,SEXP state)4560 SEXP deparseRd(SEXP e, SEXP state)
4561 {
4562     SEXP result;
4563     int  outlen, *statevals, quoteBraces, inRComment;
4564     const char *c;
4565     char *outbuf, *out, lookahead;
4566     Rboolean escape;
4567 
4568     if(!isString(e) || LENGTH(e) != 1)
4569     	error(_("'deparseRd' only supports deparsing character elements"));
4570     e = STRING_ELT(e, 0);
4571 
4572     if(!isInteger(state) || LENGTH(state) != 5) error(_("bad state"));
4573 
4574     PushState();
4575 
4576     parseState.xxbraceDepth = INTEGER(state)[0];
4577     parseState.xxinRString = INTEGER(state)[1];
4578     parseState.xxmode = INTEGER(state)[2];
4579     parseState.xxinEqn = INTEGER(state)[3];
4580     quoteBraces = INTEGER(state)[4];
4581 
4582     if (parseState.xxmode != LATEXLIKE && parseState.xxmode != RLIKE && parseState.xxmode != VERBATIM && parseState.xxmode != COMMENTMODE
4583      && parseState.xxmode != INOPTION  && parseState.xxmode != UNKNOWNMODE) {
4584         PopState();
4585     	error(_("bad text mode %d in 'deparseRd'"), parseState.xxmode);
4586     }
4587 
4588     for (c = CHAR(e), outlen=0; *c; c++) {
4589     	outlen++;
4590     	/* any special char might be escaped */
4591     	if (*c == '{' || *c == '}' || *c == '%' || *c == '\\') outlen++;
4592     }
4593     out = outbuf = R_chk_calloc(outlen+1, sizeof(char));
4594     inRComment = FALSE;
4595     for (c = CHAR(e); *c; c++) {
4596     	escape = FALSE;
4597     	if (parseState.xxmode != UNKNOWNMODE) {
4598 	    switch (*c) {
4599 	    case '\\':
4600 		if (parseState.xxmode == RLIKE && parseState.xxinRString) {
4601 		    lookahead = *(c+1);
4602 		    if (lookahead == '\\' || lookahead == parseState.xxinRString || lookahead == 'l')
4603 		    	escape = TRUE;
4604 		    break;
4605 		}          /* fall through to % case for non-strings... */
4606 	    case '%':
4607 		if (parseState.xxmode != COMMENTMODE && !parseState.xxinEqn)
4608 		    escape = TRUE;
4609 		break;
4610 	    case LBRACE:
4611 	    case RBRACE:
4612 		if (quoteBraces)
4613 		    escape = TRUE;
4614 		else if (!parseState.xxinRString && !parseState.xxinEqn && (parseState.xxmode == RLIKE || parseState.xxmode == VERBATIM)) {
4615 		    if (*c == LBRACE) parseState.xxbraceDepth++;
4616 		    else if (parseState.xxbraceDepth <= 0) escape = TRUE;
4617 		    else parseState.xxbraceDepth--;
4618 		}
4619 		break;
4620 	    case '\'':
4621 	    case '"':
4622 	    case '`':
4623 	    	if (parseState.xxmode == RLIKE) {
4624 		    if (parseState.xxinRString) {
4625 			if (parseState.xxinRString == *c) parseState.xxinRString = 0;
4626 		    } else if (!inRComment) parseState.xxinRString = *c;
4627 		}
4628 		break;
4629 	    case '#':
4630 	    	if (parseState.xxmode == RLIKE && !parseState.xxinRString)
4631 	    	    inRComment = TRUE;
4632 	    	break;
4633 	    case '\n':
4634 	    	inRComment = FALSE;
4635 	    	break;
4636 	    }
4637 	}
4638     	if (escape)
4639     	    *out++ = '\\';
4640     	*out++ = *c;
4641     }
4642     *out = '\0';
4643     PROTECT(result = allocVector(VECSXP, 2));
4644     SET_VECTOR_ELT(result, 0, ScalarString(mkChar(outbuf)));
4645     SET_VECTOR_ELT(result, 1, duplicate(state));
4646     R_chk_free(outbuf);
4647 
4648     statevals = INTEGER( VECTOR_ELT(result, 1) );
4649     statevals[0] = parseState.xxbraceDepth;
4650     statevals[1] = parseState.xxinRString;
4651 
4652     PopState();
4653 
4654     UNPROTECT(1); /* result */
4655     return result;
4656 }
4657 
4658