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--2021 The R Core Team
71 * Copyright (C) 2009--2011 Romain Francois
72 *
73 * This program is free software; you can redistribute it and/or modify
74 * it under the terms of the GNU General Public License as published by
75 * the Free Software Foundation; either version 2 of the License, or
76 * (at your option) any later version.
77 *
78 * This program is distributed in the hope that it will be useful,
79 * but WITHOUT ANY WARRANTY; without even the implied warranty of
80 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81 * GNU General Public License for more details.
82 *
83 * You should have received a copy of the GNU General Public License
84 * along with this program; if not, a copy is available at
85 * https://www.R-project.org/Licenses/
86 */
87
88 #ifdef HAVE_CONFIG_H
89 #include <config.h>
90 #endif
91
92 #define R_USE_SIGNALS 1
93 #include "IOStuff.h" /*-> Defn.h */
94 #include "Fileio.h"
95 #include "Parse.h"
96 #include <R_ext/Print.h>
97
98 #if !defined(__STDC_ISO_10646__) && (defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun))
99 /* This may not be 100% true (see the comment in rlocale.h),
100 but it seems true in normal locales.
101 */
102 # define __STDC_ISO_10646__
103 #endif
104
105 /* #define YYDEBUG 1 */
106 #define YYERROR_VERBOSE 1
107 #define PARSE_ERROR_SIZE 256 /* Parse error messages saved here */
108 #define PARSE_CONTEXT_SIZE 256 /* Recent parse context kept in a circular buffer */
109
110 static Rboolean busy = FALSE;
111 static SEXP R_NullSymbol = NULL;
112
113 static int identifier ;
114 static void incrementId(void);
115 static void initData(void);
116 static void initId(void);
117 static void record_( int, int, int, int, int, int, char* ) ;
118
119 static void yyerror(const char *);
120 static int yylex();
121 int yyparse(void);
122
123 static FILE *fp_parse;
124 static int (*ptr_getc)(void);
125
126 static int SavedToken;
127 static SEXP SavedLval;
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
141 int first_parsed;
142 int last_parsed;
143
144 int id;
145 } yyltype;
146
147
148 #define INIT_DATA_COUNT 16384 /* init parser data to this size */
149 #define MAX_DATA_COUNT 65536 /* release it at the end if it is this size or larger*/
150
151 #define DATA_COUNT (length( PS_DATA ) / DATA_ROWS)
152 #define ID_COUNT ((length( PS_IDS ) / 2) - 1)
153
154 static void finalizeData( ) ;
155 static void growData( ) ;
156 static void growID( int ) ;
157
158 #define DATA_ROWS 8
159
160 #define _FIRST_PARSED( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) ]
161 #define _FIRST_COLUMN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 1 ]
162 #define _LAST_PARSED( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 2 ]
163 #define _LAST_COLUMN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 3 ]
164 #define _TERMINAL( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 4 ]
165 #define _TOKEN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 5 ]
166 #define _ID( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 6 ]
167 #define _PARENT(i) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 7 ]
168
169 #define ID_ID( i ) INTEGER(PS_IDS)[ 2*(i) ]
170 #define ID_PARENT( i ) INTEGER(PS_IDS)[ 2*(i) + 1 ]
171
172 static void modif_token( yyltype*, int ) ;
173 static void recordParents( int, yyltype*, int) ;
174
175 static int _current_token ;
176
177 /**
178 * Records the current non-terminal token expression and gives it an id
179 *
180 * @param loc the location of the expression
181 */
setId(yyltype loc)182 static void setId(yyltype loc){
183 record_(
184 (loc).first_parsed, (loc).first_column, (loc).last_parsed, (loc).last_column,
185 _current_token, (loc).id, 0 ) ;
186 }
187
188 # define YYLTYPE yyltype
189 # define YYLLOC_DEFAULT(Current, Rhs, N) \
190 do { \
191 if (N){ \
192 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
193 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
194 (Current).first_byte = YYRHSLOC (Rhs, 1).first_byte; \
195 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
196 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
197 (Current).last_byte = YYRHSLOC (Rhs, N).last_byte; \
198 (Current).first_parsed = YYRHSLOC (Rhs, 1).first_parsed; \
199 (Current).last_parsed = YYRHSLOC (Rhs, N).last_parsed; \
200 incrementId( ) ; \
201 (Current).id = identifier ; \
202 _current_token = yyr1[yyn] ; \
203 if (ParseState.keepSrcRefs && ParseState.keepParseData) { \
204 yyltype childs[N]; \
205 int ii = 0; \
206 for(ii=0; ii<N; ii++){ \
207 childs[ii] = YYRHSLOC (Rhs, (ii+1) ) ; \
208 } \
209 recordParents( identifier, childs, N) ; \
210 } \
211 } else { \
212 (Current).first_line = (Current).last_line = \
213 YYRHSLOC (Rhs, 0).last_line; \
214 (Current).first_parsed = (Current).last_parsed = \
215 YYRHSLOC (Rhs, 0).last_parsed; \
216 (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \
217 (Current).last_column = (Current).first_column - 1; \
218 (Current).first_byte = YYRHSLOC (Rhs, 0).last_byte; \
219 (Current).last_byte = (Current).first_byte - 1; \
220 (Current).id = NA_INTEGER; \
221 } \
222 } while (0)
223
224
225 # define YY_LOCATION_PRINT(File,Loc) \
226 fprintf ( File, "%d.%d.%d-%d.%d.%d (%d)", \
227 (Loc).first_line, (Loc).first_column, (Loc).first_byte, \
228 (Loc).last_line, (Loc).last_column, (Loc).last_byte, \
229 (Loc).id )
230
231 /* Useful defines so editors don't get confused ... */
232
233 #define LBRACE '{'
234 #define RBRACE '}'
235
236 /* Functions used in the parsing process */
237
238 static void CheckFormalArgs(SEXP, SEXP, YYLTYPE *);
239 static SEXP FirstArg(SEXP, SEXP); /* create list with one element */
240 static void GrowList(SEXP, SEXP); /* add element to list end */
241
242 static void SetSingleSrcRef(SEXP);
243 static void AppendToSrcRefs(SEXP);
244 static void PrependToSrcRefs(SEXP);
245 static SEXP SrcRefsToVectorList();
246
247 static void IfPush(void);
248 static int KeywordLookup(const char *);
249 static SEXP NewList(void);
250 static void NextArg(SEXP, SEXP, SEXP); /* add named element to list end */
251 static SEXP TagArg(SEXP, SEXP, YYLTYPE *);
252 static int processLineDirective();
253
254 static SEXP R_PipeBindSymbol = NULL;
255
256 /* These routines allocate constants */
257
258 static SEXP mkComplex(const char *);
259 SEXP mkFalse(void);
260 static SEXP mkFloat(const char *);
261 static SEXP mkInt(const char *);
262 static SEXP mkNA(void);
263 SEXP mkTrue(void);
264
265 /* Internal lexer / parser state variables */
266
267 static int EatLines = 0;
268 static int GenerateCode = 0;
269 static int EndOfFile = 0;
270 static int xxgetc();
271 static int xxungetc(int);
272 static int xxcharcount, xxcharsave;
273 static int xxlinesave, xxbytesave, xxcolsave, xxparsesave;
274
275 static SrcRefState ParseState;
276
277 #define PS_SET_SRCREFS(x) SET_VECTOR_ELT(ParseState.sexps, 0, (x))
278 #define PS_SET_SRCFILE(x) SET_VECTOR_ELT(ParseState.sexps, 1, (x))
279 #define PS_SET_ORIGINAL(x) SET_VECTOR_ELT(ParseState.sexps, 2, (x))
280
281 /* direct pointer to data is kept for performance of finalizeData() */
282 #define PS_SET_DATA(x) do { \
283 SEXP __x__ = (x); \
284 SET_VECTOR_ELT(ParseState.sexps, 3, __x__); \
285 ParseState.data = __x__; \
286 } while(0);
287
288 #define PS_SET_TEXT(x) SET_VECTOR_ELT(ParseState.sexps, 4, (x))
289 #define PS_SET_IDS(x) SET_VECTOR_ELT(ParseState.sexps, 5, (x))
290 #define PS_SET_SVS(x) SET_VECTOR_ELT(ParseState.sexps, 6, (x))
291
292 #define PS_SRCREFS VECTOR_ELT(ParseState.sexps, 0)
293 #define PS_SRCFILE VECTOR_ELT(ParseState.sexps, 1)
294 #define PS_ORIGINAL VECTOR_ELT(ParseState.sexps, 2)
295 #define PS_DATA ParseState.data
296 #define PS_TEXT VECTOR_ELT(ParseState.sexps, 4)
297 #define PS_IDS VECTOR_ELT(ParseState.sexps, 5)
298 #define PS_SVS VECTOR_ELT(ParseState.sexps, 6)
299
300 /* Memory protection in the parser
301
302 The generated code of the parser keeps semantic values (SEXPs) on its
303 semantic values stack. Values are added to the stack during shift and
304 reduce operations and are removed during reduce operations or error
305 handling. Values are created by the lexer before they are added to the
306 stack. Values are also held in a local SEXP variable once removed from
307 the stack but still needed. The stack is automatically expanded on demand.
308
309 For memory protection, it would be natural to have that stack on the R heap
310 and to use PROTECT/UNPROTECT to protect values in local SEXP variables.
311 Unfortunately, bison does not seem to be customizable enough to allow this.
312
313 Hence, semantic values, when created by the lexer or reduce operations, are
314 placed on parser state precious multi-set via PRESERVE_SV. They are removed
315 from the multi-set in reduce operations using RELEASE_SV, because by design
316 of the bison parsers such values are subsequently removed from the stack.
317 They are also automatically removed when the parsing finishes, including
318 parser error (also on R error, via the context on-end action).
319
320 Previously semantic values were protected via PROTECT/UNPROTECT_PTR with
321 similar semantics but using protect stack shared with PROTECT/UNPROTECT.
322 Using a separate precious multi-set is safe even with interleaving of the
323 two protection schemes.
324 */
325
326 #define INIT_SVS() PS_SET_SVS(R_NewPreciousMSet(200))
327 #define PRESERVE_SV(x) R_PreserveInMSet((x), PS_SVS)
328 #define RELEASE_SV(x) R_ReleaseFromMSet((x), PS_SVS)
329 #define CLEAR_SVS() R_ReleaseMSet(PS_SVS, 500)
330
331 /* Memory leak
332
333 yyparse(), as generated by bison, allocates extra space for the parser
334 stack using malloc(). Unfortunately this means that there is a memory
335 leak in case of an R error (long-jump). In principle, we could define
336 yyoverflow() to relocate the parser stacks for bison and allocate say on
337 the R heap, but yyoverflow() is undocumented and somewhat complicated
338 (we would have to replicate some macros from the generated parser here).
339 The same problem exists at least in the Rd and LaTeX parsers in tools.
340 */
341
342 #include <rlocale.h>
343 #ifdef HAVE_LANGINFO_CODESET
344 # include <langinfo.h>
345 #endif
346
mbcs_get_next(int c,wchar_t * wc)347 static int mbcs_get_next(int c, wchar_t *wc)
348 {
349 int i, res, clen = 1; char s[9];
350 mbstate_t mb_st;
351
352 s[0] = (char) c;
353 /* This assumes (probably OK) that all MBCS embed ASCII as single-byte
354 lead bytes, including control chars */
355 if((unsigned int) c < 0x80) {
356 *wc = (wchar_t) c;
357 return 1;
358 }
359 if(utf8locale) {
360 clen = utf8clen((char) c);
361 for(i = 1; i < clen; i++) {
362 c = xxgetc();
363 if(c == R_EOF) error(_("EOF whilst reading MBCS char at line %d"), ParseState.xxlineno);
364 s[i] = (char) c;
365 }
366 s[clen] ='\0'; /* x86 Solaris requires this */
367 res = (int) mbrtowc(wc, s, clen, NULL);
368 if(res == -1) error(_("invalid multibyte character in parser at line %d"), ParseState.xxlineno);
369 } else {
370 /* This is not necessarily correct for stateful MBCS */
371 while(clen <= R_MB_CUR_MAX) {
372 mbs_init(&mb_st);
373 res = (int) mbrtowc(wc, s, clen, &mb_st);
374 if(res >= 0) break;
375 if(res == -1)
376 error(_("invalid multibyte character in parser at line %d"), ParseState.xxlineno);
377 /* so res == -2 */
378 c = xxgetc();
379 if(c == R_EOF) error(_("EOF whilst reading MBCS char at line %d"), ParseState.xxlineno);
380 s[clen++] = (char) c;
381 } /* we've tried enough, so must be complete or invalid by now */
382 }
383 for(i = clen - 1; i > 0; i--) xxungetc(s[i]);
384 return clen;
385 }
386
387 /* Soon to be defunct entry points */
388
389 void R_SetInput(int);
390 int R_fgetc(FILE*);
391
392 /* Routines used to build the parse tree */
393
394 static SEXP xxnullformal(void);
395 static SEXP xxfirstformal0(SEXP);
396 static SEXP xxfirstformal1(SEXP, SEXP);
397 static SEXP xxaddformal0(SEXP, SEXP, YYLTYPE *);
398 static SEXP xxaddformal1(SEXP, SEXP, SEXP, YYLTYPE *);
399 static SEXP xxexprlist0();
400 static SEXP xxexprlist1(SEXP, YYLTYPE *);
401 static SEXP xxexprlist2(SEXP, SEXP, YYLTYPE *);
402 static SEXP xxsub0(void);
403 static SEXP xxsub1(SEXP, YYLTYPE *);
404 static SEXP xxsymsub0(SEXP, YYLTYPE *);
405 static SEXP xxsymsub1(SEXP, SEXP, YYLTYPE *);
406 static SEXP xxnullsub0(YYLTYPE *);
407 static SEXP xxnullsub1(SEXP, YYLTYPE *);
408 static SEXP xxsublist1(SEXP);
409 static SEXP xxsublist2(SEXP, SEXP);
410 static SEXP xxcond(SEXP);
411 static SEXP xxifcond(SEXP);
412 static SEXP xxif(SEXP, SEXP, SEXP);
413 static SEXP xxifelse(SEXP, SEXP, SEXP, SEXP);
414 static SEXP xxforcond(SEXP, SEXP);
415 static SEXP xxfor(SEXP, SEXP, SEXP);
416 static SEXP xxwhile(SEXP, SEXP, SEXP);
417 static SEXP xxrepeat(SEXP, SEXP);
418 static SEXP xxnxtbrk(SEXP);
419 static SEXP xxfuncall(SEXP, SEXP);
420 static SEXP xxdefun(SEXP, SEXP, SEXP, YYLTYPE *);
421 static SEXP xxpipe(SEXP, SEXP);
422 static SEXP xxpipebind(SEXP, SEXP, SEXP);
423 static SEXP xxunary(SEXP, SEXP);
424 static SEXP xxbinary(SEXP, SEXP, SEXP);
425 static SEXP xxparen(SEXP, SEXP);
426 static SEXP xxsubscript(SEXP, SEXP, SEXP);
427 static SEXP xxexprlist(SEXP, YYLTYPE *, SEXP);
428 static int xxvalue(SEXP, int, YYLTYPE *);
429
430 #define YYSTYPE SEXP
431
432
433
434
435 # ifndef YY_NULLPTR
436 # if defined __cplusplus && 201103L <= __cplusplus
437 # define YY_NULLPTR nullptr
438 # else
439 # define YY_NULLPTR 0
440 # endif
441 # endif
442
443 /* Enabling verbose error messages. */
444 #ifdef YYERROR_VERBOSE
445 # undef YYERROR_VERBOSE
446 # define YYERROR_VERBOSE 1
447 #else
448 # define YYERROR_VERBOSE 0
449 #endif
450
451
452 /* Debug traces. */
453 #ifndef YYDEBUG
454 # define YYDEBUG 0
455 #endif
456 #if YYDEBUG
457 extern int yydebug;
458 #endif
459
460 /* Token type. */
461 #ifndef YYTOKENTYPE
462 # define YYTOKENTYPE
463 enum yytokentype
464 {
465 END_OF_INPUT = 258,
466 ERROR = 259,
467 STR_CONST = 260,
468 NUM_CONST = 261,
469 NULL_CONST = 262,
470 SYMBOL = 263,
471 FUNCTION = 264,
472 INCOMPLETE_STRING = 265,
473 LEFT_ASSIGN = 266,
474 EQ_ASSIGN = 267,
475 RIGHT_ASSIGN = 268,
476 LBB = 269,
477 FOR = 270,
478 IN = 271,
479 IF = 272,
480 ELSE = 273,
481 WHILE = 274,
482 NEXT = 275,
483 BREAK = 276,
484 REPEAT = 277,
485 GT = 278,
486 GE = 279,
487 LT = 280,
488 LE = 281,
489 EQ = 282,
490 NE = 283,
491 AND = 284,
492 OR = 285,
493 AND2 = 286,
494 OR2 = 287,
495 NS_GET = 288,
496 NS_GET_INT = 289,
497 COMMENT = 290,
498 LINE_DIRECTIVE = 291,
499 SYMBOL_FORMALS = 292,
500 EQ_FORMALS = 293,
501 EQ_SUB = 294,
502 SYMBOL_SUB = 295,
503 SYMBOL_FUNCTION_CALL = 296,
504 SYMBOL_PACKAGE = 297,
505 SLOT = 298,
506 PIPE = 299,
507 PIPEBIND = 300,
508 LOW = 301,
509 TILDE = 302,
510 UNOT = 303,
511 NOT = 304,
512 SPECIAL = 305,
513 UMINUS = 306,
514 UPLUS = 307
515 };
516 #endif
517 /* Tokens. */
518 #define END_OF_INPUT 258
519 #define ERROR 259
520 #define STR_CONST 260
521 #define NUM_CONST 261
522 #define NULL_CONST 262
523 #define SYMBOL 263
524 #define FUNCTION 264
525 #define INCOMPLETE_STRING 265
526 #define LEFT_ASSIGN 266
527 #define EQ_ASSIGN 267
528 #define RIGHT_ASSIGN 268
529 #define LBB 269
530 #define FOR 270
531 #define IN 271
532 #define IF 272
533 #define ELSE 273
534 #define WHILE 274
535 #define NEXT 275
536 #define BREAK 276
537 #define REPEAT 277
538 #define GT 278
539 #define GE 279
540 #define LT 280
541 #define LE 281
542 #define EQ 282
543 #define NE 283
544 #define AND 284
545 #define OR 285
546 #define AND2 286
547 #define OR2 287
548 #define NS_GET 288
549 #define NS_GET_INT 289
550 #define COMMENT 290
551 #define LINE_DIRECTIVE 291
552 #define SYMBOL_FORMALS 292
553 #define EQ_FORMALS 293
554 #define EQ_SUB 294
555 #define SYMBOL_SUB 295
556 #define SYMBOL_FUNCTION_CALL 296
557 #define SYMBOL_PACKAGE 297
558 #define SLOT 298
559 #define PIPE 299
560 #define PIPEBIND 300
561 #define LOW 301
562 #define TILDE 302
563 #define UNOT 303
564 #define NOT 304
565 #define SPECIAL 305
566 #define UMINUS 306
567 #define UPLUS 307
568
569 /* Value type. */
570 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
571 typedef int YYSTYPE;
572 # define YYSTYPE_IS_TRIVIAL 1
573 # define YYSTYPE_IS_DECLARED 1
574 #endif
575
576 /* Location type. */
577 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
578 typedef struct YYLTYPE YYLTYPE;
579 struct YYLTYPE
580 {
581 int first_line;
582 int first_column;
583 int last_line;
584 int last_column;
585 };
586 # define YYLTYPE_IS_DECLARED 1
587 # define YYLTYPE_IS_TRIVIAL 1
588 #endif
589
590
591 extern YYSTYPE yylval;
592 extern YYLTYPE yylloc;
593 int yyparse (void);
594
595
596
597 /* Copy the second part of user declarations. */
598
599
600
601 #ifdef short
602 # undef short
603 #endif
604
605 #ifdef YYTYPE_UINT8
606 typedef YYTYPE_UINT8 yytype_uint8;
607 #else
608 typedef unsigned char yytype_uint8;
609 #endif
610
611 #ifdef YYTYPE_INT8
612 typedef YYTYPE_INT8 yytype_int8;
613 #else
614 typedef signed char yytype_int8;
615 #endif
616
617 #ifdef YYTYPE_UINT16
618 typedef YYTYPE_UINT16 yytype_uint16;
619 #else
620 typedef unsigned short int yytype_uint16;
621 #endif
622
623 #ifdef YYTYPE_INT16
624 typedef YYTYPE_INT16 yytype_int16;
625 #else
626 typedef short int yytype_int16;
627 #endif
628
629 #ifndef YYSIZE_T
630 # ifdef __SIZE_TYPE__
631 # define YYSIZE_T __SIZE_TYPE__
632 # elif defined size_t
633 # define YYSIZE_T size_t
634 # elif ! defined YYSIZE_T
635 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
636 # define YYSIZE_T size_t
637 # else
638 # define YYSIZE_T unsigned int
639 # endif
640 #endif
641
642 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
643
644 #ifndef YY_
645 # if defined YYENABLE_NLS && YYENABLE_NLS
646 # if ENABLE_NLS
647 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
648 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
649 # endif
650 # endif
651 # ifndef YY_
652 # define YY_(Msgid) Msgid
653 # endif
654 #endif
655
656 #ifndef YY_ATTRIBUTE
657 # if (defined __GNUC__ \
658 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
659 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
660 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
661 # else
662 # define YY_ATTRIBUTE(Spec) /* empty */
663 # endif
664 #endif
665
666 #ifndef YY_ATTRIBUTE_PURE
667 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
668 #endif
669
670 #ifndef YY_ATTRIBUTE_UNUSED
671 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
672 #endif
673
674 #if !defined _Noreturn \
675 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
676 # if defined _MSC_VER && 1200 <= _MSC_VER
677 # define _Noreturn __declspec (noreturn)
678 # else
679 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
680 # endif
681 #endif
682
683 /* Suppress unused-variable warnings by "using" E. */
684 #if ! defined lint || defined __GNUC__
685 # define YYUSE(E) ((void) (E))
686 #else
687 # define YYUSE(E) /* empty */
688 #endif
689
690 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
691 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
692 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
693 _Pragma ("GCC diagnostic push") \
694 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
695 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
696 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
697 _Pragma ("GCC diagnostic pop")
698 #else
699 # define YY_INITIAL_VALUE(Value) Value
700 #endif
701 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
702 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
703 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
704 #endif
705 #ifndef YY_INITIAL_VALUE
706 # define YY_INITIAL_VALUE(Value) /* Nothing. */
707 #endif
708
709
710 #if ! defined yyoverflow || YYERROR_VERBOSE
711
712 /* The parser invokes alloca or malloc; define the necessary symbols. */
713
714 # ifdef YYSTACK_USE_ALLOCA
715 # if YYSTACK_USE_ALLOCA
716 # ifdef __GNUC__
717 # define YYSTACK_ALLOC __builtin_alloca
718 # elif defined __BUILTIN_VA_ARG_INCR
719 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
720 # elif defined _AIX
721 # define YYSTACK_ALLOC __alloca
722 # elif defined _MSC_VER
723 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
724 # define alloca _alloca
725 # else
726 # define YYSTACK_ALLOC alloca
727 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
728 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
729 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
730 # ifndef EXIT_SUCCESS
731 # define EXIT_SUCCESS 0
732 # endif
733 # endif
734 # endif
735 # endif
736 # endif
737
738 # ifdef YYSTACK_ALLOC
739 /* Pacify GCC's 'empty if-body' warning. */
740 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
741 # ifndef YYSTACK_ALLOC_MAXIMUM
742 /* The OS might guarantee only one guard page at the bottom of the stack,
743 and a page size can be as small as 4096 bytes. So we cannot safely
744 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
745 to allow for a few compiler-allocated temporary stack slots. */
746 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
747 # endif
748 # else
749 # define YYSTACK_ALLOC YYMALLOC
750 # define YYSTACK_FREE YYFREE
751 # ifndef YYSTACK_ALLOC_MAXIMUM
752 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
753 # endif
754 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
755 && ! ((defined YYMALLOC || defined malloc) \
756 && (defined YYFREE || defined free)))
757 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
758 # ifndef EXIT_SUCCESS
759 # define EXIT_SUCCESS 0
760 # endif
761 # endif
762 # ifndef YYMALLOC
763 # define YYMALLOC malloc
764 # if ! defined malloc && ! defined EXIT_SUCCESS
765 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
766 # endif
767 # endif
768 # ifndef YYFREE
769 # define YYFREE free
770 # if ! defined free && ! defined EXIT_SUCCESS
771 void free (void *); /* INFRINGES ON USER NAME SPACE */
772 # endif
773 # endif
774 # endif
775 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
776
777
778 #if (! defined yyoverflow \
779 && (! defined __cplusplus \
780 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
781 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
782
783 /* A type that is properly aligned for any stack member. */
784 union yyalloc
785 {
786 yytype_int16 yyss_alloc;
787 YYSTYPE yyvs_alloc;
788 YYLTYPE yyls_alloc;
789 };
790
791 /* The size of the maximum gap between one aligned stack and the next. */
792 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
793
794 /* The size of an array large to enough to hold all stacks, each with
795 N elements. */
796 # define YYSTACK_BYTES(N) \
797 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
798 + 2 * YYSTACK_GAP_MAXIMUM)
799
800 # define YYCOPY_NEEDED 1
801
802 /* Relocate STACK from its old location to the new one. The
803 local variables YYSIZE and YYSTACKSIZE give the old and new number of
804 elements in the stack, and YYPTR gives the new location of the
805 stack. Advance YYPTR to a properly aligned location for the next
806 stack. */
807 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
808 do \
809 { \
810 YYSIZE_T yynewbytes; \
811 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
812 Stack = &yyptr->Stack_alloc; \
813 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
814 yyptr += yynewbytes / sizeof (*yyptr); \
815 } \
816 while (0)
817
818 #endif
819
820 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
821 /* Copy COUNT objects from SRC to DST. The source and destination do
822 not overlap. */
823 # ifndef YYCOPY
824 # if defined __GNUC__ && 1 < __GNUC__
825 # define YYCOPY(Dst, Src, Count) \
826 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
827 # else
828 # define YYCOPY(Dst, Src, Count) \
829 do \
830 { \
831 YYSIZE_T yyi; \
832 for (yyi = 0; yyi < (Count); yyi++) \
833 (Dst)[yyi] = (Src)[yyi]; \
834 } \
835 while (0)
836 # endif
837 # endif
838 #endif /* !YYCOPY_NEEDED */
839
840 /* YYFINAL -- State number of the termination state. */
841 #define YYFINAL 47
842 /* YYLAST -- Last index in YYTABLE. */
843 #define YYLAST 550
844
845 /* YYNTOKENS -- Number of terminals. */
846 #define YYNTOKENS 74
847 /* YYNNTS -- Number of nonterminals. */
848 #define YYNNTS 13
849 /* YYNRULES -- Number of rules. */
850 #define YYNRULES 93
851 /* YYNSTATES -- Number of states. */
852 #define YYNSTATES 173
853
854 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
855 by yylex, with out-of-bounds checking. */
856 #define YYUNDEFTOK 2
857 #define YYMAXUTOK 307
858
859 #define YYTRANSLATE(YYX) \
860 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
861
862 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
863 as returned by yylex, without out-of-bounds checking. */
864 static const yytype_uint8 yytranslate[] =
865 {
866 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
867 65, 2, 2, 2, 2, 2, 2, 2, 2, 2,
868 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
869 2, 2, 2, 70, 2, 2, 61, 2, 2, 2,
870 63, 69, 54, 52, 73, 53, 2, 55, 2, 2,
871 2, 2, 2, 2, 2, 2, 2, 2, 57, 66,
872 2, 2, 2, 46, 62, 2, 2, 2, 2, 2,
873 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
874 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
875 2, 64, 71, 72, 60, 2, 2, 2, 2, 2,
876 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
877 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
878 2, 2, 2, 67, 2, 68, 48, 2, 2, 2,
879 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
880 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
881 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
882 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
883 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
884 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
885 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
886 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
887 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
888 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
889 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
890 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
891 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
892 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
893 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
894 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
895 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
896 45, 47, 49, 50, 51, 56, 58, 59
897 };
898
899 #if YYDEBUG
900 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
901 static const yytype_uint16 yyrline[] =
902 {
903 0, 415, 415, 416, 417, 418, 419, 422, 423, 424,
904 427, 428, 431, 432, 433, 434, 436, 437, 439, 440,
905 441, 442, 443, 445, 446, 447, 448, 449, 450, 451,
906 452, 453, 454, 455, 456, 457, 458, 459, 460, 461,
907 462, 463, 464, 465, 466, 467, 469, 470, 471, 472,
908 473, 474, 475, 476, 477, 478, 479, 480, 481, 482,
909 483, 484, 485, 486, 487, 488, 489, 490, 491, 495,
910 498, 501, 505, 506, 507, 508, 509, 510, 513, 514,
911 517, 518, 519, 520, 521, 522, 523, 524, 527, 528,
912 529, 530, 531, 535
913 };
914 #endif
915
916 #if YYDEBUG || YYERROR_VERBOSE || 1
917 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
918 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
919 static const char *const yytname[] =
920 {
921 "$end", "error", "$undefined", "END_OF_INPUT", "ERROR", "STR_CONST",
922 "NUM_CONST", "NULL_CONST", "SYMBOL", "FUNCTION", "INCOMPLETE_STRING",
923 "LEFT_ASSIGN", "EQ_ASSIGN", "RIGHT_ASSIGN", "LBB", "FOR", "IN", "IF",
924 "ELSE", "WHILE", "NEXT", "BREAK", "REPEAT", "GT", "GE", "LT", "LE", "EQ",
925 "NE", "AND", "OR", "AND2", "OR2", "NS_GET", "NS_GET_INT", "COMMENT",
926 "LINE_DIRECTIVE", "SYMBOL_FORMALS", "EQ_FORMALS", "EQ_SUB", "SYMBOL_SUB",
927 "SYMBOL_FUNCTION_CALL", "SYMBOL_PACKAGE", "SLOT", "PIPE", "PIPEBIND",
928 "'?'", "LOW", "'~'", "TILDE", "UNOT", "NOT", "'+'", "'-'", "'*'", "'/'",
929 "SPECIAL", "':'", "UMINUS", "UPLUS", "'^'", "'$'", "'@'", "'('", "'['",
930 "'\\n'", "';'", "'{'", "'}'", "')'", "'!'", "'\\\\'", "']'", "','",
931 "$accept", "prog", "expr_or_assign_or_help", "expr_or_help", "expr",
932 "cond", "ifcond", "forcond", "exprlist", "sublist", "sub", "formlist",
933 "cr", YY_NULLPTR
934 };
935 #endif
936
937 # ifdef YYPRINT
938 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
939 (internal) symbol number NUM (which must be that of a token). */
940 static const yytype_uint16 yytoknum[] =
941 {
942 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
943 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
944 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
945 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
946 295, 296, 297, 298, 299, 300, 63, 301, 126, 302,
947 303, 304, 43, 45, 42, 47, 305, 58, 306, 307,
948 94, 36, 64, 40, 91, 10, 59, 123, 125, 41,
949 33, 92, 93, 44
950 };
951 # endif
952
953 #define YYPACT_NINF -127
954
955 #define yypact_value_is_default(Yystate) \
956 (!!((Yystate) == (-127)))
957
958 #define YYTABLE_NINF -1
959
960 #define yytable_value_is_error(Yytable_value) \
961 (!!((Yytable_value) == (-1)))
962
963 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
964 STATE-NUM. */
965 static const yytype_int16 yypact[] =
966 {
967 149, -127, -127, 55, -127, -127, 80, -47, -41, -39,
968 -37, -127, -127, 216, 216, 216, 216, 216, 216, -127,
969 216, 216, -29, 36, 20, 287, 6, 89, 93, 94,
970 68, 74, 216, 216, 216, 216, 216, 72, 72, 375,
971 123, 123, 18, 23, 12, 442, 68, -127, 216, 216,
972 -127, -127, 216, 216, 236, 216, 216, 216, 216, 216,
973 216, 216, 216, 216, 216, 216, 216, 216, 216, 216,
974 216, 216, 216, 216, 216, 95, 100, 236, 236, -127,
975 -127, -127, -127, -127, -127, -127, -127, 78, -56, 88,
976 72, -42, 287, -3, -38, 72, -127, 216, 216, -127,
977 -50, 72, 72, 287, 331, -5, 97, 58, 60, 40,
978 -127, 486, 486, 486, 486, 486, 486, 442, 419, 442,
979 419, 79, 11, 375, 118, 118, 264, 264, 79, 123,
980 123, -127, -127, -127, -127, 48, 49, 216, -127, 115,
981 216, 216, -127, 216, -127, 23, 23, -127, 216, 216,
982 216, 56, 54, -127, -127, 60, 216, 117, -36, -127,
983 72, 216, 60, 60, 60, -127, 236, 72, 216, -127,
984 72, -127, 60
985 };
986
987 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
988 Performed when YYTABLE does not specify something else to do. Zero
989 means the default is an error. */
990 static const yytype_uint8 yydefact[] =
991 {
992 0, 6, 2, 13, 12, 14, 15, 0, 0, 0,
993 0, 67, 68, 0, 0, 0, 0, 0, 0, 3,
994 72, 0, 0, 0, 0, 7, 0, 0, 0, 0,
995 88, 0, 0, 0, 0, 0, 0, 52, 22, 21,
996 19, 18, 0, 73, 0, 20, 88, 1, 0, 0,
997 4, 5, 0, 0, 80, 0, 0, 0, 0, 0,
998 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
999 0, 0, 0, 0, 0, 0, 0, 80, 80, 58,
1000 57, 62, 61, 56, 55, 60, 59, 89, 0, 0,
1001 50, 0, 10, 48, 0, 51, 17, 77, 75, 16,
1002 0, 8, 9, 43, 44, 13, 14, 15, 81, 93,
1003 78, 36, 35, 31, 32, 33, 34, 37, 38, 39,
1004 40, 41, 42, 30, 24, 25, 26, 27, 29, 23,
1005 28, 64, 63, 66, 65, 93, 93, 0, 93, 0,
1006 0, 0, 70, 0, 69, 76, 74, 93, 84, 86,
1007 82, 0, 0, 47, 54, 90, 0, 91, 0, 11,
1008 49, 0, 85, 87, 83, 53, 80, 45, 0, 71,
1009 46, 79, 92
1010 };
1011
1012 /* YYPGOTO[NTERM-NUM]. */
1013 static const yytype_int8 yypgoto[] =
1014 {
1015 -127, -127, 47, -30, -15, -127, -127, -127, -127, 38,
1016 -35, 84, -126
1017 };
1018
1019 /* YYDEFGOTO[NTERM-NUM]. */
1020 static const yytype_int16 yydefgoto[] =
1021 {
1022 -1, 23, 24, 108, 25, 36, 34, 32, 44, 109,
1023 110, 88, 152
1024 };
1025
1026 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1027 positive, shift that token. If negative, reduce the rule whose
1028 number is the opposite. If YYTABLE_NINF, syntax error. */
1029 static const yytype_int16 yytable[] =
1030 {
1031 39, 40, 41, 91, 141, 94, 45, 148, 141, 48,
1032 141, 79, 156, 138, 80, 143, 30, 139, 92, 147,
1033 92, 161, 31, 139, 33, 54, 35, 142, 26, 27,
1034 48, 144, 48, 169, 46, 48, 47, 103, 104, 92,
1035 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
1036 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
1037 37, 38, 92, 92, 49, 42, 49, 43, 73, 49,
1038 150, 74, 75, 76, 77, 78, 87, 97, 98, 90,
1039 99, 93, 89, 95, 48, 50, 51, 96, 26, 27,
1040 137, 28, 29, 54, 81, 101, 102, 82, 83, 85,
1041 131, 84, 86, 132, 140, 133, 141, 155, 134, 149,
1042 158, 159, 151, 28, 29, 135, 136, 153, 162, 163,
1043 164, 154, 92, 157, 66, 92, 92, 166, 165, 168,
1044 100, 171, 54, 92, 92, 92, 73, 54, 172, 74,
1045 75, 76, 77, 78, 145, 146, 0, 0, 0, 0,
1046 1, 92, 2, 92, 3, 4, 5, 6, 7, 0,
1047 0, 0, 65, 66, 8, 0, 9, 0, 10, 11,
1048 12, 13, 70, 71, 72, 73, 0, 0, 74, 75,
1049 76, 77, 78, 74, 75, 76, 77, 78, 0, 0,
1050 160, 0, 0, 0, 0, 14, 0, 15, 0, 0,
1051 0, 16, 17, 167, 0, 0, 0, 0, 170, 0,
1052 0, 0, 18, 0, 19, 0, 20, 0, 0, 21,
1053 22, 3, 4, 5, 6, 7, 0, 0, 0, 0,
1054 0, 8, 0, 9, 0, 10, 11, 12, 13, 0,
1055 0, 105, 4, 106, 107, 7, 0, 0, 0, 0,
1056 0, 8, 0, 9, 0, 10, 11, 12, 13, 0,
1057 0, 0, 14, 0, 15, 0, 0, 0, 16, 17,
1058 0, 0, 0, 0, 0, 0, 0, 0, 54, 18,
1059 0, 0, 14, 20, 15, 0, 21, 22, 16, 17,
1060 0, 0, 0, 0, 0, 0, 0, 0, 52, 18,
1061 53, 54, 0, 20, 0, 0, 21, 22, 65, 66,
1062 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
1063 72, 73, 0, 0, 74, 75, 76, 77, 78, 0,
1064 0, 65, 66, 0, 0, 67, 0, 0, 0, 68,
1065 69, 70, 71, 72, 73, 54, 0, 74, 75, 76,
1066 77, 78, 0, 0, 55, 56, 57, 58, 59, 60,
1067 61, 62, 63, 64, 0, 0, 0, 0, 0, 0,
1068 0, 0, 0, 0, 0, 65, 66, 0, 0, 67,
1069 0, 0, 0, 68, 69, 70, 71, 72, 73, 54,
1070 0, 74, 75, 76, 77, 78, 0, 0, 55, 56,
1071 57, 58, 59, 60, 61, 62, 63, 64, 0, 0,
1072 0, 0, 0, 0, 0, 0, 0, 0, 0, 65,
1073 66, 0, 0, 0, 0, 0, 0, 68, 69, 70,
1074 71, 72, 73, 54, 0, 74, 75, 76, 77, 78,
1075 0, 0, 55, 56, 57, 58, 59, 60, 61, 0,
1076 63, 0, 0, 0, 0, 0, 54, 0, 0, 0,
1077 0, 0, 0, 65, 66, 55, 56, 57, 58, 59,
1078 60, 68, 69, 70, 71, 72, 73, 0, 0, 74,
1079 75, 76, 77, 78, 0, 0, 65, 66, 0, 0,
1080 0, 0, 0, 0, 68, 69, 70, 71, 72, 73,
1081 54, 0, 74, 75, 76, 77, 78, 0, 0, -1,
1082 -1, -1, -1, -1, -1, 0, 0, 0, 0, 0,
1083 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1084 65, 66, 0, 0, 0, 0, 0, 0, 68, 69,
1085 70, 71, 72, 73, 0, 0, 74, 75, 76, 77,
1086 78
1087 };
1088
1089 static const yytype_int16 yycheck[] =
1090 {
1091 15, 16, 17, 33, 46, 35, 21, 12, 46, 12,
1092 46, 5, 138, 69, 8, 18, 63, 73, 33, 69,
1093 35, 147, 63, 73, 63, 14, 63, 69, 33, 34,
1094 12, 69, 12, 69, 63, 12, 0, 52, 53, 54,
1095 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
1096 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
1097 13, 14, 77, 78, 46, 18, 46, 20, 57, 46,
1098 12, 60, 61, 62, 63, 64, 8, 65, 66, 32,
1099 68, 34, 8, 36, 12, 65, 66, 69, 33, 34,
1100 12, 33, 34, 14, 5, 48, 49, 8, 5, 5,
1101 5, 8, 8, 8, 16, 5, 46, 137, 8, 12,
1102 140, 141, 72, 33, 34, 77, 78, 69, 148, 149,
1103 150, 72, 137, 8, 45, 140, 141, 73, 72, 12,
1104 46, 166, 14, 148, 149, 150, 57, 14, 168, 60,
1105 61, 62, 63, 64, 97, 98, -1, -1, -1, -1,
1106 1, 166, 3, 168, 5, 6, 7, 8, 9, -1,
1107 -1, -1, 44, 45, 15, -1, 17, -1, 19, 20,
1108 21, 22, 54, 55, 56, 57, -1, -1, 60, 61,
1109 62, 63, 64, 60, 61, 62, 63, 64, -1, -1,
1110 143, -1, -1, -1, -1, 46, -1, 48, -1, -1,
1111 -1, 52, 53, 156, -1, -1, -1, -1, 161, -1,
1112 -1, -1, 63, -1, 65, -1, 67, -1, -1, 70,
1113 71, 5, 6, 7, 8, 9, -1, -1, -1, -1,
1114 -1, 15, -1, 17, -1, 19, 20, 21, 22, -1,
1115 -1, 5, 6, 7, 8, 9, -1, -1, -1, -1,
1116 -1, 15, -1, 17, -1, 19, 20, 21, 22, -1,
1117 -1, -1, 46, -1, 48, -1, -1, -1, 52, 53,
1118 -1, -1, -1, -1, -1, -1, -1, -1, 14, 63,
1119 -1, -1, 46, 67, 48, -1, 70, 71, 52, 53,
1120 -1, -1, -1, -1, -1, -1, -1, -1, 11, 63,
1121 13, 14, -1, 67, -1, -1, 70, 71, 44, 45,
1122 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
1123 56, 57, -1, -1, 60, 61, 62, 63, 64, -1,
1124 -1, 44, 45, -1, -1, 48, -1, -1, -1, 52,
1125 53, 54, 55, 56, 57, 14, -1, 60, 61, 62,
1126 63, 64, -1, -1, 23, 24, 25, 26, 27, 28,
1127 29, 30, 31, 32, -1, -1, -1, -1, -1, -1,
1128 -1, -1, -1, -1, -1, 44, 45, -1, -1, 48,
1129 -1, -1, -1, 52, 53, 54, 55, 56, 57, 14,
1130 -1, 60, 61, 62, 63, 64, -1, -1, 23, 24,
1131 25, 26, 27, 28, 29, 30, 31, 32, -1, -1,
1132 -1, -1, -1, -1, -1, -1, -1, -1, -1, 44,
1133 45, -1, -1, -1, -1, -1, -1, 52, 53, 54,
1134 55, 56, 57, 14, -1, 60, 61, 62, 63, 64,
1135 -1, -1, 23, 24, 25, 26, 27, 28, 29, -1,
1136 31, -1, -1, -1, -1, -1, 14, -1, -1, -1,
1137 -1, -1, -1, 44, 45, 23, 24, 25, 26, 27,
1138 28, 52, 53, 54, 55, 56, 57, -1, -1, 60,
1139 61, 62, 63, 64, -1, -1, 44, 45, -1, -1,
1140 -1, -1, -1, -1, 52, 53, 54, 55, 56, 57,
1141 14, -1, 60, 61, 62, 63, 64, -1, -1, 23,
1142 24, 25, 26, 27, 28, -1, -1, -1, -1, -1,
1143 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1144 44, 45, -1, -1, -1, -1, -1, -1, 52, 53,
1145 54, 55, 56, 57, -1, -1, 60, 61, 62, 63,
1146 64
1147 };
1148
1149 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1150 symbol of state STATE-NUM. */
1151 static const yytype_uint8 yystos[] =
1152 {
1153 0, 1, 3, 5, 6, 7, 8, 9, 15, 17,
1154 19, 20, 21, 22, 46, 48, 52, 53, 63, 65,
1155 67, 70, 71, 75, 76, 78, 33, 34, 33, 34,
1156 63, 63, 81, 63, 80, 63, 79, 76, 76, 78,
1157 78, 78, 76, 76, 82, 78, 63, 0, 12, 46,
1158 65, 66, 11, 13, 14, 23, 24, 25, 26, 27,
1159 28, 29, 30, 31, 32, 44, 45, 48, 52, 53,
1160 54, 55, 56, 57, 60, 61, 62, 63, 64, 5,
1161 8, 5, 8, 5, 8, 5, 8, 8, 85, 8,
1162 76, 77, 78, 76, 77, 76, 69, 65, 66, 68,
1163 85, 76, 76, 78, 78, 5, 7, 8, 77, 83,
1164 84, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1165 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1166 78, 5, 8, 5, 8, 83, 83, 12, 69, 73,
1167 16, 46, 69, 18, 69, 76, 76, 69, 12, 12,
1168 12, 72, 86, 69, 72, 77, 86, 8, 77, 77,
1169 76, 86, 77, 77, 77, 72, 73, 76, 12, 69,
1170 76, 84, 77
1171 };
1172
1173 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1174 static const yytype_uint8 yyr1[] =
1175 {
1176 0, 74, 75, 75, 75, 75, 75, 76, 76, 76,
1177 77, 77, 78, 78, 78, 78, 78, 78, 78, 78,
1178 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1179 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1180 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1181 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
1182 78, 78, 78, 78, 78, 78, 78, 78, 78, 79,
1183 80, 81, 82, 82, 82, 82, 82, 82, 83, 83,
1184 84, 84, 84, 84, 84, 84, 84, 84, 85, 85,
1185 85, 85, 85, 86
1186 };
1187
1188 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1189 static const yytype_uint8 yyr2[] =
1190 {
1191 0, 2, 1, 1, 2, 2, 1, 1, 3, 3,
1192 1, 3, 1, 1, 1, 1, 3, 3, 2, 2,
1193 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
1194 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1195 3, 3, 3, 3, 3, 6, 6, 4, 3, 5,
1196 3, 3, 2, 5, 4, 3, 3, 3, 3, 3,
1197 3, 3, 3, 3, 3, 3, 3, 1, 1, 3,
1198 3, 5, 0, 1, 3, 2, 3, 2, 1, 4,
1199 0, 1, 2, 3, 2, 3, 2, 3, 0, 1,
1200 3, 3, 5, 0
1201 };
1202
1203
1204 #define yyerrok (yyerrstatus = 0)
1205 #define yyclearin (yychar = YYEMPTY)
1206 #define YYEMPTY (-2)
1207 #define YYEOF 0
1208
1209 #define YYACCEPT goto yyacceptlab
1210 #define YYABORT goto yyabortlab
1211 #define YYERROR goto yyerrorlab
1212
1213
1214 #define YYRECOVERING() (!!yyerrstatus)
1215
1216 #define YYBACKUP(Token, Value) \
1217 do \
1218 if (yychar == YYEMPTY) \
1219 { \
1220 yychar = (Token); \
1221 yylval = (Value); \
1222 YYPOPSTACK (yylen); \
1223 yystate = *yyssp; \
1224 goto yybackup; \
1225 } \
1226 else \
1227 { \
1228 yyerror (YY_("syntax error: cannot back up")); \
1229 YYERROR; \
1230 } \
1231 while (0)
1232
1233 /* Error token number */
1234 #define YYTERROR 1
1235 #define YYERRCODE 256
1236
1237
1238 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1239 If N is 0, then set CURRENT to the empty location which ends
1240 the previous symbol: RHS[0] (always defined). */
1241
1242 #ifndef YYLLOC_DEFAULT
1243 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1244 do \
1245 if (N) \
1246 { \
1247 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1248 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1249 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1250 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1251 } \
1252 else \
1253 { \
1254 (Current).first_line = (Current).last_line = \
1255 YYRHSLOC (Rhs, 0).last_line; \
1256 (Current).first_column = (Current).last_column = \
1257 YYRHSLOC (Rhs, 0).last_column; \
1258 } \
1259 while (0)
1260 #endif
1261
1262 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1263
1264
1265 /* Enable debugging if requested. */
1266 #if YYDEBUG
1267
1268 # ifndef YYFPRINTF
1269 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1270 # define YYFPRINTF fprintf
1271 # endif
1272
1273 # define YYDPRINTF(Args) \
1274 do { \
1275 if (yydebug) \
1276 YYFPRINTF Args; \
1277 } while (0)
1278
1279
1280 /* YY_LOCATION_PRINT -- Print the location on the stream.
1281 This macro was not mandated originally: define only if we know
1282 we won't break user code: when these are the locations we know. */
1283
1284 #ifndef YY_LOCATION_PRINT
1285 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1286
1287 /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
1288
1289 YY_ATTRIBUTE_UNUSED
1290 static unsigned
yy_location_print_(FILE * yyo,YYLTYPE const * const yylocp)1291 yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
1292 {
1293 unsigned res = 0;
1294 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
1295 if (0 <= yylocp->first_line)
1296 {
1297 res += YYFPRINTF (yyo, "%d", yylocp->first_line);
1298 if (0 <= yylocp->first_column)
1299 res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
1300 }
1301 if (0 <= yylocp->last_line)
1302 {
1303 if (yylocp->first_line < yylocp->last_line)
1304 {
1305 res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
1306 if (0 <= end_col)
1307 res += YYFPRINTF (yyo, ".%d", end_col);
1308 }
1309 else if (0 <= end_col && yylocp->first_column < end_col)
1310 res += YYFPRINTF (yyo, "-%d", end_col);
1311 }
1312 return res;
1313 }
1314
1315 # define YY_LOCATION_PRINT(File, Loc) \
1316 yy_location_print_ (File, &(Loc))
1317
1318 # else
1319 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1320 # endif
1321 #endif
1322
1323
1324 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1325 do { \
1326 if (yydebug) \
1327 { \
1328 YYFPRINTF (stderr, "%s ", Title); \
1329 yy_symbol_print (stderr, \
1330 Type, Value, Location); \
1331 YYFPRINTF (stderr, "\n"); \
1332 } \
1333 } while (0)
1334
1335
1336 /*----------------------------------------.
1337 | Print this symbol's value on YYOUTPUT. |
1338 `----------------------------------------*/
1339
1340 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)1341 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1342 {
1343 FILE *yyo = yyoutput;
1344 YYUSE (yyo);
1345 YYUSE (yylocationp);
1346 if (!yyvaluep)
1347 return;
1348 # ifdef YYPRINT
1349 if (yytype < YYNTOKENS)
1350 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1351 # endif
1352 YYUSE (yytype);
1353 }
1354
1355
1356 /*--------------------------------.
1357 | Print this symbol on YYOUTPUT. |
1358 `--------------------------------*/
1359
1360 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,YYLTYPE const * const yylocationp)1361 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1362 {
1363 YYFPRINTF (yyoutput, "%s %s (",
1364 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1365
1366 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1367 YYFPRINTF (yyoutput, ": ");
1368 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1369 YYFPRINTF (yyoutput, ")");
1370 }
1371
1372 /*------------------------------------------------------------------.
1373 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1374 | TOP (included). |
1375 `------------------------------------------------------------------*/
1376
1377 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)1378 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1379 {
1380 YYFPRINTF (stderr, "Stack now");
1381 for (; yybottom <= yytop; yybottom++)
1382 {
1383 int yybot = *yybottom;
1384 YYFPRINTF (stderr, " %d", yybot);
1385 }
1386 YYFPRINTF (stderr, "\n");
1387 }
1388
1389 # define YY_STACK_PRINT(Bottom, Top) \
1390 do { \
1391 if (yydebug) \
1392 yy_stack_print ((Bottom), (Top)); \
1393 } while (0)
1394
1395
1396 /*------------------------------------------------.
1397 | Report that the YYRULE is going to be reduced. |
1398 `------------------------------------------------*/
1399
1400 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,YYLTYPE * yylsp,int yyrule)1401 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1402 {
1403 unsigned long int yylno = yyrline[yyrule];
1404 int yynrhs = yyr2[yyrule];
1405 int yyi;
1406 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1407 yyrule - 1, yylno);
1408 /* The symbols being reduced. */
1409 for (yyi = 0; yyi < yynrhs; yyi++)
1410 {
1411 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1412 yy_symbol_print (stderr,
1413 yystos[yyssp[yyi + 1 - yynrhs]],
1414 &(yyvsp[(yyi + 1) - (yynrhs)])
1415 , &(yylsp[(yyi + 1) - (yynrhs)]) );
1416 YYFPRINTF (stderr, "\n");
1417 }
1418 }
1419
1420 # define YY_REDUCE_PRINT(Rule) \
1421 do { \
1422 if (yydebug) \
1423 yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
1424 } while (0)
1425
1426 /* Nonzero means print parse trace. It is left uninitialized so that
1427 multiple parsers can coexist. */
1428 int yydebug;
1429 #else /* !YYDEBUG */
1430 # define YYDPRINTF(Args)
1431 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1432 # define YY_STACK_PRINT(Bottom, Top)
1433 # define YY_REDUCE_PRINT(Rule)
1434 #endif /* !YYDEBUG */
1435
1436
1437 /* YYINITDEPTH -- initial size of the parser's stacks. */
1438 #ifndef YYINITDEPTH
1439 # define YYINITDEPTH 200
1440 #endif
1441
1442 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1443 if the built-in stack extension method is used).
1444
1445 Do not make this value too large; the results are undefined if
1446 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1447 evaluated with infinite-precision integer arithmetic. */
1448
1449 #ifndef YYMAXDEPTH
1450 # define YYMAXDEPTH 10000
1451 #endif
1452
1453
1454 #if YYERROR_VERBOSE
1455
1456 # ifndef yystrlen
1457 # if defined __GLIBC__ && defined _STRING_H
1458 # define yystrlen strlen
1459 # else
1460 /* Return the length of YYSTR. */
1461 static YYSIZE_T
yystrlen(const char * yystr)1462 yystrlen (const char *yystr)
1463 {
1464 YYSIZE_T yylen;
1465 for (yylen = 0; yystr[yylen]; yylen++)
1466 continue;
1467 return yylen;
1468 }
1469 # endif
1470 # endif
1471
1472 # ifndef yystpcpy
1473 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1474 # define yystpcpy stpcpy
1475 # else
1476 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1477 YYDEST. */
1478 static char *
yystpcpy(char * yydest,const char * yysrc)1479 yystpcpy (char *yydest, const char *yysrc)
1480 {
1481 char *yyd = yydest;
1482 const char *yys = yysrc;
1483
1484 while ((*yyd++ = *yys++) != '\0')
1485 continue;
1486
1487 return yyd - 1;
1488 }
1489 # endif
1490 # endif
1491
1492 # ifndef yytnamerr
1493 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1494 quotes and backslashes, so that it's suitable for yyerror. The
1495 heuristic is that double-quoting is unnecessary unless the string
1496 contains an apostrophe, a comma, or backslash (other than
1497 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1498 null, do not copy; instead, return the length of what the result
1499 would have been. */
1500 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1501 yytnamerr (char *yyres, const char *yystr)
1502 {
1503 if (*yystr == '"')
1504 {
1505 YYSIZE_T yyn = 0;
1506 char const *yyp = yystr;
1507
1508 for (;;)
1509 switch (*++yyp)
1510 {
1511 case '\'':
1512 case ',':
1513 goto do_not_strip_quotes;
1514
1515 case '\\':
1516 if (*++yyp != '\\')
1517 goto do_not_strip_quotes;
1518 /* Fall through. */
1519 default:
1520 if (yyres)
1521 yyres[yyn] = *yyp;
1522 yyn++;
1523 break;
1524
1525 case '"':
1526 if (yyres)
1527 yyres[yyn] = '\0';
1528 return yyn;
1529 }
1530 do_not_strip_quotes: ;
1531 }
1532
1533 if (! yyres)
1534 return yystrlen (yystr);
1535
1536 return yystpcpy (yyres, yystr) - yyres;
1537 }
1538 # endif
1539
1540 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1541 about the unexpected token YYTOKEN for the state stack whose top is
1542 YYSSP.
1543
1544 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1545 not large enough to hold the message. In that case, also set
1546 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1547 required number of bytes is too large to store. */
1548 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1549 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1550 yytype_int16 *yyssp, int yytoken)
1551 {
1552 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1553 YYSIZE_T yysize = yysize0;
1554 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1555 /* Internationalized format string. */
1556 const char *yyformat = YY_NULLPTR;
1557 /* Arguments of yyformat. */
1558 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1559 /* Number of reported tokens (one for the "unexpected", one per
1560 "expected"). */
1561 int yycount = 0;
1562
1563 /* There are many possibilities here to consider:
1564 - If this state is a consistent state with a default action, then
1565 the only way this function was invoked is if the default action
1566 is an error action. In that case, don't check for expected
1567 tokens because there are none.
1568 - The only way there can be no lookahead present (in yychar) is if
1569 this state is a consistent state with a default action. Thus,
1570 detecting the absence of a lookahead is sufficient to determine
1571 that there is no unexpected or expected token to report. In that
1572 case, just report a simple "syntax error".
1573 - Don't assume there isn't a lookahead just because this state is a
1574 consistent state with a default action. There might have been a
1575 previous inconsistent state, consistent state with a non-default
1576 action, or user semantic action that manipulated yychar.
1577 - Of course, the expected token list depends on states to have
1578 correct lookahead information, and it depends on the parser not
1579 to perform extra reductions after fetching a lookahead from the
1580 scanner and before detecting a syntax error. Thus, state merging
1581 (from LALR or IELR) and default reductions corrupt the expected
1582 token list. However, the list is correct for canonical LR with
1583 one exception: it will still contain any token that will not be
1584 accepted due to an error action in a later state.
1585 */
1586 if (yytoken != YYEMPTY)
1587 {
1588 int yyn = yypact[*yyssp];
1589 yyarg[yycount++] = yytname[yytoken];
1590 if (!yypact_value_is_default (yyn))
1591 {
1592 /* Start YYX at -YYN if negative to avoid negative indexes in
1593 YYCHECK. In other words, skip the first -YYN actions for
1594 this state because they are default actions. */
1595 int yyxbegin = yyn < 0 ? -yyn : 0;
1596 /* Stay within bounds of both yycheck and yytname. */
1597 int yychecklim = YYLAST - yyn + 1;
1598 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1599 int yyx;
1600
1601 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1602 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1603 && !yytable_value_is_error (yytable[yyx + yyn]))
1604 {
1605 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1606 {
1607 yycount = 1;
1608 yysize = yysize0;
1609 break;
1610 }
1611 yyarg[yycount++] = yytname[yyx];
1612 {
1613 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1614 if (! (yysize <= yysize1
1615 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1616 return 2;
1617 yysize = yysize1;
1618 }
1619 }
1620 }
1621 }
1622
1623 switch (yycount)
1624 {
1625 # define YYCASE_(N, S) \
1626 case N: \
1627 yyformat = S; \
1628 break
1629 YYCASE_(0, YY_("syntax error"));
1630 YYCASE_(1, YY_("syntax error, unexpected %s"));
1631 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1632 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1633 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1634 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1635 # undef YYCASE_
1636 }
1637
1638 {
1639 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1640 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1641 return 2;
1642 yysize = yysize1;
1643 }
1644
1645 if (*yymsg_alloc < yysize)
1646 {
1647 *yymsg_alloc = 2 * yysize;
1648 if (! (yysize <= *yymsg_alloc
1649 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1650 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1651 return 1;
1652 }
1653
1654 /* Avoid sprintf, as that infringes on the user's name space.
1655 Don't have undefined behavior even if the translation
1656 produced a string with the wrong number of "%s"s. */
1657 {
1658 char *yyp = *yymsg;
1659 int yyi = 0;
1660 while ((*yyp = *yyformat) != '\0')
1661 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1662 {
1663 yyp += yytnamerr (yyp, yyarg[yyi++]);
1664 yyformat += 2;
1665 }
1666 else
1667 {
1668 yyp++;
1669 yyformat++;
1670 }
1671 }
1672 return 0;
1673 }
1674 #endif /* YYERROR_VERBOSE */
1675
1676 /*-----------------------------------------------.
1677 | Release the memory associated to this symbol. |
1678 `-----------------------------------------------*/
1679
1680 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp)1681 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1682 {
1683 YYUSE (yyvaluep);
1684 YYUSE (yylocationp);
1685 if (!yymsg)
1686 yymsg = "Deleting";
1687 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1688
1689 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1690 YYUSE (yytype);
1691 YY_IGNORE_MAYBE_UNINITIALIZED_END
1692 }
1693
1694
1695
1696
1697 /* The lookahead symbol. */
1698 int yychar;
1699
1700 /* The semantic value of the lookahead symbol. */
1701 YYSTYPE yylval;
1702 /* Location data for the lookahead symbol. */
1703 YYLTYPE yylloc
1704 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
1705 = { 1, 1, 1, 1 }
1706 # endif
1707 ;
1708 /* Number of syntax errors so far. */
1709 int yynerrs;
1710
1711
1712 /*----------.
1713 | yyparse. |
1714 `----------*/
1715
1716 int
yyparse(void)1717 yyparse (void)
1718 {
1719 int yystate;
1720 /* Number of tokens to shift before error messages enabled. */
1721 int yyerrstatus;
1722
1723 /* The stacks and their tools:
1724 'yyss': related to states.
1725 'yyvs': related to semantic values.
1726 'yyls': related to locations.
1727
1728 Refer to the stacks through separate pointers, to allow yyoverflow
1729 to reallocate them elsewhere. */
1730
1731 /* The state stack. */
1732 yytype_int16 yyssa[YYINITDEPTH];
1733 yytype_int16 *yyss;
1734 yytype_int16 *yyssp;
1735
1736 /* The semantic value stack. */
1737 YYSTYPE yyvsa[YYINITDEPTH];
1738 YYSTYPE *yyvs;
1739 YYSTYPE *yyvsp;
1740
1741 /* The location stack. */
1742 YYLTYPE yylsa[YYINITDEPTH];
1743 YYLTYPE *yyls;
1744 YYLTYPE *yylsp;
1745
1746 /* The locations where the error started and ended. */
1747 YYLTYPE yyerror_range[3];
1748
1749 YYSIZE_T yystacksize;
1750
1751 int yyn;
1752 int yyresult;
1753 /* Lookahead token as an internal (translated) token number. */
1754 int yytoken = 0;
1755 /* The variables used to return semantic value and location from the
1756 action routines. */
1757 YYSTYPE yyval;
1758 YYLTYPE yyloc;
1759
1760 #if YYERROR_VERBOSE
1761 /* Buffer for error messages, and its allocated size. */
1762 char yymsgbuf[128];
1763 char *yymsg = yymsgbuf;
1764 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1765 #endif
1766
1767 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1768
1769 /* The number of symbols on the RHS of the reduced rule.
1770 Keep to zero when no symbol should be popped. */
1771 int yylen = 0;
1772
1773 yyssp = yyss = yyssa;
1774 yyvsp = yyvs = yyvsa;
1775 yylsp = yyls = yylsa;
1776 yystacksize = YYINITDEPTH;
1777
1778 YYDPRINTF ((stderr, "Starting parse\n"));
1779
1780 yystate = 0;
1781 yyerrstatus = 0;
1782 yynerrs = 0;
1783 yychar = YYEMPTY; /* Cause a token to be read. */
1784 yylsp[0] = yylloc;
1785 goto yysetstate;
1786
1787 /*------------------------------------------------------------.
1788 | yynewstate -- Push a new state, which is found in yystate. |
1789 `------------------------------------------------------------*/
1790 yynewstate:
1791 /* In all cases, when you get here, the value and location stacks
1792 have just been pushed. So pushing a state here evens the stacks. */
1793 yyssp++;
1794
1795 yysetstate:
1796 *yyssp = yystate;
1797
1798 if (yyss + yystacksize - 1 <= yyssp)
1799 {
1800 /* Get the current used size of the three stacks, in elements. */
1801 YYSIZE_T yysize = yyssp - yyss + 1;
1802
1803 #ifdef yyoverflow
1804 {
1805 /* Give user a chance to reallocate the stack. Use copies of
1806 these so that the &'s don't force the real ones into
1807 memory. */
1808 YYSTYPE *yyvs1 = yyvs;
1809 yytype_int16 *yyss1 = yyss;
1810 YYLTYPE *yyls1 = yyls;
1811
1812 /* Each stack pointer address is followed by the size of the
1813 data in use in that stack, in bytes. This used to be a
1814 conditional around just the two extra args, but that might
1815 be undefined if yyoverflow is a macro. */
1816 yyoverflow (YY_("memory exhausted"),
1817 &yyss1, yysize * sizeof (*yyssp),
1818 &yyvs1, yysize * sizeof (*yyvsp),
1819 &yyls1, yysize * sizeof (*yylsp),
1820 &yystacksize);
1821
1822 yyls = yyls1;
1823 yyss = yyss1;
1824 yyvs = yyvs1;
1825 }
1826 #else /* no yyoverflow */
1827 # ifndef YYSTACK_RELOCATE
1828 goto yyexhaustedlab;
1829 # else
1830 /* Extend the stack our own way. */
1831 if (YYMAXDEPTH <= yystacksize)
1832 goto yyexhaustedlab;
1833 yystacksize *= 2;
1834 if (YYMAXDEPTH < yystacksize)
1835 yystacksize = YYMAXDEPTH;
1836
1837 {
1838 yytype_int16 *yyss1 = yyss;
1839 union yyalloc *yyptr =
1840 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1841 if (! yyptr)
1842 goto yyexhaustedlab;
1843 YYSTACK_RELOCATE (yyss_alloc, yyss);
1844 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1845 YYSTACK_RELOCATE (yyls_alloc, yyls);
1846 # undef YYSTACK_RELOCATE
1847 if (yyss1 != yyssa)
1848 YYSTACK_FREE (yyss1);
1849 }
1850 # endif
1851 #endif /* no yyoverflow */
1852
1853 yyssp = yyss + yysize - 1;
1854 yyvsp = yyvs + yysize - 1;
1855 yylsp = yyls + yysize - 1;
1856
1857 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1858 (unsigned long int) yystacksize));
1859
1860 if (yyss + yystacksize - 1 <= yyssp)
1861 YYABORT;
1862 }
1863
1864 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1865
1866 if (yystate == YYFINAL)
1867 YYACCEPT;
1868
1869 goto yybackup;
1870
1871 /*-----------.
1872 | yybackup. |
1873 `-----------*/
1874 yybackup:
1875
1876 /* Do appropriate processing given the current state. Read a
1877 lookahead token if we need one and don't already have one. */
1878
1879 /* First try to decide what to do without reference to lookahead token. */
1880 yyn = yypact[yystate];
1881 if (yypact_value_is_default (yyn))
1882 goto yydefault;
1883
1884 /* Not known => get a lookahead token if don't already have one. */
1885
1886 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1887 if (yychar == YYEMPTY)
1888 {
1889 YYDPRINTF ((stderr, "Reading a token: "));
1890 yychar = yylex ();
1891 }
1892
1893 if (yychar <= YYEOF)
1894 {
1895 yychar = yytoken = YYEOF;
1896 YYDPRINTF ((stderr, "Now at end of input.\n"));
1897 }
1898 else
1899 {
1900 yytoken = YYTRANSLATE (yychar);
1901 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1902 }
1903
1904 /* If the proper action on seeing token YYTOKEN is to reduce or to
1905 detect an error, take that action. */
1906 yyn += yytoken;
1907 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1908 goto yydefault;
1909 yyn = yytable[yyn];
1910 if (yyn <= 0)
1911 {
1912 if (yytable_value_is_error (yyn))
1913 goto yyerrlab;
1914 yyn = -yyn;
1915 goto yyreduce;
1916 }
1917
1918 /* Count tokens shifted since error; after three, turn off error
1919 status. */
1920 if (yyerrstatus)
1921 yyerrstatus--;
1922
1923 /* Shift the lookahead token. */
1924 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1925
1926 /* Discard the shifted token. */
1927 yychar = YYEMPTY;
1928
1929 yystate = yyn;
1930 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1931 *++yyvsp = yylval;
1932 YY_IGNORE_MAYBE_UNINITIALIZED_END
1933 *++yylsp = yylloc;
1934 goto yynewstate;
1935
1936
1937 /*-----------------------------------------------------------.
1938 | yydefault -- do the default action for the current state. |
1939 `-----------------------------------------------------------*/
1940 yydefault:
1941 yyn = yydefact[yystate];
1942 if (yyn == 0)
1943 goto yyerrlab;
1944 goto yyreduce;
1945
1946
1947 /*-----------------------------.
1948 | yyreduce -- Do a reduction. |
1949 `-----------------------------*/
1950 yyreduce:
1951 /* yyn is the number of a rule to reduce with. */
1952 yylen = yyr2[yyn];
1953
1954 /* If YYLEN is nonzero, implement the default value of the action:
1955 '$$ = $1'.
1956
1957 Otherwise, the following line sets YYVAL to garbage.
1958 This behavior is undocumented and Bison
1959 users should not rely upon it. Assigning to YYVAL
1960 unconditionally makes the parser a bit smaller, and it avoids a
1961 GCC warning that YYVAL may be used uninitialized. */
1962 yyval = yyvsp[1-yylen];
1963
1964 /* Default location. */
1965 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1966 YY_REDUCE_PRINT (yyn);
1967 switch (yyn)
1968 {
1969 case 2:
1970
1971 { YYACCEPT; }
1972
1973 break;
1974
1975 case 3:
1976
1977 { yyresult = xxvalue(NULL,2,NULL); goto yyreturn; }
1978
1979 break;
1980
1981 case 4:
1982
1983 { yyresult = xxvalue((yyvsp[-1]),3,&(yylsp[-1])); goto yyreturn; }
1984
1985 break;
1986
1987 case 5:
1988
1989 { yyresult = xxvalue((yyvsp[-1]),4,&(yylsp[-1])); goto yyreturn; }
1990
1991 break;
1992
1993 case 6:
1994
1995 { YYABORT; }
1996
1997 break;
1998
1999 case 7:
2000
2001 { (yyval) = (yyvsp[0]); }
2002
2003 break;
2004
2005 case 8:
2006
2007 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2008
2009 break;
2010
2011 case 9:
2012
2013 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2014
2015 break;
2016
2017 case 10:
2018
2019 { (yyval) = (yyvsp[0]); }
2020
2021 break;
2022
2023 case 11:
2024
2025 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2026
2027 break;
2028
2029 case 12:
2030
2031 { (yyval) = (yyvsp[0]); setId((yyloc)); }
2032
2033 break;
2034
2035 case 13:
2036
2037 { (yyval) = (yyvsp[0]); setId((yyloc)); }
2038
2039 break;
2040
2041 case 14:
2042
2043 { (yyval) = (yyvsp[0]); setId((yyloc)); }
2044
2045 break;
2046
2047 case 15:
2048
2049 { (yyval) = (yyvsp[0]); setId((yyloc)); }
2050
2051 break;
2052
2053 case 16:
2054
2055 { (yyval) = xxexprlist((yyvsp[-2]),&(yylsp[-2]),(yyvsp[-1])); setId((yyloc)); }
2056
2057 break;
2058
2059 case 17:
2060
2061 { (yyval) = xxparen((yyvsp[-2]),(yyvsp[-1])); setId((yyloc)); }
2062
2063 break;
2064
2065 case 18:
2066
2067 { (yyval) = xxunary((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2068
2069 break;
2070
2071 case 19:
2072
2073 { (yyval) = xxunary((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2074
2075 break;
2076
2077 case 20:
2078
2079 { (yyval) = xxunary((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2080
2081 break;
2082
2083 case 21:
2084
2085 { (yyval) = xxunary((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2086
2087 break;
2088
2089 case 22:
2090
2091 { (yyval) = xxunary((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2092
2093 break;
2094
2095 case 23:
2096
2097 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2098
2099 break;
2100
2101 case 24:
2102
2103 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2104
2105 break;
2106
2107 case 25:
2108
2109 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2110
2111 break;
2112
2113 case 26:
2114
2115 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2116
2117 break;
2118
2119 case 27:
2120
2121 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2122
2123 break;
2124
2125 case 28:
2126
2127 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2128
2129 break;
2130
2131 case 29:
2132
2133 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2134
2135 break;
2136
2137 case 30:
2138
2139 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2140
2141 break;
2142
2143 case 31:
2144
2145 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2146
2147 break;
2148
2149 case 32:
2150
2151 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2152
2153 break;
2154
2155 case 33:
2156
2157 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2158
2159 break;
2160
2161 case 34:
2162
2163 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2164
2165 break;
2166
2167 case 35:
2168
2169 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2170
2171 break;
2172
2173 case 36:
2174
2175 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2176
2177 break;
2178
2179 case 37:
2180
2181 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2182
2183 break;
2184
2185 case 38:
2186
2187 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2188
2189 break;
2190
2191 case 39:
2192
2193 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2194
2195 break;
2196
2197 case 40:
2198
2199 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2200
2201 break;
2202
2203 case 41:
2204
2205 { (yyval) = xxpipe((yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2206
2207 break;
2208
2209 case 42:
2210
2211 { (yyval) = xxpipebind((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2212
2213 break;
2214
2215 case 43:
2216
2217 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2218
2219 break;
2220
2221 case 44:
2222
2223 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[0]),(yyvsp[-2])); setId((yyloc)); }
2224
2225 break;
2226
2227 case 45:
2228
2229 { (yyval) = xxdefun((yyvsp[-5]),(yyvsp[-3]),(yyvsp[0]),&(yyloc)); setId((yyloc)); }
2230
2231 break;
2232
2233 case 46:
2234
2235 { (yyval) = xxdefun(R_FunctionSymbol,(yyvsp[-3]),(yyvsp[0]),&(yyloc)); setId((yyloc)); }
2236
2237 break;
2238
2239 case 47:
2240
2241 { (yyval) = xxfuncall((yyvsp[-3]),(yyvsp[-1])); setId((yyloc)); modif_token( &(yylsp[-3]), SYMBOL_FUNCTION_CALL ) ; }
2242
2243 break;
2244
2245 case 48:
2246
2247 { (yyval) = xxif((yyvsp[-2]),(yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2248
2249 break;
2250
2251 case 49:
2252
2253 { (yyval) = xxifelse((yyvsp[-4]),(yyvsp[-3]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2254
2255 break;
2256
2257 case 50:
2258
2259 { (yyval) = xxfor((yyvsp[-2]),(yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2260
2261 break;
2262
2263 case 51:
2264
2265 { (yyval) = xxwhile((yyvsp[-2]),(yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2266
2267 break;
2268
2269 case 52:
2270
2271 { (yyval) = xxrepeat((yyvsp[-1]),(yyvsp[0])); setId((yyloc)); }
2272
2273 break;
2274
2275 case 53:
2276
2277 { (yyval) = xxsubscript((yyvsp[-4]),(yyvsp[-3]),(yyvsp[-2])); setId((yyloc)); }
2278
2279 break;
2280
2281 case 54:
2282
2283 { (yyval) = xxsubscript((yyvsp[-3]),(yyvsp[-2]),(yyvsp[-1])); setId((yyloc)); }
2284
2285 break;
2286
2287 case 55:
2288
2289 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ; }
2290
2291 break;
2292
2293 case 56:
2294
2295 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ; }
2296
2297 break;
2298
2299 case 57:
2300
2301 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2302
2303 break;
2304
2305 case 58:
2306
2307 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2308
2309 break;
2310
2311 case 59:
2312
2313 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ;}
2314
2315 break;
2316
2317 case 60:
2318
2319 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ;}
2320
2321 break;
2322
2323 case 61:
2324
2325 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2326
2327 break;
2328
2329 case 62:
2330
2331 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2332
2333 break;
2334
2335 case 63:
2336
2337 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2338
2339 break;
2340
2341 case 64:
2342
2343 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2344
2345 break;
2346
2347 case 65:
2348
2349 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); modif_token( &(yylsp[0]), SLOT ) ; }
2350
2351 break;
2352
2353 case 66:
2354
2355 { (yyval) = xxbinary((yyvsp[-1]),(yyvsp[-2]),(yyvsp[0])); setId((yyloc)); }
2356
2357 break;
2358
2359 case 67:
2360
2361 { (yyval) = xxnxtbrk((yyvsp[0])); setId((yyloc)); }
2362
2363 break;
2364
2365 case 68:
2366
2367 { (yyval) = xxnxtbrk((yyvsp[0])); setId((yyloc)); }
2368
2369 break;
2370
2371 case 69:
2372
2373 { (yyval) = xxcond((yyvsp[-1])); }
2374
2375 break;
2376
2377 case 70:
2378
2379 { (yyval) = xxifcond((yyvsp[-1])); }
2380
2381 break;
2382
2383 case 71:
2384
2385 { (yyval) = xxforcond((yyvsp[-3]),(yyvsp[-1])); setId((yyloc)); }
2386
2387 break;
2388
2389 case 72:
2390
2391 { (yyval) = xxexprlist0(); setId((yyloc)); }
2392
2393 break;
2394
2395 case 73:
2396
2397 { (yyval) = xxexprlist1((yyvsp[0]), &(yylsp[0])); }
2398
2399 break;
2400
2401 case 74:
2402
2403 { (yyval) = xxexprlist2((yyvsp[-2]), (yyvsp[0]), &(yylsp[0])); }
2404
2405 break;
2406
2407 case 75:
2408
2409 { (yyval) = (yyvsp[-1]); setId((yyloc)); }
2410
2411 break;
2412
2413 case 76:
2414
2415 { (yyval) = xxexprlist2((yyvsp[-2]), (yyvsp[0]), &(yylsp[0])); }
2416
2417 break;
2418
2419 case 77:
2420
2421 { (yyval) = (yyvsp[-1]);}
2422
2423 break;
2424
2425 case 78:
2426
2427 { (yyval) = xxsublist1((yyvsp[0])); }
2428
2429 break;
2430
2431 case 79:
2432
2433 { (yyval) = xxsublist2((yyvsp[-3]),(yyvsp[0])); }
2434
2435 break;
2436
2437 case 80:
2438
2439 { (yyval) = xxsub0(); }
2440
2441 break;
2442
2443 case 81:
2444
2445 { (yyval) = xxsub1((yyvsp[0]), &(yylsp[0])); }
2446
2447 break;
2448
2449 case 82:
2450
2451 { (yyval) = xxsymsub0((yyvsp[-1]), &(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; modif_token( &(yylsp[-1]), SYMBOL_SUB ) ; }
2452
2453 break;
2454
2455 case 83:
2456
2457 { (yyval) = xxsymsub1((yyvsp[-2]),(yyvsp[0]), &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; modif_token( &(yylsp[-2]), SYMBOL_SUB ) ; }
2458
2459 break;
2460
2461 case 84:
2462
2463 { (yyval) = xxsymsub0((yyvsp[-1]), &(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; }
2464
2465 break;
2466
2467 case 85:
2468
2469 { (yyval) = xxsymsub1((yyvsp[-2]),(yyvsp[0]), &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; }
2470
2471 break;
2472
2473 case 86:
2474
2475 { (yyval) = xxnullsub0(&(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; }
2476
2477 break;
2478
2479 case 87:
2480
2481 { (yyval) = xxnullsub1((yyvsp[0]), &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; }
2482
2483 break;
2484
2485 case 88:
2486
2487 { (yyval) = xxnullformal(); }
2488
2489 break;
2490
2491 case 89:
2492
2493 { (yyval) = xxfirstformal0((yyvsp[0])); modif_token( &(yylsp[0]), SYMBOL_FORMALS ) ; }
2494
2495 break;
2496
2497 case 90:
2498
2499 { (yyval) = xxfirstformal1((yyvsp[-2]),(yyvsp[0])); modif_token( &(yylsp[-2]), SYMBOL_FORMALS ) ; modif_token( &(yylsp[-1]), EQ_FORMALS ) ; }
2500
2501 break;
2502
2503 case 91:
2504
2505 { (yyval) = xxaddformal0((yyvsp[-2]),(yyvsp[0]), &(yylsp[0])); modif_token( &(yylsp[0]), SYMBOL_FORMALS ) ; }
2506
2507 break;
2508
2509 case 92:
2510
2511 { (yyval) = xxaddformal1((yyvsp[-4]),(yyvsp[-2]),(yyvsp[0]),&(yylsp[-2])); modif_token( &(yylsp[-2]), SYMBOL_FORMALS ) ; modif_token( &(yylsp[-1]), EQ_FORMALS ) ;}
2512
2513 break;
2514
2515 case 93:
2516
2517 { EatLines = 1; }
2518
2519 break;
2520
2521
2522
2523 default: break;
2524 }
2525 /* User semantic actions sometimes alter yychar, and that requires
2526 that yytoken be updated with the new translation. We take the
2527 approach of translating immediately before every use of yytoken.
2528 One alternative is translating here after every semantic action,
2529 but that translation would be missed if the semantic action invokes
2530 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2531 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2532 incorrect destructor might then be invoked immediately. In the
2533 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2534 to an incorrect destructor call or verbose syntax error message
2535 before the lookahead is translated. */
2536 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2537
2538 YYPOPSTACK (yylen);
2539 yylen = 0;
2540 YY_STACK_PRINT (yyss, yyssp);
2541
2542 *++yyvsp = yyval;
2543 *++yylsp = yyloc;
2544
2545 /* Now 'shift' the result of the reduction. Determine what state
2546 that goes to, based on the state we popped back to and the rule
2547 number reduced by. */
2548
2549 yyn = yyr1[yyn];
2550
2551 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2552 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2553 yystate = yytable[yystate];
2554 else
2555 yystate = yydefgoto[yyn - YYNTOKENS];
2556
2557 goto yynewstate;
2558
2559
2560 /*--------------------------------------.
2561 | yyerrlab -- here on detecting error. |
2562 `--------------------------------------*/
2563 yyerrlab:
2564 /* Make sure we have latest lookahead translation. See comments at
2565 user semantic actions for why this is necessary. */
2566 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2567
2568 /* If not already recovering from an error, report this error. */
2569 if (!yyerrstatus)
2570 {
2571 ++yynerrs;
2572 #if ! YYERROR_VERBOSE
2573 yyerror (YY_("syntax error"));
2574 #else
2575 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2576 yyssp, yytoken)
2577 {
2578 char const *yymsgp = YY_("syntax error");
2579 int yysyntax_error_status;
2580 yysyntax_error_status = YYSYNTAX_ERROR;
2581 if (yysyntax_error_status == 0)
2582 yymsgp = yymsg;
2583 else if (yysyntax_error_status == 1)
2584 {
2585 if (yymsg != yymsgbuf)
2586 YYSTACK_FREE (yymsg);
2587 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2588 if (!yymsg)
2589 {
2590 yymsg = yymsgbuf;
2591 yymsg_alloc = sizeof yymsgbuf;
2592 yysyntax_error_status = 2;
2593 }
2594 else
2595 {
2596 yysyntax_error_status = YYSYNTAX_ERROR;
2597 yymsgp = yymsg;
2598 }
2599 }
2600 yyerror (yymsgp);
2601 if (yysyntax_error_status == 2)
2602 goto yyexhaustedlab;
2603 }
2604 # undef YYSYNTAX_ERROR
2605 #endif
2606 }
2607
2608 yyerror_range[1] = yylloc;
2609
2610 if (yyerrstatus == 3)
2611 {
2612 /* If just tried and failed to reuse lookahead token after an
2613 error, discard it. */
2614
2615 if (yychar <= YYEOF)
2616 {
2617 /* Return failure if at end of input. */
2618 if (yychar == YYEOF)
2619 YYABORT;
2620 }
2621 else
2622 {
2623 yydestruct ("Error: discarding",
2624 yytoken, &yylval, &yylloc);
2625 yychar = YYEMPTY;
2626 }
2627 }
2628
2629 /* Else will try to reuse lookahead token after shifting the error
2630 token. */
2631 goto yyerrlab1;
2632
2633
2634 /*---------------------------------------------------.
2635 | yyerrorlab -- error raised explicitly by YYERROR. |
2636 `---------------------------------------------------*/
2637 yyerrorlab:
2638
2639 /* Pacify compilers like GCC when the user code never invokes
2640 YYERROR and the label yyerrorlab therefore never appears in user
2641 code. */
2642 if (/*CONSTCOND*/ 0)
2643 goto yyerrorlab;
2644
2645 yyerror_range[1] = yylsp[1-yylen];
2646 /* Do not reclaim the symbols of the rule whose action triggered
2647 this YYERROR. */
2648 YYPOPSTACK (yylen);
2649 yylen = 0;
2650 YY_STACK_PRINT (yyss, yyssp);
2651 yystate = *yyssp;
2652 goto yyerrlab1;
2653
2654
2655 /*-------------------------------------------------------------.
2656 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2657 `-------------------------------------------------------------*/
2658 yyerrlab1:
2659 yyerrstatus = 3; /* Each real token shifted decrements this. */
2660
2661 for (;;)
2662 {
2663 yyn = yypact[yystate];
2664 if (!yypact_value_is_default (yyn))
2665 {
2666 yyn += YYTERROR;
2667 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2668 {
2669 yyn = yytable[yyn];
2670 if (0 < yyn)
2671 break;
2672 }
2673 }
2674
2675 /* Pop the current state because it cannot handle the error token. */
2676 if (yyssp == yyss)
2677 YYABORT;
2678
2679 yyerror_range[1] = *yylsp;
2680 yydestruct ("Error: popping",
2681 yystos[yystate], yyvsp, yylsp);
2682 YYPOPSTACK (1);
2683 yystate = *yyssp;
2684 YY_STACK_PRINT (yyss, yyssp);
2685 }
2686
2687 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2688 *++yyvsp = yylval;
2689 YY_IGNORE_MAYBE_UNINITIALIZED_END
2690
2691 yyerror_range[2] = yylloc;
2692 /* Using YYLLOC is tempting, but would change the location of
2693 the lookahead. YYLOC is available though. */
2694 YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
2695 *++yylsp = yyloc;
2696
2697 /* Shift the error token. */
2698 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2699
2700 yystate = yyn;
2701 goto yynewstate;
2702
2703
2704 /*-------------------------------------.
2705 | yyacceptlab -- YYACCEPT comes here. |
2706 `-------------------------------------*/
2707 yyacceptlab:
2708 yyresult = 0;
2709 goto yyreturn;
2710
2711 /*-----------------------------------.
2712 | yyabortlab -- YYABORT comes here. |
2713 `-----------------------------------*/
2714 yyabortlab:
2715 yyresult = 1;
2716 goto yyreturn;
2717
2718 #if !defined yyoverflow || YYERROR_VERBOSE
2719 /*-------------------------------------------------.
2720 | yyexhaustedlab -- memory exhaustion comes here. |
2721 `-------------------------------------------------*/
2722 yyexhaustedlab:
2723 yyerror (YY_("memory exhausted"));
2724 yyresult = 2;
2725 /* Fall through. */
2726 #endif
2727
2728 yyreturn:
2729 if (yychar != YYEMPTY)
2730 {
2731 /* Make sure we have latest lookahead translation. See comments at
2732 user semantic actions for why this is necessary. */
2733 yytoken = YYTRANSLATE (yychar);
2734 yydestruct ("Cleanup: discarding lookahead",
2735 yytoken, &yylval, &yylloc);
2736 }
2737 /* Do not reclaim the symbols of the rule whose action triggered
2738 this YYABORT or YYACCEPT. */
2739 YYPOPSTACK (yylen);
2740 YY_STACK_PRINT (yyss, yyssp);
2741 while (yyssp != yyss)
2742 {
2743 yydestruct ("Cleanup: popping",
2744 yystos[*yyssp], yyvsp, yylsp);
2745 YYPOPSTACK (1);
2746 }
2747 #ifndef yyoverflow
2748 if (yyss != yyssa)
2749 YYSTACK_FREE (yyss);
2750 #endif
2751 #if YYERROR_VERBOSE
2752 if (yymsg != yymsgbuf)
2753 YYSTACK_FREE (yymsg);
2754 #endif
2755 return yyresult;
2756 }
2757
2758
2759
2760
2761 /*----------------------------------------------------------------------------*/
2762
2763 static int (*ptr_getc)(void);
2764
2765 /* Private pushback, since file ungetc only guarantees one byte.
2766 We need up to one MBCS-worth */
2767 #define DECLARE_YYTEXT_BUFP(bp) char *bp = yytext ;
2768 #define YYTEXT_PUSH(c, bp) do { \
2769 if ((bp) - yytext >= sizeof(yytext) - 1){ \
2770 error(_("input buffer overflow at line %d"), ParseState.xxlineno); \
2771 } \
2772 *(bp)++ = ((char)c); \
2773 } while(0) ;
2774
2775 #define PUSHBACK_BUFSIZE 16
2776 static int pushback[PUSHBACK_BUFSIZE];
2777 static unsigned int npush = 0;
2778
2779 static int prevpos = 0;
2780 static int prevlines[PUSHBACK_BUFSIZE];
2781 static int prevcols[PUSHBACK_BUFSIZE];
2782 static int prevbytes[PUSHBACK_BUFSIZE];
2783 static int prevparse[PUSHBACK_BUFSIZE];
2784
xxgetc(void)2785 static int xxgetc(void)
2786 {
2787 int c;
2788
2789 if(npush) c = pushback[--npush]; else c = ptr_getc();
2790
2791 prevpos = (prevpos + 1) % PUSHBACK_BUFSIZE;
2792 prevbytes[prevpos] = ParseState.xxbyteno;
2793 prevlines[prevpos] = ParseState.xxlineno;
2794 prevparse[prevpos] = ParseState.xxparseno;
2795 prevcols[prevpos] = ParseState.xxcolno;
2796
2797 if (c == EOF) {
2798 EndOfFile = 1;
2799 return R_EOF;
2800 }
2801 R_ParseContextLast = (R_ParseContextLast + 1) % PARSE_CONTEXT_SIZE;
2802 R_ParseContext[R_ParseContextLast] = (char) c;
2803
2804 if (c == '\n') {
2805 ParseState.xxlineno += 1;
2806 ParseState.xxcolno = 0;
2807 ParseState.xxbyteno = 0;
2808 ParseState.xxparseno += 1;
2809 } else {
2810 /* We only advance the column for the 1st byte in UTF-8, so handle later bytes specially */
2811 if (!known_to_be_utf8 || (unsigned char)c < 0x80 || 0xC0 <= (unsigned char)c)
2812 ParseState.xxcolno++;
2813 ParseState.xxbyteno++;
2814 }
2815
2816 if (c == '\t') ParseState.xxcolno = ((ParseState.xxcolno + 7) & ~7);
2817
2818 R_ParseContextLine = ParseState.xxlineno;
2819
2820 xxcharcount++;
2821 return c;
2822 }
2823
xxungetc(int c)2824 static int xxungetc(int c)
2825 {
2826 /* this assumes that c was the result of xxgetc; if not, some edits will be needed */
2827 ParseState.xxlineno = prevlines[prevpos];
2828 ParseState.xxbyteno = prevbytes[prevpos];
2829 ParseState.xxcolno = prevcols[prevpos];
2830 ParseState.xxparseno = prevparse[prevpos];
2831
2832 prevpos = (prevpos + PUSHBACK_BUFSIZE - 1) % PUSHBACK_BUFSIZE;
2833
2834 R_ParseContextLine = ParseState.xxlineno;
2835
2836 xxcharcount--;
2837 R_ParseContext[R_ParseContextLast] = '\0';
2838 /* precaution as to how % is implemented for < 0 numbers */
2839 R_ParseContextLast = (R_ParseContextLast + PARSE_CONTEXT_SIZE -1) % PARSE_CONTEXT_SIZE;
2840 if(npush >= PUSHBACK_BUFSIZE) return EOF;
2841 pushback[npush++] = c;
2842 return c;
2843 }
2844
2845 /* Only used from finish_mbcs_in_parse_context. */
add_mbcs_byte_to_parse_context()2846 static int add_mbcs_byte_to_parse_context()
2847 {
2848 int c;
2849
2850 if (EndOfFile)
2851 error(_("invalid multibyte character in parser at line %d"),
2852 ParseState.xxlineno);
2853 if(npush)
2854 c = pushback[--npush];
2855 else
2856 c = ptr_getc();
2857 if (c == EOF)
2858 error(_("invalid multibyte character in parser at line %d"),
2859 ParseState.xxlineno);
2860
2861 R_ParseContextLast = (R_ParseContextLast + 1) % PARSE_CONTEXT_SIZE;
2862 R_ParseContext[R_ParseContextLast] = (char) c;
2863 return c;
2864 }
2865
2866 /* On error, the parse context may end inside a multi-byte character. Add
2867 the missing bytes to the context to so that it contains full characters. */
finish_mbcs_in_parse_context()2868 static void finish_mbcs_in_parse_context()
2869 {
2870 int i, c, nbytes = 0, first;
2871 Rboolean mbcs = FALSE;
2872
2873 /* find the first byte of the context */
2874 for(i = R_ParseContextLast;
2875 R_ParseContext[i];
2876 i = (i + PARSE_CONTEXT_SIZE - 1) % PARSE_CONTEXT_SIZE) {
2877
2878 nbytes++;
2879 if (nbytes == PARSE_CONTEXT_SIZE)
2880 break;
2881 }
2882 if (!nbytes)
2883 return;
2884 if (!R_ParseContext[i])
2885 first = (i + 1) % PARSE_CONTEXT_SIZE;
2886 else
2887 /* The beginning of the context has been overwritten and for a general
2888 encoding there is not way to recover it. It is possible for UTF-8,
2889 though. */
2890 return;
2891
2892 /* decode multi-byte characters */
2893 for(i = 0; i < nbytes; i++) {
2894 c = R_ParseContext[(first + i) % PARSE_CONTEXT_SIZE];
2895 if ((unsigned int)c < 0x80) continue; /* ASCII */
2896
2897 if (utf8locale) {
2898 /* UTF-8 could be handled more efficiently, searching from the end
2899 of the string */
2900 i += utf8clen((char) c) - 1;
2901 if (i >= nbytes) {
2902 while (i >= nbytes) {
2903 add_mbcs_byte_to_parse_context();
2904 nbytes++;
2905 }
2906 return;
2907 }
2908 } else
2909 mbcs = TRUE;
2910 }
2911 if (!mbcs)
2912 return;
2913
2914 /* copy the context to a linear buffer */
2915 char buf[nbytes + R_MB_CUR_MAX];
2916
2917 for(i = 0; i < nbytes; i++)
2918 buf[i] = R_ParseContext[(first + i) % PARSE_CONTEXT_SIZE];
2919
2920 for(i = 0; i < nbytes; i++) {
2921 wchar_t wc;
2922 int res;
2923 mbstate_t mb_st;
2924
2925 mbs_init(&mb_st);
2926 res = (int) mbrtowc(&wc, buf + i, nbytes - i, &mb_st);
2927 while (res == -2 && nbytes < sizeof(buf)) {
2928 /* This is not necessarily correct for stateful MBCS */
2929 buf[nbytes++] = (char) add_mbcs_byte_to_parse_context();
2930 mbs_init(&mb_st);
2931 res = (int) mbrtowc(&wc, buf + i, nbytes - i, &mb_st);
2932 }
2933 if (res == -1)
2934 error(_("invalid multibyte character in parser at line %d"),
2935 ParseState.xxlineno);
2936 i += res - 1;
2937 }
2938 }
2939
2940 /*
2941 * Increments/inits the token/grouping counter
2942 */
incrementId(void)2943 static void incrementId(void){
2944 identifier++;
2945 }
2946
initId(void)2947 static void initId(void){
2948 identifier = 0 ;
2949 }
2950
makeSrcref(YYLTYPE * lloc,SEXP srcfile)2951 static SEXP makeSrcref(YYLTYPE *lloc, SEXP srcfile)
2952 {
2953 SEXP val;
2954
2955 PROTECT(val = allocVector(INTSXP, 8));
2956 INTEGER(val)[0] = lloc->first_line;
2957 INTEGER(val)[1] = lloc->first_byte;
2958 INTEGER(val)[2] = lloc->last_line;
2959 INTEGER(val)[3] = lloc->last_byte;
2960 INTEGER(val)[4] = lloc->first_column;
2961 INTEGER(val)[5] = lloc->last_column;
2962 INTEGER(val)[6] = lloc->first_parsed;
2963 INTEGER(val)[7] = lloc->last_parsed;
2964 setAttrib(val, R_SrcfileSymbol, srcfile);
2965 setAttrib(val, R_ClassSymbol, mkString("srcref"));
2966 UNPROTECT(1); /* val */
2967 return val;
2968 }
2969
attachSrcrefs(SEXP val)2970 static void attachSrcrefs(SEXP val)
2971 {
2972 SEXP srval;
2973
2974 PROTECT(srval = SrcRefsToVectorList());
2975
2976 setAttrib(val, R_SrcrefSymbol, srval);
2977 setAttrib(val, R_SrcfileSymbol, PS_SRCFILE);
2978 {
2979 YYLTYPE wholeFile;
2980 wholeFile.first_line = 1;
2981 wholeFile.first_byte = 0;
2982 wholeFile.first_column = 0;
2983 wholeFile.last_line = ParseState.xxlineno;
2984 wholeFile.last_byte = ParseState.xxbyteno;
2985 wholeFile.last_column = ParseState.xxcolno;
2986 wholeFile.first_parsed = 1;
2987 wholeFile.last_parsed = ParseState.xxparseno;
2988 setAttrib(val, R_WholeSrcrefSymbol, makeSrcref(&wholeFile, PS_SRCFILE));
2989 }
2990 PS_SET_SRCREFS(R_NilValue);
2991 ParseState.didAttach = TRUE;
2992 UNPROTECT(1); /* srval */
2993 }
2994
xxvalue(SEXP v,int k,YYLTYPE * lloc)2995 static int xxvalue(SEXP v, int k, YYLTYPE *lloc)
2996 {
2997 if (k > 2) {
2998 if (ParseState.keepSrcRefs) {
2999 SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE));
3000 AppendToSrcRefs(s);
3001 UNPROTECT(1); /* s */
3002 }
3003 RELEASE_SV(v);
3004 }
3005 R_CurrentExpr = v;
3006 return k;
3007 }
3008
xxnullformal()3009 static SEXP xxnullformal()
3010 {
3011 SEXP ans;
3012 PRESERVE_SV(ans = R_NilValue);
3013 return ans;
3014 }
3015
xxfirstformal0(SEXP sym)3016 static SEXP xxfirstformal0(SEXP sym)
3017 {
3018 SEXP ans;
3019 if (GenerateCode)
3020 PRESERVE_SV(ans = FirstArg(R_MissingArg, sym));
3021 else
3022 PRESERVE_SV(ans = R_NilValue);
3023 RELEASE_SV(sym);
3024 return ans;
3025 }
3026
xxfirstformal1(SEXP sym,SEXP expr)3027 static SEXP xxfirstformal1(SEXP sym, SEXP expr)
3028 {
3029 SEXP ans;
3030 if (GenerateCode)
3031 PRESERVE_SV(ans = FirstArg(expr, sym));
3032 else
3033 PRESERVE_SV(ans = R_NilValue);
3034 RELEASE_SV(expr);
3035 RELEASE_SV(sym);
3036 return ans;
3037 }
3038
xxaddformal0(SEXP formlist,SEXP sym,YYLTYPE * lloc)3039 static SEXP xxaddformal0(SEXP formlist, SEXP sym, YYLTYPE *lloc)
3040 {
3041 SEXP ans;
3042 if (GenerateCode) {
3043 CheckFormalArgs(formlist, sym, lloc);
3044 NextArg(formlist, R_MissingArg, sym);
3045 ans = formlist;
3046 } else {
3047 RELEASE_SV(formlist);
3048 PRESERVE_SV(ans = R_NilValue);
3049 }
3050 RELEASE_SV(sym);
3051 return ans;
3052 }
3053
xxaddformal1(SEXP formlist,SEXP sym,SEXP expr,YYLTYPE * lloc)3054 static SEXP xxaddformal1(SEXP formlist, SEXP sym, SEXP expr, YYLTYPE *lloc)
3055 {
3056 SEXP ans;
3057 if (GenerateCode) {
3058 CheckFormalArgs(formlist, sym, lloc);
3059 NextArg(formlist, expr, sym);
3060 ans = formlist;
3061 } else {
3062 RELEASE_SV(formlist);
3063 PRESERVE_SV(ans = R_NilValue);
3064 }
3065 RELEASE_SV(expr);
3066 RELEASE_SV(sym);
3067 return ans;
3068 }
3069
xxexprlist0(void)3070 static SEXP xxexprlist0(void)
3071 {
3072 SEXP ans;
3073 if (GenerateCode) {
3074 PRESERVE_SV(ans = NewList());
3075 if (ParseState.keepSrcRefs) {
3076 setAttrib(ans, R_SrcrefSymbol, PS_SRCREFS);
3077 PS_SET_SRCREFS(R_NilValue);
3078 }
3079 }
3080 else
3081 PRESERVE_SV(ans = R_NilValue);
3082 return ans;
3083 }
3084
xxexprlist1(SEXP expr,YYLTYPE * lloc)3085 static SEXP xxexprlist1(SEXP expr, YYLTYPE *lloc)
3086 {
3087 SEXP ans;
3088 if (GenerateCode) {
3089 PRESERVE_SV(ans = NewList());
3090 if (ParseState.keepSrcRefs) {
3091 setAttrib(ans, R_SrcrefSymbol, PS_SRCREFS);
3092 SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE));
3093 SetSingleSrcRef(s);
3094 UNPROTECT(1); /* s */
3095 }
3096 GrowList(ans, expr);
3097 }
3098 else
3099 PRESERVE_SV(ans = R_NilValue);
3100 RELEASE_SV(expr);
3101 return ans;
3102 }
3103
xxexprlist2(SEXP exprlist,SEXP expr,YYLTYPE * lloc)3104 static SEXP xxexprlist2(SEXP exprlist, SEXP expr, YYLTYPE *lloc)
3105 {
3106 SEXP ans;
3107 if (GenerateCode) {
3108 if (ParseState.keepSrcRefs) {
3109 SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE));
3110 AppendToSrcRefs(s);
3111 UNPROTECT(1); /* s */
3112 }
3113 GrowList(exprlist, expr);
3114 ans = exprlist;
3115 } else {
3116 RELEASE_SV(exprlist);
3117 PRESERVE_SV(ans = R_NilValue);
3118 }
3119 RELEASE_SV(expr);
3120 return ans;
3121 }
3122
xxsub0(void)3123 static SEXP xxsub0(void)
3124 {
3125 SEXP ans;
3126 if (GenerateCode)
3127 PRESERVE_SV(ans = lang2(R_MissingArg,R_NilValue));
3128 else
3129 PRESERVE_SV(ans = R_NilValue);
3130 return ans;
3131 }
3132
xxsub1(SEXP expr,YYLTYPE * lloc)3133 static SEXP xxsub1(SEXP expr, YYLTYPE *lloc)
3134 {
3135 SEXP ans;
3136 if (GenerateCode)
3137 PRESERVE_SV(ans = TagArg(expr, R_NilValue, lloc));
3138 else
3139 PRESERVE_SV(ans = R_NilValue);
3140 RELEASE_SV(expr);
3141 return ans;
3142 }
3143
xxsymsub0(SEXP sym,YYLTYPE * lloc)3144 static SEXP xxsymsub0(SEXP sym, YYLTYPE *lloc)
3145 {
3146 SEXP ans;
3147 if (GenerateCode)
3148 PRESERVE_SV(ans = TagArg(R_MissingArg, sym, lloc));
3149 else
3150 PRESERVE_SV(ans = R_NilValue);
3151 RELEASE_SV(sym);
3152 return ans;
3153 }
3154
xxsymsub1(SEXP sym,SEXP expr,YYLTYPE * lloc)3155 static SEXP xxsymsub1(SEXP sym, SEXP expr, YYLTYPE *lloc)
3156 {
3157 SEXP ans;
3158 if (GenerateCode)
3159 PRESERVE_SV(ans = TagArg(expr, sym, lloc));
3160 else
3161 PRESERVE_SV(ans = R_NilValue);
3162 RELEASE_SV(expr);
3163 RELEASE_SV(sym);
3164 return ans;
3165 }
3166
xxnullsub0(YYLTYPE * lloc)3167 static SEXP xxnullsub0(YYLTYPE *lloc)
3168 {
3169 SEXP ans;
3170 if (GenerateCode)
3171 PRESERVE_SV(ans = TagArg(R_MissingArg, R_NullSymbol, lloc));
3172 else
3173 PRESERVE_SV(ans = R_NilValue);
3174 RELEASE_SV(R_NilValue);
3175 return ans;
3176 }
3177
xxnullsub1(SEXP expr,YYLTYPE * lloc)3178 static SEXP xxnullsub1(SEXP expr, YYLTYPE *lloc)
3179 {
3180 SEXP ans;
3181 if (GenerateCode)
3182 PRESERVE_SV(ans = TagArg(expr, R_NullSymbol, lloc));
3183 else
3184 PRESERVE_SV(ans = R_NilValue);
3185 RELEASE_SV(R_NilValue);
3186 RELEASE_SV(expr);
3187 return ans;
3188 }
3189
3190
xxsublist1(SEXP sub)3191 static SEXP xxsublist1(SEXP sub)
3192 {
3193 SEXP ans;
3194 if (GenerateCode)
3195 PRESERVE_SV(ans = FirstArg(CAR(sub),CADR(sub)));
3196 else
3197 PRESERVE_SV(ans = R_NilValue);
3198 RELEASE_SV(sub);
3199 return ans;
3200 }
3201
xxsublist2(SEXP sublist,SEXP sub)3202 static SEXP xxsublist2(SEXP sublist, SEXP sub)
3203 {
3204 SEXP ans;
3205 if (GenerateCode) {
3206 NextArg(sublist, CAR(sub), CADR(sub));
3207 ans = sublist;
3208 } else {
3209 RELEASE_SV(sublist);
3210 PRESERVE_SV(ans = R_NilValue);
3211 }
3212 RELEASE_SV(sub);
3213 return ans;
3214 }
3215
xxcond(SEXP expr)3216 static SEXP xxcond(SEXP expr)
3217 {
3218 EatLines = 1;
3219 return expr;
3220 }
3221
xxifcond(SEXP expr)3222 static SEXP xxifcond(SEXP expr)
3223 {
3224 EatLines = 1;
3225 return expr;
3226 }
3227
xxif(SEXP ifsym,SEXP cond,SEXP expr)3228 static SEXP xxif(SEXP ifsym, SEXP cond, SEXP expr)
3229 {
3230 SEXP ans;
3231 if (GenerateCode)
3232 PRESERVE_SV(ans = lang3(ifsym, cond, expr));
3233 else
3234 PRESERVE_SV(ans = R_NilValue);
3235 RELEASE_SV(expr);
3236 RELEASE_SV(cond);
3237 return ans;
3238 }
3239
xxifelse(SEXP ifsym,SEXP cond,SEXP ifexpr,SEXP elseexpr)3240 static SEXP xxifelse(SEXP ifsym, SEXP cond, SEXP ifexpr, SEXP elseexpr)
3241 {
3242 SEXP ans;
3243 if (GenerateCode)
3244 PRESERVE_SV(ans = lang4(ifsym, cond, ifexpr, elseexpr));
3245 else
3246 PRESERVE_SV(ans = R_NilValue);
3247 RELEASE_SV(elseexpr);
3248 RELEASE_SV(ifexpr);
3249 RELEASE_SV(cond);
3250 return ans;
3251 }
3252
xxforcond(SEXP sym,SEXP expr)3253 static SEXP xxforcond(SEXP sym, SEXP expr)
3254 {
3255 SEXP ans;
3256 EatLines = 1;
3257 if (GenerateCode)
3258 PRESERVE_SV(ans = LCONS(sym, expr));
3259 else
3260 PRESERVE_SV(ans = R_NilValue);
3261 RELEASE_SV(expr);
3262 RELEASE_SV(sym);
3263 return ans;
3264 }
3265
xxfor(SEXP forsym,SEXP forcond,SEXP body)3266 static SEXP xxfor(SEXP forsym, SEXP forcond, SEXP body)
3267 {
3268 SEXP ans;
3269 if (GenerateCode)
3270 PRESERVE_SV(ans = lang4(forsym, CAR(forcond), CDR(forcond), body));
3271 else
3272 PRESERVE_SV(ans = R_NilValue);
3273 RELEASE_SV(body);
3274 RELEASE_SV(forcond);
3275 return ans;
3276 }
3277
xxwhile(SEXP whilesym,SEXP cond,SEXP body)3278 static SEXP xxwhile(SEXP whilesym, SEXP cond, SEXP body)
3279 {
3280 SEXP ans;
3281 if (GenerateCode)
3282 PRESERVE_SV(ans = lang3(whilesym, cond, body));
3283 else
3284 PRESERVE_SV(ans = R_NilValue);
3285 RELEASE_SV(body);
3286 RELEASE_SV(cond);
3287 return ans;
3288 }
3289
xxrepeat(SEXP repeatsym,SEXP body)3290 static SEXP xxrepeat(SEXP repeatsym, SEXP body)
3291 {
3292 SEXP ans;
3293 if (GenerateCode)
3294 PRESERVE_SV(ans = lang2(repeatsym, body));
3295 else
3296 PRESERVE_SV(ans = R_NilValue);
3297 RELEASE_SV(body);
3298 return ans;
3299 }
3300
xxnxtbrk(SEXP keyword)3301 static SEXP xxnxtbrk(SEXP keyword)
3302 {
3303 if (GenerateCode)
3304 PRESERVE_SV(keyword = lang1(keyword));
3305 else
3306 PRESERVE_SV(keyword = R_NilValue);
3307 return keyword;
3308 }
3309
xxfuncall(SEXP expr,SEXP args)3310 static SEXP xxfuncall(SEXP expr, SEXP args)
3311 {
3312 SEXP ans, sav_expr = expr;
3313 if (GenerateCode) {
3314 if (isString(expr))
3315 expr = installTrChar(STRING_ELT(expr, 0));
3316 PROTECT(expr);
3317 if (length(CDR(args)) == 1 && CADR(args) == R_MissingArg && TAG(CDR(args)) == R_NilValue )
3318 ans = lang1(expr);
3319 else
3320 ans = LCONS(expr, CDR(args));
3321 UNPROTECT(1); /* expr */
3322 PRESERVE_SV(ans);
3323 } else
3324 PRESERVE_SV(ans = R_NilValue);
3325
3326 RELEASE_SV(args);
3327 RELEASE_SV(sav_expr);
3328 return ans;
3329 }
3330
mkChar2(const char * name)3331 static SEXP mkChar2(const char *name)
3332 {
3333 cetype_t enc = CE_NATIVE;
3334
3335 if(known_to_be_latin1) enc = CE_LATIN1;
3336 else if(known_to_be_utf8) enc = CE_UTF8;
3337
3338 return mkCharLenCE(name, (int) strlen(name), enc);
3339 }
3340
mkString2(const char * s,size_t len,Rboolean escaped)3341 static SEXP mkString2(const char *s, size_t len, Rboolean escaped)
3342 {
3343 SEXP t;
3344 cetype_t enc = CE_NATIVE;
3345
3346 if(known_to_be_latin1) enc = CE_LATIN1;
3347 else if(!escaped && known_to_be_utf8) enc = CE_UTF8;
3348
3349 PROTECT(t = allocVector(STRSXP, 1));
3350 SET_STRING_ELT(t, 0, mkCharLenCE(s, (int) len, enc));
3351 UNPROTECT(1); /* t */
3352 return t;
3353 }
3354
xxdefun(SEXP fname,SEXP formals,SEXP body,YYLTYPE * lloc)3355 static SEXP xxdefun(SEXP fname, SEXP formals, SEXP body, YYLTYPE *lloc)
3356 {
3357 SEXP ans, srcref;
3358
3359 if (GenerateCode) {
3360 if (ParseState.keepSrcRefs) {
3361 srcref = makeSrcref(lloc, PS_SRCFILE);
3362 ParseState.didAttach = TRUE;
3363 } else
3364 srcref = R_NilValue;
3365 PRESERVE_SV(ans = lang4(fname, CDR(formals), body, srcref));
3366 } else
3367 PRESERVE_SV(ans = R_NilValue);
3368 RELEASE_SV(body);
3369 RELEASE_SV(formals);
3370 return ans;
3371 }
3372
xxunary(SEXP op,SEXP arg)3373 static SEXP xxunary(SEXP op, SEXP arg)
3374 {
3375 SEXP ans;
3376 if (GenerateCode)
3377 PRESERVE_SV(ans = lang2(op, arg));
3378 else
3379 PRESERVE_SV(ans = R_NilValue);
3380 RELEASE_SV(arg);
3381 return ans;
3382 }
3383
xxbinary(SEXP n1,SEXP n2,SEXP n3)3384 static SEXP xxbinary(SEXP n1, SEXP n2, SEXP n3)
3385 {
3386 SEXP ans;
3387 if (GenerateCode)
3388 PRESERVE_SV(ans = lang3(n1, n2, n3));
3389 else
3390 PRESERVE_SV(ans = R_NilValue);
3391 RELEASE_SV(n2);
3392 RELEASE_SV(n3);
3393 return ans;
3394 }
3395
3396 static SEXP findPlaceholderCell(SEXP, SEXP);
3397
check_rhs(SEXP rhs)3398 static void check_rhs(SEXP rhs)
3399 {
3400 if (TYPEOF(rhs) != LANGSXP)
3401 error(_("The pipe operator requires a function call as RHS"));
3402
3403 /* rule out syntactically special functions */
3404 /* the IS_SPECIAL_SYMBOL bit is set in names.c */
3405 SEXP fun = CAR(rhs);
3406 if (TYPEOF(fun) == SYMSXP && IS_SPECIAL_SYMBOL(fun))
3407 error("function '%s' not supported in RHS call of a pipe",
3408 CHAR(PRINTNAME(fun)));
3409 }
3410
xxpipe(SEXP lhs,SEXP rhs)3411 static SEXP xxpipe(SEXP lhs, SEXP rhs)
3412 {
3413 SEXP ans;
3414 if (GenerateCode) {
3415 /* allow x => log(x) on RHS */
3416 if (TYPEOF(rhs) == LANGSXP && CAR(rhs) == R_PipeBindSymbol) {
3417 SEXP var = CADR(rhs);
3418 SEXP expr = CADDR(rhs);
3419 check_rhs(expr);
3420 SEXP phcell = findPlaceholderCell(var, expr);
3421 if (phcell == NULL)
3422 error(_("no placeholder found on RHS"));
3423 SETCAR(phcell, lhs);
3424 return expr;
3425 }
3426
3427 check_rhs(rhs);
3428
3429 SEXP fun = CAR(rhs);
3430 SEXP args = CDR(rhs);
3431 PRESERVE_SV(ans = lcons(fun, lcons(lhs, args)));
3432 }
3433 else {
3434 PRESERVE_SV(ans = R_NilValue);
3435 }
3436 RELEASE_SV(lhs);
3437 RELEASE_SV(rhs);
3438 return ans;
3439 }
3440
xxpipebind(SEXP fn,SEXP lhs,SEXP rhs)3441 static SEXP xxpipebind(SEXP fn, SEXP lhs, SEXP rhs)
3442 {
3443 static int use_pipebind = 0;
3444 if (use_pipebind != 1) {
3445 char *lookup = getenv("_R_USE_PIPEBIND_");
3446 use_pipebind = ((lookup != NULL) && StringTrue(lookup)) ? 1 : 0;
3447 }
3448
3449 if (use_pipebind)
3450 return xxbinary(fn, lhs, rhs);
3451 else
3452 error("'=>' is disabled; set '_R_USE_PIPEBIND_' envvar to a true value to enable it");
3453 }
3454
xxparen(SEXP n1,SEXP n2)3455 static SEXP xxparen(SEXP n1, SEXP n2)
3456 {
3457 SEXP ans;
3458 if (GenerateCode)
3459 PRESERVE_SV(ans = lang2(n1, n2));
3460 else
3461 PRESERVE_SV(ans = R_NilValue);
3462 RELEASE_SV(n2);
3463 return ans;
3464 }
3465
3466
3467 /* This should probably use CONS rather than LCONS, but
3468 it shouldn't matter and we would rather not meddle
3469 See PR#7055 */
3470
xxsubscript(SEXP a1,SEXP a2,SEXP a3)3471 static SEXP xxsubscript(SEXP a1, SEXP a2, SEXP a3)
3472 {
3473 SEXP ans;
3474 if (GenerateCode)
3475 PRESERVE_SV(ans = LCONS(a2, CONS(a1, CDR(a3))));
3476 else
3477 PRESERVE_SV(ans = R_NilValue);
3478 RELEASE_SV(a3);
3479 RELEASE_SV(a1);
3480 return ans;
3481 }
3482
xxexprlist(SEXP a1,YYLTYPE * lloc,SEXP a2)3483 static SEXP xxexprlist(SEXP a1, YYLTYPE *lloc, SEXP a2)
3484 {
3485 SEXP ans;
3486 SEXP prevSrcrefs;
3487
3488 EatLines = 0;
3489 if (GenerateCode) {
3490 SET_TYPEOF(a2, LANGSXP);
3491 SETCAR(a2, a1);
3492 if (ParseState.keepSrcRefs) {
3493 PROTECT(prevSrcrefs = getAttrib(a2, R_SrcrefSymbol));
3494 SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE));
3495 PrependToSrcRefs(s);
3496 attachSrcrefs(a2);
3497 UNPROTECT(2); /* prevSrcrefs, s */
3498 #ifndef SWITCH_TO_REFCNT
3499 /* SrcRefs got NAMED by being an attribute, preventively
3500 getAttrib(), but it has not in fact been referenced. Set NAMED
3501 to 0 to avoid overhead in further setAttrib calls due to cycle
3502 detection. */
3503 SET_NAMED(prevSrcrefs, 0);
3504 #endif
3505 PS_SET_SRCREFS(prevSrcrefs);
3506 }
3507 PRESERVE_SV(ans = a2);
3508 }
3509 else
3510 PRESERVE_SV(ans = R_NilValue);
3511 RELEASE_SV(a2);
3512 return ans;
3513 }
3514
3515 /*--------------------------------------------------------------------------*/
3516
TagArg(SEXP arg,SEXP tag,YYLTYPE * lloc)3517 static SEXP TagArg(SEXP arg, SEXP tag, YYLTYPE *lloc)
3518 {
3519 switch (TYPEOF(tag)) {
3520 case STRSXP:
3521 tag = installTrChar(STRING_ELT(tag, 0));
3522 case NILSXP:
3523 case SYMSXP:
3524 return lang2(arg, tag);
3525 default:
3526 error(_("incorrect tag type at line %d"), lloc->first_line); return R_NilValue/* -Wall */;
3527 }
3528 }
3529
3530
3531 /* Stretchy List Structures : Lists are created and grown using a special */
3532 /* dotted pair. The CAR of the list points to the last cons-cell in the */
3533 /* list and the CDR points to the first. The list can be extracted from */
3534 /* the pair by taking its CDR, while the CAR gives fast access to the end */
3535 /* of the list. */
3536
3537 /* These functions must be called with arguments protected */
3538
3539 /* Create a stretchy-list dotted pair */
NewList(void)3540 static SEXP NewList(void)
3541 {
3542 SEXP s = CONS(R_NilValue, R_NilValue);
3543 SETCAR(s, s);
3544 return s;
3545 }
3546
3547 /* Add a new element at the end of a stretchy list */
GrowList(SEXP l,SEXP s)3548 static void GrowList(SEXP l, SEXP s)
3549 {
3550 SEXP tmp;
3551 tmp = CONS(s, R_NilValue);
3552 SETCDR(CAR(l), tmp);
3553 SETCAR(l, tmp);
3554 }
3555
3556 /* Create a stretchy list with a single named element */
FirstArg(SEXP s,SEXP tag)3557 static SEXP FirstArg(SEXP s, SEXP tag)
3558 {
3559 SEXP tmp;
3560 PROTECT(tmp = NewList());
3561 GrowList(tmp, s);
3562 SET_TAG(CAR(tmp), tag);
3563 UNPROTECT(1); /* tmp */
3564 return tmp;
3565 }
3566
3567 /* Add named element to the end of a stretchy list */
NextArg(SEXP l,SEXP s,SEXP tag)3568 static void NextArg(SEXP l, SEXP s, SEXP tag)
3569 {
3570 GrowList(l, s);
3571 SET_TAG(CAR(l), tag);
3572 }
3573
3574 /* SrcRefs (PS_SRCREFS) are represented as R_NilValue (empty) or by
3575 a stretchy list (which includes another representation for empty)
3576 for fast append operation. */
3577
SetSingleSrcRef(SEXP r)3578 static void SetSingleSrcRef(SEXP r)
3579 {
3580 SEXP l;
3581
3582 PROTECT(l = NewList());
3583 GrowList(l, r);
3584 PS_SET_SRCREFS(l);
3585 UNPROTECT(1); /* l */
3586 }
3587
AppendToSrcRefs(SEXP r)3588 static void AppendToSrcRefs(SEXP r)
3589 {
3590 SEXP l = PS_SRCREFS;
3591 if (l == R_NilValue)
3592 SetSingleSrcRef(r);
3593 else
3594 GrowList(l, r);
3595 }
3596
PrependToSrcRefs(SEXP r)3597 static void PrependToSrcRefs(SEXP r)
3598 {
3599 SEXP l = PS_SRCREFS;
3600 if (l == R_NilValue)
3601 SetSingleSrcRef(r);
3602 else if (CDR(l) == R_NilValue)
3603 /* adding to empty stretchy list */
3604 GrowList(l, r);
3605 else {
3606 SEXP tmp = CONS(r, CDR(l));
3607 SETCDR(l, tmp);
3608 }
3609 }
3610
SrcRefsToVectorList()3611 static SEXP SrcRefsToVectorList() {
3612 SEXP l = PS_SRCREFS;
3613 if (l == R_NilValue)
3614 return PairToVectorList(l);
3615 else
3616 return PairToVectorList(CDR(l));
3617 }
3618
3619 /*--------------------------------------------------------------------------*/
3620
3621 /*
3622 * Parsing Entry Points:
3623 *
3624 * The Following entry points provide language parsing facilities.
3625 * Note that there are separate entry points for parsing IoBuffers
3626 * (i.e. interactve use), files and R character strings.
3627 *
3628 * The entry points provide the same functionality, they just
3629 * set things up in slightly different ways.
3630 *
3631 * The following routines parse a single expression:
3632 *
3633 *
3634 * SEXP R_Parse1File(FILE *fp, int gencode, ParseStatus *status, Rboolean first)
3635 * (used for R_ReplFile in main.c)
3636 *
3637 * SEXP R_Parse1Buffer(IoBuffer *buffer, int gencode, ParseStatus *status, Rboolean first)
3638 * (used for ReplIteration and R_ReplDLLdo1 in main.c)
3639 *
3640 * The success of the parse is indicated as folllows:
3641 *
3642 *
3643 * status = PARSE_NULL - there was no statement to parse
3644 * PARSE_OK - complete statement
3645 * PARSE_INCOMPLETE - incomplete statement
3646 * PARSE_ERROR - syntax error
3647 * PARSE_EOF - end of file
3648 *
3649 *
3650 * The following routines parse several expressions and return
3651 * their values in a single expression vector.
3652 *
3653 * SEXP R_ParseFile(FILE *fp, int n, ParseStatus *status, SEXP srcfile)
3654 * (used for do_edit in file edit.c)
3655 *
3656 * SEXP R_ParseVector(SEXP *text, int n, ParseStatus *status, SEXP srcfile)
3657 * (public, and used by parse(text=) in file source.c)
3658 *
3659 * SEXP R_ParseBuffer(IoBuffer *buffer, int n, ParseStatus *status, SEXP prompt, SEXP srcfile)
3660 * (used by parse(file="") in file source.c)
3661 *
3662 * SEXP R_ParseConn(Rconnection con, int n, ParseStatus *status, SEXP srcfile)
3663 * (used by parse(file=) in file source.c)
3664 *
3665 * Here, status is 1 for a successful parse and 0 if parsing failed
3666 * for some reason.
3667 */
3668
3669 #define CONTEXTSTACK_SIZE 50
3670 static int SavedToken;
3671 static SEXP SavedLval;
3672 static char contextstack[CONTEXTSTACK_SIZE], *contextp;
3673
3674 static void PutSrcRefState(SrcRefState *state);
3675 static void UseSrcRefState(SrcRefState *state);
3676
3677 /* This is called once when R starts up. */
3678 attribute_hidden
InitParser(void)3679 void InitParser(void)
3680 {
3681 ParseState.sexps = allocVector(VECSXP, 7); /* initialized to R_NilValue */
3682 ParseState.data = R_NilValue;
3683 INIT_SVS();
3684 R_PreserveObject(ParseState.sexps); /* never released in an R session */
3685 R_NullSymbol = install("NULL");
3686 R_PipeBindSymbol = install("=>");
3687 }
3688
FinalizeSrcRefStateOnError(void * dummy)3689 static void FinalizeSrcRefStateOnError(void *dummy)
3690 {
3691 R_FinalizeSrcRefState();
3692 }
3693
3694 /* This is called each time a new parse sequence begins */
3695 attribute_hidden
R_InitSrcRefState(RCNTXT * cptr)3696 void R_InitSrcRefState(RCNTXT* cptr)
3697 {
3698 if (busy) {
3699 SrcRefState *prev = malloc(sizeof(SrcRefState));
3700 if (prev == NULL)
3701 error(_("allocation of source reference state failed"));
3702 PutSrcRefState(prev);
3703 ParseState.prevState = prev;
3704 ParseState.sexps = allocVector(VECSXP, 7);
3705 ParseState.data = R_NilValue;
3706 INIT_SVS();
3707 R_PreserveObject(ParseState.sexps);
3708 /* ParseState.sexps released in R_FinalizeSrcRefState */
3709 } else
3710 /* re-use data, text, ids arrays */
3711 ParseState.prevState = NULL;
3712 /* set up context _after_ PutSrcRefState */
3713 begincontext(cptr, CTXT_CCODE, R_NilValue, R_BaseEnv, R_BaseEnv,
3714 R_NilValue, R_NilValue);
3715 cptr->cend = &FinalizeSrcRefStateOnError;
3716 cptr->cenddata = NULL;
3717 ParseState.keepSrcRefs = FALSE;
3718 ParseState.keepParseData = TRUE;
3719 ParseState.didAttach = FALSE;
3720 PS_SET_SRCFILE(R_NilValue);
3721 PS_SET_ORIGINAL(R_NilValue);
3722 ParseState.data_count = 0;
3723 ParseState.xxlineno = 1;
3724 ParseState.xxcolno = 0;
3725 ParseState.xxbyteno = 0;
3726 ParseState.xxparseno = 1;
3727 busy = TRUE;
3728 }
3729
3730 attribute_hidden
R_FinalizeSrcRefState(void)3731 void R_FinalizeSrcRefState(void)
3732 {
3733 PS_SET_SRCFILE(R_NilValue);
3734 PS_SET_ORIGINAL(R_NilValue);
3735 CLEAR_SVS();
3736
3737 /* Free the data, text and ids if we are restoring a previous state,
3738 or if they have grown too large */
3739 if (PS_DATA != R_NilValue) {
3740 if (ParseState.prevState || DATA_COUNT > MAX_DATA_COUNT) {
3741 PS_SET_DATA(R_NilValue);
3742 PS_SET_TEXT(R_NilValue);
3743 } else /* Remove all the strings from the text vector so they don't take up memory, and clean up data */
3744 for (int i=0; i < ParseState.data_count; i++) {
3745 SET_STRING_ELT(PS_TEXT, i, R_BlankString);
3746 _PARENT(i) = 0;
3747 }
3748 }
3749 if (PS_IDS != R_NilValue) {
3750 if (ParseState.prevState || ID_COUNT > MAX_DATA_COUNT) {
3751 PS_SET_IDS(R_NilValue);
3752 } else {/* Remove the parent records */
3753 if (identifier > ID_COUNT) identifier = ID_COUNT;
3754 for (int i=0; i < identifier; i++) {
3755 ID_ID(i) = 0;
3756 ID_PARENT(i) = 0;
3757 }
3758 }
3759 }
3760 ParseState.data_count = NA_INTEGER;
3761 if (ParseState.prevState) {
3762 R_ReleaseObject(ParseState.sexps);
3763 SrcRefState *prev = ParseState.prevState;
3764 UseSrcRefState(prev);
3765 free(prev);
3766 } else
3767 busy = FALSE;
3768 }
3769
UseSrcRefState(SrcRefState * state)3770 static void UseSrcRefState(SrcRefState *state)
3771 {
3772 ParseState.keepSrcRefs = state->keepSrcRefs;
3773 ParseState.keepParseData = state->keepParseData;
3774 ParseState.sexps = state->sexps;
3775 ParseState.data = state->data;
3776 ParseState.data_count = state->data_count;
3777 ParseState.xxlineno = state->xxlineno;
3778 ParseState.xxcolno = state->xxcolno;
3779 ParseState.xxbyteno = state->xxbyteno;
3780 ParseState.xxparseno = state->xxparseno;
3781 ParseState.prevState = state->prevState;
3782 busy = TRUE;
3783 }
3784
PutSrcRefState(SrcRefState * state)3785 static void PutSrcRefState(SrcRefState *state)
3786 {
3787 state->keepSrcRefs = ParseState.keepSrcRefs;
3788 state->keepParseData = ParseState.keepParseData;
3789 state->sexps = ParseState.sexps;
3790 state->data = ParseState.data;
3791 state->data_count = ParseState.data_count;
3792 state->xxlineno = ParseState.xxlineno;
3793 state->xxcolno = ParseState.xxcolno;
3794 state->xxbyteno = ParseState.xxbyteno;
3795 state->xxparseno = ParseState.xxparseno;
3796 state->prevState = ParseState.prevState;
3797 }
3798
ParseInit(void)3799 static void ParseInit(void)
3800 {
3801 contextp = contextstack;
3802 *contextp = ' ';
3803 SavedToken = 0;
3804 SavedLval = R_NilValue;
3805 EatLines = 0;
3806 EndOfFile = 0;
3807 xxcharcount = 0;
3808 npush = 0;
3809 }
3810
initData(void)3811 static void initData(void)
3812 {
3813 ParseState.data_count = 0 ;
3814 }
3815
3816
ParseContextInit(void)3817 static void ParseContextInit(void)
3818 {
3819 R_ParseContextLast = 0;
3820 R_ParseContext[0] = '\0';
3821
3822 /* starts the identifier counter*/
3823 initId();
3824 initData();
3825 }
3826
R_Parse1(ParseStatus * status)3827 static SEXP R_Parse1(ParseStatus *status)
3828 {
3829 switch(yyparse()) {
3830 case 0: /* End of file */
3831 *status = PARSE_EOF;
3832 if (EndOfFile == 2) *status = PARSE_INCOMPLETE;
3833 break;
3834 case 1: /* Syntax error / incomplete */
3835 *status = PARSE_ERROR;
3836 if (EndOfFile) *status = PARSE_INCOMPLETE;
3837 break;
3838 case 2: /* Empty Line */
3839 *status = PARSE_NULL;
3840 break;
3841 case 3: /* Valid expr '\n' terminated */
3842 case 4: /* Valid expr ';' terminated */
3843 *status = PARSE_OK;
3844 break;
3845 }
3846 return R_CurrentExpr;
3847 }
3848
3849 static FILE *fp_parse;
3850
file_getc(void)3851 static int file_getc(void)
3852 {
3853 return R_fgetc(fp_parse);
3854 }
3855
3856 /* used in main.c */
3857 attribute_hidden
R_Parse1File(FILE * fp,int gencode,ParseStatus * status)3858 SEXP R_Parse1File(FILE *fp, int gencode, ParseStatus *status)
3859 {
3860 ParseInit();
3861 ParseContextInit();
3862 GenerateCode = gencode;
3863 fp_parse = fp;
3864 ptr_getc = file_getc;
3865 R_Parse1(status);
3866 CLEAR_SVS();
3867 return R_CurrentExpr;
3868 }
3869
3870 static IoBuffer *iob;
3871
buffer_getc(void)3872 static int buffer_getc(void)
3873 {
3874 return R_IoBufferGetc(iob);
3875 }
3876
3877 /* Used only in main.c */
3878 attribute_hidden
R_Parse1Buffer(IoBuffer * buffer,int gencode,ParseStatus * status)3879 SEXP R_Parse1Buffer(IoBuffer *buffer, int gencode, ParseStatus *status)
3880 {
3881 Rboolean keepSource = FALSE;
3882 RCNTXT cntxt;
3883
3884 R_InitSrcRefState(&cntxt);
3885 if (gencode) {
3886 keepSource = asLogical(GetOption1(install("keep.source")));
3887 if (keepSource) {
3888 ParseState.keepSrcRefs = TRUE;
3889 ParseState.keepParseData =
3890 asLogical(GetOption1(install("keep.parse.data")));
3891 PS_SET_SRCFILE(NewEnvironment(R_NilValue, R_NilValue, R_EmptyEnv));
3892 PS_SET_ORIGINAL(PS_SRCFILE);
3893 PS_SET_SRCREFS(R_NilValue);
3894 }
3895 }
3896 ParseInit();
3897 ParseContextInit();
3898 GenerateCode = gencode;
3899 iob = buffer;
3900 ptr_getc = buffer_getc;
3901 R_Parse1(status);
3902 if (gencode && keepSource) {
3903 if (ParseState.didAttach) {
3904 int buflen = R_IoBufferReadOffset(buffer);
3905 char buf[buflen+1];
3906 SEXP class;
3907 R_IoBufferReadReset(buffer);
3908 for (int i=0; i<buflen; i++)
3909 buf[i] = (char) R_IoBufferGetc(buffer);
3910
3911 buf[buflen] = 0;
3912 SEXP s_filename = install("filename");
3913 defineVar(s_filename, ScalarString(mkChar("")), PS_ORIGINAL);
3914 SEXP s_lines = install("lines");
3915 defineVar(s_lines, ScalarString(mkChar2(buf)), PS_ORIGINAL);
3916 PROTECT(class = allocVector(STRSXP, 2));
3917 SET_STRING_ELT(class, 0, mkChar("srcfilecopy"));
3918 SET_STRING_ELT(class, 1, mkChar("srcfile"));
3919 setAttrib(PS_ORIGINAL, R_ClassSymbol, class);
3920 UNPROTECT(1); /* class */
3921 }
3922 }
3923 PROTECT(R_CurrentExpr);
3924 endcontext(&cntxt);
3925 R_FinalizeSrcRefState();
3926 UNPROTECT(1); /* R_CurrentExpr */
3927 return R_CurrentExpr;
3928 }
3929
3930 static TextBuffer *txtb;
3931
text_getc(void)3932 static int text_getc(void)
3933 {
3934 return R_TextBufferGetc(txtb);
3935 }
3936
R_Parse(int n,ParseStatus * status,SEXP srcfile)3937 static SEXP R_Parse(int n, ParseStatus *status, SEXP srcfile)
3938 {
3939 int i;
3940 SEXP t, rval;
3941 RCNTXT cntxt;
3942
3943 R_InitSrcRefState(&cntxt);
3944 ParseContextInit();
3945
3946 PS_SET_SRCFILE(srcfile);
3947 PS_SET_ORIGINAL(srcfile);
3948
3949 if (isEnvironment(srcfile)) {
3950 ParseState.keepSrcRefs = TRUE;
3951 ParseState.keepParseData =
3952 asLogical(GetOption1(install("keep.parse.data")));
3953 PS_SET_SRCREFS(R_NilValue);
3954 }
3955
3956 PROTECT(t = NewList());
3957 for(i = 0; ; ) {
3958 if(n >= 0 && i >= n) break;
3959 ParseInit();
3960 rval = R_Parse1(status);
3961 switch(*status) {
3962 case PARSE_NULL:
3963 break;
3964 case PARSE_OK:
3965 PROTECT(rval);
3966 GrowList(t, rval);
3967 UNPROTECT(1); /* rval */
3968 i++;
3969 break;
3970 case PARSE_INCOMPLETE:
3971 case PARSE_ERROR:
3972 UNPROTECT(1); /* t */
3973 if (ParseState.keepSrcRefs && ParseState.keepParseData)
3974 finalizeData();
3975 endcontext(&cntxt);
3976 R_FinalizeSrcRefState();
3977 return R_NilValue;
3978 break;
3979 case PARSE_EOF:
3980 goto finish;
3981 break;
3982 }
3983 }
3984
3985 finish:
3986
3987 t = CDR(t);
3988 PROTECT(rval = allocVector(EXPRSXP, length(t)));
3989 for (n = 0 ; n < LENGTH(rval) ; n++, t = CDR(t))
3990 SET_VECTOR_ELT(rval, n, CAR(t));
3991 if (ParseState.keepSrcRefs) {
3992 if (ParseState.keepParseData)
3993 finalizeData();
3994 attachSrcrefs(rval);
3995 }
3996 UNPROTECT(2); /* t, rval */
3997 PROTECT(rval);
3998 endcontext(&cntxt);
3999 R_FinalizeSrcRefState();
4000 UNPROTECT(1); /* rval */
4001 *status = PARSE_OK;
4002 return rval;
4003 }
4004
4005 /* used in edit.c */
4006 attribute_hidden
R_ParseFile(FILE * fp,int n,ParseStatus * status,SEXP srcfile)4007 SEXP R_ParseFile(FILE *fp, int n, ParseStatus *status, SEXP srcfile)
4008 {
4009 GenerateCode = 1;
4010 fp_parse = fp;
4011 ptr_getc = file_getc;
4012 return R_Parse(n, status, srcfile);
4013 }
4014
4015 #include "Rconnections.h"
4016 static Rconnection con_parse;
4017
4018 /* need to handle incomplete last line */
con_getc(void)4019 static int con_getc(void)
4020 {
4021 int c;
4022 static int last=-1000;
4023
4024 c = Rconn_fgetc(con_parse);
4025 if (c == EOF && last != '\n') c = '\n';
4026 return (last = c);
4027 }
4028
4029 /* used in source.c */
4030 attribute_hidden
R_ParseConn(Rconnection con,int n,ParseStatus * status,SEXP srcfile)4031 SEXP R_ParseConn(Rconnection con, int n, ParseStatus *status, SEXP srcfile)
4032 {
4033 GenerateCode = 1;
4034 con_parse = con;
4035 ptr_getc = con_getc;
4036 return R_Parse(n, status, srcfile);
4037 }
4038
4039 /* This one is public, and used in source.c */
R_ParseVector(SEXP text,int n,ParseStatus * status,SEXP srcfile)4040 SEXP R_ParseVector(SEXP text, int n, ParseStatus *status, SEXP srcfile)
4041 {
4042 SEXP rval;
4043 TextBuffer textb;
4044 R_TextBufferInit(&textb, text);
4045 txtb = &textb;
4046 GenerateCode = 1;
4047 ptr_getc = text_getc;
4048 rval = R_Parse(n, status, srcfile);
4049 R_TextBufferFree(&textb);
4050 return rval;
4051 }
4052
Prompt(SEXP prompt,int type)4053 static const char *Prompt(SEXP prompt, int type)
4054 {
4055 if(type == 1) {
4056 if(length(prompt) <= 0) {
4057 return CHAR(STRING_ELT(GetOption1(install("prompt")), 0));
4058 }
4059 else
4060 return CHAR(STRING_ELT(prompt, 0));
4061 }
4062 else {
4063 return CHAR(STRING_ELT(GetOption1(install("continue")), 0));
4064 }
4065 }
4066
4067 /* used in source.c */
4068 attribute_hidden
R_ParseBuffer(IoBuffer * buffer,int n,ParseStatus * status,SEXP prompt,SEXP srcfile)4069 SEXP R_ParseBuffer(IoBuffer *buffer, int n, ParseStatus *status, SEXP prompt,
4070 SEXP srcfile)
4071 {
4072 SEXP rval, t;
4073 char *bufp, buf[CONSOLE_BUFFER_SIZE];
4074 int c, i, prompt_type = 1;
4075 RCNTXT cntxt;
4076
4077 R_IoBufferWriteReset(buffer);
4078 buf[0] = '\0';
4079 bufp = buf;
4080 R_InitSrcRefState(&cntxt);
4081 ParseContextInit();
4082
4083 GenerateCode = 1;
4084 iob = buffer;
4085 ptr_getc = buffer_getc;
4086
4087 PS_SET_SRCFILE(srcfile);
4088 PS_SET_ORIGINAL(srcfile);
4089
4090 if (isEnvironment(srcfile)) {
4091 ParseState.keepSrcRefs = TRUE;
4092 ParseState.keepParseData =
4093 asLogical(GetOption1(install("keep.parse.data")));
4094 PS_SET_SRCREFS(R_NilValue);
4095 }
4096
4097 PROTECT(t = NewList());
4098 for(i = 0; ; ) {
4099 if(n >= 0 && i >= n) break;
4100 if (!*bufp) {
4101 if(R_ReadConsole((char *) Prompt(prompt, prompt_type),
4102 (unsigned char *)buf, CONSOLE_BUFFER_SIZE, 1) == 0)
4103 goto finish;
4104 bufp = buf;
4105 }
4106 while ((c = *bufp++)) {
4107 R_IoBufferPutc(c, buffer);
4108 if (c == ';' || c == '\n') break;
4109 }
4110
4111 /* Was a call to R_Parse1Buffer, but we don't want to reset
4112 xxlineno and xxcolno */
4113 ParseInit();
4114 /* Not calling ParseContextInit() as it resets parse data, and
4115 to be consistent with R_Parse */
4116 R_Parse1(status);
4117 rval = R_CurrentExpr;
4118
4119 switch(*status) {
4120 case PARSE_NULL:
4121 break;
4122 case PARSE_OK:
4123 PROTECT(rval);
4124 GrowList(t, rval);
4125 UNPROTECT(1); /* rval */
4126 i++;
4127 break;
4128 case PARSE_INCOMPLETE:
4129 case PARSE_ERROR:
4130 UNPROTECT(1); /* t */
4131 R_IoBufferWriteReset(buffer);
4132 endcontext(&cntxt);
4133 R_FinalizeSrcRefState();
4134 return R_NilValue;
4135 break;
4136 case PARSE_EOF:
4137 goto finish;
4138 break;
4139 }
4140 }
4141 finish:
4142 R_IoBufferWriteReset(buffer);
4143 t = CDR(t);
4144 PROTECT(rval = allocVector(EXPRSXP, length(t)));
4145 for (n = 0 ; n < LENGTH(rval) ; n++, t = CDR(t))
4146 SET_VECTOR_ELT(rval, n, CAR(t));
4147 if (ParseState.keepSrcRefs) {
4148 if (ParseState.keepParseData)
4149 finalizeData();
4150 attachSrcrefs(rval);
4151 }
4152 UNPROTECT(2); /* t, rval */
4153 PROTECT(rval);
4154 endcontext(&cntxt);
4155 R_FinalizeSrcRefState();
4156 UNPROTECT(1); /* rval */
4157 *status = PARSE_OK;
4158 return rval;
4159 }
4160
4161
4162 /*----------------------------------------------------------------------------
4163 *
4164 * The Lexical Analyzer:
4165 *
4166 * Basic lexical analysis is performed by the following
4167 * routines. Input is read a line at a time, and, if the
4168 * program is in batch mode, each input line is echoed to
4169 * standard output after it is read.
4170 *
4171 * The function yylex() scans the input, breaking it into
4172 * tokens which are then passed to the parser. The lexical
4173 * analyser maintains a symbol table (in a very messy fashion).
4174 *
4175 * The fact that if statements need to parse differently
4176 * depending on whether the statement is being interpreted or
4177 * part of the body of a function causes the need for ifpop
4178 * and IfPush. When an if statement is encountered an 'i' is
4179 * pushed on a stack (provided there are parentheses active).
4180 * At later points this 'i' needs to be popped off of the if
4181 * stack.
4182 *
4183 */
4184
IfPush(void)4185 static void IfPush(void)
4186 {
4187 if (*contextp==LBRACE ||
4188 *contextp=='[' ||
4189 *contextp=='(' ||
4190 *contextp == 'i') {
4191 if(contextp - contextstack >= CONTEXTSTACK_SIZE)
4192 error(_("contextstack overflow"));
4193 *++contextp = 'i';
4194 }
4195
4196 }
4197
ifpop(void)4198 static void ifpop(void)
4199 {
4200 if (*contextp=='i')
4201 *contextp-- = 0;
4202 }
4203
4204 /* This is only called following ., so we only care if it is
4205 an ANSI digit or not */
typeofnext(void)4206 static int typeofnext(void)
4207 {
4208 int k, c;
4209
4210 c = xxgetc();
4211 if (isdigit(c)) k = 1; else k = 2;
4212 xxungetc(c);
4213 return k;
4214 }
4215
nextchar(int expect)4216 static int nextchar(int expect)
4217 {
4218 int c = xxgetc();
4219 if (c == expect)
4220 return 1;
4221 else
4222 xxungetc(c);
4223 return 0;
4224 }
4225
4226 /* Special Symbols */
4227 /* Syntactic Keywords + Symbolic Constants */
4228
4229 struct {
4230 char *name;
4231 int token;
4232 }
4233 static keywords[] = {
4234 { "NULL", NULL_CONST },
4235 { "NA", NUM_CONST },
4236 { "TRUE", NUM_CONST },
4237 { "FALSE", NUM_CONST },
4238 { "Inf", NUM_CONST },
4239 { "NaN", NUM_CONST },
4240 { "NA_integer_", NUM_CONST },
4241 { "NA_real_", NUM_CONST },
4242 { "NA_character_", NUM_CONST },
4243 { "NA_complex_", NUM_CONST },
4244 { "function", FUNCTION },
4245 { "while", WHILE },
4246 { "repeat", REPEAT },
4247 { "for", FOR },
4248 { "if", IF },
4249 { "in", IN },
4250 { "else", ELSE },
4251 { "next", NEXT },
4252 { "break", BREAK },
4253 { "...", SYMBOL },
4254 { 0, 0 }
4255 };
4256
4257 /* KeywordLookup has side effects, it sets yylval */
4258
KeywordLookup(const char * s)4259 static int KeywordLookup(const char *s)
4260 {
4261 int i;
4262 for (i = 0; keywords[i].name; i++) {
4263 if (strcmp(keywords[i].name, s) == 0) {
4264 switch (keywords[i].token) {
4265 case NULL_CONST:
4266 PRESERVE_SV(yylval = R_NilValue);
4267 break;
4268 case NUM_CONST:
4269 if(GenerateCode) {
4270 switch(i) {
4271 case 1:
4272 PRESERVE_SV(yylval = mkNA());
4273 break;
4274 case 2:
4275 PRESERVE_SV(yylval = mkTrue());
4276 break;
4277 case 3:
4278 PRESERVE_SV(yylval = mkFalse());
4279 break;
4280 case 4:
4281 PRESERVE_SV(yylval = allocVector(REALSXP, 1));
4282 REAL(yylval)[0] = R_PosInf;
4283 break;
4284 case 5:
4285 PRESERVE_SV(yylval = allocVector(REALSXP, 1));
4286 REAL(yylval)[0] = R_NaN;
4287 break;
4288 case 6:
4289 PRESERVE_SV(yylval = allocVector(INTSXP, 1));
4290 INTEGER(yylval)[0] = NA_INTEGER;
4291 break;
4292 case 7:
4293 PRESERVE_SV(yylval = allocVector(REALSXP, 1));
4294 REAL(yylval)[0] = NA_REAL;
4295 break;
4296 case 8:
4297 PRESERVE_SV(yylval = allocVector(STRSXP, 1));
4298 SET_STRING_ELT(yylval, 0, NA_STRING);
4299 break;
4300 case 9:
4301 PRESERVE_SV(yylval = allocVector(CPLXSXP, 1));
4302 COMPLEX(yylval)[0].r = COMPLEX(yylval)[0].i = NA_REAL;
4303 break;
4304 }
4305 } else
4306 PRESERVE_SV(yylval = R_NilValue);
4307 break;
4308 case FUNCTION:
4309 case WHILE:
4310 case REPEAT:
4311 case FOR:
4312 case IF:
4313 case NEXT:
4314 case BREAK:
4315 yylval = install(s);
4316 break;
4317 case IN:
4318 case ELSE:
4319 break;
4320 case SYMBOL:
4321 PRESERVE_SV(yylval = install(s));
4322 break;
4323 }
4324 return keywords[i].token;
4325 }
4326 }
4327 return 0;
4328 }
4329
mkFloat(const char * s)4330 static SEXP mkFloat(const char *s)
4331 {
4332 return ScalarReal(R_atof(s));
4333 }
4334
mkInt(const char * s)4335 static SEXP mkInt(const char *s)
4336 {
4337 double f = R_atof(s); /* or R_strtol? */
4338 return ScalarInteger((int) f);
4339 }
4340
mkComplex(const char * s)4341 static SEXP mkComplex(const char *s)
4342 {
4343 SEXP t = R_NilValue;
4344 double f;
4345 f = R_atof(s); /* FIXME: make certain the value is legitimate. */
4346 t = allocVector(CPLXSXP, 1);
4347 COMPLEX(t)[0].r = 0;
4348 COMPLEX(t)[0].i = f;
4349 return t;
4350 }
4351
mkNA(void)4352 static SEXP mkNA(void)
4353 {
4354 SEXP t = allocVector(LGLSXP, 1);
4355 LOGICAL(t)[0] = NA_LOGICAL;
4356 return t;
4357 }
4358
4359 attribute_hidden
mkTrue(void)4360 SEXP mkTrue(void)
4361 {
4362 SEXP s = allocVector(LGLSXP, 1);
4363 LOGICAL(s)[0] = 1;
4364 return s;
4365 }
4366
mkFalse(void)4367 SEXP mkFalse(void)
4368 {
4369 SEXP s = allocVector(LGLSXP, 1);
4370 LOGICAL(s)[0] = 0;
4371 return s;
4372 }
4373
yyerror(const char * s)4374 static void yyerror(const char *s)
4375 {
4376 static const char *const yytname_translations[] =
4377 {
4378 /* the left column are strings coming from bison, the right
4379 column are translations for users.
4380 The first YYENGLISH from the right column are English to be translated,
4381 the rest are to be copied literally. The #if 0 block below allows xgettext
4382 to see these.
4383 */
4384 #define YYENGLISH 8
4385 "$undefined", "input",
4386 "END_OF_INPUT", "end of input",
4387 "ERROR", "input",
4388 "STR_CONST", "string constant",
4389 "NUM_CONST", "numeric constant",
4390 "SYMBOL", "symbol",
4391 "LEFT_ASSIGN", "assignment",
4392 "'\\n'", "end of line",
4393 "NULL_CONST", "'NULL'",
4394 "FUNCTION", "'function'",
4395 "EQ_ASSIGN", "'='",
4396 "RIGHT_ASSIGN", "'->'",
4397 "LBB", "'[['",
4398 "FOR", "'for'",
4399 "IN", "'in'",
4400 "IF", "'if'",
4401 "ELSE", "'else'",
4402 "WHILE", "'while'",
4403 "NEXT", "'next'",
4404 "BREAK", "'break'",
4405 "REPEAT", "'repeat'",
4406 "GT", "'>'",
4407 "GE", "'>='",
4408 "LT", "'<'",
4409 "LE", "'<='",
4410 "EQ", "'=='",
4411 "NE", "'!='",
4412 "AND", "'&'",
4413 "OR", "'|'",
4414 "AND2", "'&&'",
4415 "OR2", "'||'",
4416 "NS_GET", "'::'",
4417 "NS_GET_INT", "':::'",
4418 "PIPE", "'|>'",
4419 "PIPEBIND", "'=>'",
4420 0
4421 };
4422 static char const yyunexpected[] = "syntax error, unexpected ";
4423 static char const yyexpecting[] = ", expecting ";
4424 char *expecting;
4425
4426 if (!EndOfFile)
4427 /* On EndOfFile, there are no more bytes to add, but trying to do
4428 so may have non-trivial performance overhead and this can be
4429 reached also in non-error situations, e.g. from repl.
4430 */
4431 finish_mbcs_in_parse_context();
4432
4433 R_ParseError = yylloc.first_line;
4434 R_ParseErrorCol = yylloc.first_column;
4435 R_ParseErrorFile = PS_SRCFILE;
4436
4437 if (!strncmp(s, yyunexpected, sizeof yyunexpected -1)) {
4438 int i;
4439 /* Edit the error message */
4440 expecting = strstr(s + sizeof yyunexpected -1, yyexpecting);
4441 if (expecting) *expecting = '\0';
4442 for (i = 0; yytname_translations[i]; i += 2) {
4443 if (!strcmp(s + sizeof yyunexpected - 1, yytname_translations[i])) {
4444 switch(i/2)
4445 {
4446 case 0:
4447 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected input"));
4448 break;
4449 case 1:
4450 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected end of input"));
4451 break;
4452 case 2:
4453 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected input"));
4454 break;
4455 case 3:
4456 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected string constant"));
4457 break;
4458 case 4:
4459 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected numeric constant"));
4460 break;
4461 case 5:
4462 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected symbol"));
4463 break;
4464 case 6:
4465 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected assignment"));
4466 break;
4467 case 7:
4468 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected end of line"));
4469 break;
4470 default:
4471 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected %s"),
4472 yytname_translations[i+1]);
4473 break;
4474 }
4475
4476 return;
4477 }
4478 }
4479 snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE - 1, _("unexpected %s"),
4480 s + sizeof yyunexpected - 1);
4481 } else {
4482 strncpy(R_ParseErrorMsg, s, PARSE_ERROR_SIZE - 1);
4483 R_ParseErrorMsg[PARSE_ERROR_SIZE - 1] = '\0';
4484 }
4485 }
4486
CheckFormalArgs(SEXP formlist,SEXP _new,YYLTYPE * lloc)4487 static void CheckFormalArgs(SEXP formlist, SEXP _new, YYLTYPE *lloc)
4488 {
4489 while (formlist != R_NilValue) {
4490 if (TAG(formlist) == _new) {
4491 error(_("repeated formal argument '%s' on line %d"), EncodeChar(PRINTNAME(_new)),
4492 lloc->first_line);
4493 }
4494 formlist = CDR(formlist);
4495 }
4496 }
4497
4498 /* This is used as the buffer for NumericValue, SpecialValue and
4499 SymbolValue. None of these could conceivably need 8192 bytes.
4500
4501 It has not been used as the buffer for input character strings
4502 since Oct 2007 (released as 2.7.0), and for comments since 2.8.0
4503 */
4504 static char yytext[MAXELTSIZE];
4505
SkipSpace(void)4506 static int SkipSpace(void)
4507 {
4508 int c;
4509
4510 #if defined(USE_RI18N_FNS) // includes Win32
4511 static wctype_t blankwct = 0;
4512 if (!blankwct)
4513 blankwct = Ri18n_wctype("blank");
4514 #endif
4515
4516 #ifdef Win32
4517 if(!mbcslocale) { /* 0xa0 is NBSP in all 8-bit Windows locales */
4518 while ((c = xxgetc()) == ' ' || c == '\t' || c == '\f' ||
4519 (unsigned int) c == 0xa0) ;
4520 return c;
4521 } else {
4522 int i, clen;
4523 wchar_t wc;
4524 while (1) {
4525 c = xxgetc();
4526 if (c == ' ' || c == '\t' || c == '\f') continue;
4527 if (c == '\n' || c == R_EOF) break;
4528 if ((unsigned int) c < 0x80) break;
4529 clen = mbcs_get_next(c, &wc); /* always 2 */
4530 if(! Ri18n_iswctype(wc, blankwct) ) break;
4531 for(i = 1; i < clen; i++) c = xxgetc();
4532 }
4533 return c;
4534 }
4535 #endif
4536 #if defined(__STDC_ISO_10646__)
4537 if(mbcslocale) { /* wctype functions need Unicode wchar_t */
4538 int i, clen;
4539 wchar_t wc;
4540 while (1) {
4541 c = xxgetc();
4542 if (c == ' ' || c == '\t' || c == '\f') continue;
4543 if (c == '\n' || c == R_EOF) break;
4544 if ((unsigned int) c < 0x80) break;
4545 clen = mbcs_get_next(c, &wc);
4546 #if defined(USE_RI18N_FNS)
4547 if(! Ri18n_iswctype(wc, blankwct) ) break;
4548 #else
4549 if(! iswblank(wc) ) break;
4550 #endif
4551 for(i = 1; i < clen; i++) c = xxgetc();
4552 }
4553 } else
4554 #endif
4555 // does not support non-ASCII spaces, unlike Windows
4556 while ((c = xxgetc()) == ' ' || c == '\t' || c == '\f') ;
4557 return c;
4558 }
4559
4560 /* Note that with interactive use, EOF cannot occur inside */
4561 /* a comment. However, semicolons inside comments make it */
4562 /* appear that this does happen. For this reason we use the */
4563 /* special assignment EndOfFile=2 to indicate that this is */
4564 /* going on. This is detected and dealt with in Parse1Buffer. */
4565
SkipComment(void)4566 static int SkipComment(void)
4567 {
4568 int c='#', i;
4569
4570 /* locations before the # character was read */
4571 int _first_column = ParseState.xxcolno ;
4572 int _first_parsed = ParseState.xxparseno ;
4573 int type = COMMENT ;
4574
4575 Rboolean maybeLine = (ParseState.xxcolno == 1);
4576 Rboolean doSave;
4577
4578 DECLARE_YYTEXT_BUFP(yyp);
4579
4580 if (maybeLine) {
4581 char lineDirective[] = "#line";
4582 YYTEXT_PUSH(c, yyp);
4583 for (i=1; i<5; i++) {
4584 c = xxgetc();
4585 if (c != (int)(lineDirective[i])) {
4586 maybeLine = FALSE;
4587 break;
4588 }
4589 YYTEXT_PUSH(c, yyp);
4590 }
4591 if (maybeLine)
4592 c = processLineDirective(&type);
4593 }
4594 // we want to track down the character
4595 // __before__ the new line character
4596 int _last_column = ParseState.xxcolno ;
4597 int _last_parsed = ParseState.xxparseno ;
4598
4599 if (c == '\n') {
4600 _last_column = prevcols[prevpos];
4601 _last_parsed = prevparse[prevpos];
4602 }
4603
4604 doSave = !maybeLine;
4605
4606 while (c != '\n' && c != R_EOF) {
4607 // Comments can be any length; we only record the ones that fit in yytext.
4608 if (doSave) {
4609 YYTEXT_PUSH(c, yyp);
4610 doSave = (yyp - yytext) < sizeof(yytext) - 2;
4611 }
4612 _last_column = ParseState.xxcolno ;
4613 _last_parsed = ParseState.xxparseno ;
4614 c = xxgetc();
4615 }
4616 if (c == R_EOF) EndOfFile = 2;
4617 incrementId( ) ;
4618 YYTEXT_PUSH('\0', yyp);
4619 record_( _first_parsed, _first_column, _last_parsed, _last_column,
4620 type, identifier, doSave ? yytext : 0 ) ;
4621 return c;
4622 }
4623
NumericValue(int c)4624 static int NumericValue(int c)
4625 {
4626 int seendot = (c == '.');
4627 int seenexp = 0;
4628 int last = c;
4629 int nd = 0;
4630 int asNumeric = 0;
4631 int count = 1; /* The number of characters seen */
4632
4633 DECLARE_YYTEXT_BUFP(yyp);
4634 YYTEXT_PUSH(c, yyp);
4635 /* We don't care about other than ASCII digits */
4636 while (isdigit(c = xxgetc()) || c == '.' || c == 'e' || c == 'E'
4637 || c == 'x' || c == 'X' || c == 'L')
4638 {
4639 count++;
4640 if (c == 'L') /* must be at the end. Won't allow 1Le3 (at present). */
4641 { YYTEXT_PUSH(c, yyp);
4642 break;
4643 }
4644
4645 if (c == 'x' || c == 'X') {
4646 if (count > 2 || last != '0') break; /* 0x must be first */
4647 YYTEXT_PUSH(c, yyp);
4648 while(isdigit(c = xxgetc()) || ('a' <= c && c <= 'f') ||
4649 ('A' <= c && c <= 'F') || c == '.') {
4650 if (c == '.') {
4651 if (seendot) return ERROR;
4652 seendot = 1;
4653 }
4654 YYTEXT_PUSH(c, yyp);
4655 nd++;
4656 }
4657 if (nd == 0) return ERROR;
4658 if (c == 'p' || c == 'P') {
4659 seenexp = 1;
4660 YYTEXT_PUSH(c, yyp);
4661 c = xxgetc();
4662 if (!isdigit(c) && c != '+' && c != '-') return ERROR;
4663 if (c == '+' || c == '-') {
4664 YYTEXT_PUSH(c, yyp);
4665 c = xxgetc();
4666 }
4667 for(nd = 0; isdigit(c); c = xxgetc(), nd++)
4668 YYTEXT_PUSH(c, yyp);
4669 if (nd == 0) return ERROR;
4670 }
4671 if (seendot && !seenexp) return ERROR;
4672 if (c == 'L') /* for getParseData */
4673 {
4674 // seenexp will be checked later
4675 YYTEXT_PUSH(c, yyp);
4676 break;
4677 }
4678 break;
4679 }
4680 if (c == 'E' || c == 'e') {
4681 if (seenexp)
4682 break;
4683 seenexp = 1;
4684 seendot = seendot == 1 ? seendot : 2;
4685 YYTEXT_PUSH(c, yyp);
4686 c = xxgetc();
4687 if (!isdigit(c) && c != '+' && c != '-') return ERROR;
4688 if (c == '+' || c == '-') {
4689 YYTEXT_PUSH(c, yyp);
4690 c = xxgetc();
4691 if (!isdigit(c)) return ERROR;
4692 }
4693 }
4694 if (c == '.') {
4695 if (seendot)
4696 break;
4697 seendot = 1;
4698 }
4699 YYTEXT_PUSH(c, yyp);
4700 last = c;
4701 }
4702
4703 if(c == 'i')
4704 YYTEXT_PUSH(c, yyp); /* for getParseData */
4705
4706 YYTEXT_PUSH('\0', yyp);
4707 /* Make certain that things are okay. */
4708 if(c == 'L') {
4709 double a = R_atof(yytext);
4710 int b = (int) a;
4711 /* We are asked to create an integer via the L, so we check that the
4712 double and int values are the same. If not, this is a problem and we
4713 will not lose information and so use the numeric value.
4714 */
4715 if(a != (double) b) {
4716 if(GenerateCode) {
4717 if(seendot == 1 && seenexp == 0)
4718 warning(_("integer literal %s contains decimal; using numeric value"), yytext);
4719 else {
4720 /* hide the L for the warning message */
4721 warning(_("non-integer value %s qualified with L; using numeric value"), yytext);
4722 }
4723 }
4724 asNumeric = 1;
4725 seenexp = 1;
4726 }
4727 }
4728
4729 if(c == 'i') {
4730 yylval = GenerateCode ? mkComplex(yytext) : R_NilValue;
4731 } else if(c == 'L' && asNumeric == 0) {
4732 if(GenerateCode && seendot == 1 && seenexp == 0)
4733 warning(_("integer literal %s contains unnecessary decimal point"), yytext);
4734 yylval = GenerateCode ? mkInt(yytext) : R_NilValue;
4735 #if 0 /* do this to make 123 integer not double */
4736 } else if(!(seendot || seenexp)) {
4737 if(c != 'L') xxungetc(c);
4738 if (GenerateCode) {
4739 double a = R_atof(yytext);
4740 int b = (int) a;
4741 yylval = (a != (double) b) ? mkFloat(yytext) : mkInt(yytext);
4742 } else yylval = R_NilValue;
4743 #endif
4744 } else {
4745 if(c != 'L')
4746 xxungetc(c);
4747 yylval = GenerateCode ? mkFloat(yytext) : R_NilValue;
4748 }
4749
4750 PRESERVE_SV(yylval);
4751 return NUM_CONST;
4752 }
4753
4754 /* Strings may contain the standard ANSI escapes and octal */
4755 /* specifications of the form \o, \oo or \ooo, where 'o' */
4756 /* is an octal digit. */
4757
4758 /* The buffer is reallocated on the R heap if needed; not by malloc */
4759 /* to avoid memory leak in case of R error (long jump) */
4760 #define STEXT_PUSH(c) do { \
4761 size_t nc = bp - stext; \
4762 if (nc >= nstext - 1) { \
4763 char *old = stext; \
4764 SEXP st1; \
4765 nstext *= 2; \
4766 PROTECT(st1 = allocVector(RAWSXP, nstext)); \
4767 stext = (char *)RAW(st1); \
4768 memmove(stext, old, nc); \
4769 REPROTECT(st1, sti); \
4770 UNPROTECT(1); /* st1 */ \
4771 bp = stext+nc; } \
4772 *bp++ = ((char) c); \
4773 } while(0)
4774
4775
4776 /* The idea here is that if a string contains \u escapes that are not
4777 valid in the current locale, we should switch to UTF-8 for that
4778 string. Needs Unicode wide-char support or out substitutes.
4779
4780 Defining __STDC_ISO_10646__ is done by the OS (or not) in wchar.t.
4781 Some (e.g. macOS, Solaris, FreeBSD) have Unicode wchar_t but do not
4782 define it: we override macOS and FreeBSD earlier in this file.
4783 */
4784
4785 #if defined(Win32) || defined(__STDC_ISO_10646__)
4786 typedef wchar_t ucs_t;
4787 # define mbcs_get_next2 mbcs_get_next
4788 #else
4789 typedef unsigned int ucs_t;
4790 # define WC_NOT_UNICODE
4791 // which is used to select our mbtoucs rather than system mbrtowc
mbcs_get_next2(int c,ucs_t * wc)4792 static int mbcs_get_next2(int c, ucs_t *wc)
4793 {
4794 int i, res, clen = 1; char s[9];
4795
4796 s[0] = c;
4797 /* This assumes (probably OK) that all MBCS embed ASCII as single-byte
4798 lead bytes, including control chars */
4799 if((unsigned int) c < 0x80) {
4800 *wc = (wchar_t) c;
4801 return 1;
4802 }
4803 if(utf8locale) {
4804 clen = utf8clen(c);
4805 for(i = 1; i < clen; i++) {
4806 c = xxgetc();
4807 if(c == R_EOF) error(_("EOF whilst reading MBCS char at line %d"), ParseState.xxlineno);
4808 s[i] = (char) c;
4809 }
4810 s[clen] ='\0'; /* x86 Solaris requires this */
4811 res = mbtoucs(wc, s, clen);
4812 if(res == -1) error(_("invalid multibyte character in parser at line %d"), ParseState.xxlineno);
4813 } else {
4814 /* This is not necessarily correct for stateful MBCS */
4815 while(clen <= R_MB_CUR_MAX) {
4816 res = mbtoucs(wc, s, clen);
4817 if(res >= 0) break;
4818 if(res == -1)
4819 error(_("invalid multibyte character in parser at line %d"), ParseState.xxlineno);
4820 /* so res == -2 */
4821 c = xxgetc();
4822 if(c == R_EOF) error(_("EOF whilst reading MBCS char at line %d"), ParseState.xxlineno);
4823 s[clen++] = c;
4824 } /* we've tried enough, so must be complete or invalid by now */
4825 }
4826 for(i = clen - 1; i > 0; i--) xxungetc(s[i]);
4827 return clen;
4828 }
4829 #endif
4830
4831 #define WTEXT_PUSH(c) do { if(wcnt < 10000) wcs[wcnt++] = c; } while(0)
4832
mkStringUTF8(const ucs_t * wcs,int cnt)4833 static SEXP mkStringUTF8(const ucs_t *wcs, int cnt)
4834 {
4835 SEXP t;
4836 int nb;
4837
4838 /* NB: cnt includes the terminator */
4839 #ifdef Win32
4840 nb = cnt*4; /* UCS-2/UTF-16 so max 4 bytes per wchar_t */
4841 #else
4842 nb = cnt*6;
4843 #endif
4844 R_CheckStack2(nb);
4845 char s[nb];
4846 memset(s, 0, nb); /* safety */
4847 // This used to differentiate WC_NOT_UNICODE but not needed
4848 wcstoutf8(s, (const wchar_t *)wcs, sizeof(s));
4849 PROTECT(t = allocVector(STRSXP, 1));
4850 SET_STRING_ELT(t, 0, mkCharCE(s, CE_UTF8));
4851 UNPROTECT(1); /* t */
4852 return t;
4853 }
4854
4855 #define CTEXT_PUSH(c) do { \
4856 if (ct - currtext >= 1000) { \
4857 memmove(currtext, currtext+100, 901); memmove(currtext, "... ", 4); ct -= 100; \
4858 currtext_truncated = TRUE; \
4859 } \
4860 *ct++ = ((char) c); \
4861 } while(0)
4862 #define CTEXT_POP() ct--
4863
4864
4865 /* forSymbol is true when parsing backticked symbols */
StringValue(int c,Rboolean forSymbol)4866 static int StringValue(int c, Rboolean forSymbol)
4867 {
4868 int quote = c;
4869 char currtext[1010], *ct = currtext;
4870 char st0[MAXELTSIZE];
4871 unsigned int nstext = MAXELTSIZE;
4872 char *stext = st0, *bp = st0;
4873 PROTECT_INDEX sti;
4874 int wcnt = 0;
4875 ucs_t wcs[10001];
4876 Rboolean oct_or_hex = FALSE, use_wcs = FALSE, currtext_truncated = FALSE;
4877
4878 PROTECT_WITH_INDEX(R_NilValue, &sti);
4879 CTEXT_PUSH(c);
4880 while ((c = xxgetc()) != R_EOF && c != quote) {
4881 CTEXT_PUSH(c);
4882 if (c == '\n') {
4883 xxungetc(c); CTEXT_POP();
4884 /* Fix suggested by Mark Bravington to allow multiline strings
4885 * by pretending we've seen a backslash. Was:
4886 * return ERROR;
4887 */
4888 c = '\\';
4889 }
4890 if (c == '\\') {
4891 c = xxgetc(); CTEXT_PUSH(c);
4892 if ('0' <= c && c <= '7') {
4893 int octal = c - '0';
4894 if ('0' <= (c = xxgetc()) && c <= '7') {
4895 CTEXT_PUSH(c);
4896 octal = 8 * octal + c - '0';
4897 if ('0' <= (c = xxgetc()) && c <= '7') {
4898 CTEXT_PUSH(c);
4899 octal = 8 * octal + c - '0';
4900 } else {
4901 xxungetc(c);
4902 CTEXT_POP();
4903 }
4904 } else {
4905 xxungetc(c);
4906 CTEXT_POP();
4907 }
4908 if (!octal)
4909 error(_("nul character not allowed (line %d)"), ParseState.xxlineno);
4910 c = octal;
4911 oct_or_hex = TRUE;
4912 }
4913 else if(c == 'x') {
4914 int val = 0; int i, ext;
4915 for(i = 0; i < 2; i++) {
4916 c = xxgetc(); CTEXT_PUSH(c);
4917 if(c >= '0' && c <= '9') ext = c - '0';
4918 else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10;
4919 else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10;
4920 else {
4921 xxungetc(c);
4922 CTEXT_POP();
4923 if (i == 0) { /* was just \x */
4924 *ct = '\0';
4925 errorcall(R_NilValue, _("'\\x' used without hex digits in character string starting \"%s\""), currtext);
4926 }
4927 break;
4928 }
4929 val = 16*val + ext;
4930 }
4931 if (!val)
4932 error(_("nul character not allowed (line %d)"), ParseState.xxlineno);
4933 c = val;
4934 oct_or_hex = TRUE;
4935 }
4936 else if(c == 'u') {
4937 unsigned int val = 0; int i, ext;
4938 Rboolean delim = FALSE;
4939
4940 if(forSymbol)
4941 error(_("\\uxxxx sequences not supported inside backticks (line %d)"), ParseState.xxlineno);
4942 if((c = xxgetc()) == '{') {
4943 delim = TRUE;
4944 CTEXT_PUSH(c);
4945 } else xxungetc(c);
4946 for(i = 0; i < 4; i++) {
4947 c = xxgetc(); CTEXT_PUSH(c);
4948 if(c >= '0' && c <= '9') ext = c - '0';
4949 else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10;
4950 else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10;
4951 else {
4952 xxungetc(c);
4953 CTEXT_POP();
4954 if (i == 0) { /* was just \u */
4955 *ct = '\0';
4956 errorcall(R_NilValue, _("'\\u' used without hex digits in character string starting \"%s\""), currtext);
4957 }
4958 break;
4959 }
4960 val = 16*val + ext;
4961 }
4962 if(delim) {
4963 if((c = xxgetc()) != '}')
4964 error(_("invalid \\u{xxxx} sequence (line %d)"),
4965 ParseState.xxlineno);
4966 else CTEXT_PUSH(c);
4967 }
4968 if (!val)
4969 error(_("nul character not allowed (line %d)"), ParseState.xxlineno);
4970 WTEXT_PUSH(val); /* this assumes wchar_t is Unicode */
4971 use_wcs = TRUE;
4972 continue;
4973 }
4974 else if(c == 'U') {
4975 unsigned int val = 0; int i, ext;
4976 Rboolean delim = FALSE;
4977 if(forSymbol)
4978 error(_("\\Uxxxxxxxx sequences not supported inside backticks (line %d)"), ParseState.xxlineno);
4979 if((c = xxgetc()) == '{') {
4980 delim = TRUE;
4981 CTEXT_PUSH(c);
4982 } else xxungetc(c);
4983 for(i = 0; i < 8; i++) {
4984 c = xxgetc(); CTEXT_PUSH(c);
4985 if(c >= '0' && c <= '9') ext = c - '0';
4986 else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10;
4987 else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10;
4988 else {
4989 xxungetc(c);
4990 CTEXT_POP();
4991 if (i == 0) { /* was just \U */
4992 *ct = '\0';
4993 errorcall(R_NilValue, _("'\\U' used without hex digits in character string starting \"%s\""), currtext);
4994 }
4995 break;
4996 }
4997 val = 16*val + ext;
4998 }
4999 if(delim) {
5000 if((c = xxgetc()) != '}')
5001 error(_("invalid \\U{xxxxxxxx} sequence (line %d)"),
5002 ParseState.xxlineno);
5003 else CTEXT_PUSH(c);
5004 }
5005 if (!val)
5006 error(_("nul character not allowed (line %d)"),
5007 ParseState.xxlineno);
5008 if (val > 0x10FFFF) {
5009 if(delim)
5010 error(_("invalid \\U{xxxxxxxx} value %6x (line %d)"),
5011 val, ParseState.xxlineno);
5012 else
5013 error(_("invalid \\Uxxxxxxxx value %6x (line %d)"),
5014 val, ParseState.xxlineno);
5015 }
5016 #ifdef Win32
5017 if (0x010000 <= val && val <= 0x10FFFF) { /* Need surrogate pair in Windows */
5018 val = val - 0x010000;
5019 WTEXT_PUSH( 0xD800 | (val >> 10) );
5020 val = 0xDC00 | (val & 0x03FF);
5021 }
5022 #endif
5023 WTEXT_PUSH(val);
5024 use_wcs = TRUE;
5025 continue;
5026 }
5027 else {
5028 switch (c) {
5029 case 'a':
5030 c = '\a';
5031 break;
5032 case 'b':
5033 c = '\b';
5034 break;
5035 case 'f':
5036 c = '\f';
5037 break;
5038 case 'n':
5039 c = '\n';
5040 break;
5041 case 'r':
5042 c = '\r';
5043 break;
5044 case 't':
5045 c = '\t';
5046 break;
5047 case 'v':
5048 c = '\v';
5049 break;
5050 case '\\':
5051 c = '\\';
5052 break;
5053 case '"':
5054 case '\'':
5055 case '`':
5056 case ' ':
5057 case '\n':
5058 break;
5059 default:
5060 *ct = '\0';
5061 errorcall(R_NilValue, _("'\\%c' is an unrecognized escape in character string starting \"%s\""), c, currtext);
5062 }
5063 }
5064 } else if(mbcslocale) {
5065 int i, clen;
5066 ucs_t wc;
5067 clen = mbcs_get_next2(c, &wc);
5068 WTEXT_PUSH(wc);
5069 ParseState.xxbyteno += clen-1;
5070
5071 for(i = 0; i < clen - 1; i++){
5072 STEXT_PUSH(c);
5073 c = xxgetc();
5074 if (c == R_EOF) break;
5075 CTEXT_PUSH(c);
5076 if (c == '\n') {
5077 xxungetc(c); CTEXT_POP();
5078 c = '\\';
5079 }
5080 }
5081 if (c == R_EOF) break;
5082 STEXT_PUSH(c);
5083 continue;
5084 }
5085 STEXT_PUSH(c);
5086 if ((unsigned int) c < 0x80) WTEXT_PUSH(c);
5087 else { /* have an 8-bit char in the current encoding */
5088 #ifdef WC_NOT_UNICODE
5089 ucs_t wc;
5090 char s[2] = " ";
5091 s[0] = (char) c;
5092 mbtoucs(&wc, s, 2);
5093 #else
5094 wchar_t wc;
5095 char s[2] = " ";
5096 s[0] = (char) c;
5097 mbrtowc(&wc, s, 2, NULL);
5098 #endif
5099 WTEXT_PUSH(wc);
5100 }
5101 }
5102 STEXT_PUSH('\0');
5103 WTEXT_PUSH(0);
5104 yytext[0] = '\0';
5105 if (c == R_EOF) {
5106 PRESERVE_SV(yylval = R_NilValue);
5107 UNPROTECT(1); /* release stext */
5108 return INCOMPLETE_STRING;
5109 } else {
5110 CTEXT_PUSH(c);
5111 CTEXT_PUSH('\0');
5112 }
5113 if (!currtext_truncated)
5114 strcpy(yytext, currtext);
5115 else if (forSymbol || !use_wcs) {
5116 size_t total = strlen(stext);
5117 snprintf(yytext, MAXELTSIZE, "[%u chars quoted with '%c']", (unsigned int)total, quote);
5118 } else
5119 snprintf(yytext, MAXELTSIZE, "[%d wide chars quoted with '%c']", wcnt, quote);
5120 if(forSymbol) {
5121 PRESERVE_SV(yylval = install(stext));
5122 UNPROTECT(1); /* release stext */
5123 return SYMBOL;
5124 } else {
5125 if(use_wcs) {
5126 if(oct_or_hex)
5127 error(_("mixing Unicode and octal/hex escapes in a string is not allowed"));
5128 if(wcnt < 10000)
5129 PRESERVE_SV(yylval = mkStringUTF8(wcs, wcnt)); /* include terminator */
5130 else
5131 error(_("string at line %d containing Unicode escapes not in this locale\nis too long (max 10000 chars)"), ParseState.xxlineno);
5132 } else
5133 PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1, oct_or_hex));
5134 UNPROTECT(1); /* release stext */
5135 return STR_CONST;
5136 }
5137 }
5138
RawStringValue(int c0,int c)5139 static int RawStringValue(int c0, int c)
5140 {
5141 int quote = c;
5142 int delim = ')';
5143 char currtext[1010], *ct = currtext;
5144 char st0[MAXELTSIZE];
5145 unsigned int nstext = MAXELTSIZE;
5146 char *stext = st0, *bp = st0;
5147 PROTECT_INDEX sti;
5148 int wcnt = 0;
5149 ucs_t wcs[10001];
5150 Rboolean oct_or_hex = FALSE, use_wcs = FALSE, currtext_truncated = FALSE;
5151
5152 CTEXT_PUSH(c0); /* 'r' or 'R' */
5153 CTEXT_PUSH(c); /* opening quote */
5154
5155 /* count dashes between the opening quote and opening delimiter */
5156 int ndash = 0;
5157 while (nextchar('-')) { CTEXT_PUSH('-'); ndash++; }
5158
5159 c = xxgetc();
5160 CTEXT_PUSH(c);
5161 switch(c) {
5162 case '(': delim = ')'; break;
5163 case '[': delim = ']'; break;
5164 case '{': delim = '}'; break;
5165 case '|': delim = '|'; break;
5166 default:
5167 error(_("malformed raw string literal at line %d"),
5168 ParseState.xxlineno);
5169 }
5170
5171 PROTECT_WITH_INDEX(R_NilValue, &sti);
5172 while ((c = xxgetc()) != R_EOF) {
5173 if (c == delim) {
5174 /* count the dashes after the closing delimiter */
5175 int nd = 0;
5176 while (nd < ndash && nextchar('-')) nd++;
5177
5178 if (nd == ndash && nextchar(quote))
5179 /* right number of dashes, right quote: were done! */
5180 break;
5181 else {
5182 /* not done: emit closing delimiter, dashes, and continue */
5183 CTEXT_PUSH(delim);
5184 STEXT_PUSH(delim);
5185 WTEXT_PUSH(delim);
5186 for (int i = 0; i < nd; i++) {
5187 CTEXT_PUSH('-');
5188 STEXT_PUSH('-');
5189 WTEXT_PUSH('-');
5190 }
5191 continue;
5192 }
5193 }
5194 CTEXT_PUSH(c);
5195 if(mbcslocale) {
5196 int i, clen;
5197 ucs_t wc;
5198 clen = mbcs_get_next2(c, &wc);
5199 WTEXT_PUSH(wc);
5200 ParseState.xxbyteno += clen-1;
5201
5202 for(i = 0; i < clen - 1; i++){
5203 STEXT_PUSH(c);
5204 c = xxgetc();
5205 if (c == R_EOF) break;
5206 CTEXT_PUSH(c);
5207 }
5208 if (c == R_EOF) break;
5209 STEXT_PUSH(c);
5210 continue;
5211 }
5212 STEXT_PUSH(c);
5213 if ((unsigned int) c < 0x80) WTEXT_PUSH(c);
5214 else { /* have an 8-bit char in the current encoding */
5215 #ifdef WC_NOT_UNICODE
5216 ucs_t wc;
5217 char s[2] = " ";
5218 s[0] = (char) c;
5219 mbtoucs(&wc, s, 2);
5220 #else
5221 wchar_t wc;
5222 char s[2] = " ";
5223 s[0] = (char) c;
5224 mbrtowc(&wc, s, 2, NULL);
5225 #endif
5226 WTEXT_PUSH(wc);
5227 }
5228 }
5229 STEXT_PUSH('\0');
5230 WTEXT_PUSH(0);
5231 yytext[0] = '\0';
5232 if (c == R_EOF) {
5233 PRESERVE_SV(yylval = R_NilValue);
5234 UNPROTECT(1); /* release stext */
5235 return INCOMPLETE_STRING;
5236 } else {
5237 /* record delim, dashes, and quote, and terminate string */
5238 CTEXT_PUSH(delim);
5239 for (int i = 0; i < ndash; i++)
5240 CTEXT_PUSH('-');
5241 CTEXT_PUSH(quote);
5242 CTEXT_PUSH('\0');
5243 }
5244 if (!currtext_truncated)
5245 strcpy(yytext, currtext);
5246 else if (!use_wcs) {
5247 size_t total = strlen(stext);
5248 snprintf(yytext, MAXELTSIZE, "[%u chars quoted with '%c']", (unsigned int)total, quote);
5249 } else
5250 snprintf(yytext, MAXELTSIZE, "[%d wide chars quoted with '%c']", wcnt, quote);
5251 if(use_wcs) {
5252 if(oct_or_hex)
5253 error(_("mixing Unicode and octal/hex escapes in a string is not allowed"));
5254 if(wcnt < 10000)
5255 PRESERVE_SV(yylval = mkStringUTF8(wcs, wcnt)); /* include terminator */
5256 else
5257 error(_("string at line %d containing Unicode escapes not in this locale\nis too long (max 10000 chars)"), ParseState.xxlineno);
5258 } else
5259 PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1, oct_or_hex));
5260 UNPROTECT(1); /* release stext */
5261 return STR_CONST;
5262 }
5263
SpecialValue(int c)5264 static int SpecialValue(int c)
5265 {
5266 DECLARE_YYTEXT_BUFP(yyp);
5267 YYTEXT_PUSH(c, yyp);
5268 while ((c = xxgetc()) != R_EOF && c != '%') {
5269 if (c == '\n') {
5270 xxungetc(c);
5271 return ERROR;
5272 }
5273 YYTEXT_PUSH(c, yyp);
5274 }
5275 if (c == '%')
5276 YYTEXT_PUSH(c, yyp);
5277 YYTEXT_PUSH('\0', yyp);
5278 yylval = install(yytext);
5279 return SPECIAL;
5280 }
5281
5282 /* return 1 if name is a valid name 0 otherwise */
5283 attribute_hidden
isValidName(const char * name)5284 int isValidName(const char *name)
5285 {
5286 const char *p = name;
5287 int i;
5288
5289 if(mbcslocale) {
5290 /* the only way to establish which chars are alpha etc is to
5291 use the wchar variants */
5292 size_t n = strlen(name), used;
5293 wchar_t wc;
5294 used = Mbrtowc(&wc, p, n, NULL); p += used; n -= used;
5295 if(used == 0) return 0;
5296 if (wc != L'.' && !iswalpha(wc) ) return 0;
5297 if (wc == L'.') {
5298 /* We don't care about other than ASCII digits */
5299 if(isdigit(0xff & (int)*p)) return 0;
5300 /* Mbrtowc(&wc, p, n, NULL); if(iswdigit(wc)) return 0; */
5301 }
5302 while((used = Mbrtowc(&wc, p, n, NULL))) {
5303 if (!(iswalnum(wc) || wc == L'.' || wc == L'_')) break;
5304 p += used; n -= used;
5305 }
5306 if (*p != '\0') return 0;
5307 } else {
5308 int c = 0xff & *p++;
5309 if (c != '.' && !isalpha(c) ) return 0;
5310 if (c == '.' && isdigit(0xff & (int)*p)) return 0;
5311 while ( c = 0xff & *p++, (isalnum(c) || c == '.' || c == '_') ) ;
5312 if (c != '\0') return 0;
5313 }
5314
5315 if (strcmp(name, "...") == 0) return 1;
5316
5317 for (i = 0; keywords[i].name != NULL; i++)
5318 if (strcmp(keywords[i].name, name) == 0) return 0;
5319
5320 return 1;
5321 }
5322
5323
SymbolValue(int c)5324 static int SymbolValue(int c)
5325 {
5326 int kw;
5327 DECLARE_YYTEXT_BUFP(yyp);
5328 if(mbcslocale) {
5329 // FIXME potentially need R_wchar_t with UTF-8 Windows.
5330 wchar_t wc; int i, clen;
5331 clen = mbcs_get_next(c, &wc);
5332 while(1) {
5333 /* at this point we have seen one char, so push its bytes
5334 and get one more */
5335 for(i = 0; i < clen; i++) {
5336 YYTEXT_PUSH(c, yyp);
5337 c = xxgetc();
5338 }
5339 if(c == R_EOF) break;
5340 if(c == '.' || c == '_') {
5341 clen = 1;
5342 continue;
5343 }
5344 clen = mbcs_get_next(c, &wc);
5345 if(!iswalnum(wc)) break;
5346 }
5347 } else
5348 do {
5349 YYTEXT_PUSH(c, yyp);
5350 } while ((c = xxgetc()) != R_EOF &&
5351 (isalnum(c) || c == '.' || c == '_'));
5352 xxungetc(c);
5353 YYTEXT_PUSH('\0', yyp);
5354 if ((kw = KeywordLookup(yytext)))
5355 return kw;
5356
5357 PRESERVE_SV(yylval = install(yytext));
5358 return SYMBOL;
5359 }
5360
setParseFilename(SEXP newname)5361 static void setParseFilename(SEXP newname) {
5362 SEXP class;
5363
5364 if (isEnvironment(PS_SRCFILE)) {
5365 SEXP oldname = findVar(install("filename"), PS_SRCFILE);
5366 if (isString(oldname) && length(oldname) > 0 &&
5367 strcmp(CHAR(STRING_ELT(oldname, 0)),
5368 CHAR(STRING_ELT(newname, 0))) == 0) return;
5369 PS_SET_SRCFILE(NewEnvironment(R_NilValue, R_NilValue, R_EmptyEnv));
5370 defineVar(install("filename"), newname, PS_SRCFILE);
5371 defineVar(install("original"), PS_ORIGINAL, PS_SRCFILE);
5372
5373 PROTECT(class = allocVector(STRSXP, 2));
5374 SET_STRING_ELT(class, 0, mkChar("srcfilealias"));
5375 SET_STRING_ELT(class, 1, mkChar("srcfile"));
5376 setAttrib(PS_SRCFILE, R_ClassSymbol, class);
5377 UNPROTECT(1); /* class */
5378 } else
5379 PS_SET_SRCFILE(duplicate(newname));
5380 RELEASE_SV(newname);
5381 }
5382
processLineDirective(int * type)5383 static int processLineDirective(int *type)
5384 {
5385 int c, tok, linenumber;
5386 c = SkipSpace();
5387 if (!isdigit(c)) return(c);
5388 tok = NumericValue(c);
5389 linenumber = atoi(yytext);
5390 c = SkipSpace();
5391 if (c == '"')
5392 tok = StringValue(c, FALSE);
5393 else
5394 xxungetc(c);
5395 if (tok == STR_CONST)
5396 setParseFilename(yylval);
5397 while ((c = xxgetc()) != '\n' && c != R_EOF) /* skip */ ;
5398 ParseState.xxlineno = linenumber;
5399 *type = LINE_DIRECTIVE;
5400 /* we don't change xxparseno here: it counts parsed lines, not official lines */
5401 R_ParseContext[R_ParseContextLast] = '\0'; /* Context report shouldn't show the directive */
5402 return(c);
5403 }
5404
5405 /* Get the R symbol, and set yytext at the same time */
install_and_save(char * text)5406 static SEXP install_and_save(char * text)
5407 {
5408 strcpy(yytext, text);
5409 return install(text);
5410 }
5411
5412 /* Get an R symbol, and set different yytext. Used for translation of -> to <-. ->> to <<- */
install_and_save2(char * text,char * savetext)5413 static SEXP install_and_save2(char * text, char * savetext)
5414 {
5415 strcpy(yytext, savetext);
5416 return install(text);
5417 }
5418
5419
5420 /* Split the input stream into tokens. */
5421 /* This is the lowest of the parsing levels. */
5422
token(void)5423 static int token(void)
5424 {
5425 int c;
5426 wchar_t wc;
5427
5428 if (SavedToken) {
5429 c = SavedToken;
5430 yylval = SavedLval;
5431 SavedLval = R_NilValue;
5432 SavedToken = 0;
5433 yylloc.first_line = xxlinesave;
5434 yylloc.first_column = xxcolsave;
5435 yylloc.first_byte = xxbytesave;
5436 yylloc.first_parsed = xxparsesave;
5437 return c;
5438 }
5439 xxcharsave = xxcharcount; /* want to be able to go back one token */
5440
5441 c = SkipSpace();
5442 if (c == '#') c = SkipComment();
5443
5444 yylloc.first_line = ParseState.xxlineno;
5445 yylloc.first_column = ParseState.xxcolno;
5446 yylloc.first_byte = ParseState.xxbyteno;
5447 yylloc.first_parsed = ParseState.xxparseno;
5448
5449 if (c == R_EOF) return END_OF_INPUT;
5450
5451 /* Either digits or symbols can start with a "." */
5452 /* so we need to decide which it is and jump to */
5453 /* the correct spot. */
5454
5455 if (c == '.' && typeofnext() >= 2) goto symbol;
5456
5457 /* literal numbers */
5458
5459 if (c == '.') return NumericValue(c);
5460 /* We don't care about other than ASCII digits */
5461 if (isdigit(c)) return NumericValue(c);
5462
5463 /* raw string literal */
5464
5465 if (c == 'r' || c == 'R') {
5466 if (nextchar('"'))
5467 return RawStringValue(c, '"');
5468 else if (nextchar('\''))
5469 return RawStringValue(c, '\'');
5470 }
5471
5472 /* literal strings */
5473
5474 if (c == '\"' || c == '\'')
5475 return StringValue(c, FALSE);
5476
5477 /* special functions */
5478
5479 if (c == '%')
5480 return SpecialValue(c);
5481
5482 /* functions, constants and variables */
5483
5484 if (c == '`')
5485 return StringValue(c, TRUE);
5486 symbol:
5487
5488 if (c == '.') return SymbolValue(c);
5489 if(mbcslocale) {
5490 // FIXME potentially need R_wchar_t with UTF-8 Windows.
5491 mbcs_get_next(c, &wc);
5492 if (iswalpha(wc)) return SymbolValue(c);
5493 } else
5494 if (isalpha(c)) return SymbolValue(c);
5495
5496 /* compound tokens */
5497
5498 switch (c) {
5499 case '<':
5500 if (nextchar('=')) {
5501 yylval = install_and_save("<=");
5502 return LE;
5503 }
5504 if (nextchar('-')) {
5505 yylval = install_and_save("<-");
5506 return LEFT_ASSIGN;
5507 }
5508 if (nextchar('<')) {
5509 if (nextchar('-')) {
5510 yylval = install_and_save("<<-");
5511 return LEFT_ASSIGN;
5512 }
5513 else
5514 return ERROR;
5515 }
5516 yylval = install_and_save("<");
5517 return LT;
5518 case '-':
5519 if (nextchar('>')) {
5520 if (nextchar('>')) {
5521 yylval = install_and_save2("<<-", "->>");
5522 return RIGHT_ASSIGN;
5523 }
5524 else {
5525 yylval = install_and_save2("<-", "->");
5526 return RIGHT_ASSIGN;
5527 }
5528 }
5529 yylval = install_and_save("-");
5530 return '-';
5531 case '>':
5532 if (nextchar('=')) {
5533 yylval = install_and_save(">=");
5534 return GE;
5535 }
5536 yylval = install_and_save(">");
5537 return GT;
5538 case '!':
5539 if (nextchar('=')) {
5540 yylval = install_and_save("!=");
5541 return NE;
5542 }
5543 yylval = install_and_save("!");
5544 return '!';
5545 case '=':
5546 if (nextchar('=')) {
5547 yylval = install_and_save("==");
5548 return EQ;
5549 }
5550 else if (nextchar('>')) {
5551 yylval = install_and_save("=>");
5552 return PIPEBIND;
5553 }
5554 yylval = install_and_save("=");
5555 return EQ_ASSIGN;
5556 case ':':
5557 if (nextchar(':')) {
5558 if (nextchar(':')) {
5559 yylval = install_and_save(":::");
5560 return NS_GET_INT;
5561 }
5562 else {
5563 yylval = install_and_save("::");
5564 return NS_GET;
5565 }
5566 }
5567 if (nextchar('=')) {
5568 yylval = install_and_save(":=");
5569 return LEFT_ASSIGN;
5570 }
5571 yylval = install_and_save(":");
5572 return ':';
5573 case '&':
5574 if (nextchar('&')) {
5575 yylval = install_and_save("&&");
5576 return AND2;
5577 }
5578 yylval = install_and_save("&");
5579 return AND;
5580 case '|':
5581 if (nextchar('|')) {
5582 yylval = install_and_save("||");
5583 return OR2;
5584 }
5585 else if (nextchar('>')) {
5586 yylval = install_and_save("|>");
5587 return PIPE;
5588 }
5589 yylval = install_and_save("|");
5590 return OR;
5591 case LBRACE:
5592 yylval = install_and_save("{");
5593 return c;
5594 case RBRACE:
5595 strcpy(yytext, "}");
5596 return c;
5597 case '(':
5598 yylval = install_and_save("(");
5599 return c;
5600 case ')':
5601 strcpy(yytext, ")");
5602 return c;
5603 case '[':
5604 if (nextchar('[')) {
5605 yylval = install_and_save("[[");
5606 return LBB;
5607 }
5608 yylval = install_and_save("[");
5609 return c;
5610 case ']':
5611 strcpy(yytext, "]");
5612 return c;
5613 case '?':
5614 yylval = install_and_save("?");
5615 return c;
5616 case '*':
5617 /* Replace ** by ^. This has been here since 1998, but is
5618 undocumented (at least in the obvious places). It is in
5619 the index of the Blue Book with a reference to p. 431, the
5620 help for 'Deprecated'. S-PLUS 6.2 still allowed this, so
5621 presumably it was for compatibility with S. */
5622 if (nextchar('*')) {
5623 yylval = install_and_save2("^", "**");
5624 return '^';
5625 } else
5626 yylval = install_and_save("*");
5627 return c;
5628 case '+':
5629 case '/':
5630 case '^':
5631 case '~':
5632 case '$':
5633 case '@':
5634 case '\\':
5635 yytext[0] = (char) c;
5636 yytext[1] = '\0';
5637 yylval = install(yytext);
5638 return c;
5639 default:
5640 yytext[0] = (char) c;
5641 yytext[1] = '\0';
5642 return c;
5643 }
5644 }
5645
5646 /**
5647 * Sets the first elements of the yyloc structure with current
5648 * information
5649 */
setfirstloc(void)5650 static void setfirstloc(void)
5651 {
5652 yylloc.first_line = ParseState.xxlineno;
5653 yylloc.first_column = ParseState.xxcolno;
5654 yylloc.first_byte = ParseState.xxbyteno;
5655 yylloc.first_parsed = ParseState.xxparseno;
5656 }
5657
setlastloc(void)5658 static void setlastloc(void)
5659 {
5660 yylloc.last_line = ParseState.xxlineno;
5661 yylloc.last_column = ParseState.xxcolno;
5662 yylloc.last_byte = ParseState.xxbyteno;
5663 yylloc.last_parsed = ParseState.xxparseno;
5664 }
5665
5666 /**
5667 * Wrap around the token function. Returns the same result
5668 * but increments the identifier, after a call to token_,
5669 * the identifier variable contains the id of the token
5670 * just returned
5671 *
5672 * @return the same as token
5673 */
5674
token_(void)5675 static int token_(void){
5676 // capture the position before retrieving the token
5677 setfirstloc( ) ;
5678
5679 // get the token
5680 int res = token( ) ;
5681
5682 // capture the position after
5683 int _last_col = ParseState.xxcolno ;
5684 int _last_parsed = ParseState.xxparseno ;
5685
5686 _current_token = res ;
5687 incrementId( ) ;
5688 yylloc.id = identifier ;
5689
5690 // record the position
5691 if( res != '\n' && res != END_OF_INPUT)
5692 record_( yylloc.first_parsed, yylloc.first_column,
5693 _last_parsed, _last_col,
5694 res, identifier, yytext );
5695
5696 return res;
5697 }
5698
5699
yylex(void)5700 static int yylex(void)
5701 {
5702 int tok;
5703
5704 again:
5705
5706 tok = token_();
5707
5708 /* Newlines must be handled in a context */
5709 /* sensitive way. The following block of */
5710 /* deals directly with newlines in the */
5711 /* body of "if" statements. */
5712
5713 if (tok == '\n') {
5714
5715 if (EatLines || *contextp == '[' || *contextp == '(')
5716 goto again;
5717
5718 /* The essence of this is that in the body of */
5719 /* an "if", any newline must be checked to */
5720 /* see if it is followed by an "else". */
5721 /* such newlines are discarded. */
5722
5723 if (*contextp == 'i') {
5724
5725 /* Find the next non-newline token */
5726
5727 while(tok == '\n')
5728 tok = token_();
5729
5730 /* If we encounter "}", ")" or "]" then */
5731 /* we know that all immediately preceding */
5732 /* "if" bodies have been terminated. */
5733 /* The corresponding "i" values are */
5734 /* popped off the context stack. */
5735
5736 if (tok == RBRACE || tok == ')' || tok == ']' ) {
5737 while (*contextp == 'i')
5738 ifpop();
5739 *contextp-- = 0;
5740 setlastloc();
5741 return tok;
5742 }
5743
5744 /* When a "," is encountered, it terminates */
5745 /* just the immediately preceding "if" body */
5746 /* so we pop just a single "i" of the */
5747 /* context stack. */
5748
5749 if (tok == ',') {
5750 ifpop();
5751 setlastloc();
5752 return tok;
5753 }
5754
5755 /* Tricky! If we find an "else" we must */
5756 /* ignore the preceding newline. Any other */
5757 /* token means that we must return the newline */
5758 /* to terminate the "if" and "push back" that */
5759 /* token so that we will obtain it on the next */
5760 /* call to token. In either case sensitivity */
5761 /* is lost, so we pop the "i" from the context */
5762 /* stack. */
5763
5764 if(tok == ELSE) {
5765 EatLines = 1;
5766 ifpop();
5767 setlastloc();
5768 return ELSE;
5769 }
5770 else {
5771 ifpop();
5772 SavedToken = tok;
5773 xxlinesave = yylloc.first_line;
5774 xxcolsave = yylloc.first_column;
5775 xxbytesave = yylloc.first_byte;
5776 xxparsesave = yylloc.first_parsed;
5777 SavedLval = yylval;
5778 setlastloc();
5779 if (ParseState.keepSrcRefs && ParseState.keepParseData &&
5780 yytext[0])
5781
5782 /* unrecord the pushed back token if not null */
5783 ParseState.data_count--;
5784 return '\n';
5785 }
5786 }
5787 else {
5788 setlastloc();
5789 return '\n';
5790 }
5791 }
5792
5793 /* Additional context sensitivities */
5794
5795 switch(tok) {
5796
5797 /* Any newlines immediately following the */
5798 /* the following tokens are discarded. The */
5799 /* expressions are clearly incomplete. */
5800
5801 case '+':
5802 case '-':
5803 case '*':
5804 case '/':
5805 case '^':
5806 case LT:
5807 case LE:
5808 case GE:
5809 case GT:
5810 case EQ:
5811 case NE:
5812 case OR:
5813 case AND:
5814 case OR2:
5815 case AND2:
5816 case PIPE:
5817 case PIPEBIND:
5818 case SPECIAL:
5819 case FUNCTION:
5820 case WHILE:
5821 case REPEAT:
5822 case FOR:
5823 case IN:
5824 case '?':
5825 case '!':
5826 case '=':
5827 case ':':
5828 case '~':
5829 case '$':
5830 case '@':
5831 case LEFT_ASSIGN:
5832 case RIGHT_ASSIGN:
5833 case EQ_ASSIGN:
5834 EatLines = 1;
5835 break;
5836
5837 /* Push any "if" statements found and */
5838 /* discard any immediately following newlines. */
5839
5840 case IF:
5841 IfPush();
5842 EatLines = 1;
5843 break;
5844
5845 /* Terminate any immediately preceding "if" */
5846 /* statements and discard any immediately */
5847 /* following newlines. */
5848
5849 case ELSE:
5850 ifpop();
5851 EatLines = 1;
5852 break;
5853
5854 /* These tokens terminate any immediately */
5855 /* preceding "if" statements. */
5856
5857 case ';':
5858 case ',':
5859 ifpop();
5860 break;
5861
5862 /* Any newlines following these tokens can */
5863 /* indicate the end of an expression. */
5864
5865 case SYMBOL:
5866 case STR_CONST:
5867 case NUM_CONST:
5868 case NULL_CONST:
5869 case NEXT:
5870 case BREAK:
5871 EatLines = 0;
5872 break;
5873
5874 /* Handle brackets, braces and parentheses */
5875
5876 case LBB:
5877 if(contextp - contextstack >= CONTEXTSTACK_SIZE - 1)
5878 error(_("contextstack overflow at line %d"), ParseState.xxlineno);
5879 *++contextp = '[';
5880 *++contextp = '[';
5881 break;
5882
5883 case '[':
5884 if(contextp - contextstack >= CONTEXTSTACK_SIZE)
5885 error(_("contextstack overflow at line %d"), ParseState.xxlineno);
5886 *++contextp = (char) tok;
5887 break;
5888
5889 case LBRACE:
5890 if(contextp - contextstack >= CONTEXTSTACK_SIZE)
5891 error(_("contextstack overflow at line %d"), ParseState.xxlineno);
5892 *++contextp = (char) tok;
5893 EatLines = 1;
5894 break;
5895
5896 case '(':
5897 if(contextp - contextstack >= CONTEXTSTACK_SIZE)
5898 error(_("contextstack overflow at line %d"), ParseState.xxlineno);
5899 *++contextp = (char) tok;
5900 break;
5901
5902 case ']':
5903 while (*contextp == 'i')
5904 ifpop();
5905 *contextp-- = 0;
5906 EatLines = 0;
5907 break;
5908
5909 case RBRACE:
5910 while (*contextp == 'i')
5911 ifpop();
5912 *contextp-- = 0;
5913 break;
5914
5915 case ')':
5916 while (*contextp == 'i')
5917 ifpop();
5918 *contextp-- = 0;
5919 EatLines = 0;
5920 break;
5921
5922 }
5923 setlastloc();
5924 return tok;
5925 }
5926 /**
5927 * Records location information about a symbol. The information is
5928 * used to fill the data
5929 *
5930 */
record_(int first_parsed,int first_column,int last_parsed,int last_column,int token,int id,char * text_in)5931 static void record_( int first_parsed, int first_column, int last_parsed, int last_column,
5932 int token, int id, char* text_in ){
5933
5934 if (!ParseState.keepSrcRefs || !ParseState.keepParseData
5935 || id == NA_INTEGER) return;
5936
5937 // don't care about zero sized things
5938 if( !yytext[0] ) return ;
5939
5940 if (ParseState.data_count == DATA_COUNT)
5941 growData();
5942
5943 _FIRST_COLUMN( ParseState.data_count ) = first_column;
5944 _FIRST_PARSED( ParseState.data_count ) = first_parsed;
5945 _LAST_COLUMN( ParseState.data_count ) = last_column;
5946 _LAST_PARSED( ParseState.data_count ) = last_parsed;
5947 _TOKEN( ParseState.data_count ) = token;
5948 _ID( ParseState.data_count ) = id ;
5949 _PARENT(ParseState.data_count) = 0 ;
5950 if ( text_in )
5951 SET_STRING_ELT(PS_TEXT, ParseState.data_count, mkChar2(text_in));
5952 else
5953 SET_STRING_ELT(PS_TEXT, ParseState.data_count, mkChar(""));
5954
5955 if( id > ID_COUNT )
5956 growID(id) ;
5957
5958 ID_ID( id ) = ParseState.data_count ;
5959
5960 ParseState.data_count++ ;
5961 }
5962
5963 /**
5964 * records parent as the parent of all its childs. This grows the
5965 * parents list with a new vector. The first element of the new
5966 * vector is the parent id, and other elements are childs id
5967 *
5968 * @param parent id of the parent expression
5969 * @param childs array of location information for all child symbols
5970 * @param nchilds number of childs
5971 */
recordParents(int parent,yyltype * childs,int nchilds)5972 static void recordParents( int parent, yyltype * childs, int nchilds){
5973
5974 if( parent > ID_COUNT ){
5975 growID(parent) ;
5976 }
5977
5978 /* some of the childs might be an empty token (like cr)
5979 which we do not want to track */
5980 int ii; /* loop index */
5981 yyltype loc ;
5982 for( ii=0; ii<nchilds; ii++){
5983 loc = childs[ii] ;
5984 if( loc.id == NA_INTEGER || (loc.first_line == loc.last_line && loc.first_byte > loc.last_byte) )
5985 continue ;
5986 /* This shouldn't happen... */
5987 if (loc.id < 0 || loc.id > identifier) {
5988 error(_("internal parser error at line %d"), ParseState.xxlineno);
5989 }
5990 ID_PARENT( loc.id ) = parent;
5991 }
5992
5993 }
5994
5995 /**
5996 * The token pointed by the location has the wrong token type,
5997 * This updates the type
5998 *
5999 * @param loc location information for the token to track
6000 */
modif_token(yyltype * loc,int tok)6001 static void modif_token( yyltype* loc, int tok ){
6002
6003 int id = loc->id ;
6004
6005 if (!ParseState.keepSrcRefs || !ParseState.keepParseData
6006 || id < 0 || id > ID_COUNT) return;
6007
6008 if( tok == SYMBOL_FUNCTION_CALL ){
6009 // looking for first child of id
6010 int j = ID_ID( id ) ;
6011 int parent = id ;
6012
6013 if (j < 0 || j > ID_COUNT)
6014 return;
6015
6016 while( ID_PARENT( _ID(j) ) != parent ){
6017 j-- ;
6018 if (j < 0)
6019 return;
6020 }
6021
6022 if( _TOKEN(j) == SYMBOL ){
6023 _TOKEN(j) = SYMBOL_FUNCTION_CALL ;
6024 }
6025
6026 } else{
6027 _TOKEN( ID_ID(id) ) = tok ;
6028 }
6029
6030 }
6031
6032 /* this local version of lengthgets() always copies and doesn't fill with NA */
lengthgets2(SEXP x,int len)6033 static SEXP lengthgets2(SEXP x, int len) {
6034 SEXP result;
6035 PROTECT(result = allocVector( TYPEOF(x), len ));
6036
6037 len = (len < length(x)) ? len : length(x);
6038 switch(TYPEOF(x)) {
6039 case INTSXP:
6040 for (int i = 0; i < len; i++)
6041 INTEGER(result)[i] = INTEGER(x)[i];
6042 for (int i = len; i < length(result); i++)
6043 INTEGER(result)[i] = 0;
6044 break;
6045 case STRSXP:
6046 for (int i = 0; i < len; i++)
6047 SET_STRING_ELT(result, i, STRING_ELT(x, i));
6048 break;
6049 default:
6050 UNIMPLEMENTED_TYPE("lengthgets2", x);
6051 }
6052 UNPROTECT(1); /* result */
6053 return result;
6054 }
6055
finalizeData()6056 static void finalizeData( ){
6057
6058 int nloc = ParseState.data_count ;
6059
6060 int i, j, id ;
6061 int parent ;
6062
6063 /* store parents in the data */
6064 for( i=0; i<nloc; i++){
6065 id = _ID(i);
6066 parent = ID_PARENT( id ) ;
6067 while( parent != 0 && ID_ID(parent) == 0 )
6068 parent = ID_PARENT( parent ) ;
6069 _PARENT(i) = parent ;
6070
6071 #define FD_FAST_UPDATE_PARENTS
6072 #ifdef FD_FAST_UPDATE_PARENTS
6073 /*
6074 With long generated expressions, updating the parents can take
6075 a lot of time due to long chains of nodes not represented in the
6076 parse data. To reduce the overhead somewhat, we create shortcuts
6077 in the IDS array to point directly to the parent that is in the
6078 parse data.
6079 */
6080 int data_parent = parent;
6081 parent = ID_PARENT( id ) ;
6082 while( parent != data_parent ){
6083 ID_PARENT( id ) = data_parent; /* set shortcut */
6084 id = parent;
6085 parent = ID_PARENT( parent );
6086 }
6087 #endif
6088 }
6089
6090 /* attach comments to closest enclosing symbol */
6091 /* not updating ID_PARENT anymore */
6092
6093 #define FD_FAST_ASSIGN_COMMENTS
6094 #ifdef FD_FAST_ASSIGN_COMMENTS
6095 /*
6096 All terminals (tokens) are ordered by start and end location, including
6097 the comments, in the data.
6098
6099 All non-terminals, including to be found parents of the comments, are
6100 ordered by their end location. When they have the same end location
6101 in the code, they are ordered by their decreasing start location
6102 (children before parents).
6103
6104 All terminals and non-terminals are also before their parents (if any),
6105 so a comment is also befor its parent in the data.
6106
6107 Consequently: the first non-terminal after a comment that encloses the
6108 comment is its (immediate) parent. The original algorithm for every
6109 comment linearly searches for the first enclosing non-terminal and
6110 returns it, but it has quadratic complexity and dominates the whole
6111 parsing for long inputs (used when FD_FAST_ASSIGN_COMMENTS is not
6112 defined).
6113
6114 This algorithm uses the parental information available on nodes that
6115 follow the comments. That information has been filled by the parser
6116 during reductions (but not for comments, because those are not in the
6117 grammar). A node following a comment is either the parent of the
6118 comment, or some of its parents are, or is an orphan.
6119
6120 Note that a non-terminal may end before a terminal (e.g. comment) in the
6121 code but be after the terminal in the data (due to look-ahead). It seems
6122 that the parent of the comment has to be within parents of the
6123 non-terminal as well, but I am not sure how to prove it, so the algorithm
6124 just skips non-terminals preceding the comment in the code (so is not
6125 strictly linear).
6126 */
6127
6128 for(i = nloc-1; i >= 0; i--) {
6129 if (_TOKEN(i) == COMMENT) {
6130 int orphan = 1;
6131 int istartl = _FIRST_PARSED(i);
6132 int istartc = _FIRST_COLUMN(i);
6133
6134 /* look for first node j that does not end before the comment i */
6135 for(j = i + 1; j < nloc && _LAST_PARSED(j) <= istartl; j++);
6136
6137 if (j < nloc) {
6138 for(;;) {
6139 int jstartl = _FIRST_PARSED(j);
6140 int jstartc = _FIRST_COLUMN(j);
6141
6142 if (jstartl < istartl || (jstartl == istartl
6143 && jstartc <= istartc)) {
6144 /* j starts before or at the comment */
6145 _PARENT(i) = _ID(j);
6146 orphan = 0;
6147 break;
6148 }
6149 /* find parent of j */
6150 int jparent = _PARENT(j);
6151 if (jparent == 0)
6152 break; /* orphan */
6153 j = ID_ID(jparent);
6154 }
6155 }
6156 if (orphan)
6157 _PARENT(i) = 0;
6158 }
6159 }
6160 #else
6161 /* the original algorithm, which is slow for large inputs */
6162
6163 int comment_line, comment_first_col;
6164 int this_first_parsed, this_last_parsed, this_first_col ;
6165 int orphan ;
6166
6167 for( i=0; i<nloc; i++){
6168 if( _TOKEN(i) == COMMENT ){
6169 comment_line = _FIRST_PARSED( i ) ;
6170 comment_first_col = _FIRST_COLUMN( i ) ;
6171
6172 orphan = 1 ;
6173 for( j=i+1; j<nloc; j++){
6174 this_first_parsed = _FIRST_PARSED( j ) ;
6175 this_first_col = _FIRST_COLUMN( j ) ;
6176 this_last_parsed = _LAST_PARSED( j ) ;
6177
6178 /* the comment needs to start after the current symbol */
6179 if( comment_line < this_first_parsed ) continue ;
6180 if( (comment_line == this_first_parsed) & (comment_first_col < this_first_col) ) continue ;
6181
6182 /* the current symbol must finish after the comment */
6183 if( this_last_parsed <= comment_line ) continue ;
6184
6185 /* we have a match, record the parent and stop looking */
6186 _PARENT(i) = _ID(j);
6187 orphan = 0;
6188 break ;
6189 }
6190 if(orphan){
6191 _PARENT(i) = 0 ;
6192 }
6193 }
6194 }
6195 #endif
6196
6197
6198 /* now rework the parents of comments, we try to attach
6199 comments that are not already attached (parent=0) to the next
6200 enclosing top-level expression */
6201
6202 for( i=0; i<nloc; i++){
6203 int token = _TOKEN(i);
6204 if( token == COMMENT && _PARENT(i) == 0 ){
6205 for( j=i; j<nloc; j++){
6206 int token_j = _TOKEN(j);
6207 if( token_j == COMMENT ) continue ;
6208 if( _PARENT(j) != 0 ) continue ;
6209 _PARENT(i) = - _ID(j) ;
6210 break ;
6211 }
6212 }
6213 }
6214
6215 /* attach the token names as an attribute so we don't need to switch to a dataframe, and decide on terminals */
6216 SEXP tokens;
6217 PROTECT(tokens = allocVector( STRSXP, nloc ) );
6218 for (int i=0; i<nloc; i++) {
6219 int token = _TOKEN(i);
6220 int xlat = yytranslate[token];
6221 if (xlat == 2) /* "unknown" */
6222 xlat = token;
6223 if (xlat < YYNTOKENS + YYNNTS)
6224 SET_STRING_ELT(tokens, i, mkChar(yytname[xlat]));
6225 else { /* we have a token which doesn't have a name, e.g. an illegal character as in PR#15518 */
6226 char name[2];
6227 name[0] = (char) xlat;
6228 name[1] = 0;
6229 SET_STRING_ELT(tokens, i, mkChar(name));
6230 }
6231 _TERMINAL(i) = xlat < YYNTOKENS;
6232 }
6233 SEXP dims, newdata, newtext;
6234 if (nloc) {
6235 PROTECT( newdata = lengthgets2(PS_DATA, nloc * DATA_ROWS));
6236 PROTECT( newtext = lengthgets2(PS_TEXT, nloc));
6237 } else {
6238 PROTECT( newdata = allocVector( INTSXP, 0));
6239 PROTECT( newtext = allocVector( STRSXP, 0));
6240 }
6241 PROTECT( dims = allocVector( INTSXP, 2 ) ) ;
6242 INTEGER(dims)[0] = DATA_ROWS ;
6243 INTEGER(dims)[1] = nloc ;
6244 setAttrib( newdata, install( "dim" ), dims ) ;
6245 setAttrib( newdata, install("tokens"), tokens );
6246 setAttrib( newdata, install("text"), newtext );
6247
6248 setAttrib(newdata, R_ClassSymbol, mkString("parseData"));
6249
6250 /* Put it into the srcfile environment */
6251 if (isEnvironment(PS_SRCFILE))
6252 defineVar(install("parseData"), newdata, PS_SRCFILE);
6253 UNPROTECT(4); /* tokens, newdata, newtext, dims */
6254 }
6255
6256 /**
6257 * Grows the data
6258 */
growData()6259 static void growData(){
6260
6261 int new_data_count;
6262 if (PS_DATA == R_NilValue) {
6263 new_data_count = INIT_DATA_COUNT;
6264 PS_SET_DATA(allocVector(INTSXP, 0));
6265 PS_SET_TEXT(allocVector(STRSXP, 0));
6266 } else
6267 new_data_count = 2*DATA_COUNT;
6268
6269 PS_SET_DATA(lengthgets2(PS_DATA, new_data_count * DATA_ROWS));
6270 PS_SET_TEXT(lengthgets2(PS_TEXT, new_data_count));
6271 }
6272
6273 /**
6274 * Grows the ids vector so that ID_ID(target) can be called
6275 */
growID(int target)6276 static void growID( int target ){
6277
6278 int new_count;
6279 if (PS_IDS == R_NilValue) {
6280 new_count = INIT_DATA_COUNT/2 - 1;
6281 PS_SET_IDS(allocVector(INTSXP, 0));
6282 } else
6283 new_count = ID_COUNT;
6284
6285 while (target > new_count)
6286 new_count = 2*new_count + 1;
6287
6288 if (new_count <= ID_COUNT)
6289 return;
6290
6291 int new_size = (1 + new_count)*2;
6292 PS_SET_IDS(lengthgets2(PS_IDS, new_size));
6293 }
6294
checkForPlaceholder(SEXP placeholder,SEXP arg)6295 static int checkForPlaceholder(SEXP placeholder, SEXP arg)
6296 {
6297 if (arg == placeholder)
6298 return TRUE;
6299 else if (TYPEOF(arg) == LANGSXP)
6300 for (SEXP cur = arg; cur != R_NilValue; cur = CDR(cur))
6301 if (checkForPlaceholder(placeholder, CAR(cur)))
6302 return TRUE;
6303 return FALSE;
6304 }
6305
signal_ph_error(SEXP rhs,SEXP ph)6306 static void NORET signal_ph_error(SEXP rhs, SEXP ph) {
6307 errorcall(rhs, _("pipe placeholder must only appear as a top-level "
6308 "argument in the RHS call"));
6309 }
6310
findPlaceholderCell(SEXP placeholder,SEXP rhs)6311 static SEXP findPlaceholderCell(SEXP placeholder, SEXP rhs)
6312 {
6313 SEXP phcell = NULL;
6314 int count = 0;
6315 if (checkForPlaceholder(placeholder, CAR(rhs)))
6316 signal_ph_error(rhs, placeholder);
6317 for (SEXP a = CDR(rhs); a != R_NilValue; a = CDR(a))
6318 if (CAR(a) == placeholder) {
6319 if (phcell == NULL)
6320 phcell = a;
6321 count++;
6322 }
6323 else if (checkForPlaceholder(placeholder, CAR(a)))
6324 signal_ph_error(rhs, placeholder);
6325 if (count > 1)
6326 errorcall(rhs, _("pipe placeholder may only appear once"));
6327 return phcell;
6328 }
6329