Coverage Report

Created: 2026-11-30 07:09

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