/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 | 6.82k | #define PARSE_ERROR_SIZE 256 /* Parse error messages saved here */ |
112 | 10.9M | #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 | 12.2k | #define MAX_DATA_COUNT 65536 /* release it at the end if it is this size or larger*/ |
154 | | |
155 | 1.07M | #define DATA_COUNT (length( PS_DATA ) / DATA_ROWS) |
156 | 2.04M | #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 | 19.3M | #define DATA_ROWS 8 |
163 | | |
164 | 1.74M | #define _FIRST_PARSED( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) ] |
165 | 1.74M | #define _FIRST_COLUMN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 1 ] |
166 | 1.51M | #define _LAST_PARSED( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 2 ] |
167 | 1.07M | #define _LAST_COLUMN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 3 ] |
168 | 941k | #define _TERMINAL( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 4 ] |
169 | 4.47M | #define _TOKEN( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 5 ] |
170 | 2.24M | #define _ID( i ) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 6 ] |
171 | 4.49M | #define _PARENT(i) INTEGER( PS_DATA )[ DATA_ROWS*(i) + 7 ] |
172 | | |
173 | 6.42M | #define ID_ID( i ) INTEGER(PS_IDS)[ 2*(i) ] |
174 | 8.90M | #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 | 1.19M | static void setId(yyltype loc){ |
187 | 1.19M | record_( |
188 | 1.19M | (loc).first_parsed, (loc).first_column, (loc).last_parsed, (loc).last_column, |
189 | 1.19M | _current_token, (loc).id, 0 ) ; |
190 | 1.19M | } |
191 | | |
192 | 1.63M | # define YYLTYPE yyltype |
193 | | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
194 | 2.46M | do { \ |
195 | 2.46M | if (N){ \ |
196 | 2.44M | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ |
197 | 2.44M | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ |
198 | 2.44M | (Current).first_byte = YYRHSLOC (Rhs, 1).first_byte; \ |
199 | 2.44M | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ |
200 | 2.44M | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ |
201 | 2.44M | (Current).last_byte = YYRHSLOC (Rhs, N).last_byte; \ |
202 | 2.44M | (Current).first_parsed = YYRHSLOC (Rhs, 1).first_parsed; \ |
203 | 2.44M | (Current).last_parsed = YYRHSLOC (Rhs, N).last_parsed; \ |
204 | 2.44M | incrementId( ) ; \ |
205 | 2.44M | (Current).id = identifier ; \ |
206 | 2.44M | _current_token = yyr1[yyn] ; \ |
207 | 2.44M | if (ParseState.keepSrcRefs && ParseState.keepParseData) { \ |
208 | 954k | yyltype childs[N]; \ |
209 | 954k | int ii = 0; \ |
210 | 2.32M | for(ii=0; ii<N; ii++){ \ |
211 | 1.37M | childs[ii] = YYRHSLOC (Rhs, (ii+1) ) ; \ |
212 | 1.37M | } \ |
213 | 954k | recordParents( identifier, childs, N) ; \ |
214 | 954k | } \ |
215 | 2.44M | } else { \ |
216 | 19.2k | (Current).first_line = (Current).last_line = \ |
217 | 19.2k | YYRHSLOC (Rhs, 0).last_line; \ |
218 | 19.2k | (Current).first_parsed = (Current).last_parsed = \ |
219 | 19.2k | YYRHSLOC (Rhs, 0).last_parsed; \ |
220 | 19.2k | (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \ |
221 | 19.2k | (Current).last_column = (Current).first_column - 1; \ |
222 | 19.2k | (Current).first_byte = YYRHSLOC (Rhs, 0).last_byte; \ |
223 | 19.2k | (Current).last_byte = (Current).first_byte - 1; \ |
224 | 19.2k | (Current).id = NA_INTEGER; \ |
225 | 19.2k | } \ |
226 | 2.46M | } 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 | 11.9k | #define LBRACE '{' |
238 | 5.58k | #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 | 4.11k | #define PS_SET_SRCREFS(x) SET_VECTOR_ELT(ParseState.sexps, 0, (x)) |
288 | 19.7k | #define PS_SET_SRCFILE(x) SET_VECTOR_ELT(ParseState.sexps, 1, (x)) |
289 | 19.7k | #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 | 6 | #define PS_SET_IDS(x) SET_VECTOR_ELT(ParseState.sexps, 5, (x)) |
300 | 32 | #define PS_SET_SVS(x) SET_VECTOR_ELT(ParseState.sexps, 6, (x)) |
301 | | |
302 | 205k | #define PS_SRCREFS VECTOR_ELT(ParseState.sexps, 0) |
303 | 7.36k | #define PS_SRCFILE VECTOR_ELT(ParseState.sexps, 1) |
304 | 2.60k | #define PS_ORIGINAL VECTOR_ELT(ParseState.sexps, 2) |
305 | 18.2M | #define PS_DATA ParseState.data |
306 | 2.14M | #define PS_TEXT VECTOR_ELT(ParseState.sexps, 4) |
307 | 15.3M | #define PS_IDS VECTOR_ELT(ParseState.sexps, 5) |
308 | 2.65M | #define PS_SVS VECTOR_ELT(ParseState.sexps, 6) |
309 | | |
310 | | /* These definitions are for error conditions */ |
311 | 4.92k | #define NO_VALUE 0 |
312 | 891 | #define STRING_VALUE 1 |
313 | 102 | #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 | 32 | #define INIT_SVS() PS_SET_SVS(R_NewPreciousMSet(200)) |
350 | 1.33M | #define PRESERVE_SV(x) R_PreserveInMSet((x), PS_SVS) |
351 | 1.31M | #define RELEASE_SV(x) R_ReleaseFromMSet((x), PS_SVS) |
352 | 10.8k | #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 | 1.09k | #define YYFREE yystack_free |
370 | | |
371 | | static void *yystack_malloc(size_t size) |
372 | 1.10k | { |
373 | 1.10k | void *p = malloc(size); |
374 | 1.10k | if (p) |
375 | 1.10k | ParseState.yystack = p; |
376 | 1.10k | return p; |
377 | 1.10k | } |
378 | | |
379 | | static void yystack_free(void *p) |
380 | 1.09k | { |
381 | 1.09k | if (p == ParseState.yystack) |
382 | 536 | ParseState.yystack = NULL; |
383 | 1.09k | free(p); |
384 | 1.09k | } |
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.30M | #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 | 8.66M | # 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 | 8.91k | # 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 | 5.81M | #define YYEMPTY -2 |
583 | 3.47M | #define YYEOF 0 |
584 | 3.47M | #define YYerror 256 |
585 | 0 | #define YYUNDEF 257 |
586 | 1.36M | #define END_OF_INPUT 258 |
587 | 1.05k | #define ERROR 259 |
588 | 437k | #define STR_CONST 260 |
589 | 794k | #define NUM_CONST 261 |
590 | 608k | #define NULL_CONST 262 |
591 | 772k | #define SYMBOL 263 |
592 | 51.1k | #define FUNCTION 264 |
593 | 572 | #define INCOMPLETE_STRING 265 |
594 | 441k | #define LEFT_ASSIGN 266 |
595 | 746k | #define EQ_ASSIGN 267 |
596 | 438k | #define RIGHT_ASSIGN 268 |
597 | 702 | #define LBB 269 |
598 | 53.8k | #define FOR 270 |
599 | 51.0k | #define IN 271 |
600 | 10.6k | #define IF 272 |
601 | 4.14k | #define ELSE 273 |
602 | 52.1k | #define WHILE 274 |
603 | 617k | #define NEXT 275 |
604 | 618k | #define BREAK 276 |
605 | 53.1k | #define REPEAT 277 |
606 | 40.8k | #define GT 278 |
607 | 38.8k | #define GE 279 |
608 | 38.9k | #define LT 280 |
609 | 38.4k | #define LE 281 |
610 | 41.9k | #define EQ 282 |
611 | 41.4k | #define NE 283 |
612 | 43.7k | #define AND 284 |
613 | 43.4k | #define OR 285 |
614 | 44.6k | #define AND2 286 |
615 | 43.2k | #define OR2 287 |
616 | 1.84k | #define NS_GET 288 |
617 | 302 | #define NS_GET_INT 289 |
618 | 5.20M | #define COMMENT 290 |
619 | 4.19M | #define LINE_DIRECTIVE 291 |
620 | 4.03k | #define SYMBOL_FORMALS 292 |
621 | 515 | #define EQ_FORMALS 293 |
622 | 5.46k | #define EQ_SUB 294 |
623 | 3.97k | #define SYMBOL_SUB 295 |
624 | 51.6k | #define SYMBOL_FUNCTION_CALL 296 |
625 | 643 | #define SYMBOL_PACKAGE 297 |
626 | 766 | #define SLOT 298 |
627 | 46.4k | #define PIPE 299 |
628 | 431k | #define PLACEHOLDER 300 |
629 | 46.5k | #define PIPEBIND 301 |
630 | | #define LOW 302 |
631 | | #define TILDE 303 |
632 | | #define UNOT 304 |
633 | | #define NOT 305 |
634 | 48.2k | #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 | 667k | # 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 | 6.49k | YY_CAST (YYPTRDIFF_T, \ |
867 | | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ |
868 | | ? YYPTRDIFF_MAXIMUM \ |
869 | | : YY_CAST (YYSIZE_T, -1))) |
870 | | |
871 | 9.98k | #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 | 2.42k | # 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 | 178k | # 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 | 4.14M | #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 | 1.09k | # define YYSTACK_FREE YYFREE |
997 | | # ifndef YYSTACK_ALLOC_MAXIMUM |
998 | 6.49k | # 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 | 3.32k | # 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 | 3.32k | do \ |
1055 | 3.32k | { \ |
1056 | 3.32k | YYPTRDIFF_T yynewbytes; \ |
1057 | 3.32k | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
1058 | 3.32k | Stack = &yyptr->Stack_alloc; \ |
1059 | 3.32k | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
1060 | 3.32k | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ |
1061 | 3.32k | } \ |
1062 | 3.32k | 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 | 3.32k | __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 | 4.14M | #define YYFINAL 48 |
1088 | | /* YYLAST -- Last index in YYTABLE. */ |
1089 | 7.21M | #define YYLAST 572 |
1090 | | |
1091 | | /* YYNTOKENS -- Number of terminals. */ |
1092 | 4.02M | #define YYNTOKENS 75 |
1093 | | /* YYNNTS -- Number of nonterminals. */ |
1094 | 941k | #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 | 4.42M | #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 | 4.42M | (0 <= (YYX) && (YYX) <= YYMAXUTOK \ |
1108 | 4.42M | ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ |
1109 | 4.42M | : 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 | 57.6k | #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 | 4.20M | #define YYPACT_NINF (-130) |
1201 | | |
1202 | | #define yypact_value_is_default(Yyn) \ |
1203 | 4.20M | ((Yyn) == YYPACT_NINF) |
1204 | | |
1205 | 8.72k | #define YYTABLE_NINF (-1) |
1206 | | |
1207 | | #define yytable_value_is_error(Yyn) \ |
1208 | 8.72k | ((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 | 323k | #define YYACCEPT goto yyacceptlab |
1461 | 1.97k | #define YYABORT goto yyabortlab |
1462 | 0 | #define YYERROR goto yyerrorlab |
1463 | 1 | #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 | 21.0M | #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 | 6.16M | # 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 | 326k | # 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 | 2.23k | # 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 | 2.42k | { |
1739 | | /* Actual size of YYARG. */ |
1740 | 2.42k | int yycount = 0; |
1741 | 2.42k | int yyn = yypact[+*yyctx->yyssp]; |
1742 | 2.42k | if (!yypact_value_is_default (yyn)) |
1743 | 2.42k | { |
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 | 2.42k | int yyxbegin = yyn < 0 ? -yyn : 0; |
1748 | | /* Stay within bounds of both yycheck and yytname. */ |
1749 | 2.42k | int yychecklim = YYLAST - yyn + 1; |
1750 | 2.42k | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
1751 | 2.42k | int yyx; |
1752 | 117k | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
1753 | 115k | if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror |
1754 | 8.71k | && !yytable_value_is_error (yytable[yyx + yyn])) |
1755 | 8.63k | { |
1756 | 8.63k | if (!yyarg) |
1757 | 0 | ++yycount; |
1758 | 8.63k | else if (yycount == yyargn) |
1759 | 912 | return 0; |
1760 | 7.72k | else |
1761 | 7.72k | yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); |
1762 | 8.63k | } |
1763 | 2.42k | } |
1764 | 1.51k | if (yyarg && yycount == 0 && 0 < yyargn) |
1765 | 0 | yyarg[0] = YYSYMBOL_YYEMPTY; |
1766 | 1.51k | return yycount; |
1767 | 2.42k | } |
1768 | | |
1769 | | |
1770 | | |
1771 | | |
1772 | | #ifndef yystrlen |
1773 | | # if defined __GLIBC__ && defined _STRING_H |
1774 | 8.43k | # 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 | 6.01k | # 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 | 12.9k | { |
1819 | 12.9k | if (*yystr == '"') |
1820 | 962 | { |
1821 | 962 | YYPTRDIFF_T yyn = 0; |
1822 | 962 | char const *yyp = yystr; |
1823 | 962 | for (;;) |
1824 | 13.4k | switch (*++yyp) |
1825 | 13.4k | { |
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 | 12.5k | default: |
1838 | 12.5k | if (yyres) |
1839 | 6.25k | yyres[yyn] = *yyp; |
1840 | 12.5k | yyn++; |
1841 | 12.5k | break; |
1842 | | |
1843 | 962 | case '"': |
1844 | 962 | if (yyres) |
1845 | 481 | yyres[yyn] = '\0'; |
1846 | 962 | return yyn; |
1847 | 13.4k | } |
1848 | 0 | do_not_strip_quotes: ; |
1849 | 0 | } |
1850 | | |
1851 | 12.0k | if (yyres) |
1852 | 6.01k | return yystpcpy (yyres, yystr) - yyres; |
1853 | 6.01k | else |
1854 | 6.01k | return yystrlen (yystr); |
1855 | 12.0k | } |
1856 | | #endif |
1857 | | |
1858 | | |
1859 | | static int |
1860 | | yy_syntax_error_arguments (const yypcontext_t *yyctx, |
1861 | | yysymbol_kind_t yyarg[], int yyargn) |
1862 | 2.42k | { |
1863 | | /* Actual size of YYARG. */ |
1864 | 2.42k | 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 | 2.42k | if (yyctx->yytoken != YYSYMBOL_YYEMPTY) |
1889 | 2.42k | { |
1890 | 2.42k | int yyn; |
1891 | 2.42k | if (yyarg) |
1892 | 2.42k | yyarg[yycount] = yyctx->yytoken; |
1893 | 2.42k | ++yycount; |
1894 | 2.42k | yyn = yypcontext_expected_tokens (yyctx, |
1895 | 2.42k | yyarg ? yyarg + 1 : yyarg, yyargn - 1); |
1896 | 2.42k | if (yyn == YYENOMEM) |
1897 | 0 | return YYENOMEM; |
1898 | 2.42k | else |
1899 | 2.42k | yycount += yyn; |
1900 | 2.42k | } |
1901 | 2.42k | return yycount; |
1902 | 2.42k | } |
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 | 2.42k | { |
1916 | 2.42k | enum { YYARGS_MAX = 5 }; |
1917 | | /* Internationalized format string. */ |
1918 | 2.42k | const char *yyformat = YY_NULLPTR; |
1919 | | /* Arguments of yyformat: reported tokens (one for the "unexpected", |
1920 | | one per "expected"). */ |
1921 | 2.42k | yysymbol_kind_t yyarg[YYARGS_MAX]; |
1922 | | /* Cumulated lengths of YYARG. */ |
1923 | 2.42k | YYPTRDIFF_T yysize = 0; |
1924 | | |
1925 | | /* Actual size of YYARG. */ |
1926 | 2.42k | int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); |
1927 | 2.42k | if (yycount == YYENOMEM) |
1928 | 0 | return YYENOMEM; |
1929 | | |
1930 | 2.42k | switch (yycount) |
1931 | 2.42k | { |
1932 | 0 | #define YYCASE_(N, S) \ |
1933 | 2.42k | case N: \ |
1934 | 2.42k | yyformat = S; \ |
1935 | 2.42k | break |
1936 | 0 | default: /* Avoid compiler warnings. */ |
1937 | 0 | YYCASE_(0, YY_("syntax error")); |
1938 | 912 | YYCASE_(1, YY_("syntax error, unexpected %s")); |
1939 | 561 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); |
1940 | 62 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); |
1941 | 159 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); |
1942 | 2.42k | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); |
1943 | 2.42k | #undef YYCASE_ |
1944 | 2.42k | } |
1945 | | |
1946 | | /* Compute error message size. Don't count the "%s"s, but reserve |
1947 | | room for the terminator. */ |
1948 | 2.42k | yysize = yystrlen (yyformat) - 2 * yycount + 1; |
1949 | 2.42k | { |
1950 | 2.42k | int yyi; |
1951 | 8.91k | for (yyi = 0; yyi < yycount; ++yyi) |
1952 | 6.49k | { |
1953 | 6.49k | YYPTRDIFF_T yysize1 |
1954 | 6.49k | = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]); |
1955 | 6.49k | if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) |
1956 | 6.49k | yysize = yysize1; |
1957 | 0 | else |
1958 | 0 | return YYENOMEM; |
1959 | 6.49k | } |
1960 | 2.42k | } |
1961 | | |
1962 | 2.42k | 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 | 2.42k | { |
1975 | 2.42k | char *yyp = *yymsg; |
1976 | 2.42k | int yyi = 0; |
1977 | 97.8k | while ((*yyp = *yyformat) != '\0') |
1978 | 95.4k | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) |
1979 | 6.49k | { |
1980 | 6.49k | yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]); |
1981 | 6.49k | yyformat += 2; |
1982 | 6.49k | } |
1983 | 88.9k | else |
1984 | 88.9k | { |
1985 | 88.9k | ++yyp; |
1986 | 88.9k | ++yyformat; |
1987 | 88.9k | } |
1988 | 2.42k | } |
1989 | 2.42k | return 0; |
1990 | 2.42k | } |
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 | 59.6k | { |
2001 | 59.6k | YY_USE (yyvaluep); |
2002 | 59.6k | YY_USE (yylocationp); |
2003 | 59.6k | if (!yymsg) |
2004 | 0 | yymsg = "Deleting"; |
2005 | 59.6k | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); |
2006 | | |
2007 | 59.6k | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
2008 | 59.6k | YY_USE (yykind); |
2009 | 59.6k | YY_IGNORE_MAYBE_UNINITIALIZED_END |
2010 | 59.6k | } |
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 | 326k | { |
2037 | 326k | yy_state_fast_t yystate = 0; |
2038 | | /* Number of tokens to shift before error messages enabled. */ |
2039 | 326k | 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 | 326k | YYPTRDIFF_T yystacksize = YYINITDEPTH; |
2046 | | |
2047 | | /* The state stack: array, bottom, top. */ |
2048 | 326k | yy_state_t yyssa[YYINITDEPTH]; |
2049 | 326k | yy_state_t *yyss = yyssa; |
2050 | 326k | yy_state_t *yyssp = yyss; |
2051 | | |
2052 | | /* The semantic value stack: array, bottom, top. */ |
2053 | 326k | YYSTYPE yyvsa[YYINITDEPTH]; |
2054 | 326k | YYSTYPE *yyvs = yyvsa; |
2055 | 326k | YYSTYPE *yyvsp = yyvs; |
2056 | | |
2057 | | /* The location stack: array, bottom, top. */ |
2058 | 326k | YYLTYPE yylsa[YYINITDEPTH]; |
2059 | 326k | YYLTYPE *yyls = yylsa; |
2060 | 326k | YYLTYPE *yylsp = yyls; |
2061 | | |
2062 | 326k | int yyn; |
2063 | | /* The return value of yyparse. */ |
2064 | 326k | int yyresult; |
2065 | | /* Lookahead symbol kind. */ |
2066 | 326k | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; |
2067 | | /* The variables used to return semantic value and location from the |
2068 | | action routines. */ |
2069 | 326k | YYSTYPE yyval; |
2070 | 326k | YYLTYPE yyloc; |
2071 | | |
2072 | | /* The locations where the error started and ended. */ |
2073 | 326k | YYLTYPE yyerror_range[3]; |
2074 | | |
2075 | | /* Buffer for error messages, and its allocated size. */ |
2076 | 326k | char yymsgbuf[128]; |
2077 | 326k | char *yymsg = yymsgbuf; |
2078 | 326k | YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; |
2079 | | |
2080 | 2.52M | #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 | 326k | int yylen = 0; |
2085 | | |
2086 | 326k | YYDPRINTF ((stderr, "Starting parse\n")); |
2087 | | |
2088 | 326k | yychar = YYEMPTY; /* Cause a token to be read. */ |
2089 | | |
2090 | 326k | yylsp[0] = yylloc; |
2091 | 326k | goto yysetstate; |
2092 | | |
2093 | | |
2094 | | /*------------------------------------------------------------. |
2095 | | | yynewstate -- push a new state, which is found in yystate. | |
2096 | | `------------------------------------------------------------*/ |
2097 | 3.82M | 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 | 3.82M | yyssp++; |
2101 | | |
2102 | | |
2103 | | /*--------------------------------------------------------------------. |
2104 | | | yysetstate -- set current state (the top of the stack) to yystate. | |
2105 | | `--------------------------------------------------------------------*/ |
2106 | 4.14M | yysetstate: |
2107 | 4.14M | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
2108 | 4.14M | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); |
2109 | 4.14M | YY_IGNORE_USELESS_CAST_BEGIN |
2110 | 4.14M | *yyssp = YY_CAST (yy_state_t, yystate); |
2111 | 4.14M | YY_IGNORE_USELESS_CAST_END |
2112 | 4.14M | YY_STACK_PRINT (yyss, yyssp); |
2113 | | |
2114 | 4.14M | if (yyss + yystacksize - 1 <= yyssp) |
2115 | | #if !defined yyoverflow && !defined YYSTACK_RELOCATE |
2116 | | YYNOMEM; |
2117 | | #else |
2118 | 1.11k | { |
2119 | | /* Get the current used size of the three stacks, in elements. */ |
2120 | 1.11k | 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 | 1.11k | if (YYMAXDEPTH <= yystacksize) |
2147 | 1 | YYNOMEM; |
2148 | 1.10k | yystacksize *= 2; |
2149 | 1.10k | if (YYMAXDEPTH < yystacksize) |
2150 | 14 | yystacksize = YYMAXDEPTH; |
2151 | | |
2152 | 1.10k | { |
2153 | 1.10k | yy_state_t *yyss1 = yyss; |
2154 | 1.10k | union yyalloc *yyptr = |
2155 | 1.10k | YY_CAST (union yyalloc *, |
2156 | 1.10k | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); |
2157 | 1.10k | if (! yyptr) |
2158 | 0 | YYNOMEM; |
2159 | 1.10k | YYSTACK_RELOCATE (yyss_alloc, yyss); |
2160 | 1.10k | YYSTACK_RELOCATE (yyvs_alloc, yyvs); |
2161 | 1.10k | YYSTACK_RELOCATE (yyls_alloc, yyls); |
2162 | 1.10k | # undef YYSTACK_RELOCATE |
2163 | 1.10k | if (yyss1 != yyssa) |
2164 | 555 | YYSTACK_FREE (yyss1); |
2165 | 1.10k | } |
2166 | 0 | # endif |
2167 | | |
2168 | 0 | yyssp = yyss + yysize - 1; |
2169 | 1.10k | yyvsp = yyvs + yysize - 1; |
2170 | 1.10k | yylsp = yyls + yysize - 1; |
2171 | | |
2172 | 1.10k | YY_IGNORE_USELESS_CAST_BEGIN |
2173 | 1.10k | YYDPRINTF ((stderr, "Stack size increased to %ld\n", |
2174 | 1.10k | YY_CAST (long, yystacksize))); |
2175 | 1.10k | YY_IGNORE_USELESS_CAST_END |
2176 | | |
2177 | 1.10k | if (yyss + yystacksize - 1 <= yyssp) |
2178 | 0 | YYABORT; |
2179 | 1.10k | } |
2180 | 4.14M | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ |
2181 | | |
2182 | | |
2183 | 4.14M | if (yystate == YYFINAL) |
2184 | 0 | YYACCEPT; |
2185 | | |
2186 | 4.14M | goto yybackup; |
2187 | | |
2188 | | |
2189 | | /*-----------. |
2190 | | | yybackup. | |
2191 | | `-----------*/ |
2192 | 4.14M | 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 | 4.14M | yyn = yypact[yystate]; |
2198 | 4.14M | if (yypact_value_is_default (yyn)) |
2199 | 669k | 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 | 3.47M | if (yychar == YYEMPTY) |
2205 | 1.68M | { |
2206 | 1.68M | YYDPRINTF ((stderr, "Reading a token\n")); |
2207 | 1.68M | yychar = yylex (); |
2208 | 1.68M | } |
2209 | | |
2210 | 3.47M | 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 | 3.47M | 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 | 3.47M | else |
2228 | 3.47M | { |
2229 | 3.47M | yytoken = YYTRANSLATE (yychar); |
2230 | 3.47M | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); |
2231 | 3.47M | } |
2232 | | |
2233 | | /* If the proper action on seeing token YYTOKEN is to reduce or to |
2234 | | detect an error, take that action. */ |
2235 | 3.47M | yyn += yytoken; |
2236 | 3.47M | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) |
2237 | 1.79M | goto yydefault; |
2238 | 1.68M | yyn = yytable[yyn]; |
2239 | 1.68M | if (yyn <= 0) |
2240 | 13 | { |
2241 | 13 | if (yytable_value_is_error (yyn)) |
2242 | 13 | goto yyerrlab; |
2243 | 0 | yyn = -yyn; |
2244 | 0 | goto yyreduce; |
2245 | 13 | } |
2246 | | |
2247 | | /* Count tokens shifted since error; after three, turn off error |
2248 | | status. */ |
2249 | 1.68M | if (yyerrstatus) |
2250 | 0 | yyerrstatus--; |
2251 | | |
2252 | | /* Shift the lookahead token. */ |
2253 | 1.68M | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
2254 | 1.68M | yystate = yyn; |
2255 | 1.68M | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
2256 | 1.68M | *++yyvsp = yylval; |
2257 | 1.68M | YY_IGNORE_MAYBE_UNINITIALIZED_END |
2258 | 1.68M | *++yylsp = yylloc; |
2259 | | |
2260 | | /* Discard the shifted token. */ |
2261 | 1.68M | yychar = YYEMPTY; |
2262 | 1.68M | goto yynewstate; |
2263 | | |
2264 | | |
2265 | | /*-----------------------------------------------------------. |
2266 | | | yydefault -- do the default action for the current state. | |
2267 | | `-----------------------------------------------------------*/ |
2268 | 2.46M | yydefault: |
2269 | 2.46M | yyn = yydefact[yystate]; |
2270 | 2.46M | if (yyn == 0) |
2271 | 2.40k | goto yyerrlab; |
2272 | 2.46M | goto yyreduce; |
2273 | | |
2274 | | |
2275 | | /*-----------------------------. |
2276 | | | yyreduce -- do a reduction. | |
2277 | | `-----------------------------*/ |
2278 | 2.46M | yyreduce: |
2279 | | /* yyn is the number of a rule to reduce with. */ |
2280 | 2.46M | 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 | 2.46M | yyval = yyvsp[1-yylen]; |
2291 | | |
2292 | | /* Default location. */ |
2293 | 2.46M | YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); |
2294 | 2.46M | yyerror_range[1] = yyloc; |
2295 | 2.46M | YY_REDUCE_PRINT (yyn); |
2296 | 2.46M | switch (yyn) |
2297 | 2.46M | { |
2298 | 2.62k | case 2: /* prog: END_OF_INPUT */ |
2299 | 2.62k | { Status = 0; YYACCEPT; } |
2300 | 0 | break; |
2301 | | |
2302 | 45.5k | case 3: /* prog: '\n' */ |
2303 | 45.5k | { Status = 2; yyresult = xxvalue(NULL,2,NULL); YYACCEPT; } |
2304 | 0 | break; |
2305 | | |
2306 | 273k | case 4: /* prog: expr_or_assign_or_help '\n' */ |
2307 | 273k | { Status = 3; yyresult = xxvalue(yyvsp[-1],3,&(yylsp[-1])); YYACCEPT; } |
2308 | 0 | break; |
2309 | | |
2310 | 2.30k | case 5: /* prog: expr_or_assign_or_help ';' */ |
2311 | 2.30k | { Status = 4; yyresult = xxvalue(yyvsp[-1],4,&(yylsp[-1])); YYACCEPT; } |
2312 | 0 | break; |
2313 | | |
2314 | 1.97k | case 6: /* prog: error */ |
2315 | 1.97k | { Status = 1; YYABORT; } |
2316 | 0 | break; |
2317 | | |
2318 | 720k | case 7: /* expr_or_assign_or_help: expr */ |
2319 | 720k | { yyval = yyvsp[0]; } |
2320 | 720k | break; |
2321 | | |
2322 | 136k | case 8: /* expr_or_assign_or_help: expr_or_assign_or_help EQ_ASSIGN expr_or_assign_or_help */ |
2323 | 136k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2324 | 136k | break; |
2325 | | |
2326 | 7.82k | case 9: /* expr_or_assign_or_help: expr_or_assign_or_help '?' expr_or_assign_or_help */ |
2327 | 7.82k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2328 | 7.82k | break; |
2329 | | |
2330 | 64.9k | case 10: /* expr_or_help: expr */ |
2331 | 64.9k | { yyval = yyvsp[0]; } |
2332 | 64.9k | break; |
2333 | | |
2334 | 3.57k | case 11: /* expr_or_help: expr_or_help '?' expr_or_help */ |
2335 | 3.57k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2336 | 3.57k | break; |
2337 | | |
2338 | 185k | case 12: /* expr: NUM_CONST */ |
2339 | 185k | { yyval = yyvsp[0]; setId((yyloc)); } |
2340 | 185k | break; |
2341 | | |
2342 | 8.96k | case 13: /* expr: STR_CONST */ |
2343 | 8.96k | { yyval = yyvsp[0]; setId((yyloc)); } |
2344 | 8.96k | break; |
2345 | | |
2346 | 657 | case 14: /* expr: NULL_CONST */ |
2347 | 657 | { yyval = yyvsp[0]; setId((yyloc)); } |
2348 | 657 | break; |
2349 | | |
2350 | 23.2k | case 15: /* expr: PLACEHOLDER */ |
2351 | 23.2k | { yyval = yyvsp[0]; setId((yyloc)); } |
2352 | 23.2k | break; |
2353 | | |
2354 | 371k | case 16: /* expr: SYMBOL */ |
2355 | 371k | { yyval = yyvsp[0]; setId((yyloc)); } |
2356 | 371k | break; |
2357 | | |
2358 | 1.61k | case 17: /* expr: '{' exprlist '}' */ |
2359 | 1.61k | { yyval = xxexprlist(yyvsp[-2],&(yylsp[-2]),yyvsp[-1]); setId((yyloc)); } |
2360 | 1.61k | break; |
2361 | | |
2362 | 969 | case 18: /* expr: '(' expr_or_assign_or_help ')' */ |
2363 | 969 | { yyval = xxparen(yyvsp[-2],yyvsp[-1]); setId((yyloc)); } |
2364 | 969 | break; |
2365 | | |
2366 | 3.10k | case 19: /* expr: '-' expr */ |
2367 | 3.10k | { yyval = xxunary(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2368 | 3.10k | break; |
2369 | | |
2370 | 6.97k | case 20: /* expr: '+' expr */ |
2371 | 6.97k | { yyval = xxunary(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2372 | 6.97k | break; |
2373 | | |
2374 | 1.35k | case 21: /* expr: '!' expr */ |
2375 | 1.35k | { yyval = xxunary(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2376 | 1.35k | break; |
2377 | | |
2378 | 23.2k | case 22: /* expr: '~' expr */ |
2379 | 23.2k | { yyval = xxunary(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2380 | 23.2k | break; |
2381 | | |
2382 | 272k | case 23: /* expr: '?' expr_or_assign_or_help */ |
2383 | 272k | { yyval = xxunary(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2384 | 272k | break; |
2385 | | |
2386 | 17.6k | case 24: /* expr: expr ':' expr */ |
2387 | 17.6k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2388 | 17.6k | break; |
2389 | | |
2390 | 3.09k | case 25: /* expr: expr '+' expr */ |
2391 | 3.09k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2392 | 3.09k | break; |
2393 | | |
2394 | 8.33k | case 26: /* expr: expr '-' expr */ |
2395 | 8.33k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2396 | 8.33k | break; |
2397 | | |
2398 | 2.37k | case 27: /* expr: expr '*' expr */ |
2399 | 2.37k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2400 | 2.37k | break; |
2401 | | |
2402 | 1.44k | case 28: /* expr: expr '/' expr */ |
2403 | 1.44k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2404 | 1.44k | break; |
2405 | | |
2406 | 10.9k | case 29: /* expr: expr '^' expr */ |
2407 | 10.9k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2408 | 10.9k | break; |
2409 | | |
2410 | 1.11k | case 30: /* expr: expr SPECIAL expr */ |
2411 | 1.11k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2412 | 1.11k | break; |
2413 | | |
2414 | 24.5k | case 31: /* expr: expr '~' expr */ |
2415 | 24.5k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2416 | 24.5k | break; |
2417 | | |
2418 | 693 | case 32: /* expr: expr LT expr */ |
2419 | 693 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2420 | 693 | break; |
2421 | | |
2422 | 48 | case 33: /* expr: expr LE expr */ |
2423 | 48 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2424 | 48 | break; |
2425 | | |
2426 | 1.11k | case 34: /* expr: expr EQ expr */ |
2427 | 1.11k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2428 | 1.11k | break; |
2429 | | |
2430 | 294 | case 35: /* expr: expr NE expr */ |
2431 | 294 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2432 | 294 | break; |
2433 | | |
2434 | 217 | case 36: /* expr: expr GE expr */ |
2435 | 217 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2436 | 217 | break; |
2437 | | |
2438 | 732 | case 37: /* expr: expr GT expr */ |
2439 | 732 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2440 | 732 | break; |
2441 | | |
2442 | 589 | case 38: /* expr: expr AND expr */ |
2443 | 589 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2444 | 589 | break; |
2445 | | |
2446 | 1.14k | case 39: /* expr: expr OR expr */ |
2447 | 1.14k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2448 | 1.14k | break; |
2449 | | |
2450 | 725 | case 40: /* expr: expr AND2 expr */ |
2451 | 725 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2452 | 725 | break; |
2453 | | |
2454 | 118 | case 41: /* expr: expr OR2 expr */ |
2455 | 118 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2456 | 118 | break; |
2457 | | |
2458 | 1.00k | case 42: /* expr: expr PIPE expr */ |
2459 | 1.00k | { yyval = xxpipe(yyvsp[-2],yyvsp[0],&(yylsp[0])); setId((yyloc)); } |
2460 | 1.00k | break; |
2461 | | |
2462 | 667 | case 43: /* expr: expr PIPEBIND expr */ |
2463 | 667 | { yyval = xxpipebind(yyvsp[-1],yyvsp[-2],yyvsp[0],&(yylsp[-1])); setId((yyloc)); } |
2464 | 667 | break; |
2465 | | |
2466 | 5.04k | case 44: /* expr: expr LEFT_ASSIGN expr */ |
2467 | 5.04k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2468 | 5.04k | break; |
2469 | | |
2470 | 984 | case 45: /* expr: expr RIGHT_ASSIGN expr */ |
2471 | 984 | { yyval = xxbinary(yyvsp[-1],yyvsp[0],yyvsp[-2]); setId((yyloc)); } |
2472 | 984 | break; |
2473 | | |
2474 | 1.73k | case 46: /* expr: FUNCTION '(' formlist ')' cr expr_or_assign_or_help */ |
2475 | 1.73k | { yyval = xxdefun(yyvsp[-5],yyvsp[-3],yyvsp[0],&(yyloc)); setId((yyloc)); } |
2476 | 1.73k | break; |
2477 | | |
2478 | 302 | case 47: /* expr: '\\' '(' formlist ')' cr expr_or_assign_or_help */ |
2479 | 302 | { yyval = xxdefun(R_FunctionSymbol,yyvsp[-3],yyvsp[0],&(yyloc)); setId((yyloc)); } |
2480 | 302 | break; |
2481 | | |
2482 | 47.7k | case 48: /* expr: expr '(' sublist ')' */ |
2483 | 47.7k | { yyval = xxfuncall(yyvsp[-3],yyvsp[-1]); setId((yyloc)); modif_token( &(yylsp[-3]), SYMBOL_FUNCTION_CALL ) ; } |
2484 | 47.7k | break; |
2485 | | |
2486 | 1.82k | case 49: /* expr: IF ifcond expr_or_assign_or_help */ |
2487 | 1.82k | { yyval = xxif(yyvsp[-2],yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2488 | 1.82k | break; |
2489 | | |
2490 | 1.17k | case 50: /* expr: IF ifcond expr_or_assign_or_help ELSE expr_or_assign_or_help */ |
2491 | 1.17k | { yyval = xxifelse(yyvsp[-4],yyvsp[-3],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2492 | 1.17k | break; |
2493 | | |
2494 | 327 | case 51: /* expr: FOR forcond expr_or_assign_or_help */ |
2495 | 327 | { yyval = xxfor(yyvsp[-2],yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2496 | 327 | break; |
2497 | | |
2498 | 208 | case 52: /* expr: WHILE cond expr_or_assign_or_help */ |
2499 | 208 | { yyval = xxwhile(yyvsp[-2],yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2500 | 208 | break; |
2501 | | |
2502 | 477 | case 53: /* expr: REPEAT expr_or_assign_or_help */ |
2503 | 477 | { yyval = xxrepeat(yyvsp[-1],yyvsp[0]); setId((yyloc)); } |
2504 | 477 | break; |
2505 | | |
2506 | 324 | case 54: /* expr: expr LBB sublist ']' ']' */ |
2507 | 324 | { yyval = xxsubscript(yyvsp[-4],yyvsp[-3],yyvsp[-2]); setId((yyloc)); } |
2508 | 324 | break; |
2509 | | |
2510 | 3.40k | case 55: /* expr: expr '[' sublist ']' */ |
2511 | 3.40k | { yyval = xxsubscript(yyvsp[-3],yyvsp[-2],yyvsp[-1]); setId((yyloc)); } |
2512 | 3.40k | break; |
2513 | | |
2514 | 264 | case 56: /* expr: SYMBOL NS_GET SYMBOL */ |
2515 | 264 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ; } |
2516 | 264 | break; |
2517 | | |
2518 | 142 | case 57: /* expr: SYMBOL NS_GET STR_CONST */ |
2519 | 142 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ; } |
2520 | 142 | break; |
2521 | | |
2522 | 1.41k | case 58: /* expr: STR_CONST NS_GET SYMBOL */ |
2523 | 1.41k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2524 | 1.41k | break; |
2525 | | |
2526 | 18 | case 59: /* expr: STR_CONST NS_GET STR_CONST */ |
2527 | 18 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2528 | 18 | break; |
2529 | | |
2530 | 237 | case 60: /* expr: SYMBOL NS_GET_INT SYMBOL */ |
2531 | 237 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ;} |
2532 | 237 | break; |
2533 | | |
2534 | 0 | case 61: /* expr: SYMBOL NS_GET_INT STR_CONST */ |
2535 | 0 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); modif_token( &(yylsp[-2]), SYMBOL_PACKAGE ) ;} |
2536 | 0 | break; |
2537 | | |
2538 | 20 | case 62: /* expr: STR_CONST NS_GET_INT SYMBOL */ |
2539 | 20 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2540 | 20 | break; |
2541 | | |
2542 | 40 | case 63: /* expr: STR_CONST NS_GET_INT STR_CONST */ |
2543 | 40 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2544 | 40 | break; |
2545 | | |
2546 | 1.49k | case 64: /* expr: expr '$' SYMBOL */ |
2547 | 1.49k | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2548 | 1.49k | break; |
2549 | | |
2550 | 727 | case 65: /* expr: expr '$' STR_CONST */ |
2551 | 727 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2552 | 727 | break; |
2553 | | |
2554 | 766 | case 66: /* expr: expr '@' SYMBOL */ |
2555 | 766 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); modif_token( &(yylsp[0]), SLOT ) ; } |
2556 | 766 | break; |
2557 | | |
2558 | 227 | case 67: /* expr: expr '@' STR_CONST */ |
2559 | 227 | { yyval = xxbinary(yyvsp[-1],yyvsp[-2],yyvsp[0]); setId((yyloc)); } |
2560 | 227 | break; |
2561 | | |
2562 | 1.44k | case 68: /* expr: NEXT */ |
2563 | 1.44k | { yyval = xxnxtbrk(yyvsp[0]); setId((yyloc)); } |
2564 | 1.44k | break; |
2565 | | |
2566 | 449 | case 69: /* expr: BREAK */ |
2567 | 449 | { yyval = xxnxtbrk(yyvsp[0]); setId((yyloc)); } |
2568 | 449 | break; |
2569 | | |
2570 | 412 | case 70: /* cond: '(' expr_or_help ')' */ |
2571 | 412 | { yyval = xxcond(yyvsp[-1]); } |
2572 | 412 | break; |
2573 | | |
2574 | 3.51k | case 71: /* ifcond: '(' expr_or_help ')' */ |
2575 | 3.51k | { yyval = xxifcond(yyvsp[-1]); } |
2576 | 3.51k | break; |
2577 | | |
2578 | 330 | case 72: /* forcond: '(' SYMBOL IN expr_or_help ')' */ |
2579 | 330 | { yyval = xxforcond(yyvsp[-3],yyvsp[-1]); setId((yyloc)); } |
2580 | 330 | break; |
2581 | | |
2582 | 101 | case 73: /* exprlist: %empty */ |
2583 | 101 | { yyval = xxexprlist0(); setId((yyloc)); } |
2584 | 101 | break; |
2585 | | |
2586 | 1.66k | case 74: /* exprlist: expr_or_assign_or_help */ |
2587 | 1.66k | { yyval = xxexprlist1(yyvsp[0], &(yylsp[0])); } |
2588 | 1.66k | break; |
2589 | | |
2590 | 597 | case 75: /* exprlist: exprlist ';' expr_or_assign_or_help */ |
2591 | 597 | { yyval = xxexprlist2(yyvsp[-2], yyvsp[0], &(yylsp[0])); } |
2592 | 597 | break; |
2593 | | |
2594 | 532 | case 76: /* exprlist: exprlist ';' */ |
2595 | 532 | { yyval = yyvsp[-1]; setId((yyloc)); } |
2596 | 532 | break; |
2597 | | |
2598 | 4.85k | case 77: /* exprlist: exprlist '\n' expr_or_assign_or_help */ |
2599 | 4.85k | { yyval = xxexprlist2(yyvsp[-2], yyvsp[0], &(yylsp[0])); } |
2600 | 4.85k | break; |
2601 | | |
2602 | 2.63k | case 78: /* exprlist: exprlist '\n' */ |
2603 | 2.63k | { yyval = yyvsp[-1];} |
2604 | 2.63k | break; |
2605 | | |
2606 | 52.0k | case 79: /* sublist: sub */ |
2607 | 52.0k | { yyval = xxsublist1(yyvsp[0]); } |
2608 | 52.0k | break; |
2609 | | |
2610 | 10.7k | case 80: /* sublist: sublist cr ',' sub */ |
2611 | 10.7k | { yyval = xxsublist2(yyvsp[-3],yyvsp[0]); } |
2612 | 10.7k | break; |
2613 | | |
2614 | 5.27k | case 81: /* sub: %empty */ |
2615 | 5.27k | { yyval = xxsub0(); } |
2616 | 5.27k | break; |
2617 | | |
2618 | 51.9k | case 82: /* sub: expr_or_help */ |
2619 | 51.9k | { yyval = xxsub1(yyvsp[0], &(yylsp[0])); } |
2620 | 51.9k | break; |
2621 | | |
2622 | 385 | case 83: /* sub: SYMBOL EQ_ASSIGN */ |
2623 | 385 | { yyval = xxsymsub0(yyvsp[-1], &(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; modif_token( &(yylsp[-1]), SYMBOL_SUB ) ; } |
2624 | 385 | break; |
2625 | | |
2626 | 3.59k | case 84: /* sub: SYMBOL EQ_ASSIGN expr_or_help */ |
2627 | 3.59k | { yyval = xxsymsub1(yyvsp[-2],yyvsp[0], &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; modif_token( &(yylsp[-2]), SYMBOL_SUB ) ; } |
2628 | 3.59k | break; |
2629 | | |
2630 | 506 | case 85: /* sub: STR_CONST EQ_ASSIGN */ |
2631 | 506 | { yyval = xxsymsub0(yyvsp[-1], &(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; } |
2632 | 506 | break; |
2633 | | |
2634 | 888 | case 86: /* sub: STR_CONST EQ_ASSIGN expr_or_help */ |
2635 | 888 | { yyval = xxsymsub1(yyvsp[-2],yyvsp[0], &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; } |
2636 | 888 | break; |
2637 | | |
2638 | 10 | case 87: /* sub: NULL_CONST EQ_ASSIGN */ |
2639 | 10 | { yyval = xxnullsub0(&(yylsp[-1])); modif_token( &(yylsp[0]), EQ_SUB ) ; } |
2640 | 10 | break; |
2641 | | |
2642 | 89 | case 88: /* sub: NULL_CONST EQ_ASSIGN expr_or_help */ |
2643 | 89 | { yyval = xxnullsub1(yyvsp[0], &(yylsp[-2])); modif_token( &(yylsp[-1]), EQ_SUB ) ; } |
2644 | 89 | break; |
2645 | | |
2646 | 173 | case 89: /* formlist: %empty */ |
2647 | 173 | { yyval = xxnullformal(); } |
2648 | 173 | break; |
2649 | | |
2650 | 1.99k | case 90: /* formlist: SYMBOL */ |
2651 | 1.99k | { yyval = xxfirstformal0(yyvsp[0]); modif_token( &(yylsp[0]), SYMBOL_FORMALS ) ; } |
2652 | 1.99k | break; |
2653 | | |
2654 | 309 | case 91: /* formlist: SYMBOL EQ_ASSIGN expr_or_help */ |
2655 | 309 | { yyval = xxfirstformal1(yyvsp[-2],yyvsp[0]); modif_token( &(yylsp[-2]), SYMBOL_FORMALS ) ; modif_token( &(yylsp[-1]), EQ_FORMALS ) ; } |
2656 | 309 | break; |
2657 | | |
2658 | 1.52k | case 92: /* formlist: formlist ',' SYMBOL */ |
2659 | 1.52k | { yyval = xxaddformal0(yyvsp[-2],yyvsp[0], &(yylsp[0])); modif_token( &(yylsp[0]), SYMBOL_FORMALS ) ; } |
2660 | 1.52k | break; |
2661 | | |
2662 | 206 | case 93: /* formlist: formlist ',' SYMBOL EQ_ASSIGN expr_or_help */ |
2663 | 206 | { yyval = xxaddformal1(yyvsp[-4],yyvsp[-2],yyvsp[0],&(yylsp[-2])); modif_token( &(yylsp[-2]), SYMBOL_FORMALS ) ; modif_token( &(yylsp[-1]), EQ_FORMALS ) ;} |
2664 | 206 | break; |
2665 | | |
2666 | 13.7k | case 94: /* cr: %empty */ |
2667 | 13.7k | { EatLines = 1; } |
2668 | 13.7k | break; |
2669 | | |
2670 | | |
2671 | | |
2672 | 0 | default: break; |
2673 | 2.46M | } |
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 | 2.13M | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); |
2686 | | |
2687 | 2.13M | YYPOPSTACK (yylen); |
2688 | 2.13M | yylen = 0; |
2689 | | |
2690 | 2.13M | *++yyvsp = yyval; |
2691 | 2.13M | *++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 | 2.13M | { |
2697 | 2.13M | const int yylhs = yyr1[yyn] - YYNTOKENS; |
2698 | 2.13M | const int yyi = yypgoto[yylhs] + *yyssp; |
2699 | 2.13M | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp |
2700 | 2.13M | ? yytable[yyi] |
2701 | 2.13M | : yydefgoto[yylhs]); |
2702 | 2.13M | } |
2703 | | |
2704 | 2.13M | goto yynewstate; |
2705 | | |
2706 | | |
2707 | | /*--------------------------------------. |
2708 | | | yyerrlab -- here on detecting error. | |
2709 | | `--------------------------------------*/ |
2710 | 2.42k | yyerrlab: |
2711 | | /* Make sure we have latest lookahead translation. See comments at |
2712 | | user semantic actions for why this is necessary. */ |
2713 | 2.42k | yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); |
2714 | | /* If not already recovering from an error, report this error. */ |
2715 | 2.42k | if (!yyerrstatus) |
2716 | 2.42k | { |
2717 | 2.42k | ++yynerrs; |
2718 | 2.42k | { |
2719 | 2.42k | yypcontext_t yyctx |
2720 | 2.42k | = {yyssp, yytoken, &yylloc}; |
2721 | 2.42k | char const *yymsgp = YY_("syntax error"); |
2722 | 2.42k | int yysyntax_error_status; |
2723 | 2.42k | yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); |
2724 | 2.42k | if (yysyntax_error_status == 0) |
2725 | 2.42k | 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 | 2.42k | yyerror (yymsgp); |
2746 | 2.42k | if (yysyntax_error_status == YYENOMEM) |
2747 | 0 | YYNOMEM; |
2748 | 2.42k | } |
2749 | 2.42k | } |
2750 | | |
2751 | 2.42k | yyerror_range[1] = yylloc; |
2752 | 2.42k | 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 | 2.42k | goto yyerrlab1; |
2774 | | |
2775 | | |
2776 | | /*---------------------------------------------------. |
2777 | | | yyerrorlab -- error raised explicitly by YYERROR. | |
2778 | | `---------------------------------------------------*/ |
2779 | 2.42k | 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 | 1.97k | yyerrlab1: |
2799 | 1.97k | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
2800 | | |
2801 | | /* Pop stack until we find a state that shifts the error token. */ |
2802 | 1.97k | for (;;) |
2803 | 49.6k | { |
2804 | 49.6k | yyn = yypact[yystate]; |
2805 | 49.6k | if (!yypact_value_is_default (yyn)) |
2806 | 49.2k | { |
2807 | 49.2k | yyn += YYSYMBOL_YYerror; |
2808 | 49.2k | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) |
2809 | 1.97k | { |
2810 | 1.97k | yyn = yytable[yyn]; |
2811 | 1.97k | if (0 < yyn) |
2812 | 1.97k | break; |
2813 | 1.97k | } |
2814 | 49.2k | } |
2815 | | |
2816 | | /* Pop the current state because it cannot handle the error token. */ |
2817 | 47.6k | if (yyssp == yyss) |
2818 | 0 | YYABORT; |
2819 | | |
2820 | 47.6k | yyerror_range[1] = *yylsp; |
2821 | 47.6k | yydestruct ("Error: popping", |
2822 | 47.6k | YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp); |
2823 | 47.6k | YYPOPSTACK (1); |
2824 | 47.6k | yystate = *yyssp; |
2825 | 47.6k | YY_STACK_PRINT (yyss, yyssp); |
2826 | 47.6k | } |
2827 | | |
2828 | 1.97k | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
2829 | 1.97k | *++yyvsp = yylval; |
2830 | 1.97k | YY_IGNORE_MAYBE_UNINITIALIZED_END |
2831 | | |
2832 | 1.97k | yyerror_range[2] = yylloc; |
2833 | 1.97k | ++yylsp; |
2834 | 1.97k | YYLLOC_DEFAULT (*yylsp, yyerror_range, 2); |
2835 | | |
2836 | | /* Shift the error token. */ |
2837 | 1.97k | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); |
2838 | | |
2839 | 1.97k | yystate = yyn; |
2840 | 1.97k | goto yynewstate; |
2841 | | |
2842 | | |
2843 | | /*-------------------------------------. |
2844 | | | yyacceptlab -- YYACCEPT comes here. | |
2845 | | `-------------------------------------*/ |
2846 | 323k | yyacceptlab: |
2847 | 323k | yyresult = 0; |
2848 | 323k | goto yyreturnlab; |
2849 | | |
2850 | | |
2851 | | /*-----------------------------------. |
2852 | | | yyabortlab -- YYABORT comes here. | |
2853 | | `-----------------------------------*/ |
2854 | 1.97k | yyabortlab: |
2855 | 1.97k | yyresult = 1; |
2856 | 1.97k | goto yyreturnlab; |
2857 | | |
2858 | | |
2859 | | /*-----------------------------------------------------------. |
2860 | | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | |
2861 | | `-----------------------------------------------------------*/ |
2862 | 1 | yyexhaustedlab: |
2863 | 1 | yyerror (YY_("memory exhausted")); |
2864 | 1 | yyresult = 2; |
2865 | 1 | goto yyreturnlab; |
2866 | | |
2867 | | |
2868 | | /*----------------------------------------------------------. |
2869 | | | yyreturnlab -- parsing is finished, clean up and return. | |
2870 | | `----------------------------------------------------------*/ |
2871 | 325k | yyreturnlab: |
2872 | 325k | if (yychar != YYEMPTY) |
2873 | 1.97k | { |
2874 | | /* Make sure we have latest lookahead translation. See comments at |
2875 | | user semantic actions for why this is necessary. */ |
2876 | 1.97k | yytoken = YYTRANSLATE (yychar); |
2877 | 1.97k | yydestruct ("Cleanup: discarding lookahead", |
2878 | 1.97k | yytoken, &yylval, &yylloc); |
2879 | 1.97k | } |
2880 | | /* Do not reclaim the symbols of the rule whose action triggered |
2881 | | this YYABORT or YYACCEPT. */ |
2882 | 325k | YYPOPSTACK (yylen); |
2883 | 325k | YY_STACK_PRINT (yyss, yyssp); |
2884 | 335k | while (yyssp != yyss) |
2885 | 9.99k | { |
2886 | 9.99k | yydestruct ("Cleanup: popping", |
2887 | 9.99k | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp); |
2888 | 9.99k | YYPOPSTACK (1); |
2889 | 9.99k | } |
2890 | 325k | #ifndef yyoverflow |
2891 | 325k | if (yyss != yyssa) |
2892 | 536 | YYSTACK_FREE (yyss); |
2893 | 325k | #endif |
2894 | 325k | if (yymsg != yymsgbuf) |
2895 | 0 | YYSTACK_FREE (yymsg); |
2896 | 325k | return yyresult; |
2897 | 1.97k | } |
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 | 889k | #define DECLARE_YYTEXT_BUFP(bp) char *bp = yytext ; |
2909 | 4.03M | #define YYTEXT_PUSH(c, bp) do { \ |
2910 | 4.03M | if ((bp) - yytext >= sizeof(yytext) - 1){ \ |
2911 | 10 | raiseLexError("bufferOverflow", NO_VALUE, NULL, \ |
2912 | 10 | _("input buffer overflow (%s:%d:%d)")); \ |
2913 | 10 | } \ |
2914 | 4.03M | *(bp)++ = ((char)c); \ |
2915 | 4.03M | } while(0) ; |
2916 | | |
2917 | 11.5M | #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 | 8.19M | { |
2929 | 8.19M | int c; |
2930 | | |
2931 | 8.19M | if(npush) c = pushback[--npush]; else c = ptr_getc(); |
2932 | | |
2933 | 8.19M | prevpos = (prevpos + 1) % PUSHBACK_BUFSIZE; |
2934 | 8.19M | prevbytes[prevpos] = ParseState.xxbyteno; |
2935 | 8.19M | prevlines[prevpos] = ParseState.xxlineno; |
2936 | 8.19M | prevparse[prevpos] = ParseState.xxparseno; |
2937 | 8.19M | prevcols[prevpos] = ParseState.xxcolno; |
2938 | | |
2939 | 8.19M | if (c == EOF) { |
2940 | 3.60k | EndOfFile = 1; |
2941 | 3.60k | return R_EOF; |
2942 | 3.60k | } |
2943 | 8.19M | R_ParseContextLast = (R_ParseContextLast + 1) % PARSE_CONTEXT_SIZE; |
2944 | 8.19M | R_ParseContext[R_ParseContextLast] = (char) c; |
2945 | | |
2946 | 8.19M | if (c == '\n') { |
2947 | 480k | ParseState.xxlineno += 1; |
2948 | 480k | ParseState.xxcolno = 0; |
2949 | 480k | ParseState.xxbyteno = 0; |
2950 | 480k | ParseState.xxparseno += 1; |
2951 | 7.71M | } else { |
2952 | | /* We only advance the column for the 1st byte in UTF-8, so handle later bytes specially */ |
2953 | 7.71M | if (!known_to_be_utf8 || (unsigned char)c < 0x80 || 0xC0 <= (unsigned char)c) |
2954 | 7.71M | ParseState.xxcolno++; |
2955 | 7.71M | ParseState.xxbyteno++; |
2956 | 7.71M | } |
2957 | | |
2958 | 8.19M | if (c == '\t') ParseState.xxcolno = ((ParseState.xxcolno + 7) & ~7); |
2959 | | |
2960 | 8.19M | R_ParseContextLine = ParseState.xxlineno; |
2961 | | |
2962 | 8.19M | xxcharcount++; |
2963 | 8.19M | return c; |
2964 | 8.19M | } |
2965 | | |
2966 | | static int xxungetc(int c) |
2967 | 1.12M | { |
2968 | | /* this assumes that c was the result of xxgetc; if not, some edits will be needed */ |
2969 | 1.12M | ParseState.xxlineno = prevlines[prevpos]; |
2970 | 1.12M | ParseState.xxbyteno = prevbytes[prevpos]; |
2971 | 1.12M | ParseState.xxcolno = prevcols[prevpos]; |
2972 | 1.12M | ParseState.xxparseno = prevparse[prevpos]; |
2973 | | |
2974 | 1.12M | prevpos = (prevpos + PUSHBACK_BUFSIZE - 1) % PUSHBACK_BUFSIZE; |
2975 | | |
2976 | 1.12M | R_ParseContextLine = ParseState.xxlineno; |
2977 | | |
2978 | 1.12M | xxcharcount--; |
2979 | 1.12M | R_ParseContext[R_ParseContextLast] = '\0'; |
2980 | | /* precaution as to how % is implemented for < 0 numbers */ |
2981 | 1.12M | R_ParseContextLast = (R_ParseContextLast + PARSE_CONTEXT_SIZE -1) % PARSE_CONTEXT_SIZE; |
2982 | 1.12M | if(npush >= PUSHBACK_BUFSIZE) return EOF; |
2983 | 1.12M | pushback[npush++] = c; |
2984 | 1.12M | return c; |
2985 | 1.12M | } |
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 | 1.46k | { |
3012 | 1.46k | int i, c, nbytes = 0, first; |
3013 | 1.46k | bool mbcs = false; |
3014 | | |
3015 | | /* find the first byte of the context */ |
3016 | 1.46k | for(i = R_ParseContextLast; |
3017 | 136k | R_ParseContext[i]; |
3018 | 135k | i = (i + PARSE_CONTEXT_SIZE - 1) % PARSE_CONTEXT_SIZE) { |
3019 | | |
3020 | 135k | nbytes++; |
3021 | 135k | if (nbytes == PARSE_CONTEXT_SIZE) |
3022 | 184 | break; |
3023 | 135k | } |
3024 | 1.46k | if (!nbytes) |
3025 | 0 | return; |
3026 | 1.46k | if (!R_ParseContext[i]) |
3027 | 1.28k | first = (i + 1) % PARSE_CONTEXT_SIZE; |
3028 | 184 | 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 | 184 | return; |
3033 | | |
3034 | | /* decode multi-byte characters */ |
3035 | 89.7k | for(i = 0; i < nbytes; i++) { |
3036 | 88.4k | c = R_ParseContext[(first + i) % PARSE_CONTEXT_SIZE]; |
3037 | 88.4k | if ((unsigned int)c < 0x80) continue; /* ASCII */ |
3038 | | |
3039 | 2.15k | 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.15k | mbcs = true; |
3052 | 2.15k | } |
3053 | 1.28k | if (!mbcs) |
3054 | 839 | return; |
3055 | | |
3056 | | /* copy the context to a linear buffer */ |
3057 | 443 | char buf[nbytes + R_MB_CUR_MAX]; |
3058 | | |
3059 | 20.2k | for(i = 0; i < nbytes; i++) |
3060 | 19.7k | buf[i] = R_ParseContext[(first + i) % PARSE_CONTEXT_SIZE]; |
3061 | | |
3062 | 16.0k | for(i = 0; i < nbytes; i++) { |
3063 | 15.6k | wchar_t wc; |
3064 | 15.6k | int res; |
3065 | 15.6k | mbstate_t mb_st; |
3066 | | |
3067 | 15.6k | mbs_init(&mb_st); |
3068 | 15.6k | res = (int) mbrtowc(&wc, buf + i, nbytes - i, &mb_st); |
3069 | 15.6k | 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 | 15.6k | if (res == -1) |
3076 | 443 | raiseLexError("invalidMBCS", NO_VALUE, NULL, |
3077 | 443 | _("invalid multibyte character in parser (%s:%d:%d)")); |
3078 | 15.6k | i += res - 1; |
3079 | 15.6k | } |
3080 | 443 | } |
3081 | | |
3082 | | /* |
3083 | | * Increments/inits the token/grouping counter |
3084 | | */ |
3085 | 4.42M | static void incrementId(void){ |
3086 | 4.42M | identifier++; |
3087 | 4.42M | } |
3088 | | |
3089 | 10.8k | static void initId(void){ |
3090 | 10.8k | identifier = 0 ; |
3091 | 10.8k | } |
3092 | | |
3093 | | static SEXP makeSrcref(YYLTYPE *lloc, SEXP srcfile) |
3094 | 205k | { |
3095 | 205k | SEXP val; |
3096 | | |
3097 | 205k | PROTECT(val = allocVector(INTSXP, 8)); |
3098 | 205k | INTEGER(val)[0] = lloc->first_line; |
3099 | 205k | INTEGER(val)[1] = lloc->first_byte; |
3100 | 205k | INTEGER(val)[2] = lloc->last_line; |
3101 | 205k | INTEGER(val)[3] = lloc->last_byte; |
3102 | 205k | INTEGER(val)[4] = lloc->first_column; |
3103 | 205k | INTEGER(val)[5] = lloc->last_column; |
3104 | 205k | INTEGER(val)[6] = lloc->first_parsed; |
3105 | 205k | INTEGER(val)[7] = lloc->last_parsed; |
3106 | 205k | setAttrib(val, R_SrcfileSymbol, srcfile); |
3107 | 205k | setAttrib(val, R_ClassSymbol, mkString("srcref")); |
3108 | 205k | UNPROTECT(1); /* val */ |
3109 | 205k | return val; |
3110 | 205k | } |
3111 | | |
3112 | | static void attachSrcrefs(SEXP val) |
3113 | 825 | { |
3114 | 825 | SEXP srval; |
3115 | | |
3116 | 825 | PROTECT(srval = SrcRefsToVectorList()); |
3117 | | |
3118 | 825 | setAttrib(val, R_SrcrefSymbol, srval); |
3119 | 825 | setAttrib(val, R_SrcfileSymbol, PS_SRCFILE); |
3120 | 825 | { |
3121 | 825 | YYLTYPE wholeFile; |
3122 | 825 | wholeFile.first_line = 1; |
3123 | 825 | wholeFile.first_byte = 0; |
3124 | 825 | wholeFile.first_column = 0; |
3125 | 825 | wholeFile.last_line = ParseState.xxlineno; |
3126 | 825 | wholeFile.last_byte = ParseState.xxbyteno; |
3127 | 825 | wholeFile.last_column = ParseState.xxcolno; |
3128 | 825 | wholeFile.first_parsed = 1; |
3129 | 825 | wholeFile.last_parsed = ParseState.xxparseno; |
3130 | 825 | setAttrib(val, R_WholeSrcrefSymbol, PROTECT(makeSrcref(&wholeFile, PS_SRCFILE))); |
3131 | 825 | UNPROTECT(1); |
3132 | 825 | } |
3133 | 825 | PS_SET_SRCREFS(R_NilValue); |
3134 | 825 | ParseState.didAttach = true; |
3135 | 825 | UNPROTECT(1); /* srval */ |
3136 | 825 | } |
3137 | | |
3138 | | static int xxvalue(SEXP v, int k, YYLTYPE *lloc) |
3139 | 321k | { |
3140 | 321k | if (k > 2) { |
3141 | 275k | if (ParseState.keepSrcRefs) { |
3142 | 203k | SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE)); |
3143 | 203k | AppendToSrcRefs(s); |
3144 | 203k | UNPROTECT(1); /* s */ |
3145 | 203k | } |
3146 | 275k | RELEASE_SV(v); |
3147 | 275k | } |
3148 | 321k | R_CurrentExpr = v; |
3149 | 321k | return k; |
3150 | 321k | } |
3151 | | |
3152 | | static SEXP xxnullformal(void) |
3153 | 173 | { |
3154 | 173 | SEXP ans; |
3155 | 173 | PRESERVE_SV(ans = R_NilValue); |
3156 | 173 | return ans; |
3157 | 173 | } |
3158 | | |
3159 | | static SEXP xxfirstformal0(SEXP sym) |
3160 | 1.99k | { |
3161 | 1.99k | SEXP ans; |
3162 | 1.99k | if (GenerateCode) |
3163 | 1.99k | PRESERVE_SV(ans = FirstArg(R_MissingArg, sym)); |
3164 | 0 | else |
3165 | 0 | PRESERVE_SV(ans = R_NilValue); |
3166 | 1.99k | RELEASE_SV(sym); |
3167 | 1.99k | return ans; |
3168 | 1.99k | } |
3169 | | |
3170 | | static SEXP xxfirstformal1(SEXP sym, SEXP expr) |
3171 | 309 | { |
3172 | 309 | SEXP ans; |
3173 | 309 | if (GenerateCode) |
3174 | 309 | PRESERVE_SV(ans = FirstArg(expr, sym)); |
3175 | 0 | else |
3176 | 0 | PRESERVE_SV(ans = R_NilValue); |
3177 | 309 | RELEASE_SV(expr); |
3178 | 309 | RELEASE_SV(sym); |
3179 | 309 | return ans; |
3180 | 309 | } |
3181 | | |
3182 | | static SEXP xxaddformal0(SEXP formlist, SEXP sym, YYLTYPE *lloc) |
3183 | 1.52k | { |
3184 | 1.52k | SEXP ans; |
3185 | 1.52k | if (GenerateCode) { |
3186 | 1.52k | CheckFormalArgs(formlist, sym, lloc); |
3187 | 1.52k | NextArg(formlist, R_MissingArg, sym); |
3188 | 1.52k | ans = formlist; |
3189 | 1.52k | } else { |
3190 | 0 | RELEASE_SV(formlist); |
3191 | 0 | PRESERVE_SV(ans = R_NilValue); |
3192 | 0 | } |
3193 | 1.52k | RELEASE_SV(sym); |
3194 | 1.52k | return ans; |
3195 | 1.52k | } |
3196 | | |
3197 | | static SEXP xxaddformal1(SEXP formlist, SEXP sym, SEXP expr, YYLTYPE *lloc) |
3198 | 206 | { |
3199 | 206 | SEXP ans; |
3200 | 206 | if (GenerateCode) { |
3201 | 206 | CheckFormalArgs(formlist, sym, lloc); |
3202 | 206 | NextArg(formlist, expr, sym); |
3203 | 206 | ans = formlist; |
3204 | 206 | } else { |
3205 | 0 | RELEASE_SV(formlist); |
3206 | 0 | PRESERVE_SV(ans = R_NilValue); |
3207 | 0 | } |
3208 | 206 | RELEASE_SV(expr); |
3209 | 206 | RELEASE_SV(sym); |
3210 | 206 | return ans; |
3211 | 206 | } |
3212 | | |
3213 | | static SEXP xxexprlist0(void) |
3214 | 101 | { |
3215 | 101 | SEXP ans; |
3216 | 101 | if (GenerateCode) { |
3217 | 101 | PRESERVE_SV(ans = NewList()); |
3218 | 101 | if (ParseState.keepSrcRefs) { |
3219 | 38 | setAttrib(ans, R_SrcrefSymbol, PS_SRCREFS); |
3220 | 38 | PS_SET_SRCREFS(R_NilValue); |
3221 | 38 | } |
3222 | 101 | } |
3223 | 0 | else |
3224 | 0 | PRESERVE_SV(ans = R_NilValue); |
3225 | 101 | return ans; |
3226 | 101 | } |
3227 | | |
3228 | | static SEXP xxexprlist1(SEXP expr, YYLTYPE *lloc) |
3229 | 1.66k | { |
3230 | 1.66k | SEXP ans; |
3231 | 1.66k | if (GenerateCode) { |
3232 | 1.66k | PRESERVE_SV(ans = NewList()); |
3233 | 1.66k | if (ParseState.keepSrcRefs) { |
3234 | 221 | setAttrib(ans, R_SrcrefSymbol, PS_SRCREFS); |
3235 | 221 | SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE)); |
3236 | 221 | SetSingleSrcRef(s); |
3237 | 221 | UNPROTECT(1); /* s */ |
3238 | 221 | } |
3239 | 1.66k | GrowList(ans, expr); |
3240 | 1.66k | } |
3241 | 0 | else |
3242 | 0 | PRESERVE_SV(ans = R_NilValue); |
3243 | 1.66k | RELEASE_SV(expr); |
3244 | 1.66k | return ans; |
3245 | 1.66k | } |
3246 | | |
3247 | | static SEXP xxexprlist2(SEXP exprlist, SEXP expr, YYLTYPE *lloc) |
3248 | 5.45k | { |
3249 | 5.45k | SEXP ans; |
3250 | 5.45k | if (GenerateCode) { |
3251 | 5.45k | if (ParseState.keepSrcRefs) { |
3252 | 1.01k | SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE)); |
3253 | 1.01k | AppendToSrcRefs(s); |
3254 | 1.01k | UNPROTECT(1); /* s */ |
3255 | 1.01k | } |
3256 | 5.45k | GrowList(exprlist, expr); |
3257 | 5.45k | ans = exprlist; |
3258 | 5.45k | } else { |
3259 | 0 | RELEASE_SV(exprlist); |
3260 | 0 | PRESERVE_SV(ans = R_NilValue); |
3261 | 0 | } |
3262 | 5.45k | RELEASE_SV(expr); |
3263 | 5.45k | return ans; |
3264 | 5.45k | } |
3265 | | |
3266 | | static SEXP xxsub0(void) |
3267 | 5.27k | { |
3268 | 5.27k | SEXP ans; |
3269 | 5.27k | if (GenerateCode) |
3270 | 5.27k | PRESERVE_SV(ans = lang2(R_MissingArg,R_NilValue)); |
3271 | 0 | else |
3272 | 0 | PRESERVE_SV(ans = R_NilValue); |
3273 | 5.27k | return ans; |
3274 | 5.27k | } |
3275 | | |
3276 | | static SEXP xxsub1(SEXP expr, YYLTYPE *lloc) |
3277 | 51.9k | { |
3278 | 51.9k | SEXP ans; |
3279 | 51.9k | if (GenerateCode) |
3280 | 51.9k | PRESERVE_SV(ans = TagArg(expr, R_NilValue, lloc)); |
3281 | 0 | else |
3282 | 0 | PRESERVE_SV(ans = R_NilValue); |
3283 | 51.9k | RELEASE_SV(expr); |
3284 | 51.9k | return ans; |
3285 | 51.9k | } |
3286 | | |
3287 | | static SEXP xxsymsub0(SEXP sym, YYLTYPE *lloc) |
3288 | 891 | { |
3289 | 891 | SEXP ans; |
3290 | 891 | if (GenerateCode) |
3291 | 891 | PRESERVE_SV(ans = TagArg(R_MissingArg, sym, lloc)); |
3292 | 0 | else |
3293 | 0 | PRESERVE_SV(ans = R_NilValue); |
3294 | 891 | RELEASE_SV(sym); |
3295 | 891 | return ans; |
3296 | 891 | } |
3297 | | |
3298 | | static SEXP xxsymsub1(SEXP sym, SEXP expr, YYLTYPE *lloc) |
3299 | 4.47k | { |
3300 | 4.47k | SEXP ans; |
3301 | 4.47k | if (GenerateCode) |
3302 | 4.47k | PRESERVE_SV(ans = TagArg(expr, sym, lloc)); |
3303 | 0 | else |
3304 | 0 | PRESERVE_SV(ans = R_NilValue); |
3305 | 4.47k | RELEASE_SV(expr); |
3306 | 4.47k | RELEASE_SV(sym); |
3307 | 4.47k | return ans; |
3308 | 4.47k | } |
3309 | | |
3310 | | static SEXP xxnullsub0(YYLTYPE *lloc) |
3311 | 10 | { |
3312 | 10 | SEXP ans; |
3313 | 10 | if (GenerateCode) |
3314 | 10 | PRESERVE_SV(ans = TagArg(R_MissingArg, R_NullSymbol, lloc)); |
3315 | 0 | else |
3316 | 0 | PRESERVE_SV(ans = R_NilValue); |
3317 | 10 | RELEASE_SV(R_NilValue); |
3318 | 10 | return ans; |
3319 | 10 | } |
3320 | | |
3321 | | static SEXP xxnullsub1(SEXP expr, YYLTYPE *lloc) |
3322 | 89 | { |
3323 | 89 | SEXP ans; |
3324 | 89 | if (GenerateCode) |
3325 | 89 | PRESERVE_SV(ans = TagArg(expr, R_NullSymbol, lloc)); |
3326 | 0 | else |
3327 | 0 | PRESERVE_SV(ans = R_NilValue); |
3328 | 89 | RELEASE_SV(R_NilValue); |
3329 | 89 | RELEASE_SV(expr); |
3330 | 89 | return ans; |
3331 | 89 | } |
3332 | | |
3333 | | |
3334 | | static SEXP xxsublist1(SEXP sub) |
3335 | 52.0k | { |
3336 | 52.0k | SEXP ans; |
3337 | 52.0k | if (GenerateCode) |
3338 | 52.0k | PRESERVE_SV(ans = FirstArg(CAR(sub),CADR(sub))); |
3339 | 0 | else |
3340 | 0 | PRESERVE_SV(ans = R_NilValue); |
3341 | 52.0k | RELEASE_SV(sub); |
3342 | 52.0k | return ans; |
3343 | 52.0k | } |
3344 | | |
3345 | | static SEXP xxsublist2(SEXP sublist, SEXP sub) |
3346 | 10.7k | { |
3347 | 10.7k | SEXP ans; |
3348 | 10.7k | if (GenerateCode) { |
3349 | 10.7k | NextArg(sublist, CAR(sub), CADR(sub)); |
3350 | 10.7k | ans = sublist; |
3351 | 10.7k | } else { |
3352 | 0 | RELEASE_SV(sublist); |
3353 | 0 | PRESERVE_SV(ans = R_NilValue); |
3354 | 0 | } |
3355 | 10.7k | RELEASE_SV(sub); |
3356 | 10.7k | return ans; |
3357 | 10.7k | } |
3358 | | |
3359 | | static SEXP xxcond(SEXP expr) |
3360 | 412 | { |
3361 | 412 | EatLines = 1; |
3362 | 412 | return expr; |
3363 | 412 | } |
3364 | | |
3365 | | static SEXP xxifcond(SEXP expr) |
3366 | 3.51k | { |
3367 | 3.51k | EatLines = 1; |
3368 | 3.51k | return expr; |
3369 | 3.51k | } |
3370 | | |
3371 | | static SEXP xxif(SEXP ifsym, SEXP cond, SEXP expr) |
3372 | 1.82k | { |
3373 | 1.82k | SEXP ans; |
3374 | 1.82k | if (GenerateCode) |
3375 | 1.82k | PRESERVE_SV(ans = lang3(ifsym, cond, expr)); |
3376 | 0 | else |
3377 | 0 | PRESERVE_SV(ans = R_NilValue); |
3378 | 1.82k | RELEASE_SV(expr); |
3379 | 1.82k | RELEASE_SV(cond); |
3380 | 1.82k | return ans; |
3381 | 1.82k | } |
3382 | | |
3383 | | static SEXP xxifelse(SEXP ifsym, SEXP cond, SEXP ifexpr, SEXP elseexpr) |
3384 | 1.17k | { |
3385 | 1.17k | SEXP ans; |
3386 | 1.17k | if (GenerateCode) |
3387 | 1.17k | PRESERVE_SV(ans = lang4(ifsym, cond, ifexpr, elseexpr)); |
3388 | 0 | else |
3389 | 0 | PRESERVE_SV(ans = R_NilValue); |
3390 | 1.17k | RELEASE_SV(elseexpr); |
3391 | 1.17k | RELEASE_SV(ifexpr); |
3392 | 1.17k | RELEASE_SV(cond); |
3393 | 1.17k | return ans; |
3394 | 1.17k | } |
3395 | | |
3396 | | static SEXP xxforcond(SEXP sym, SEXP expr) |
3397 | 330 | { |
3398 | 330 | SEXP ans; |
3399 | 330 | EatLines = 1; |
3400 | 330 | if (GenerateCode) |
3401 | 330 | PRESERVE_SV(ans = LCONS(sym, expr)); |
3402 | 0 | else |
3403 | 0 | PRESERVE_SV(ans = R_NilValue); |
3404 | 330 | RELEASE_SV(expr); |
3405 | 330 | RELEASE_SV(sym); |
3406 | 330 | return ans; |
3407 | 330 | } |
3408 | | |
3409 | | static SEXP xxfor(SEXP forsym, SEXP forcond, SEXP body) |
3410 | 327 | { |
3411 | 327 | SEXP ans; |
3412 | 327 | if (GenerateCode) |
3413 | 327 | PRESERVE_SV(ans = lang4(forsym, CAR(forcond), CDR(forcond), body)); |
3414 | 0 | else |
3415 | 0 | PRESERVE_SV(ans = R_NilValue); |
3416 | 327 | RELEASE_SV(body); |
3417 | 327 | RELEASE_SV(forcond); |
3418 | 327 | return ans; |
3419 | 327 | } |
3420 | | |
3421 | | static SEXP xxwhile(SEXP whilesym, SEXP cond, SEXP body) |
3422 | 208 | { |
3423 | 208 | SEXP ans; |
3424 | 208 | if (GenerateCode) |
3425 | 208 | PRESERVE_SV(ans = lang3(whilesym, cond, body)); |
3426 | 0 | else |
3427 | 0 | PRESERVE_SV(ans = R_NilValue); |
3428 | 208 | RELEASE_SV(body); |
3429 | 208 | RELEASE_SV(cond); |
3430 | 208 | return ans; |
3431 | 208 | } |
3432 | | |
3433 | | static SEXP xxrepeat(SEXP repeatsym, SEXP body) |
3434 | 477 | { |
3435 | 477 | SEXP ans; |
3436 | 477 | if (GenerateCode) |
3437 | 477 | PRESERVE_SV(ans = lang2(repeatsym, body)); |
3438 | 0 | else |
3439 | 0 | PRESERVE_SV(ans = R_NilValue); |
3440 | 477 | RELEASE_SV(body); |
3441 | 477 | return ans; |
3442 | 477 | } |
3443 | | |
3444 | | static SEXP xxnxtbrk(SEXP keyword) |
3445 | 1.89k | { |
3446 | 1.89k | if (GenerateCode) |
3447 | 1.89k | PRESERVE_SV(keyword = lang1(keyword)); |
3448 | 0 | else |
3449 | 0 | PRESERVE_SV(keyword = R_NilValue); |
3450 | 1.89k | return keyword; |
3451 | 1.89k | } |
3452 | | |
3453 | | static SEXP xxfuncall(SEXP expr, SEXP args) |
3454 | 47.7k | { |
3455 | 47.7k | SEXP ans, sav_expr = expr; |
3456 | 47.7k | if (GenerateCode) { |
3457 | 47.7k | if (isString(expr) && expr != R_PlaceholderToken) |
3458 | 1.72k | expr = installTrChar(STRING_ELT(expr, 0)); |
3459 | 47.7k | PROTECT(expr); |
3460 | 47.7k | if (length(CDR(args)) == 1 && CADR(args) == R_MissingArg && TAG(CDR(args)) == R_NilValue ) |
3461 | 2.94k | ans = lang1(expr); |
3462 | 44.7k | else |
3463 | 44.7k | ans = LCONS(expr, CDR(args)); |
3464 | 47.7k | UNPROTECT(1); /* expr */ |
3465 | 47.7k | PRESERVE_SV(ans); |
3466 | 47.7k | } else |
3467 | 0 | PRESERVE_SV(ans = R_NilValue); |
3468 | | |
3469 | 47.7k | RELEASE_SV(args); |
3470 | 47.7k | RELEASE_SV(sav_expr); |
3471 | 47.7k | return ans; |
3472 | 47.7k | } |
3473 | | |
3474 | | static SEXP mkChar2(const char *name) |
3475 | 660k | { |
3476 | 660k | cetype_t enc = CE_NATIVE; |
3477 | | |
3478 | 660k | if(known_to_be_latin1) enc = CE_LATIN1; |
3479 | 660k | else if(known_to_be_utf8) enc = CE_UTF8; |
3480 | | |
3481 | 660k | return mkCharLenCE(name, (int) strlen(name), enc); |
3482 | 660k | } |
3483 | | |
3484 | | static SEXP mkString2(const char *s, size_t len, bool escaped) |
3485 | 11.0k | { |
3486 | 11.0k | SEXP t; |
3487 | 11.0k | cetype_t enc = CE_NATIVE; |
3488 | | |
3489 | 11.0k | if(known_to_be_latin1) enc = CE_LATIN1; |
3490 | 11.0k | else if(!escaped && known_to_be_utf8) enc = CE_UTF8; |
3491 | | |
3492 | 11.0k | PROTECT(t = allocVector(STRSXP, 1)); |
3493 | 11.0k | SET_STRING_ELT(t, 0, mkCharLenCE(s, (int) len, enc)); |
3494 | 11.0k | UNPROTECT(1); /* t */ |
3495 | 11.0k | return t; |
3496 | 11.0k | } |
3497 | | |
3498 | | static SEXP xxdefun(SEXP fname, SEXP formals, SEXP body, YYLTYPE *lloc) |
3499 | 2.03k | { |
3500 | 2.03k | SEXP ans, srcref; |
3501 | | |
3502 | 2.03k | if (GenerateCode) { |
3503 | 2.03k | if (ParseState.keepSrcRefs) { |
3504 | 134 | srcref = makeSrcref(lloc, PS_SRCFILE); |
3505 | 134 | ParseState.didAttach = true; |
3506 | 134 | } else |
3507 | 1.89k | srcref = R_NilValue; |
3508 | 2.03k | PRESERVE_SV(ans = lang4(fname, CDR(formals), body, PROTECT(srcref))); |
3509 | 2.03k | UNPROTECT(1); |
3510 | 2.03k | } else |
3511 | 0 | PRESERVE_SV(ans = R_NilValue); |
3512 | 2.03k | RELEASE_SV(body); |
3513 | 2.03k | RELEASE_SV(formals); |
3514 | 2.03k | return ans; |
3515 | 2.03k | } |
3516 | | |
3517 | | static SEXP xxunary(SEXP op, SEXP arg) |
3518 | 306k | { |
3519 | 306k | SEXP ans; |
3520 | 306k | if (GenerateCode) |
3521 | 306k | PRESERVE_SV(ans = lang2(op, arg)); |
3522 | 0 | else |
3523 | 0 | PRESERVE_SV(ans = R_NilValue); |
3524 | 306k | RELEASE_SV(arg); |
3525 | 306k | return ans; |
3526 | 306k | } |
3527 | | |
3528 | | static SEXP xxbinary(SEXP n1, SEXP n2, SEXP n3) |
3529 | 235k | { |
3530 | 235k | SEXP ans; |
3531 | 235k | if (GenerateCode) |
3532 | 235k | PRESERVE_SV(ans = lang3(n1, n2, n3)); |
3533 | 0 | else |
3534 | 0 | PRESERVE_SV(ans = R_NilValue); |
3535 | 235k | RELEASE_SV(n2); |
3536 | 235k | RELEASE_SV(n3); |
3537 | 235k | return ans; |
3538 | 235k | } |
3539 | | |
3540 | | static void check_rhs(SEXP rhs, YYLTYPE *lloc) |
3541 | 639 | { |
3542 | | /* rule out syntactically special functions */ |
3543 | | /* the IS_SPECIAL_SYMBOL bit is set in names.c */ |
3544 | 639 | SEXP fun = CAR(rhs); |
3545 | 639 | if (TYPEOF(fun) == SYMSXP && IS_SPECIAL_SYMBOL(fun)) |
3546 | 258 | raiseParseError("unsupportedInPipe", rhs, STRING_VALUE, |
3547 | 258 | CHAR(PRINTNAME(fun)), lloc, |
3548 | 258 | _("function '%s' not supported in RHS call of a pipe (%s:%d:%d)")); |
3549 | 639 | } |
3550 | | |
3551 | | static void checkTooManyPlaceholders(SEXP rhs, SEXP args, YYLTYPE *lloc) |
3552 | 67 | { |
3553 | 90 | for (SEXP rest = args; rest != R_NilValue; rest = CDR(rest)) |
3554 | 23 | if (CAR(rest) == R_PlaceholderToken) |
3555 | 3 | raiseParseError("tooManyPlaceholders", rhs, NO_VALUE, NULL, lloc, |
3556 | 3 | _("pipe placeholder may only appear once (%s:%d:%d)")); |
3557 | 67 | } |
3558 | | |
3559 | | static bool checkForPlaceholderList(SEXP placeholder, SEXP list) |
3560 | 374 | { |
3561 | 747 | for (; list != R_NilValue; list = CDR(list)) |
3562 | 373 | if (checkForPlaceholder(placeholder, CAR(list))) |
3563 | 0 | return true; |
3564 | 374 | return false; |
3565 | 374 | } |
3566 | | |
3567 | | static SEXP findExtractorChainPHCell(SEXP placeholder, SEXP rhs, SEXP expr, |
3568 | | YYLTYPE *lloc) |
3569 | 1.25k | { |
3570 | 1.25k | SEXP fun = CAR(expr); |
3571 | 1.25k | if (fun == R_BracketSymbol || |
3572 | 1.23k | fun == R_Bracket2Symbol || |
3573 | 1.22k | fun == R_DollarSymbol || |
3574 | 966 | 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 | 535 | SEXP arg1 = CADR(expr); |
3580 | 535 | SEXP phcell = arg1 == placeholder ? |
3581 | 147 | CDR(expr) : |
3582 | 535 | 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 | 535 | if (phcell != NULL && |
3586 | 374 | checkForPlaceholderList(placeholder, CDDR(expr))) |
3587 | 0 | raiseParseError("tooManyPlaceholders", rhs, NO_VALUE, NULL, lloc, |
3588 | 0 | _("pipe placeholder may only appear once (%s:%d:%d)")); |
3589 | 535 | return phcell; |
3590 | 535 | } |
3591 | 721 | else return NULL; |
3592 | 1.25k | } |
3593 | | |
3594 | | static SEXP xxpipe(SEXP lhs, SEXP rhs, YYLTYPE *lloc_rhs) |
3595 | 1.00k | { |
3596 | 1.00k | SEXP ans; |
3597 | 1.00k | if (GenerateCode) { |
3598 | 1.00k | if (TYPEOF(rhs) != LANGSXP) |
3599 | 110 | raiseParseError("RHSnotFnCall", rhs, NO_VALUE, NULL, lloc_rhs, |
3600 | 110 | _("The pipe operator requires a function call as RHS (%s:%d:%d)")); |
3601 | | |
3602 | | /* allow x => log(x) on RHS */ |
3603 | 1.00k | if (CAR(rhs) == R_PipeBindSymbol) { |
3604 | 30 | SEXP var = CADR(rhs); |
3605 | 30 | SEXP expr = CADDR(rhs); |
3606 | 30 | 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 | 30 | SEXP alist = list1(R_MissingArg); |
3610 | 30 | SET_TAG(alist, var); |
3611 | 30 | 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 | 30 | PRESERVE_SV(ans = lang2(fun, lhs)); |
3615 | 30 | RELEASE_SV(lhs); |
3616 | 30 | RELEASE_SV(rhs); |
3617 | 30 | return ans; |
3618 | 30 | } |
3619 | | |
3620 | | /* check for placeholder in the RHS function */ |
3621 | 979 | if (checkForPlaceholder(R_PlaceholderToken, CAR(rhs))) |
3622 | 1 | raiseParseError("placeholderInRHSFn",R_NilValue, |
3623 | 1 | NO_VALUE, NULL, lloc_rhs, |
3624 | 1 | _("pipe placeholder cannot be used in the RHS function (%s:%d:%d)")); |
3625 | | |
3626 | | /* allow for _$a[1]$b and the like */ |
3627 | 979 | SEXP phcell = findExtractorChainPHCell(R_PlaceholderToken, rhs, rhs, |
3628 | 979 | lloc_rhs); |
3629 | 979 | if (phcell != NULL) { |
3630 | 147 | SETCAR(phcell, lhs); |
3631 | 147 | return rhs; |
3632 | 147 | } |
3633 | | |
3634 | | /* allow top-level placeholder */ |
3635 | 1.76k | for (SEXP a = CDR(rhs); a != R_NilValue; a = CDR(a)) |
3636 | 1.00k | if (CAR(a) == R_PlaceholderToken) { |
3637 | 69 | if (TAG(a) == R_NilValue) |
3638 | 2 | raiseParseError("placeholderNotNamed", rhs, |
3639 | 2 | NO_VALUE, NULL, lloc_rhs, |
3640 | 2 | _("pipe placeholder can only be used as a named argument (%s:%d:%d)")); |
3641 | 69 | checkTooManyPlaceholders(rhs, CDR(a), lloc_rhs); |
3642 | 69 | SETCAR(a, lhs); |
3643 | 69 | return rhs; |
3644 | 69 | } |
3645 | | |
3646 | 763 | check_rhs(rhs, lloc_rhs); |
3647 | | |
3648 | 763 | SEXP fun = CAR(rhs); |
3649 | 763 | SEXP args = CDR(rhs); |
3650 | 763 | PRESERVE_SV(ans = lcons(fun, lcons(lhs, args))); |
3651 | 763 | } |
3652 | 0 | else { |
3653 | 0 | PRESERVE_SV(ans = R_NilValue); |
3654 | 0 | } |
3655 | 763 | RELEASE_SV(lhs); |
3656 | 763 | RELEASE_SV(rhs); |
3657 | 763 | return ans; |
3658 | 1.00k | } |
3659 | | |
3660 | | static SEXP xxpipebind(SEXP fn, SEXP lhs, SEXP rhs, YYLTYPE *lloc_bind) |
3661 | 667 | { |
3662 | 667 | static int use_pipebind = 0; |
3663 | 667 | if (use_pipebind != 1) { |
3664 | 1 | char *lookup = getenv("_R_USE_PIPEBIND_"); |
3665 | 1 | use_pipebind = ((lookup != NULL) && StringTrue(lookup)) ? 1 : 0; |
3666 | 1 | } |
3667 | | |
3668 | 667 | if (use_pipebind) |
3669 | 667 | return xxbinary(fn, lhs, rhs); |
3670 | 0 | else |
3671 | 0 | raiseParseError("pipebindDisabled", R_NilValue, |
3672 | 0 | NO_VALUE, NULL, lloc_bind, |
3673 | 0 | _("'=>' is disabled; set '_R_USE_PIPEBIND_' envvar to a true value to enable it (%s:%d:%d)")); |
3674 | 667 | } |
3675 | | |
3676 | | static SEXP xxparen(SEXP n1, SEXP n2) |
3677 | 969 | { |
3678 | 969 | SEXP ans; |
3679 | 969 | if (GenerateCode) |
3680 | 969 | PRESERVE_SV(ans = lang2(n1, n2)); |
3681 | 0 | else |
3682 | 0 | PRESERVE_SV(ans = R_NilValue); |
3683 | 969 | RELEASE_SV(n2); |
3684 | 969 | return ans; |
3685 | 969 | } |
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 | 3.72k | { |
3694 | 3.72k | SEXP ans; |
3695 | 3.72k | if (GenerateCode) |
3696 | 3.72k | PRESERVE_SV(ans = LCONS(a2, CONS(a1, CDR(a3)))); |
3697 | 0 | else |
3698 | 0 | PRESERVE_SV(ans = R_NilValue); |
3699 | 3.72k | RELEASE_SV(a3); |
3700 | 3.72k | RELEASE_SV(a1); |
3701 | 3.72k | return ans; |
3702 | 3.72k | } |
3703 | | |
3704 | | static SEXP xxexprlist(SEXP a1, YYLTYPE *lloc, SEXP a2) |
3705 | 1.61k | { |
3706 | 1.61k | SEXP ans; |
3707 | 1.61k | SEXP prevSrcrefs; |
3708 | | |
3709 | 1.61k | EatLines = 0; |
3710 | 1.61k | if (GenerateCode) { |
3711 | 1.61k | SET_TYPEOF(a2, LANGSXP); |
3712 | 1.61k | SETCAR(a2, a1); |
3713 | 1.61k | if (ParseState.keepSrcRefs) { |
3714 | 196 | PROTECT(prevSrcrefs = getAttrib(a2, R_SrcrefSymbol)); |
3715 | 196 | SEXP s = PROTECT(makeSrcref(lloc, PS_SRCFILE)); |
3716 | 196 | PrependToSrcRefs(s); |
3717 | 196 | attachSrcrefs(a2); |
3718 | 196 | 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 | 196 | PS_SET_SRCREFS(prevSrcrefs); |
3727 | 196 | } |
3728 | 1.61k | PRESERVE_SV(ans = a2); |
3729 | 1.61k | } |
3730 | 0 | else |
3731 | 0 | PRESERVE_SV(ans = R_NilValue); |
3732 | 1.61k | RELEASE_SV(a2); |
3733 | 1.61k | return ans; |
3734 | 1.61k | } |
3735 | | |
3736 | | /*--------------------------------------------------------------------------*/ |
3737 | | |
3738 | | static SEXP TagArg(SEXP arg, SEXP tag, YYLTYPE *lloc) |
3739 | 57.4k | { |
3740 | 57.4k | switch (TYPEOF(tag)) { |
3741 | 1.39k | case STRSXP: |
3742 | 1.39k | tag = installTrChar(STRING_ELT(tag, 0)); |
3743 | 53.3k | case NILSXP: |
3744 | 57.4k | case SYMSXP: |
3745 | 57.4k | 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 | 57.4k | } |
3752 | 57.4k | } |
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 | 63.8k | { |
3766 | 63.8k | SEXP s = CONS(R_NilValue, R_NilValue); |
3767 | 63.8k | SETCAR(s, s); |
3768 | 63.8k | return s; |
3769 | 63.8k | } |
3770 | | |
3771 | | /* Add a new element at the end of a stretchy list */ |
3772 | | static void GrowList(SEXP l, SEXP s) |
3773 | 551k | { |
3774 | 551k | SEXP tmp; |
3775 | 551k | tmp = CONS(s, R_NilValue); |
3776 | 551k | SETCDR(CAR(l), tmp); |
3777 | 551k | SETCAR(l, tmp); |
3778 | 551k | } |
3779 | | |
3780 | | /* Create a stretchy list with a single named element */ |
3781 | | static SEXP FirstArg(SEXP s, SEXP tag) |
3782 | 54.3k | { |
3783 | 54.3k | SEXP tmp; |
3784 | 54.3k | PROTECT(tmp = NewList()); |
3785 | 54.3k | GrowList(tmp, s); |
3786 | 54.3k | SET_TAG(CAR(tmp), tag); |
3787 | 54.3k | UNPROTECT(1); /* tmp */ |
3788 | 54.3k | return tmp; |
3789 | 54.3k | } |
3790 | | |
3791 | | /* Add named element to the end of a stretchy list */ |
3792 | | static void NextArg(SEXP l, SEXP s, SEXP tag) |
3793 | 12.4k | { |
3794 | 12.4k | GrowList(l, s); |
3795 | 12.4k | SET_TAG(CAR(l), tag); |
3796 | 12.4k | } |
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 | 1.19k | { |
3804 | 1.19k | SEXP l; |
3805 | | |
3806 | 1.19k | PROTECT(l = NewList()); |
3807 | 1.19k | GrowList(l, r); |
3808 | 1.19k | PS_SET_SRCREFS(l); |
3809 | 1.19k | UNPROTECT(1); /* l */ |
3810 | 1.19k | } |
3811 | | |
3812 | | static void AppendToSrcRefs(SEXP r) |
3813 | 204k | { |
3814 | 204k | SEXP l = PS_SRCREFS; |
3815 | 204k | if (l == R_NilValue) |
3816 | 946 | SetSingleSrcRef(r); |
3817 | 203k | else |
3818 | 203k | GrowList(l, r); |
3819 | 204k | } |
3820 | | |
3821 | | static void PrependToSrcRefs(SEXP r) |
3822 | 196 | { |
3823 | 196 | SEXP l = PS_SRCREFS; |
3824 | 196 | if (l == R_NilValue) |
3825 | 24 | SetSingleSrcRef(r); |
3826 | 172 | else if (CDR(l) == R_NilValue) |
3827 | | /* adding to empty stretchy list */ |
3828 | 0 | GrowList(l, r); |
3829 | 172 | else { |
3830 | 172 | SEXP tmp = CONS(r, CDR(l)); |
3831 | 172 | SETCDR(l, tmp); |
3832 | 172 | } |
3833 | 196 | } |
3834 | | |
3835 | 825 | static SEXP SrcRefsToVectorList(void) { |
3836 | 825 | SEXP l = PS_SRCREFS; |
3837 | 825 | if (l == R_NilValue) |
3838 | 17 | return PairToVectorList(l); |
3839 | 808 | else |
3840 | 808 | return PairToVectorList(CDR(l)); |
3841 | 825 | } |
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 | 69.4k | #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 | 32 | { |
3905 | 32 | ParseState.sexps = allocVector(VECSXP, 7); /* initialized to R_NilValue */ |
3906 | 32 | ParseState.data = R_NilValue; |
3907 | 32 | INIT_SVS(); |
3908 | 32 | R_PreserveObject(ParseState.sexps); /* never released in an R session */ |
3909 | 32 | R_NullSymbol = install("NULL"); |
3910 | 32 | R_PlaceholderToken = ScalarString(mkChar("_")); |
3911 | 32 | MARK_NOT_MUTABLE(R_PlaceholderToken); |
3912 | 32 | R_PreserveObject(R_PlaceholderToken); |
3913 | 32 | R_PipeBindSymbol = install("=>"); |
3914 | 32 | } |
3915 | | |
3916 | | static void FinalizeSrcRefStateOnError(void *dummy) |
3917 | 1.99k | { |
3918 | 1.99k | R_FinalizeSrcRefState(); |
3919 | 1.99k | } |
3920 | | |
3921 | | /* This is called each time a new parse sequence begins */ |
3922 | | attribute_hidden |
3923 | | void R_InitSrcRefState(RCNTXT* cptr) |
3924 | 6.59k | { |
3925 | 6.59k | 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 | 6.59k | ParseState.prevState = NULL; |
3940 | | /* set up context _after_ PutSrcRefState */ |
3941 | 6.59k | begincontext(cptr, CTXT_CCODE, R_NilValue, R_BaseEnv, R_BaseEnv, |
3942 | 6.59k | R_NilValue, R_NilValue); |
3943 | 6.59k | cptr->cend = &FinalizeSrcRefStateOnError; |
3944 | 6.59k | cptr->cenddata = NULL; |
3945 | 6.59k | ParseState.keepSrcRefs = false; |
3946 | 6.59k | ParseState.keepParseData = true; |
3947 | 6.59k | ParseState.didAttach = false; |
3948 | 6.59k | PS_SET_SRCFILE(R_NilValue); |
3949 | 6.59k | PS_SET_ORIGINAL(R_NilValue); |
3950 | 6.59k | ParseState.data_count = 0; |
3951 | 6.59k | ParseState.xxlineno = 1; |
3952 | 6.59k | ParseState.xxcolno = 0; |
3953 | 6.59k | ParseState.xxbyteno = 0; |
3954 | 6.59k | ParseState.xxparseno = 1; |
3955 | 6.59k | busy = true; |
3956 | 6.59k | } |
3957 | | |
3958 | | attribute_hidden |
3959 | | void R_FinalizeSrcRefState(void) |
3960 | 6.59k | { |
3961 | 6.59k | PS_SET_SRCFILE(R_NilValue); |
3962 | 6.59k | PS_SET_ORIGINAL(R_NilValue); |
3963 | 6.59k | CLEAR_SVS(); |
3964 | | |
3965 | | /* a stack yyparse() was still using when an error unwound past it */ |
3966 | 6.59k | if (ParseState.yystack) { |
3967 | 18 | free(ParseState.yystack); |
3968 | 18 | ParseState.yystack = NULL; |
3969 | 18 | } |
3970 | | |
3971 | | /* Free the data, text and ids if we are restoring a previous state, |
3972 | | or if they have grown too large */ |
3973 | 6.59k | if (PS_DATA != R_NilValue) { |
3974 | 6.13k | 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 | 1.07M | for (int i=0; i < ParseState.data_count; i++) { |
3979 | 1.07M | SET_STRING_ELT(PS_TEXT, i, R_BlankString); |
3980 | 1.07M | _PARENT(i) = 0; |
3981 | 1.07M | } |
3982 | 6.13k | } |
3983 | 6.59k | if (PS_IDS != R_NilValue) { |
3984 | 6.13k | if (ParseState.prevState || ID_COUNT > MAX_DATA_COUNT) { |
3985 | 0 | PS_SET_IDS(R_NilValue); |
3986 | 6.13k | } else {/* Remove the parent records */ |
3987 | 6.13k | if (identifier > ID_COUNT) identifier = ID_COUNT; |
3988 | 4.16M | for (int i=0; i < identifier; i++) { |
3989 | 4.15M | ID_ID(i) = 0; |
3990 | 4.15M | ID_PARENT(i) = 0; |
3991 | 4.15M | } |
3992 | 6.13k | } |
3993 | 6.13k | } |
3994 | 6.59k | ParseState.data_count = NA_INTEGER; |
3995 | 6.59k | if (ParseState.prevState) { |
3996 | 0 | R_ReleaseObject(ParseState.sexps); |
3997 | 0 | SrcRefState *prev = ParseState.prevState; |
3998 | 0 | UseSrcRefState(prev); |
3999 | 0 | free(prev); |
4000 | 0 | } else |
4001 | 6.59k | busy = false; |
4002 | 6.59k | } |
4003 | | |
4004 | | static void UseSrcRefState(SrcRefState *state) |
4005 | 0 | { |
4006 | 0 | ParseState.keepSrcRefs = state->keepSrcRefs; |
4007 | 0 | ParseState.keepParseData = state->keepParseData; |
4008 | 0 | ParseState.sexps = state->sexps; |
4009 | 0 | ParseState.data = state->data; |
4010 | 0 | ParseState.data_count = state->data_count; |
4011 | 0 | ParseState.xxlineno = state->xxlineno; |
4012 | 0 | ParseState.xxcolno = state->xxcolno; |
4013 | 0 | ParseState.xxbyteno = state->xxbyteno; |
4014 | 0 | ParseState.xxparseno = state->xxparseno; |
4015 | 0 | ParseState.yystack = state->yystack; |
4016 | 0 | ParseState.prevState = state->prevState; |
4017 | 0 | busy = true; |
4018 | 0 | } |
4019 | | |
4020 | | static void PutSrcRefState(SrcRefState *state) |
4021 | 0 | { |
4022 | 0 | state->keepSrcRefs = ParseState.keepSrcRefs; |
4023 | 0 | state->keepParseData = ParseState.keepParseData; |
4024 | 0 | state->sexps = ParseState.sexps; |
4025 | 0 | state->data = ParseState.data; |
4026 | 0 | state->data_count = ParseState.data_count; |
4027 | 0 | state->xxlineno = ParseState.xxlineno; |
4028 | 0 | state->xxcolno = ParseState.xxcolno; |
4029 | 0 | state->xxbyteno = ParseState.xxbyteno; |
4030 | 0 | state->xxparseno = ParseState.xxparseno; |
4031 | 0 | state->yystack = ParseState.yystack; |
4032 | 0 | state->prevState = ParseState.prevState; |
4033 | 0 | } |
4034 | | |
4035 | | static void ParseInit(void) |
4036 | 326k | { |
4037 | 326k | contextp = contextstack; |
4038 | 326k | *contextp = ' '; |
4039 | 326k | SavedToken = 0; |
4040 | 326k | SavedLval = R_NilValue; |
4041 | 326k | EatLines = 0; |
4042 | 326k | EndOfFile = 0; |
4043 | 326k | xxcharcount = 0; |
4044 | 326k | npush = 0; |
4045 | 326k | HavePipeBind = FALSE; |
4046 | 326k | } |
4047 | | |
4048 | | static void initData(void) |
4049 | 10.8k | { |
4050 | 10.8k | ParseState.data_count = 0 ; |
4051 | 10.8k | } |
4052 | | |
4053 | | |
4054 | | static void ParseContextInit(void) |
4055 | 10.8k | { |
4056 | 10.8k | R_ParseContextLast = 0; |
4057 | 10.8k | R_ParseContext[0] = '\0'; |
4058 | | |
4059 | | /* starts the identifier counter*/ |
4060 | 10.8k | initId(); |
4061 | 10.8k | initData(); |
4062 | 10.8k | } |
4063 | | |
4064 | | static bool checkForPipeBind(SEXP arg) |
4065 | 278k | { |
4066 | 278k | if (! HavePipeBind) |
4067 | 274k | return false; |
4068 | 3.77k | else if (arg == R_PipeBindSymbol) |
4069 | 153 | return true; |
4070 | 3.61k | else if (TYPEOF(arg) == LANGSXP) |
4071 | 4.26k | for (SEXP cur = arg; cur != R_NilValue; cur = CDR(cur)) |
4072 | 3.61k | if (checkForPipeBind(CAR(cur))) |
4073 | 991 | return true; |
4074 | 2.62k | return false; |
4075 | 278k | } |
4076 | | |
4077 | | static bool isCommentLike(int token) |
4078 | 2.46M | { |
4079 | 2.46M | return token == COMMENT || token == LINE_DIRECTIVE; |
4080 | 2.46M | } |
4081 | | |
4082 | | static SEXP R_Parse1(ParseStatus *status) |
4083 | 326k | { |
4084 | 326k | Status = 1; /* safety */ |
4085 | 326k | switch(yyparse()) { |
4086 | 323k | case 0: |
4087 | 323k | switch(Status) { |
4088 | 2.62k | case 0: /* End of file */ |
4089 | 2.62k | *status = PARSE_EOF; |
4090 | 2.62k | if (EndOfFile == 2) *status = PARSE_INCOMPLETE; |
4091 | 2.62k | break; |
4092 | 0 | case 1: /* Error (currently unreachable) */ |
4093 | 0 | *status = PARSE_ERROR; |
4094 | 0 | if (EndOfFile) *status = PARSE_INCOMPLETE; |
4095 | 0 | break; |
4096 | 45.5k | case 2: /* Empty Line */ |
4097 | 45.5k | *status = PARSE_NULL; |
4098 | 45.5k | break; |
4099 | 273k | case 3: /* Valid expr '\n' terminated */ |
4100 | 275k | case 4: /* Valid expr ';' terminated */ |
4101 | 275k | if (checkForPlaceholder(R_PlaceholderToken, R_CurrentExpr)) { |
4102 | 754 | YYLTYPE lloc; |
4103 | 754 | lloc.first_line = ParseState.xxlineno; |
4104 | 754 | lloc.first_column = ParseState.xxcolno; |
4105 | 754 | if (Status == 3) lloc.first_line--; |
4106 | 754 | raiseParseError("invalidPlaceholder", R_CurrentExpr, |
4107 | 754 | NO_VALUE, NULL, &lloc, |
4108 | 754 | _("invalid use of pipe placeholder (%s:%d:%d)")); |
4109 | 754 | } |
4110 | 275k | if (checkForPipeBind(R_CurrentExpr)) { |
4111 | 153 | YYLTYPE lloc; |
4112 | 153 | lloc.first_line = ParseState.xxlineno; |
4113 | 153 | lloc.first_column = ParseState.xxcolno; |
4114 | 153 | if (Status == 3) lloc.first_line--; |
4115 | 153 | raiseParseError("invalidPipeBind", R_CurrentExpr, |
4116 | 153 | NO_VALUE, NULL, &lloc, |
4117 | 153 | _("invalid use of pipe bind symbol (%s:%d:%d)")); |
4118 | 153 | } |
4119 | 275k | *status = PARSE_OK; |
4120 | 275k | break; |
4121 | 323k | } |
4122 | 322k | break; |
4123 | 322k | case 1: /* Syntax error / incomplete */ |
4124 | 1.97k | *status = PARSE_ERROR; |
4125 | 1.97k | if (EndOfFile) *status = PARSE_INCOMPLETE; |
4126 | 1.97k | break; |
4127 | 1 | case 2: |
4128 | 1 | error(_("out of memory while parsing")); |
4129 | 326k | } |
4130 | 324k | return R_CurrentExpr; |
4131 | 326k | } |
4132 | | |
4133 | | static FILE *fp_parse; |
4134 | | |
4135 | | static int file_getc(void) |
4136 | 404k | { |
4137 | 404k | return R_fgetc(fp_parse); |
4138 | 404k | } |
4139 | | |
4140 | | /* used in main.c */ |
4141 | | attribute_hidden |
4142 | | SEXP R_Parse1File(FILE *fp, int gencode, ParseStatus *status) |
4143 | 4.28k | { |
4144 | 4.28k | ParseInit(); |
4145 | 4.28k | ParseContextInit(); |
4146 | 4.28k | GenerateCode = gencode; |
4147 | 4.28k | fp_parse = fp; |
4148 | 4.28k | ptr_getc = file_getc; |
4149 | 4.28k | R_Parse1(status); |
4150 | 4.28k | CLEAR_SVS(); |
4151 | 4.28k | return R_CurrentExpr; |
4152 | 4.28k | } |
4153 | | |
4154 | | static IoBuffer *iob; |
4155 | | |
4156 | | static int buffer_getc(void) |
4157 | 0 | { |
4158 | 0 | return R_IoBufferGetc(iob); |
4159 | 0 | } |
4160 | | |
4161 | | /* Used only in main.c */ |
4162 | | attribute_hidden |
4163 | | SEXP R_Parse1Buffer(IoBuffer *buffer, int gencode, ParseStatus *status) |
4164 | 0 | { |
4165 | 0 | bool keepSource = false; |
4166 | 0 | RCNTXT cntxt; |
4167 | |
|
4168 | 0 | R_InitSrcRefState(&cntxt); |
4169 | 0 | if (gencode) { |
4170 | 0 | keepSource = asBool(GetOption1(install("keep.source"))); |
4171 | 0 | if (keepSource) { |
4172 | 0 | ParseState.keepSrcRefs = true; |
4173 | 0 | ParseState.keepParseData = |
4174 | 0 | asRbool(GetOption1(install("keep.parse.data")), R_NilValue); |
4175 | 0 | PS_SET_SRCFILE(NewEnvironment(R_NilValue, R_NilValue, R_EmptyEnv)); |
4176 | 0 | PS_SET_ORIGINAL(PS_SRCFILE); |
4177 | 0 | PS_SET_SRCREFS(R_NilValue); |
4178 | 0 | } |
4179 | 0 | } |
4180 | 0 | ParseInit(); |
4181 | 0 | ParseContextInit(); |
4182 | 0 | GenerateCode = gencode; |
4183 | 0 | iob = buffer; |
4184 | 0 | ptr_getc = buffer_getc; |
4185 | 0 | R_Parse1(status); |
4186 | 0 | if (gencode && keepSource) { |
4187 | 0 | if (ParseState.didAttach) { |
4188 | 0 | int buflen = R_IoBufferReadOffset(buffer); |
4189 | 0 | char buf[buflen+1]; |
4190 | 0 | SEXP class; |
4191 | 0 | R_IoBufferReadReset(buffer); |
4192 | 0 | for (int i=0; i<buflen; i++) |
4193 | 0 | buf[i] = (char) R_IoBufferGetc(buffer); |
4194 | |
|
4195 | 0 | buf[buflen] = 0; |
4196 | 0 | SEXP s_filename = install("filename"); |
4197 | 0 | defineVar(s_filename, ScalarString(mkChar("")), PS_ORIGINAL); |
4198 | 0 | SEXP s_lines = install("lines"); |
4199 | 0 | defineVar(s_lines, ScalarString(mkChar2(buf)), PS_ORIGINAL); |
4200 | 0 | PROTECT(class = allocVector(STRSXP, 2)); |
4201 | 0 | SET_STRING_ELT(class, 0, mkChar("srcfilecopy")); |
4202 | 0 | SET_STRING_ELT(class, 1, mkChar("srcfile")); |
4203 | 0 | setAttrib(PS_ORIGINAL, R_ClassSymbol, class); |
4204 | 0 | UNPROTECT(1); /* class */ |
4205 | 0 | } |
4206 | 0 | } |
4207 | 0 | PROTECT(R_CurrentExpr); |
4208 | 0 | endcontext(&cntxt); |
4209 | 0 | R_FinalizeSrcRefState(); |
4210 | 0 | UNPROTECT(1); /* R_CurrentExpr */ |
4211 | 0 | return R_CurrentExpr; |
4212 | 0 | } |
4213 | | |
4214 | | static TextBuffer *txtb; |
4215 | | |
4216 | | static int text_getc(void) |
4217 | 6.46M | { |
4218 | 6.46M | return R_TextBufferGetc(txtb); |
4219 | 6.46M | } |
4220 | | |
4221 | | static SEXP R_Parse(int n, ParseStatus *status, SEXP srcfile) |
4222 | 6.53k | { |
4223 | 6.53k | int i; |
4224 | 6.53k | SEXP t, rval; |
4225 | 6.53k | RCNTXT cntxt; |
4226 | | |
4227 | 6.53k | R_InitSrcRefState(&cntxt); |
4228 | 6.53k | ParseContextInit(); |
4229 | | |
4230 | 6.53k | PS_SET_SRCFILE(srcfile); |
4231 | 6.53k | PS_SET_ORIGINAL(srcfile); |
4232 | | |
4233 | 6.53k | if (isEnvironment(srcfile)) { |
4234 | 1.86k | ParseState.keepSrcRefs = true; |
4235 | 1.86k | ParseState.keepParseData = |
4236 | 1.86k | asRbool(GetOption1(install("keep.parse.data")), R_NilValue); |
4237 | 1.86k | PS_SET_SRCREFS(R_NilValue); |
4238 | 1.86k | } |
4239 | | |
4240 | 6.53k | PROTECT(t = NewList()); |
4241 | 322k | for(i = 0; ; ) { |
4242 | 322k | if(n >= 0 && i >= n) break; |
4243 | 322k | ParseInit(); |
4244 | 322k | rval = R_Parse1(status); |
4245 | 322k | switch(*status) { |
4246 | 42.9k | case PARSE_NULL: |
4247 | 42.9k | break; |
4248 | 273k | case PARSE_OK: |
4249 | 273k | PROTECT(rval); |
4250 | 273k | GrowList(t, rval); |
4251 | 273k | UNPROTECT(1); /* rval */ |
4252 | 273k | i++; |
4253 | 273k | break; |
4254 | 960 | case PARSE_INCOMPLETE: |
4255 | 1.98k | case PARSE_ERROR: |
4256 | 1.98k | UNPROTECT(1); /* t */ |
4257 | 1.98k | if (ParseState.keepSrcRefs && ParseState.keepParseData) |
4258 | 669 | finalizeData(); |
4259 | 1.98k | endcontext(&cntxt); |
4260 | 1.98k | R_FinalizeSrcRefState(); |
4261 | 1.98k | return R_NilValue; |
4262 | 0 | break; |
4263 | 2.55k | case PARSE_EOF: |
4264 | 2.55k | goto finish; |
4265 | 0 | break; |
4266 | 322k | } |
4267 | 322k | } |
4268 | | |
4269 | 2.55k | finish: |
4270 | | |
4271 | 2.55k | t = CDR(t); |
4272 | 2.55k | PROTECT(rval = allocVector(EXPRSXP, length(t))); |
4273 | 264k | for (n = 0 ; n < LENGTH(rval) ; n++, t = CDR(t)) |
4274 | 261k | SET_VECTOR_ELT(rval, n, CAR(t)); |
4275 | 2.55k | if (ParseState.keepSrcRefs) { |
4276 | 629 | if (ParseState.keepParseData) |
4277 | 629 | finalizeData(); |
4278 | 629 | attachSrcrefs(rval); |
4279 | 629 | } |
4280 | 2.55k | UNPROTECT(2); /* t, rval */ |
4281 | 2.55k | PROTECT(rval); |
4282 | 2.55k | endcontext(&cntxt); |
4283 | 2.55k | R_FinalizeSrcRefState(); |
4284 | 2.55k | UNPROTECT(1); /* rval */ |
4285 | 2.55k | *status = PARSE_OK; |
4286 | 2.55k | return rval; |
4287 | 6.53k | } |
4288 | | |
4289 | | /* used in edit.c */ |
4290 | | attribute_hidden |
4291 | | SEXP R_ParseFile(FILE *fp, int n, ParseStatus *status, SEXP srcfile) |
4292 | 0 | { |
4293 | 0 | GenerateCode = 1; |
4294 | 0 | fp_parse = fp; |
4295 | 0 | ptr_getc = file_getc; |
4296 | 0 | return R_Parse(n, status, srcfile); |
4297 | 0 | } |
4298 | | |
4299 | | #include "Rconnections.h" |
4300 | | static Rconnection con_parse; |
4301 | | |
4302 | | /* need to handle incomplete last line */ |
4303 | | static int con_getc(void) |
4304 | 203k | { |
4305 | 203k | int c; |
4306 | 203k | static int last=-1000; |
4307 | | |
4308 | 203k | c = Rconn_fgetc(con_parse); |
4309 | 203k | if (c == EOF && last != '\n') c = '\n'; |
4310 | 203k | return (last = c); |
4311 | 203k | } |
4312 | | |
4313 | | /* used in source.c */ |
4314 | | attribute_hidden |
4315 | | SEXP R_ParseConn(Rconnection con, int n, ParseStatus *status, SEXP srcfile) |
4316 | 192 | { |
4317 | 192 | GenerateCode = 1; |
4318 | 192 | con_parse = con; |
4319 | 192 | ptr_getc = con_getc; |
4320 | 192 | return R_Parse(n, status, srcfile); |
4321 | 192 | } |
4322 | | |
4323 | | /* This one is public, and used in source.c */ |
4324 | | SEXP R_ParseVector(SEXP text, int n, ParseStatus *status, SEXP srcfile) |
4325 | 6.33k | { |
4326 | 6.33k | SEXP rval; |
4327 | 6.33k | TextBuffer textb; |
4328 | 6.33k | R_TextBufferInit(&textb, text); |
4329 | 6.33k | txtb = &textb; |
4330 | 6.33k | GenerateCode = 1; |
4331 | 6.33k | ptr_getc = text_getc; |
4332 | 6.33k | rval = R_Parse(n, status, srcfile); |
4333 | 6.33k | R_TextBufferFree(&textb); |
4334 | 6.33k | return rval; |
4335 | 6.33k | } |
4336 | | |
4337 | | static const char *Prompt(SEXP prompt, int type) |
4338 | 0 | { |
4339 | 0 | if(type == 1) { |
4340 | 0 | if(length(prompt) <= 0) { |
4341 | 0 | return CHAR(STRING_ELT(GetOption1(install("prompt")), 0)); |
4342 | 0 | } |
4343 | 0 | else |
4344 | 0 | return CHAR(STRING_ELT(prompt, 0)); |
4345 | 0 | } |
4346 | 0 | else { |
4347 | 0 | return CHAR(STRING_ELT(GetOption1(install("continue")), 0)); |
4348 | 0 | } |
4349 | 0 | } |
4350 | | |
4351 | | /* used in source.c */ |
4352 | | attribute_hidden |
4353 | | SEXP R_ParseBuffer(IoBuffer *buffer, int n, ParseStatus *status, SEXP prompt, |
4354 | | SEXP srcfile) |
4355 | 0 | { |
4356 | 0 | SEXP rval, t; |
4357 | 0 | char *bufp, buf[CONSOLE_BUFFER_SIZE]; |
4358 | 0 | int c, i, prompt_type = 1; |
4359 | 0 | RCNTXT cntxt; |
4360 | |
|
4361 | 0 | R_IoBufferWriteReset(buffer); |
4362 | 0 | buf[0] = '\0'; |
4363 | 0 | bufp = buf; |
4364 | 0 | R_InitSrcRefState(&cntxt); |
4365 | 0 | ParseContextInit(); |
4366 | | |
4367 | 0 | GenerateCode = 1; |
4368 | 0 | iob = buffer; |
4369 | 0 | ptr_getc = buffer_getc; |
4370 | |
|
4371 | 0 | PS_SET_SRCFILE(srcfile); |
4372 | 0 | PS_SET_ORIGINAL(srcfile); |
4373 | | |
4374 | 0 | if (isEnvironment(srcfile)) { |
4375 | 0 | ParseState.keepSrcRefs = true; |
4376 | 0 | ParseState.keepParseData = |
4377 | 0 | asRbool(GetOption1(install("keep.parse.data")), R_NilValue); |
4378 | 0 | PS_SET_SRCREFS(R_NilValue); |
4379 | 0 | } |
4380 | | |
4381 | 0 | PROTECT(t = NewList()); |
4382 | 0 | for(i = 0; ; ) { |
4383 | 0 | if(n >= 0 && i >= n) break; |
4384 | 0 | if (!*bufp) { |
4385 | 0 | if(R_ReadConsole((char *) Prompt(prompt, prompt_type), |
4386 | 0 | (unsigned char *)buf, CONSOLE_BUFFER_SIZE, 1) == 0) |
4387 | 0 | goto finish; |
4388 | 0 | bufp = buf; |
4389 | 0 | } |
4390 | 0 | while ((c = *bufp++)) { |
4391 | 0 | R_IoBufferPutc(c, buffer); |
4392 | 0 | if (c == ';' || c == '\n') break; |
4393 | 0 | } |
4394 | | |
4395 | | /* Was a call to R_Parse1Buffer, but we don't want to reset |
4396 | | xxlineno and xxcolno */ |
4397 | 0 | ParseInit(); |
4398 | | /* Not calling ParseContextInit() as it resets parse data, and |
4399 | | to be consistent with R_Parse */ |
4400 | 0 | R_Parse1(status); |
4401 | 0 | rval = R_CurrentExpr; |
4402 | |
|
4403 | 0 | switch(*status) { |
4404 | 0 | case PARSE_NULL: |
4405 | 0 | break; |
4406 | 0 | case PARSE_OK: |
4407 | 0 | PROTECT(rval); |
4408 | 0 | GrowList(t, rval); |
4409 | 0 | UNPROTECT(1); /* rval */ |
4410 | 0 | i++; |
4411 | 0 | break; |
4412 | 0 | case PARSE_INCOMPLETE: |
4413 | 0 | case PARSE_ERROR: |
4414 | 0 | UNPROTECT(1); /* t */ |
4415 | 0 | R_IoBufferWriteReset(buffer); |
4416 | 0 | endcontext(&cntxt); |
4417 | 0 | R_FinalizeSrcRefState(); |
4418 | 0 | return R_NilValue; |
4419 | 0 | break; |
4420 | 0 | case PARSE_EOF: |
4421 | 0 | goto finish; |
4422 | 0 | break; |
4423 | 0 | } |
4424 | 0 | } |
4425 | 0 | finish: |
4426 | 0 | R_IoBufferWriteReset(buffer); |
4427 | 0 | t = CDR(t); |
4428 | 0 | PROTECT(rval = allocVector(EXPRSXP, length(t))); |
4429 | 0 | for (n = 0 ; n < LENGTH(rval) ; n++, t = CDR(t)) |
4430 | 0 | SET_VECTOR_ELT(rval, n, CAR(t)); |
4431 | 0 | if (ParseState.keepSrcRefs) { |
4432 | 0 | if (ParseState.keepParseData) |
4433 | 0 | finalizeData(); |
4434 | 0 | attachSrcrefs(rval); |
4435 | 0 | } |
4436 | 0 | UNPROTECT(2); /* t, rval */ |
4437 | 0 | PROTECT(rval); |
4438 | 0 | endcontext(&cntxt); |
4439 | 0 | R_FinalizeSrcRefState(); |
4440 | 0 | UNPROTECT(1); /* rval */ |
4441 | 0 | *status = PARSE_OK; |
4442 | 0 | return rval; |
4443 | 0 | } |
4444 | | |
4445 | | |
4446 | | /*---------------------------------------------------------------------------- |
4447 | | * |
4448 | | * The Lexical Analyzer: |
4449 | | * |
4450 | | * Basic lexical analysis is performed by the following |
4451 | | * routines. Input is read a line at a time, and, if the |
4452 | | * program is in batch mode, each input line is echoed to |
4453 | | * standard output after it is read. |
4454 | | * |
4455 | | * The function yylex() scans the input, breaking it into |
4456 | | * tokens which are then passed to the parser. The lexical |
4457 | | * analyser maintains a symbol table (in a very messy fashion). |
4458 | | * |
4459 | | * The fact that if statements need to parse differently |
4460 | | * depending on whether the statement is being interpreted or |
4461 | | * part of the body of a function causes the need for ifpop |
4462 | | * and IfPush. When an if statement is encountered an 'i' is |
4463 | | * pushed on a stack (provided there are parentheses active). |
4464 | | * At later points this 'i' needs to be popped off of the if |
4465 | | * stack. |
4466 | | * |
4467 | | */ |
4468 | | |
4469 | | static void IfPush(void) |
4470 | 3.64k | { |
4471 | 3.64k | if (*contextp==LBRACE || |
4472 | 2.68k | *contextp=='[' || |
4473 | 2.66k | *contextp=='(' || |
4474 | 2.83k | *contextp == 'i') { |
4475 | 2.83k | if(contextp - contextstack >= CONTEXTSTACK_SIZE - 1) |
4476 | 0 | raiseLexError("contextstackOverflow", NO_VALUE, NULL, |
4477 | 0 | _("contextstack overflow (%s:%d:%d)")); |
4478 | 2.83k | *++contextp = 'i'; |
4479 | 2.83k | } |
4480 | | |
4481 | 3.64k | } |
4482 | | |
4483 | | static void ifpop(void) |
4484 | 18.5k | { |
4485 | 18.5k | if (*contextp=='i') |
4486 | 2.55k | *contextp-- = 0; |
4487 | 18.5k | } |
4488 | | |
4489 | | /* This is only called following ., so we only care if it is |
4490 | | an ANSI digit or not */ |
4491 | | static int typeofnext(void) |
4492 | 130k | { |
4493 | 130k | int k, c; |
4494 | | |
4495 | 130k | c = xxgetc(); |
4496 | 130k | if (isdigit(c)) k = 1; else k = 2; |
4497 | 130k | xxungetc(c); |
4498 | 130k | return k; |
4499 | 130k | } |
4500 | | |
4501 | | static int nextchar(int expect) |
4502 | 496k | { |
4503 | 496k | int c = xxgetc(); |
4504 | 496k | if (c == expect) |
4505 | 45.7k | return 1; |
4506 | 450k | else |
4507 | 450k | xxungetc(c); |
4508 | 450k | return 0; |
4509 | 496k | } |
4510 | | |
4511 | | /* Special Symbols */ |
4512 | | /* Syntactic Keywords + Symbolic Constants */ |
4513 | | |
4514 | | struct { |
4515 | | char *name; |
4516 | | int token; |
4517 | | } |
4518 | | static keywords[] = { |
4519 | | { "NULL", NULL_CONST }, |
4520 | | { "NA", NUM_CONST }, |
4521 | | { "TRUE", NUM_CONST }, |
4522 | | { "FALSE", NUM_CONST }, |
4523 | | { "Inf", NUM_CONST }, |
4524 | | { "NaN", NUM_CONST }, |
4525 | | { "NA_integer_", NUM_CONST }, |
4526 | | { "NA_real_", NUM_CONST }, |
4527 | | { "NA_character_", NUM_CONST }, |
4528 | | { "NA_complex_", NUM_CONST }, |
4529 | | { "function", FUNCTION }, |
4530 | | { "while", WHILE }, |
4531 | | { "repeat", REPEAT }, |
4532 | | { "for", FOR }, |
4533 | | { "if", IF }, |
4534 | | { "in", IN }, |
4535 | | { "else", ELSE }, |
4536 | | { "next", NEXT }, |
4537 | | { "break", BREAK }, |
4538 | | { "...", SYMBOL }, |
4539 | | { 0, 0 } |
4540 | | }; |
4541 | | |
4542 | | /* KeywordLookup has side effects, it sets yylval */ |
4543 | | |
4544 | | static int KeywordLookup(const char *s) |
4545 | 400k | { |
4546 | 400k | int i; |
4547 | 8.21M | for (i = 0; keywords[i].name; i++) { |
4548 | 7.83M | if (strcmp(keywords[i].name, s) == 0) { |
4549 | 19.2k | switch (keywords[i].token) { |
4550 | 760 | case NULL_CONST: |
4551 | 760 | PRESERVE_SV(yylval = R_NilValue); |
4552 | 760 | break; |
4553 | 7.13k | case NUM_CONST: |
4554 | 7.13k | if(GenerateCode) { |
4555 | 7.13k | switch(i) { |
4556 | 2.36k | case 1: |
4557 | 2.36k | PRESERVE_SV(yylval = mkNA()); |
4558 | 2.36k | break; |
4559 | 1.34k | case 2: |
4560 | 1.34k | PRESERVE_SV(yylval = mkTrue()); |
4561 | 1.34k | break; |
4562 | 1.17k | case 3: |
4563 | 1.17k | PRESERVE_SV(yylval = mkFalse()); |
4564 | 1.17k | break; |
4565 | 319 | case 4: |
4566 | 319 | PRESERVE_SV(yylval = allocVector(REALSXP, 1)); |
4567 | 319 | REAL(yylval)[0] = R_PosInf; |
4568 | 319 | break; |
4569 | 150 | case 5: |
4570 | 150 | PRESERVE_SV(yylval = allocVector(REALSXP, 1)); |
4571 | 150 | REAL(yylval)[0] = R_NaN; |
4572 | 150 | break; |
4573 | 450 | case 6: |
4574 | 450 | PRESERVE_SV(yylval = allocVector(INTSXP, 1)); |
4575 | 450 | INTEGER(yylval)[0] = NA_INTEGER; |
4576 | 450 | break; |
4577 | 81 | case 7: |
4578 | 81 | PRESERVE_SV(yylval = allocVector(REALSXP, 1)); |
4579 | 81 | REAL(yylval)[0] = NA_REAL; |
4580 | 81 | break; |
4581 | 908 | case 8: |
4582 | 908 | PRESERVE_SV(yylval = allocVector(STRSXP, 1)); |
4583 | 908 | SET_STRING_ELT(yylval, 0, NA_STRING); |
4584 | 908 | break; |
4585 | 348 | case 9: |
4586 | 348 | PRESERVE_SV(yylval = allocVector(CPLXSXP, 1)); |
4587 | 348 | COMPLEX(yylval)[0].r = COMPLEX(yylval)[0].i = NA_REAL; |
4588 | 348 | break; |
4589 | 7.13k | } |
4590 | 7.13k | } else |
4591 | 0 | PRESERVE_SV(yylval = R_NilValue); |
4592 | 7.13k | break; |
4593 | 7.13k | case FUNCTION: |
4594 | 2.56k | case WHILE: |
4595 | 3.04k | case REPEAT: |
4596 | 3.38k | case FOR: |
4597 | 7.02k | case IF: |
4598 | 8.47k | case NEXT: |
4599 | 8.92k | case BREAK: |
4600 | 8.92k | yylval = install(s); |
4601 | 8.92k | break; |
4602 | 333 | case IN: |
4603 | 1.76k | case ELSE: |
4604 | 1.76k | break; |
4605 | 689 | case SYMBOL: |
4606 | 689 | PRESERVE_SV(yylval = install(s)); |
4607 | 689 | break; |
4608 | 19.2k | } |
4609 | 19.2k | return keywords[i].token; |
4610 | 19.2k | } |
4611 | 7.83M | } |
4612 | 381k | return 0; |
4613 | 400k | } |
4614 | | |
4615 | | static SEXP mkFloat(const char *s) |
4616 | 170k | { |
4617 | 170k | return ScalarReal(R_atof(s)); |
4618 | 170k | } |
4619 | | |
4620 | | static SEXP mkInt(const char *s) |
4621 | 5.70k | { |
4622 | 5.70k | double f = R_atof(s); /* or R_strtol? */ |
4623 | 5.70k | return ScalarInteger((int) f); |
4624 | 5.70k | } |
4625 | | |
4626 | | static SEXP mkComplex(const char *s) |
4627 | 4.05k | { |
4628 | 4.05k | SEXP t = R_NilValue; |
4629 | 4.05k | double f; |
4630 | 4.05k | f = R_atof(s); /* FIXME: make certain the value is legitimate. */ |
4631 | 4.05k | t = allocVector(CPLXSXP, 1); |
4632 | 4.05k | COMPLEX(t)[0].r = 0; |
4633 | 4.05k | COMPLEX(t)[0].i = f; |
4634 | 4.05k | return t; |
4635 | 4.05k | } |
4636 | | |
4637 | | static SEXP mkNA(void) |
4638 | 2.36k | { |
4639 | 2.36k | SEXP t = allocVector(LGLSXP, 1); |
4640 | 2.36k | LOGICAL(t)[0] = NA_LOGICAL; |
4641 | 2.36k | return t; |
4642 | 2.36k | } |
4643 | | |
4644 | | attribute_hidden |
4645 | | SEXP mkTrue(void) |
4646 | 1.22M | { |
4647 | 1.22M | SEXP s = allocVector(LGLSXP, 1); |
4648 | 1.22M | LOGICAL(s)[0] = 1; |
4649 | 1.22M | return s; |
4650 | 1.22M | } |
4651 | | |
4652 | | SEXP mkFalse(void) |
4653 | 1.16M | { |
4654 | 1.16M | SEXP s = allocVector(LGLSXP, 1); |
4655 | 1.16M | LOGICAL(s)[0] = 0; |
4656 | 1.16M | return s; |
4657 | 1.16M | } |
4658 | | |
4659 | | static void yyerror(const char *s) |
4660 | 2.42k | { |
4661 | 2.42k | static const char *const yytname_translations[] = |
4662 | 2.42k | { |
4663 | | /* the left column are strings coming from bison, the right |
4664 | | column are translations for users. |
4665 | | The first YYENGLISH from the right column are English to be translated, |
4666 | | the rest are to be copied literally. The #if 0 block below allows xgettext |
4667 | | to see these. |
4668 | | */ |
4669 | 2.42k | #define YYENGLISH 8 |
4670 | 2.42k | "$undefined", "input", |
4671 | 2.42k | "END_OF_INPUT", "end of input", |
4672 | 2.42k | "ERROR", "input", |
4673 | 2.42k | "STR_CONST", "string constant", |
4674 | 2.42k | "NUM_CONST", "numeric constant", |
4675 | 2.42k | "SYMBOL", "symbol", |
4676 | 2.42k | "LEFT_ASSIGN", "assignment", |
4677 | 2.42k | "'\\n'", "end of line", |
4678 | 2.42k | "NULL_CONST", "'NULL'", |
4679 | 2.42k | "FUNCTION", "'function'", |
4680 | 2.42k | "EQ_ASSIGN", "'='", |
4681 | 2.42k | "RIGHT_ASSIGN", "'->'", |
4682 | 2.42k | "LBB", "'[['", |
4683 | 2.42k | "FOR", "'for'", |
4684 | 2.42k | "IN", "'in'", |
4685 | 2.42k | "IF", "'if'", |
4686 | 2.42k | "ELSE", "'else'", |
4687 | 2.42k | "WHILE", "'while'", |
4688 | 2.42k | "NEXT", "'next'", |
4689 | 2.42k | "BREAK", "'break'", |
4690 | 2.42k | "REPEAT", "'repeat'", |
4691 | 2.42k | "GT", "'>'", |
4692 | 2.42k | "GE", "'>='", |
4693 | 2.42k | "LT", "'<'", |
4694 | 2.42k | "LE", "'<='", |
4695 | 2.42k | "EQ", "'=='", |
4696 | 2.42k | "NE", "'!='", |
4697 | 2.42k | "AND", "'&'", |
4698 | 2.42k | "OR", "'|'", |
4699 | 2.42k | "AND2", "'&&'", |
4700 | 2.42k | "OR2", "'||'", |
4701 | 2.42k | "NS_GET", "'::'", |
4702 | 2.42k | "NS_GET_INT", "':::'", |
4703 | 2.42k | "PIPE", "'|>'", |
4704 | 2.42k | "PIPEBIND", "'=>'", |
4705 | 2.42k | "PLACEHOLDER", "'_'", |
4706 | 2.42k | 0 |
4707 | 2.42k | }; |
4708 | 2.42k | static char const yyunexpected[] = "syntax error, unexpected "; |
4709 | 2.42k | static char const yyexpecting[] = ", expecting "; |
4710 | 2.42k | char *expecting; |
4711 | | |
4712 | 2.42k | if (!EndOfFile) |
4713 | | /* On EndOfFile, there are no more bytes to add, but trying to do |
4714 | | so may have non-trivial performance overhead and this can be |
4715 | | reached also in non-error situations, e.g. from repl. |
4716 | | */ |
4717 | 1.46k | finish_mbcs_in_parse_context(); |
4718 | | |
4719 | 2.42k | R_ParseError = yylloc.first_line; |
4720 | 2.42k | R_ParseErrorCol = yylloc.first_column; |
4721 | 2.42k | R_ParseErrorFile = PS_SRCFILE; |
4722 | | |
4723 | 2.42k | if (!strncmp(s, yyunexpected, sizeof yyunexpected -1)) { |
4724 | 1.97k | int i; |
4725 | | /* Edit the error message: needs a copy */ |
4726 | 1.97k | char s1[PARSE_ERROR_SIZE + 1]; |
4727 | 1.97k | strncpy(s1, s, PARSE_ERROR_SIZE); |
4728 | 1.97k | s1[PARSE_ERROR_SIZE] = 0; |
4729 | 1.97k | expecting = strstr(s1 + sizeof yyunexpected -1, yyexpecting); |
4730 | 1.97k | if (expecting) *expecting = '\0'; |
4731 | | |
4732 | 41.2k | for (i = 0; yytname_translations[i]; i += 2) { |
4733 | 40.2k | if (!strcmp(s1 + sizeof yyunexpected - 1, yytname_translations[i])) { |
4734 | 1.03k | switch(i/2) |
4735 | 1.03k | { |
4736 | 0 | case 0: |
4737 | 0 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected input")); |
4738 | 0 | break; |
4739 | 384 | case 1: |
4740 | 384 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected end of input")); |
4741 | 384 | break; |
4742 | 70 | case 2: |
4743 | 70 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected input")); |
4744 | 70 | break; |
4745 | 44 | case 3: |
4746 | 44 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected string constant")); |
4747 | 44 | break; |
4748 | 110 | case 4: |
4749 | 110 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected numeric constant")); |
4750 | 110 | break; |
4751 | 221 | case 5: |
4752 | 221 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected symbol")); |
4753 | 221 | break; |
4754 | 6 | case 6: |
4755 | 6 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected assignment")); |
4756 | 6 | break; |
4757 | 20 | case 7: |
4758 | 20 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected end of line")); |
4759 | 20 | break; |
4760 | 179 | default: |
4761 | 179 | if (!strcmp(s1 + sizeof yyunexpected - 1, "PLACEHOLDER")) { |
4762 | | /* cheat to avoid changing the parse error |
4763 | | message for mis-use of _ */ |
4764 | 7 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, |
4765 | 7 | _("unexpected input")); |
4766 | 7 | break; |
4767 | 7 | } |
4768 | 172 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE, _("unexpected %s"), |
4769 | 172 | yytname_translations[i+1]); |
4770 | 172 | break; |
4771 | 1.03k | } |
4772 | | |
4773 | 1.03k | return; |
4774 | 1.03k | } |
4775 | 40.2k | } |
4776 | 945 | snprintf(R_ParseErrorMsg, PARSE_ERROR_SIZE - 1, _("unexpected %s"), |
4777 | 945 | s1 + sizeof yyunexpected - 1); |
4778 | 945 | } else { |
4779 | 444 | strncpy(R_ParseErrorMsg, s, PARSE_ERROR_SIZE - 1); |
4780 | 444 | R_ParseErrorMsg[PARSE_ERROR_SIZE - 1] = '\0'; |
4781 | 444 | } |
4782 | 2.42k | } |
4783 | | |
4784 | | static void CheckFormalArgs(SEXP formlist, SEXP _new, YYLTYPE *lloc) |
4785 | 1.73k | { |
4786 | 5.81k | while (formlist != R_NilValue) { |
4787 | 4.08k | if (TAG(formlist) == _new) { |
4788 | 2 | raiseParseError("repeatedFormal", R_NilValue, |
4789 | 2 | STRING_VALUE, EncodeChar(PRINTNAME(_new)), lloc, |
4790 | 2 | _("repeated formal argument '%s' (%s:%d:%d)")); |
4791 | 2 | } |
4792 | 4.08k | formlist = CDR(formlist); |
4793 | 4.08k | } |
4794 | 1.73k | } |
4795 | | |
4796 | | /* This is used as the buffer for NumericValue, SpecialValue and |
4797 | | SymbolValue. None of these could conceivably need 8192 bytes. |
4798 | | |
4799 | | It has not been used as the buffer for input character strings |
4800 | | since Oct 2007 (released as 2.7.0), and for comments since 2.8.0 |
4801 | | */ |
4802 | | static char yytext[MAXELTSIZE]; |
4803 | | |
4804 | | static int SkipSpace(void) |
4805 | 1.70M | { |
4806 | 1.70M | int c; |
4807 | | |
4808 | | #if defined(USE_RI18N_FNS) // includes Win32 |
4809 | | static wctype_t blankwct = 0; |
4810 | | if (!blankwct) |
4811 | | blankwct = Ri18n_wctype("blank"); |
4812 | | #endif |
4813 | | |
4814 | | #ifdef Win32 |
4815 | | if(!mbcslocale) { /* 0xa0 is NBSP in all 8-bit Windows locales */ |
4816 | | while ((c = xxgetc()) == ' ' || c == '\t' || c == '\f' || |
4817 | | (unsigned int) c == 0xa0) {}; |
4818 | | return c; |
4819 | | } else { |
4820 | | int i, clen; |
4821 | | wchar_t wc; |
4822 | | while (1) { |
4823 | | c = xxgetc(); |
4824 | | if (c == ' ' || c == '\t' || c == '\f') continue; |
4825 | | if (c == '\n' || c == R_EOF) break; |
4826 | | if ((unsigned int) c < 0x80) break; |
4827 | | clen = mbcs_get_next(c, &wc); /* always 2 */ |
4828 | | if (clen == -1) { /* EOF whilst reading MBCS char */ |
4829 | | xxungetc(c); |
4830 | | c = R_EOF; |
4831 | | break; |
4832 | | } |
4833 | | if(! Ri18n_iswctype(wc, blankwct) ) break; |
4834 | | for(i = 1; i < clen; i++) c = xxgetc(); |
4835 | | } |
4836 | | return c; |
4837 | | } |
4838 | | #endif |
4839 | 1.70M | #if defined(__STDC_ISO_10646__) |
4840 | 1.70M | if(mbcslocale) { /* wctype functions need Unicode wchar_t */ |
4841 | 0 | int i, clen; |
4842 | 0 | wchar_t wc; |
4843 | 0 | while (1) { |
4844 | 0 | c = xxgetc(); |
4845 | 0 | if (c == ' ' || c == '\t' || c == '\f') continue; |
4846 | 0 | if (c == '\n' || c == R_EOF) break; |
4847 | 0 | if ((unsigned int) c < 0x80) break; |
4848 | 0 | clen = mbcs_get_next(c, &wc); |
4849 | 0 | if (clen == -1) { /* EOF whilst reading MBCS char */ |
4850 | 0 | xxungetc(c); |
4851 | 0 | c = R_EOF; |
4852 | 0 | break; |
4853 | 0 | } |
4854 | | #if defined(USE_RI18N_FNS) |
4855 | | if(! Ri18n_iswctype(wc, blankwct) ) break; |
4856 | | #else |
4857 | 0 | if(! iswblank(wc) ) break; |
4858 | 0 | #endif |
4859 | 0 | for(i = 1; i < clen; i++) c = xxgetc(); |
4860 | 0 | } |
4861 | 0 | } else |
4862 | 1.70M | #endif |
4863 | | // does not support non-ASCII spaces, unlike Windows |
4864 | 1.79M | while ((c = xxgetc()) == ' ' || c == '\t' || c == '\f') {}; |
4865 | 1.70M | return c; |
4866 | 1.70M | } |
4867 | | |
4868 | | /* Note that with interactive use, EOF cannot occur inside */ |
4869 | | /* a comment. However, semicolons inside comments make it */ |
4870 | | /* appear that this does happen. For this reason we use the */ |
4871 | | /* special assignment EndOfFile=2 to indicate that this is */ |
4872 | | /* going on. This is detected and dealt with in Parse1Buffer. */ |
4873 | | |
4874 | | static int SkipComment(void) |
4875 | 283k | { |
4876 | 283k | int c='#', i; |
4877 | | |
4878 | | /* locations before the # character was read */ |
4879 | 283k | int _first_column = ParseState.xxcolno ; |
4880 | 283k | int _first_parsed = ParseState.xxparseno ; |
4881 | 283k | int type = COMMENT ; |
4882 | | |
4883 | 283k | bool maybeLine = (ParseState.xxcolno == 1); |
4884 | 283k | bool doSave; |
4885 | | |
4886 | 283k | DECLARE_YYTEXT_BUFP(yyp); |
4887 | | |
4888 | 283k | if (maybeLine) { |
4889 | 44.2k | char lineDirective[] = "#line"; |
4890 | 44.2k | YYTEXT_PUSH(c, yyp); |
4891 | 56.6k | for (i=1; i<5; i++) { |
4892 | 53.7k | c = xxgetc(); |
4893 | 53.7k | if (c != (int)(lineDirective[i])) { |
4894 | 41.2k | maybeLine = false; |
4895 | 41.2k | break; |
4896 | 41.2k | } |
4897 | 12.4k | YYTEXT_PUSH(c, yyp); |
4898 | 12.4k | } |
4899 | 44.2k | if (maybeLine) |
4900 | 2.95k | c = processLineDirective(&type); |
4901 | 44.2k | } |
4902 | | // we want to track down the character |
4903 | | // __before__ the new line character |
4904 | 283k | int _last_column = ParseState.xxcolno ; |
4905 | 283k | int _last_parsed = ParseState.xxparseno ; |
4906 | | |
4907 | 283k | if (c == '\n') { |
4908 | 37.0k | _last_column = prevcols[prevpos]; |
4909 | 37.0k | _last_parsed = prevparse[prevpos]; |
4910 | 37.0k | } |
4911 | | |
4912 | 283k | doSave = !maybeLine; |
4913 | | |
4914 | 1.14M | while (c != '\n' && c != R_EOF) { |
4915 | | // Comments can be any length; we only record the ones that fit in yytext. |
4916 | 857k | if (doSave) { |
4917 | 855k | YYTEXT_PUSH(c, yyp); |
4918 | 855k | doSave = (yyp - yytext) < sizeof(yytext) - 2; |
4919 | 855k | } |
4920 | 857k | _last_column = ParseState.xxcolno ; |
4921 | 857k | _last_parsed = ParseState.xxparseno ; |
4922 | 857k | c = xxgetc(); |
4923 | 857k | } |
4924 | 283k | if (c == R_EOF) EndOfFile = 2; |
4925 | 283k | incrementId( ) ; |
4926 | 283k | YYTEXT_PUSH('\0', yyp); |
4927 | 283k | record_( _first_parsed, _first_column, _last_parsed, _last_column, |
4928 | 283k | type, identifier, doSave ? yytext : 0 ) ; |
4929 | 283k | return c; |
4930 | 283k | } |
4931 | | |
4932 | | static int NumericValue(int c) |
4933 | 181k | { |
4934 | 181k | int seendot = (c == '.'); |
4935 | 181k | int seenexp = 0; |
4936 | 181k | int last = c; |
4937 | 181k | int nd = 0; |
4938 | 181k | int asNumeric = 0; |
4939 | 181k | int count = 1; /* The number of characters seen */ |
4940 | | |
4941 | 181k | DECLARE_YYTEXT_BUFP(yyp); |
4942 | 181k | YYTEXT_PUSH(c, yyp); |
4943 | | /* We don't care about other than ASCII digits */ |
4944 | 595k | while (isdigit(c = xxgetc()) || c == '.' || c == 'e' || c == 'E' |
4945 | 179k | || c == 'x' || c == 'X' || c == 'L') |
4946 | 543k | { |
4947 | 543k | count++; |
4948 | 543k | if (c == 'L') /* must be at the end. Won't allow 1Le3 (at present). */ |
4949 | 123k | { YYTEXT_PUSH(c, yyp); |
4950 | 123k | break; |
4951 | 123k | } |
4952 | | |
4953 | 419k | if (c == 'x' || c == 'X') { |
4954 | 4.11k | if (count > 2 || last != '0') break; /* 0x must be first */ |
4955 | 3.59k | YYTEXT_PUSH(c, yyp); |
4956 | 65.3k | while(isdigit(c = xxgetc()) || ('a' <= c && c <= 'f') || |
4957 | 61.8k | ('A' <= c && c <= 'F') || c == '.') { |
4958 | 61.8k | if (c == '.') { |
4959 | 2.76k | if (seendot) return ERROR; |
4960 | 2.68k | seendot = 1; |
4961 | 2.68k | } |
4962 | 61.7k | YYTEXT_PUSH(c, yyp); |
4963 | 61.7k | nd++; |
4964 | 61.7k | } |
4965 | 3.52k | if (nd == 0) return ERROR; |
4966 | 3.43k | if (c == 'p' || c == 'P') { |
4967 | 2.00k | seenexp = 1; |
4968 | 2.00k | YYTEXT_PUSH(c, yyp); |
4969 | 2.00k | c = xxgetc(); |
4970 | 2.00k | if (!isdigit(c) && c != '+' && c != '-') return ERROR; |
4971 | 1.86k | if (c == '+' || c == '-') { |
4972 | 1.02k | YYTEXT_PUSH(c, yyp); |
4973 | 1.02k | c = xxgetc(); |
4974 | 1.02k | } |
4975 | 68.0k | for(nd = 0; isdigit(c); c = xxgetc(), nd++) |
4976 | 68.0k | YYTEXT_PUSH(c, yyp); |
4977 | 1.86k | if (nd == 0) return ERROR; |
4978 | 1.86k | } |
4979 | | // ?NumericComstants says exponent is optional (as does C99) |
4980 | | // if (seendot && !seenexp) return ERROR; |
4981 | 2.75k | if (c == 'L') /* for getParseData */ |
4982 | 1.41k | { |
4983 | | // seenexp will be checked later |
4984 | 1.41k | YYTEXT_PUSH(c, yyp); |
4985 | 1.41k | break; |
4986 | 1.41k | } |
4987 | 1.34k | break; |
4988 | 2.75k | } |
4989 | 415k | if (c == 'E' || c == 'e') { |
4990 | 7.33k | if (seenexp) |
4991 | 873 | break; |
4992 | 6.46k | seenexp = 1; |
4993 | 6.46k | seendot = seendot == 1 ? seendot : 2; |
4994 | 6.46k | YYTEXT_PUSH(c, yyp); |
4995 | 6.46k | c = xxgetc(); |
4996 | 6.46k | if (!isdigit(c) && c != '+' && c != '-') return ERROR; |
4997 | 6.35k | if (c == '+' || c == '-') { |
4998 | 1.17k | YYTEXT_PUSH(c, yyp); |
4999 | 1.17k | c = xxgetc(); |
5000 | 1.17k | if (!isdigit(c)) return ERROR; |
5001 | 1.17k | } |
5002 | 6.35k | } |
5003 | 414k | if (c == '.') { |
5004 | 5.65k | if (seendot) |
5005 | 92 | break; |
5006 | 5.56k | seendot = 1; |
5007 | 5.56k | } |
5008 | 414k | YYTEXT_PUSH(c, yyp); |
5009 | 414k | last = c; |
5010 | 414k | } |
5011 | | |
5012 | 180k | if(c == 'i') |
5013 | 4.05k | YYTEXT_PUSH(c, yyp); /* for getParseData */ |
5014 | | |
5015 | 180k | YYTEXT_PUSH('\0', yyp); |
5016 | | /* Make certain that things are okay. */ |
5017 | 180k | if(c == 'L') { |
5018 | 125k | double a = R_atof(yytext); |
5019 | 125k | int b = (int) a; |
5020 | | /* We are asked to create an integer via the L, so we check that the |
5021 | | double and int values are the same. If not, this is a problem and we |
5022 | | will not lose information and so use the numeric value. |
5023 | | */ |
5024 | 125k | if(a != (double) b) { |
5025 | 119k | if(GenerateCode) { |
5026 | 119k | if(seendot == 1 && seenexp == 0) |
5027 | 117k | warning(_("integer literal %s contains decimal; using numeric value"), yytext); |
5028 | 2.25k | else { |
5029 | | /* hide the L for the warning message */ |
5030 | 2.25k | warning(_("non-integer value %s qualified with L; using numeric value"), yytext); |
5031 | 2.25k | } |
5032 | 119k | } |
5033 | 119k | asNumeric = 1; |
5034 | 119k | seenexp = 1; |
5035 | 119k | } |
5036 | 125k | } |
5037 | | |
5038 | 180k | if(c == 'i') { |
5039 | 4.05k | yylval = GenerateCode ? mkComplex(yytext) : R_NilValue; |
5040 | 176k | } else if(c == 'L' && asNumeric == 0) { |
5041 | 5.70k | if(GenerateCode && seendot == 1 && seenexp == 0) |
5042 | 2.40k | warning(_("integer literal %s contains unnecessary decimal point"), yytext); |
5043 | 5.70k | yylval = GenerateCode ? mkInt(yytext) : R_NilValue; |
5044 | | #if 0 /* do this to make 123 integer not double */ |
5045 | | } else if(!(seendot || seenexp)) { |
5046 | | if(c != 'L') xxungetc(c); |
5047 | | if (GenerateCode) { |
5048 | | double a = R_atof(yytext); |
5049 | | int b = (int) a; |
5050 | | yylval = (a != (double) b) ? mkFloat(yytext) : mkInt(yytext); |
5051 | | } else yylval = R_NilValue; |
5052 | | #endif |
5053 | 170k | } else { |
5054 | 170k | if(c != 'L') |
5055 | 50.7k | xxungetc(c); |
5056 | 170k | yylval = GenerateCode ? mkFloat(yytext) : R_NilValue; |
5057 | 170k | } |
5058 | | |
5059 | 180k | PRESERVE_SV(yylval); |
5060 | 180k | return NUM_CONST; |
5061 | 181k | } |
5062 | | |
5063 | | /* Strings may contain the standard ANSI escapes and octal */ |
5064 | | /* specifications of the form \o, \oo or \ooo, where 'o' */ |
5065 | | /* is an octal digit. */ |
5066 | | |
5067 | | /* The buffer is reallocated on the R heap if needed; not by malloc */ |
5068 | | /* to avoid memory leak in case of R error (long jump) */ |
5069 | 2.39M | #define STEXT_PUSH(c) do { \ |
5070 | 2.39M | size_t nc = bp - stext; \ |
5071 | 2.39M | if (nc >= nstext - 1) { \ |
5072 | 113 | char *old = stext; \ |
5073 | 113 | SEXP st1; \ |
5074 | 113 | nstext *= 2; \ |
5075 | 113 | PROTECT(st1 = allocVector(RAWSXP, nstext)); \ |
5076 | 113 | stext = (char *)RAW(st1); \ |
5077 | 113 | memmove(stext, old, nc); \ |
5078 | 113 | REPROTECT(st1, sti); \ |
5079 | 113 | UNPROTECT(1); /* st1 */ \ |
5080 | 113 | bp = stext+nc; } \ |
5081 | 2.39M | *bp++ = ((char) c); \ |
5082 | 2.39M | } while(0) |
5083 | | |
5084 | | |
5085 | | /* The idea here is that if a string contains \u escapes that are not |
5086 | | valid in the current locale, we should switch to UTF-8 for that |
5087 | | string. Needs Unicode wide-char support or out substitutes. |
5088 | | |
5089 | | Defining __STDC_ISO_10646__ is done by the OS (or not) in wchar.t. |
5090 | | Some (e.g. macOS, Solaris, FreeBSD) have Unicode wchar_t but do not |
5091 | | define it: we override macOS and FreeBSD earlier in this file. |
5092 | | */ |
5093 | | |
5094 | | #if defined(Win32) || defined(__STDC_ISO_10646__) |
5095 | | typedef wchar_t ucs_t; |
5096 | 0 | # define mbcs_get_next2 mbcs_get_next |
5097 | | #else |
5098 | | typedef unsigned int ucs_t; |
5099 | | # define WC_NOT_UNICODE |
5100 | | // which is used to select our mbtoucs rather than system mbrtowc |
5101 | | static int mbcs_get_next2(int c, ucs_t *wc) |
5102 | | { |
5103 | | int i, res, clen = 1; char s[9]; |
5104 | | |
5105 | | s[0] = c; |
5106 | | /* This assumes (probably OK) that all MBCS embed ASCII as single-byte |
5107 | | lead bytes, including control chars */ |
5108 | | if((unsigned int) c < 0x80) { |
5109 | | *wc = (wchar_t) c; |
5110 | | return 1; |
5111 | | } |
5112 | | if(utf8locale) { |
5113 | | clen = utf8clen(c); |
5114 | | for(i = 1; i < clen; i++) { |
5115 | | c = xxgetc(); |
5116 | | if(c == R_EOF) { /* EOF whilst reading MBCS char */ |
5117 | | for(i--; i > 0; i--) xxungetc(s[i]); |
5118 | | return -1; |
5119 | | } |
5120 | | s[i] = (char) c; |
5121 | | } |
5122 | | s[clen] ='\0'; /* x86 Solaris requires this */ |
5123 | | res = mbtoucs(wc, s, clen); |
5124 | | if(res == -1) raiseLexError("invalidMultibyteCharacter", |
5125 | | NO_VALUE, NULL, |
5126 | | _("invalid multibyte character (%s:%d:%d)")); |
5127 | | } else { |
5128 | | /* This is not necessarily correct for stateful MBCS */ |
5129 | | while(clen <= R_MB_CUR_MAX) { |
5130 | | res = mbtoucs(wc, s, clen); |
5131 | | if(res >= 0) break; |
5132 | | if(res == -1) |
5133 | | raiseLexError("invalidMultibyte", NO_VALUE, NULL, |
5134 | | _("invalid multibyte character (%s:%d:%d)")); |
5135 | | /* so res == -2 */ |
5136 | | c = xxgetc(); |
5137 | | if(c == R_EOF) {/* EOF whilst reading MBCS char */ |
5138 | | for(i = clen - 1; i > 0; i--) xxungetc(s[i]); |
5139 | | return -1; |
5140 | | } |
5141 | | s[clen++] = c; |
5142 | | } /* we've tried enough, so must be complete or invalid by now */ |
5143 | | } |
5144 | | for(i = clen - 1; i > 0; i--) xxungetc(s[i]); |
5145 | | return clen; |
5146 | | } |
5147 | | #endif |
5148 | | |
5149 | 2.41M | #define WTEXT_PUSH(c) do { if(wcnt < 10000) wcs[wcnt++] = c; } while(0) |
5150 | | |
5151 | | static SEXP mkStringUTF8(const ucs_t *wcs, int cnt) |
5152 | 2.06k | { |
5153 | 2.06k | SEXP t; |
5154 | 2.06k | int nb; |
5155 | | |
5156 | | /* NB: cnt includes the terminator */ |
5157 | | #ifdef Win32 |
5158 | | nb = cnt*4; /* UCS-2/UTF-16 so max 4 bytes per wchar_t */ |
5159 | | #else |
5160 | 2.06k | nb = cnt*6; |
5161 | 2.06k | #endif |
5162 | 2.06k | R_CheckStack2(nb); |
5163 | 2.06k | char s[nb]; |
5164 | 2.06k | if (nb) |
5165 | 2.06k | memset(s, 0, nb); /* safety */ |
5166 | | // This used to differentiate WC_NOT_UNICODE but not needed |
5167 | 2.06k | wcstoutf8(s, (const wchar_t *)wcs, sizeof(s)); |
5168 | 2.06k | PROTECT(t = allocVector(STRSXP, 1)); |
5169 | 2.06k | SET_STRING_ELT(t, 0, mkCharCE(s, CE_UTF8)); |
5170 | 2.06k | UNPROTECT(1); /* t */ |
5171 | 2.06k | return t; |
5172 | 2.06k | } |
5173 | | /* |
5174 | | * Skip at Least `min` Bytes in Complete Character Steps |
5175 | | * |
5176 | | * min: minimum number bytes of prefix of "c" to skip |
5177 | | * returns: min or more as needed to skip complete characters |
5178 | | * |
5179 | | * Assumptions: |
5180 | | * - sizeof(buffer) >= min + R_MB_CUR_MAX, i.e. at least 1 full char in buffer. |
5181 | | * - MBCS encodings are valid (they've been read already so should be). |
5182 | | * - Stateless encodings. |
5183 | | */ |
5184 | | |
5185 | 17.6k | static int skipBytesByChar(char *c, int min) { |
5186 | 17.6k | int res = 0; |
5187 | | |
5188 | 17.6k | if(!mbcslocale) |
5189 | 17.6k | res = min; |
5190 | 0 | else { |
5191 | 0 | if(utf8locale) { |
5192 | | /* Find first non continuation byte; we assume UTF-8 is valid. */ |
5193 | 0 | char *cc = c + min; |
5194 | 0 | while(((unsigned char)*cc & 0xc0) == 0x80) ++cc; |
5195 | 0 | res = (int) (cc - c); |
5196 | 0 | } else { |
5197 | 0 | mbstate_t mb_st; |
5198 | 0 | mbs_init(&mb_st); |
5199 | 0 | while(res < min) |
5200 | 0 | res += (int) mbrtowc(NULL, c + res, R_MB_CUR_MAX, &mb_st); |
5201 | 0 | } |
5202 | 0 | } |
5203 | 17.6k | return res; |
5204 | 17.6k | } |
5205 | | |
5206 | 2.77M | #define CTEXT_PUSH(c) do { \ |
5207 | 2.77M | if (ct - currtext >= 1000) { \ |
5208 | 17.6k | int skip = skipBytesByChar(currtext, 100 + 4); \ |
5209 | 17.6k | memmove(currtext, "... ", 4); \ |
5210 | 17.6k | memmove(currtext + 4, currtext + skip, 1000 - skip + 1); \ |
5211 | 17.6k | ct -= skip - 4; \ |
5212 | 17.6k | currtext_truncated = true; \ |
5213 | 17.6k | } \ |
5214 | 2.77M | *ct++ = ((char) c); \ |
5215 | 2.77M | } while(0) |
5216 | 68.8k | #define CTEXT_POP() ct-- |
5217 | | |
5218 | | /* Bidi formatting could confuse the code */ |
5219 | 0 | #define BIDI_CHECK(wc) do { \ |
5220 | 0 | if((wc) >= 0x202A && (wc) <= 0x2069 && \ |
5221 | 0 | !((wc) > 0x202E && (wc) < 0x2066)) \ |
5222 | 0 | raiseLexError("bidiNotAllowed", UCS_VALUE, &wc, \ |
5223 | 0 | _("bidi formatting not allowed, use escapes instead (\\u%04x) (%s:%d:%d)")); \ |
5224 | 0 | } while(0) |
5225 | | |
5226 | | /* forSymbol is true when parsing backticked symbols */ |
5227 | | static int StringValue(int c, bool forSymbol) |
5228 | 15.8k | { |
5229 | 15.8k | int quote = c; |
5230 | 15.8k | char currtext[1010], *ct = currtext; |
5231 | 15.8k | char st0[MAXELTSIZE]; |
5232 | 15.8k | unsigned int nstext = MAXELTSIZE; |
5233 | 15.8k | char *stext = st0, *bp = st0; |
5234 | 15.8k | PROTECT_INDEX sti; |
5235 | 15.8k | int wcnt = 0; |
5236 | 15.8k | ucs_t wcs[10001]; |
5237 | 15.8k | bool oct_or_hex = false, use_wcs = false, currtext_truncated = false; |
5238 | | |
5239 | 15.8k | PROTECT_WITH_INDEX(R_NilValue, &sti); |
5240 | 15.8k | CTEXT_PUSH(c); |
5241 | 1.90M | while ((c = xxgetc()) != R_EOF && c != quote) { |
5242 | 1.88M | CTEXT_PUSH(c); |
5243 | 1.88M | if (c == '\n') { |
5244 | 56.8k | xxungetc(c); CTEXT_POP(); |
5245 | | /* Fix suggested by Mark Bravington to allow multiline strings |
5246 | | * by pretending we've seen a backslash. Was: |
5247 | | * return ERROR; |
5248 | | */ |
5249 | 56.8k | c = '\\'; |
5250 | 56.8k | } |
5251 | 1.88M | if (c == '\\') { |
5252 | 138k | c = xxgetc(); |
5253 | 138k | if (c == R_EOF) break; |
5254 | 138k | CTEXT_PUSH(c); |
5255 | 138k | if ('0' <= c && c <= '7') { |
5256 | 31.0k | int octal = c - '0'; |
5257 | 31.0k | c = xxgetc(); |
5258 | 31.0k | if (c == R_EOF) break; |
5259 | 31.0k | if ('0' <= c && c <= '7') { |
5260 | 29.2k | CTEXT_PUSH(c); |
5261 | 29.2k | octal = 8 * octal + c - '0'; |
5262 | 29.2k | c = xxgetc(); |
5263 | 29.2k | if (c == R_EOF) break; |
5264 | 29.2k | if ('0' <= c && c <= '7') { |
5265 | 28.0k | CTEXT_PUSH(c); |
5266 | 28.0k | octal = 8 * octal + c - '0'; |
5267 | 28.0k | } else { |
5268 | 1.15k | xxungetc(c); |
5269 | 1.15k | } |
5270 | 29.2k | } else { |
5271 | 1.79k | xxungetc(c); |
5272 | 1.79k | } |
5273 | 31.0k | if (!octal) |
5274 | 16 | raiseLexError("nulNotAllowed", NO_VALUE, NULL, |
5275 | 16 | _("nul character not allowed (%s:%d:%d)")); |
5276 | 31.0k | if(octal > 0xff) |
5277 | 2 | raiseLexError("invalidOctal", INT_VALUE, &octal, |
5278 | 2 | _("\\%o exceeds maximum allowed octal value \\377 (%s:%d:%d)")); |
5279 | 31.0k | c = octal; |
5280 | 31.0k | oct_or_hex = true; |
5281 | 31.0k | } |
5282 | 107k | else if(c == 'x') { |
5283 | 5.33k | int val = 0; int i, ext; |
5284 | 15.6k | for(i = 0; i < 2; i++) { |
5285 | 10.6k | c = xxgetc(); |
5286 | 10.6k | if (c == R_EOF) break; |
5287 | 10.6k | CTEXT_PUSH(c); |
5288 | 10.6k | if(c >= '0' && c <= '9') ext = c - '0'; |
5289 | 7.62k | else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10; |
5290 | 3.46k | else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10; |
5291 | 359 | else { |
5292 | 359 | xxungetc(c); |
5293 | 359 | CTEXT_POP(); |
5294 | 359 | if (i == 0) { /* was just \x */ |
5295 | 10 | *ct = '\0'; |
5296 | 10 | raiseLexError("badHex", NO_VALUE, NULL, |
5297 | 10 | _("'\\x' used without hex digits in character string (%s:%d:%d)")); |
5298 | 10 | } |
5299 | 359 | break; |
5300 | 359 | } |
5301 | 10.3k | val = 16*val + ext; |
5302 | 10.3k | } |
5303 | 5.33k | if (c == R_EOF) break; |
5304 | 5.33k | if (!val) |
5305 | 2 | raiseLexError("nulNotAllowed", NO_VALUE, NULL, |
5306 | 2 | _("nul character not allowed (%s:%d:%d)")); |
5307 | 5.33k | c = val; |
5308 | 5.33k | oct_or_hex = true; |
5309 | 5.33k | } |
5310 | 102k | else if(c == 'u') { |
5311 | 11.0k | unsigned int val = 0; int i, ext; |
5312 | 11.0k | bool delim = false; |
5313 | | |
5314 | 11.0k | if(forSymbol) |
5315 | 1 | raiseLexError("unicodeInBackticks", NO_VALUE, NULL, |
5316 | 1 | _("\\uxxxx sequences not supported inside backticks (%s:%d:%d)")); |
5317 | 11.0k | c = xxgetc(); |
5318 | 11.0k | if (c == R_EOF) break; |
5319 | 11.0k | if (c == '{') { |
5320 | 1.06k | delim = true; |
5321 | 1.06k | CTEXT_PUSH(c); |
5322 | 9.97k | } else xxungetc(c); |
5323 | 42.4k | for(i = 0; i < 4; i++) { |
5324 | 37.0k | c = xxgetc(); |
5325 | 37.0k | if (c == R_EOF) break; |
5326 | 37.0k | CTEXT_PUSH(c); |
5327 | 37.0k | if(c >= '0' && c <= '9') ext = c - '0'; |
5328 | 26.3k | else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10; |
5329 | 7.75k | else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10; |
5330 | 5.69k | else { |
5331 | 5.69k | xxungetc(c); |
5332 | 5.69k | CTEXT_POP(); |
5333 | 5.69k | if (i == 0) { /* was just \u */ |
5334 | 18 | *ct = '\0'; |
5335 | 18 | raiseLexError("badUnicodeHex", NO_VALUE, NULL, |
5336 | 18 | _("'\\u' used without hex digits in character string (%s:%d:%d)")); |
5337 | 18 | } |
5338 | 5.69k | break; |
5339 | 5.69k | } |
5340 | 31.3k | val = 16*val + ext; |
5341 | 31.3k | } |
5342 | 11.0k | if (c == R_EOF) break; |
5343 | 11.0k | if(delim) { |
5344 | 1.05k | c = xxgetc(); |
5345 | 1.05k | if (c == R_EOF) break; |
5346 | 1.05k | if (c != '}') |
5347 | 11 | raiseLexError("invalidUnicode", NO_VALUE, NULL, |
5348 | 11 | _("invalid \\u{xxxx} sequence (line %d)")); |
5349 | 1.04k | else CTEXT_PUSH(c); |
5350 | 1.05k | } |
5351 | 11.0k | if (!val) |
5352 | 3 | raiseLexError("nulNotAllowed", NO_VALUE, NULL, |
5353 | 3 | _("nul character not allowed (%s:%d:%d)")); |
5354 | 11.0k | WTEXT_PUSH(val); /* this assumes wchar_t is Unicode */ |
5355 | 11.0k | use_wcs = true; |
5356 | 11.0k | continue; |
5357 | 11.0k | } |
5358 | 91.3k | else if(c == 'U') { |
5359 | 8.25k | unsigned int val = 0; int i, ext; |
5360 | 8.25k | bool delim = false; |
5361 | 8.25k | if(forSymbol) |
5362 | 1 | raiseLexError("unicodeInBackticks", NO_VALUE, NULL, |
5363 | 1 | _("\\Uxxxxxxxx sequences not supported inside backticks (%s:%d:%d)")); |
5364 | 8.25k | c = xxgetc(); |
5365 | 8.25k | if (c == R_EOF) break; |
5366 | 8.25k | if (c == '{') { |
5367 | 1.11k | delim = true; |
5368 | 1.11k | CTEXT_PUSH(c); |
5369 | 7.13k | } else xxungetc(c); |
5370 | 57.4k | for(i = 0; i < 8; i++) { |
5371 | 55.1k | c = xxgetc(); |
5372 | 55.1k | if (c == R_EOF) break; |
5373 | 55.1k | CTEXT_PUSH(c); |
5374 | 55.1k | if(c >= '0' && c <= '9') ext = c - '0'; |
5375 | 17.6k | else if (c >= 'A' && c <= 'F') ext = c - 'A' + 10; |
5376 | 12.9k | else if (c >= 'a' && c <= 'f') ext = c - 'a' + 10; |
5377 | 5.98k | else { |
5378 | 5.98k | xxungetc(c); |
5379 | 5.98k | CTEXT_POP(); |
5380 | 5.98k | if (i == 0) { /* was just \U */ |
5381 | 11 | *ct = '\0'; |
5382 | 11 | raiseLexError("badUnicodeHex", NO_VALUE, NULL, |
5383 | 11 | _("'\\U' used without hex digits in character string (%s:%d:%d)")); |
5384 | 11 | } |
5385 | 5.98k | break; |
5386 | 5.98k | } |
5387 | 49.2k | val = 16*val + ext; |
5388 | 49.2k | } |
5389 | 8.25k | if (c == R_EOF) break; |
5390 | 8.25k | if(delim) { |
5391 | 1.11k | c = xxgetc(); |
5392 | 1.11k | if (c == R_EOF) break; |
5393 | 1.11k | if (c != '}') |
5394 | 19 | raiseLexError("invalidUnicode", NO_VALUE, NULL, |
5395 | 19 | _("invalid \\U{xxxxxxxx} sequence (%s:%d:%d)")); |
5396 | 1.09k | else CTEXT_PUSH(c); |
5397 | 1.11k | } |
5398 | 8.25k | if (!val) |
5399 | 3 | raiseLexError("nulNotAllowed", NO_VALUE, NULL, |
5400 | 3 | _("nul character not allowed (%s:%d:%d)")); |
5401 | 8.25k | if (val > 0x10FFFF) { |
5402 | 32 | if(delim) |
5403 | 1 | raiseLexError("invalidUnicode", INT_VALUE, &val, |
5404 | 1 | _("invalid \\U{xxxxxxxx} value %6x (%s:%d:%d)")); |
5405 | 31 | else |
5406 | 31 | raiseLexError("invalidUnicode", INT_VALUE, &val, |
5407 | 31 | _("invalid \\Uxxxxxxxx value %6x (%s:%d:%d)")); |
5408 | 32 | } |
5409 | | #ifdef Win32 |
5410 | | if (0x010000 <= val && val <= 0x10FFFF) { /* Need surrogate pair in Windows */ |
5411 | | val = val - 0x010000; |
5412 | | WTEXT_PUSH( 0xD800 | (val >> 10) ); |
5413 | | val = 0xDC00 | (val & 0x03FF); |
5414 | | } |
5415 | | #endif |
5416 | 8.25k | WTEXT_PUSH(val); |
5417 | 8.25k | use_wcs = true; |
5418 | 8.25k | continue; |
5419 | 8.25k | } |
5420 | 83.0k | else { |
5421 | 83.0k | switch (c) { |
5422 | 116 | case 'a': |
5423 | 116 | c = '\a'; |
5424 | 116 | break; |
5425 | 343 | case 'b': |
5426 | 343 | c = '\b'; |
5427 | 343 | break; |
5428 | 551 | case 'f': |
5429 | 551 | c = '\f'; |
5430 | 551 | break; |
5431 | 17.5k | case 'n': |
5432 | 17.5k | c = '\n'; |
5433 | 17.5k | break; |
5434 | 111 | case 'r': |
5435 | 111 | c = '\r'; |
5436 | 111 | break; |
5437 | 562 | case 't': |
5438 | 562 | c = '\t'; |
5439 | 562 | break; |
5440 | 397 | case 'v': |
5441 | 397 | c = '\v'; |
5442 | 397 | break; |
5443 | 4.21k | case '\\': |
5444 | 5.23k | case '"': |
5445 | 6.07k | case '\'': |
5446 | 6.47k | case '`': |
5447 | 6.58k | case ' ': |
5448 | 63.4k | case '\n': |
5449 | 63.4k | break; |
5450 | 37 | default: { |
5451 | 37 | char ch[2]; |
5452 | 37 | ch[0] = (char) c; |
5453 | 37 | ch[1] = '\0'; |
5454 | 37 | raiseLexError("unrecognizedEscape", STRING_VALUE, ch, |
5455 | 37 | _("'\\%s' is an unrecognized escape in character string (%s:%d:%d)")); |
5456 | 37 | } |
5457 | 83.0k | } |
5458 | 83.0k | } |
5459 | 1.74M | } else if(mbcslocale) { |
5460 | 0 | ucs_t wc; |
5461 | 0 | int clen = mbcs_get_next2(c, &wc); |
5462 | 0 | if (clen == -1) { /* EOF whilst reading MBCS char */ |
5463 | 0 | xxungetc(c); |
5464 | 0 | c = R_EOF; |
5465 | 0 | break; |
5466 | 0 | } |
5467 | 0 | BIDI_CHECK(wc); |
5468 | 0 | WTEXT_PUSH(wc); |
5469 | 0 | ParseState.xxbyteno += clen-1; |
5470 | | |
5471 | 0 | for(int i = 0; i < clen - 1; i++){ |
5472 | 0 | STEXT_PUSH(c); |
5473 | 0 | c = xxgetc(); |
5474 | 0 | if (c == R_EOF) break; |
5475 | 0 | CTEXT_PUSH(c); |
5476 | 0 | if (c == '\n') { |
5477 | 0 | xxungetc(c); CTEXT_POP(); |
5478 | 0 | c = '\\'; |
5479 | 0 | } |
5480 | 0 | } |
5481 | 0 | if (c == R_EOF) break; |
5482 | 0 | STEXT_PUSH(c); |
5483 | 0 | continue; |
5484 | 0 | } |
5485 | 1.86M | STEXT_PUSH(c); |
5486 | 1.86M | if ((unsigned int) c < 0x80) WTEXT_PUSH(c); |
5487 | 37.6k | else { |
5488 | | /* have an 8-bit char in the current encoding */ |
5489 | | /* FIXME: `wc` values will be wrong when native encoding differs |
5490 | | from that indicated by `known_to_be*` */ |
5491 | 37.6k | int res = 0; |
5492 | | #ifdef WC_NOT_UNICODE |
5493 | | ucs_t wc; |
5494 | | char s[2] = " "; |
5495 | | s[0] = (char) c; |
5496 | | res = (int) mbtoucs(&wc, s, 2); |
5497 | | #else |
5498 | 37.6k | wchar_t wc; |
5499 | 37.6k | char s[2] = " "; |
5500 | 37.6k | s[0] = (char) c; |
5501 | | /* This is not necessarily correct for stateful SBCS */ |
5502 | 37.6k | mbstate_t mb_st; |
5503 | 37.6k | mbs_init(&mb_st); |
5504 | 37.6k | res = (int) mbrtowc(&wc, s, 2, &mb_st); |
5505 | 37.6k | #endif |
5506 | 37.6k | if(res < 0) wc = 0xFFFD; /* placeholder for invalid encoding */ |
5507 | 37.6k | WTEXT_PUSH(wc); |
5508 | 37.6k | } |
5509 | 1.86M | } |
5510 | 15.8k | STEXT_PUSH('\0'); |
5511 | 15.8k | WTEXT_PUSH(0); |
5512 | 15.8k | yytext[0] = '\0'; |
5513 | 15.8k | if (c == R_EOF) { |
5514 | 381 | PRESERVE_SV(yylval = R_NilValue); |
5515 | 381 | UNPROTECT(1); /* release stext */ |
5516 | 381 | return INCOMPLETE_STRING; |
5517 | 15.4k | } else { |
5518 | 15.4k | CTEXT_PUSH(c); |
5519 | 15.4k | CTEXT_PUSH('\0'); |
5520 | 15.4k | } |
5521 | 15.4k | if (!currtext_truncated) |
5522 | 14.9k | strcpy(yytext, currtext); |
5523 | 439 | else if (forSymbol || !use_wcs) { |
5524 | 187 | size_t total = strlen(stext); |
5525 | 187 | snprintf(yytext, MAXELTSIZE, "[%u chars quoted with '%c']", (unsigned int)total, quote); |
5526 | 187 | } else |
5527 | 252 | snprintf(yytext, MAXELTSIZE, "[%d wide chars quoted with '%c']", wcnt, quote); |
5528 | 15.4k | if(forSymbol) { |
5529 | 3.25k | PRESERVE_SV(yylval = install(stext)); |
5530 | 3.25k | UNPROTECT(1); /* release stext */ |
5531 | 3.25k | return SYMBOL; |
5532 | 12.1k | } else { |
5533 | 12.1k | if(use_wcs) { |
5534 | 2.08k | if(oct_or_hex) |
5535 | 13 | raiseLexError("mixedEscapes", NO_VALUE, NULL, |
5536 | 13 | _("mixing Unicode and octal/hex escapes in a string is not allowed (%s:%d:%d)")); |
5537 | 2.08k | if(wcnt < 10000) |
5538 | 2.06k | PRESERVE_SV(yylval = mkStringUTF8(wcs, wcnt)); /* include terminator */ |
5539 | 19 | else |
5540 | 19 | raiseLexError("UnicodeTooLong", NO_VALUE, NULL, |
5541 | 19 | _("string containing Unicode escapes not in this locale\n" |
5542 | 19 | "is too long (max 10000 chars) (%s:%d:%d)")); |
5543 | 2.08k | } else |
5544 | 10.0k | PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1, oct_or_hex)); |
5545 | 12.1k | UNPROTECT(1); /* release stext */ |
5546 | 12.1k | return STR_CONST; |
5547 | 12.1k | } |
5548 | 15.4k | } |
5549 | | |
5550 | | static int RawStringValue(int c0, int c) |
5551 | 1.28k | { |
5552 | 1.28k | int quote = c; |
5553 | 1.28k | int delim = ')'; |
5554 | 1.28k | char currtext[1010], *ct = currtext; |
5555 | 1.28k | char st0[MAXELTSIZE]; |
5556 | 1.28k | unsigned int nstext = MAXELTSIZE; |
5557 | 1.28k | char *stext = st0, *bp = st0; |
5558 | 1.28k | PROTECT_INDEX sti; |
5559 | 1.28k | int wcnt = 0; |
5560 | 1.28k | ucs_t wcs[10001]; |
5561 | 1.28k | bool oct_or_hex = false, use_wcs = false, currtext_truncated = false; |
5562 | | |
5563 | 1.28k | CTEXT_PUSH(c0); /* 'r' or 'R' */ |
5564 | 1.28k | CTEXT_PUSH(c); /* opening quote */ |
5565 | | |
5566 | | /* count dashes between the opening quote and opening delimiter */ |
5567 | 1.28k | int ndash = 0; |
5568 | 22.5k | while (nextchar('-')) { CTEXT_PUSH('-'); ndash++; } |
5569 | | |
5570 | 1.28k | c = xxgetc(); |
5571 | 1.28k | CTEXT_PUSH(c); |
5572 | 1.28k | switch(c) { |
5573 | 835 | case '(': delim = ')'; break; |
5574 | 82 | case '[': delim = ']'; break; |
5575 | 20 | case '{': delim = '}'; break; |
5576 | 332 | case '|': delim = '|'; break; |
5577 | 19 | default: |
5578 | 19 | raiseLexError("invalidRawLiteral", NO_VALUE, NULL, |
5579 | 19 | _("malformed raw string literal (%s:%d:%d)")); |
5580 | 1.28k | } |
5581 | | |
5582 | 1.26k | PROTECT_WITH_INDEX(R_NilValue, &sti); |
5583 | 505k | while ((c = xxgetc()) != R_EOF) { |
5584 | 505k | if (c == delim) { |
5585 | | /* count the dashes after the closing delimiter */ |
5586 | 60.6k | int nd = 0; |
5587 | 67.9k | while (nd < ndash && nextchar('-')) nd++; |
5588 | | |
5589 | 60.6k | if (nd == ndash && nextchar(quote)) |
5590 | | /* right number of dashes, right quote: were done! */ |
5591 | 1.07k | break; |
5592 | 59.5k | else { |
5593 | | /* not done: emit closing delimiter, dashes, and continue */ |
5594 | 59.5k | CTEXT_PUSH(delim); |
5595 | 59.5k | STEXT_PUSH(delim); |
5596 | 59.5k | WTEXT_PUSH(delim); |
5597 | 65.6k | for (int i = 0; i < nd; i++) { |
5598 | 6.14k | CTEXT_PUSH('-'); |
5599 | 6.14k | STEXT_PUSH('-'); |
5600 | 6.14k | WTEXT_PUSH('-'); |
5601 | 6.14k | } |
5602 | 59.5k | continue; |
5603 | 59.5k | } |
5604 | 60.6k | } |
5605 | 444k | CTEXT_PUSH(c); |
5606 | 444k | if(mbcslocale) { |
5607 | 0 | int i, clen; |
5608 | 0 | ucs_t wc; |
5609 | 0 | clen = mbcs_get_next2(c, &wc); |
5610 | 0 | if (clen == -1) { /* EOF whilst reading MBCS char */ |
5611 | 0 | xxungetc(c); |
5612 | 0 | c = R_EOF; |
5613 | 0 | break; |
5614 | 0 | } |
5615 | 0 | BIDI_CHECK(wc); |
5616 | 0 | WTEXT_PUSH(wc); |
5617 | 0 | ParseState.xxbyteno += clen-1; |
5618 | | |
5619 | 0 | for(i = 0; i < clen - 1; i++){ |
5620 | 0 | STEXT_PUSH(c); |
5621 | 0 | c = xxgetc(); |
5622 | 0 | if (c == R_EOF) break; |
5623 | 0 | CTEXT_PUSH(c); |
5624 | 0 | } |
5625 | 0 | if (c == R_EOF) break; |
5626 | 0 | STEXT_PUSH(c); |
5627 | 0 | continue; |
5628 | 0 | } |
5629 | 444k | STEXT_PUSH(c); |
5630 | 444k | if ((unsigned int) c < 0x80) WTEXT_PUSH(c); |
5631 | 24.2k | else { /* have an 8-bit char in the current encoding */ |
5632 | 24.2k | int res = 0; |
5633 | | #ifdef WC_NOT_UNICODE |
5634 | | ucs_t wc; |
5635 | | char s[2] = " "; |
5636 | | s[0] = (char) c; |
5637 | | res = (int) mbtoucs(&wc, s, 2); |
5638 | | #else |
5639 | 24.2k | wchar_t wc; |
5640 | 24.2k | char s[2] = " "; |
5641 | 24.2k | s[0] = (char) c; |
5642 | | /* This is not necessarily correct for stateful SBCS */ |
5643 | 24.2k | mbstate_t mb_st; |
5644 | 24.2k | mbs_init(&mb_st); |
5645 | 24.2k | res = (int) mbrtowc(&wc, s, 2, &mb_st); |
5646 | 24.2k | #endif |
5647 | 24.2k | if(res < 0) wc = 0xFFFD; /* placeholder for invalid encoding */ |
5648 | 24.2k | WTEXT_PUSH(wc); |
5649 | 24.2k | } |
5650 | 444k | } |
5651 | 1.26k | STEXT_PUSH('\0'); |
5652 | 1.26k | WTEXT_PUSH(0); |
5653 | 1.26k | yytext[0] = '\0'; |
5654 | 1.26k | if (c == R_EOF) { |
5655 | 191 | PRESERVE_SV(yylval = R_NilValue); |
5656 | 191 | UNPROTECT(1); /* release stext */ |
5657 | 191 | return INCOMPLETE_STRING; |
5658 | 1.07k | } else { |
5659 | | /* record delim, dashes, and quote, and terminate string */ |
5660 | 1.07k | CTEXT_PUSH(delim); |
5661 | 2.25k | for (int i = 0; i < ndash; i++) |
5662 | 1.18k | CTEXT_PUSH('-'); |
5663 | 1.07k | CTEXT_PUSH(quote); |
5664 | 1.07k | CTEXT_PUSH('\0'); |
5665 | 1.07k | } |
5666 | 1.07k | if (!currtext_truncated) |
5667 | 1.00k | strcpy(yytext, currtext); |
5668 | 78 | else if (!use_wcs) { |
5669 | 78 | size_t total = strlen(stext); |
5670 | 78 | snprintf(yytext, MAXELTSIZE, "[%u chars quoted with '%c']", (unsigned int)total, quote); |
5671 | 78 | } else |
5672 | 0 | snprintf(yytext, MAXELTSIZE, "[%d wide chars quoted with '%c']", wcnt, quote); |
5673 | 1.07k | if(use_wcs) { |
5674 | 0 | if(oct_or_hex) |
5675 | 0 | raiseLexError("mixedEscapes", NO_VALUE, NULL, |
5676 | 0 | _("mixing Unicode and octal/hex escapes in a string is not allowed (%s:%d:%d)")); |
5677 | 0 | if(wcnt < 10000) |
5678 | 0 | PRESERVE_SV(yylval = mkStringUTF8(wcs, wcnt)); /* include terminator */ |
5679 | 0 | else |
5680 | 0 | raiseLexError("UnicodeTooLong", NO_VALUE, NULL, |
5681 | 0 | _("string containing Unicode escapes not in this locale\n" |
5682 | 0 | "is too long (max 10000 chars) (%s:%d:%d)")); |
5683 | 0 | } else |
5684 | 1.07k | PRESERVE_SV(yylval = mkString2(stext, bp - stext - 1, oct_or_hex)); |
5685 | 1.07k | UNPROTECT(1); /* release stext */ |
5686 | 1.07k | return STR_CONST; |
5687 | 1.26k | } |
5688 | | |
5689 | | static int SpecialValue(int c) |
5690 | 1.20k | { |
5691 | 1.20k | DECLARE_YYTEXT_BUFP(yyp); |
5692 | 1.20k | YYTEXT_PUSH(c, yyp); |
5693 | 125k | while ((c = xxgetc()) != R_EOF && c != '%') { |
5694 | 123k | if (c == '\n') { |
5695 | 33 | xxungetc(c); |
5696 | 33 | return ERROR; |
5697 | 33 | } |
5698 | 123k | YYTEXT_PUSH(c, yyp); |
5699 | 123k | } |
5700 | 1.17k | if (c == '%') |
5701 | 1.17k | YYTEXT_PUSH(c, yyp); |
5702 | 1.17k | YYTEXT_PUSH('\0', yyp); |
5703 | 1.17k | yylval = install(yytext); |
5704 | 1.17k | return SPECIAL; |
5705 | 1.20k | } |
5706 | | |
5707 | | /* return 1 if name is a valid name 0 otherwise */ |
5708 | | attribute_hidden |
5709 | | int isValidName(const char *name) |
5710 | 328k | { |
5711 | 328k | const char *p = name; |
5712 | 328k | int i; |
5713 | | |
5714 | 328k | if(mbcslocale) { |
5715 | | /* the only way to establish which chars are alpha etc is to |
5716 | | use the wchar variants */ |
5717 | 1.49k | size_t n = strlen(name), used; |
5718 | 1.49k | wchar_t wc; |
5719 | | /* This is not necessarily correct for stateful MBCS */ |
5720 | 1.49k | mbstate_t mb_st; |
5721 | 1.49k | mbs_init(&mb_st); |
5722 | | /* mbrtowc, not Mbrtowc: an undecodable string is not a valid name, |
5723 | | and must not signal an error, as this is reached while deparsing |
5724 | | calls for error messages */ |
5725 | 1.49k | used = mbrtowc(&wc, p, n, &mb_st); |
5726 | 1.49k | if((int) used <= 0) return 0; |
5727 | 1.49k | p += used; n -= used; |
5728 | 1.49k | if (wc != L'.' && !iswalpha(wc) ) return 0; |
5729 | 1.49k | if (wc == L'.') { |
5730 | | /* We don't care about other than ASCII digits */ |
5731 | 0 | if(isdigit(0xff & (int)*p)) return 0; |
5732 | | /* Mbrtowc(&wc, p, n, NULL); if(iswdigit(wc)) return 0; */ |
5733 | 0 | } |
5734 | 7.95k | while(n > 0) { |
5735 | 6.46k | used = mbrtowc(&wc, p, n, &mb_st); |
5736 | 6.46k | if((int) used <= 0) break; |
5737 | 6.46k | if (!(iswalnum(wc) || wc == L'.' || wc == L'_')) break; |
5738 | 6.46k | p += used; n -= used; |
5739 | 6.46k | } |
5740 | 1.49k | if (*p != '\0') return 0; |
5741 | 326k | } else { |
5742 | 326k | int c = 0xff & *p++; |
5743 | 326k | if (c != '.' && !isalpha(c) ) return 0; |
5744 | 97.0k | if (c == '.' && isdigit(0xff & (int)*p)) return 0; |
5745 | 1.04M | while ( c = 0xff & *p++, (isalnum(c) || c == '.' || c == '_') ) ; |
5746 | 96.7k | if (c != '\0') return 0; |
5747 | 96.7k | } |
5748 | | |
5749 | 97.9k | if (strcmp(name, "...") == 0) return 1; |
5750 | | |
5751 | 2.05M | for (i = 0; keywords[i].name != NULL; i++) |
5752 | 1.95M | if (strcmp(keywords[i].name, name) == 0) return 0; |
5753 | | |
5754 | 97.6k | return 1; |
5755 | 97.7k | } |
5756 | | |
5757 | | static int SymbolValue(int c) |
5758 | 400k | { |
5759 | 400k | int kw; |
5760 | 400k | DECLARE_YYTEXT_BUFP(yyp); |
5761 | 400k | if(mbcslocale) { |
5762 | | // FIXME potentially need R_wchar_t with UTF-8 Windows. |
5763 | 0 | wchar_t wc; int i, clen; |
5764 | 0 | clen = mbcs_get_next(c, &wc); |
5765 | 0 | while(clen != -1) { |
5766 | | /* at this point we have seen one char, so push its bytes |
5767 | | and get one more */ |
5768 | 0 | for(i = 0; i < clen; i++) { |
5769 | 0 | YYTEXT_PUSH(c, yyp); |
5770 | 0 | c = xxgetc(); |
5771 | 0 | } |
5772 | 0 | if(c == R_EOF) break; |
5773 | 0 | if(c == '.' || c == '_') { |
5774 | 0 | clen = 1; |
5775 | 0 | continue; |
5776 | 0 | } |
5777 | 0 | clen = mbcs_get_next(c, &wc); |
5778 | 0 | if (clen == -1) break; /* EOF whilst reading MBCS char */ |
5779 | 0 | if(!iswalnum(wc)) break; |
5780 | 0 | } |
5781 | 0 | } else |
5782 | 1.21M | do { |
5783 | 1.21M | YYTEXT_PUSH(c, yyp); |
5784 | 1.21M | } while ((c = xxgetc()) != R_EOF && |
5785 | 1.21M | (isalnum(c) || c == '.' || c == '_')); |
5786 | 400k | xxungetc(c); |
5787 | 400k | YYTEXT_PUSH('\0', yyp); |
5788 | 400k | if ((kw = KeywordLookup(yytext))) |
5789 | 19.2k | return kw; |
5790 | | |
5791 | 381k | PRESERVE_SV(yylval = install(yytext)); |
5792 | 381k | return SYMBOL; |
5793 | 400k | } |
5794 | | |
5795 | | static int Placeholder(int c) |
5796 | 23.2k | { |
5797 | 23.2k | DECLARE_YYTEXT_BUFP(yyp); |
5798 | 23.2k | YYTEXT_PUSH(c, yyp); |
5799 | 23.2k | YYTEXT_PUSH('\0', yyp); |
5800 | 23.2k | HavePlaceholder = true; |
5801 | 23.2k | PRESERVE_SV(yylval = R_PlaceholderToken); |
5802 | 23.2k | return PLACEHOLDER; |
5803 | 23.2k | } |
5804 | | |
5805 | 23 | static void setParseFilename(SEXP newname) { |
5806 | 23 | SEXP class; |
5807 | | |
5808 | 23 | if (isEnvironment(PS_SRCFILE)) { |
5809 | 8 | SEXP oldname = R_findVar(install("filename"), PS_SRCFILE); |
5810 | 8 | if (isString(oldname) && length(oldname) > 0 && |
5811 | 8 | strcmp(CHAR(STRING_ELT(oldname, 0)), |
5812 | 8 | CHAR(STRING_ELT(newname, 0))) == 0) return; |
5813 | 5 | PS_SET_SRCFILE(NewEnvironment(R_NilValue, R_NilValue, R_EmptyEnv)); |
5814 | 5 | defineVar(install("filename"), newname, PS_SRCFILE); |
5815 | 5 | defineVar(install("original"), PS_ORIGINAL, PS_SRCFILE); |
5816 | | |
5817 | 5 | PROTECT(class = allocVector(STRSXP, 2)); |
5818 | 5 | SET_STRING_ELT(class, 0, mkChar("srcfilealias")); |
5819 | 5 | SET_STRING_ELT(class, 1, mkChar("srcfile")); |
5820 | 5 | setAttrib(PS_SRCFILE, R_ClassSymbol, class); |
5821 | 5 | UNPROTECT(1); /* class */ |
5822 | 5 | } else |
5823 | 15 | PS_SET_SRCFILE(duplicate(newname)); |
5824 | 20 | RELEASE_SV(newname); |
5825 | 20 | } |
5826 | | |
5827 | | static int processLineDirective(int *type) |
5828 | 2.95k | { |
5829 | 2.95k | int c, tok, linenumber; |
5830 | 2.95k | c = SkipSpace(); |
5831 | 2.95k | if (!isdigit(c)) return(c); |
5832 | 2.60k | tok = NumericValue(c); |
5833 | 2.60k | linenumber = atoi(yytext); |
5834 | 2.60k | c = SkipSpace(); |
5835 | 2.60k | if (c == '"') |
5836 | 24 | tok = StringValue(c, false); |
5837 | 2.57k | else |
5838 | 2.57k | xxungetc(c); |
5839 | 2.60k | if (tok == STR_CONST) |
5840 | 23 | setParseFilename(yylval); |
5841 | 50.6k | while ((c = xxgetc()) != '\n' && c != R_EOF) /* skip */ ; |
5842 | 2.60k | ParseState.xxlineno = linenumber; |
5843 | 2.60k | *type = LINE_DIRECTIVE; |
5844 | | /* we don't change xxparseno here: it counts parsed lines, not official lines */ |
5845 | 2.60k | R_ParseContext[R_ParseContextLast] = '\0'; /* Context report shouldn't show the directive */ |
5846 | 2.60k | return(c); |
5847 | 2.95k | } |
5848 | | |
5849 | | /* Get the R symbol, and set yytext at the same time */ |
5850 | | static SEXP install_and_save(char * text) |
5851 | 578k | { |
5852 | 578k | strcpy(yytext, text); |
5853 | 578k | return install(text); |
5854 | 578k | } |
5855 | | |
5856 | | /* Get an R symbol, and set different yytext. Used for translation of -> to <-. ->> to <<- */ |
5857 | | static SEXP install_and_save2(char * text, char * savetext) |
5858 | 1.22k | { |
5859 | 1.22k | strcpy(yytext, savetext); |
5860 | 1.22k | return install(text); |
5861 | 1.22k | } |
5862 | | |
5863 | | |
5864 | | /* Split the input stream into tokens. */ |
5865 | | /* This is the lowest of the parsing levels. */ |
5866 | | |
5867 | | static int token(void) |
5868 | 1.69M | { |
5869 | 1.69M | int c, clen, i; |
5870 | 1.69M | wchar_t wc; |
5871 | | |
5872 | 1.69M | if (SavedToken) { |
5873 | 342 | c = SavedToken; |
5874 | 342 | yylval = SavedLval; |
5875 | 342 | SavedLval = R_NilValue; |
5876 | 342 | SavedToken = 0; |
5877 | 342 | yylloc.first_line = xxlinesave; |
5878 | 342 | yylloc.first_column = xxcolsave; |
5879 | 342 | yylloc.first_byte = xxbytesave; |
5880 | 342 | yylloc.first_parsed = xxparsesave; |
5881 | 342 | return c; |
5882 | 342 | } |
5883 | 1.69M | xxcharsave = xxcharcount; /* want to be able to go back one token */ |
5884 | | |
5885 | 1.69M | c = SkipSpace(); |
5886 | 1.69M | if (c == '#') c = SkipComment(); |
5887 | | |
5888 | 1.69M | yylloc.first_line = ParseState.xxlineno; |
5889 | 1.69M | yylloc.first_column = ParseState.xxcolno; |
5890 | 1.69M | yylloc.first_byte = ParseState.xxbyteno; |
5891 | 1.69M | yylloc.first_parsed = ParseState.xxparseno; |
5892 | | |
5893 | 1.69M | if (c == R_EOF) return END_OF_INPUT; |
5894 | | |
5895 | | /* Either digits or symbols can start with a "." */ |
5896 | | /* so we need to decide which it is and jump to */ |
5897 | | /* the correct spot. */ |
5898 | | |
5899 | 1.69M | if (c == '.' && typeofnext() >= 2) goto symbol; |
5900 | | |
5901 | | /* literal numbers */ |
5902 | | |
5903 | 1.68M | if (c == '.') return NumericValue(c); |
5904 | | /* We don't care about other than ASCII digits */ |
5905 | 1.56M | if (isdigit(c)) return NumericValue(c); |
5906 | | |
5907 | | /* raw string literal */ |
5908 | | |
5909 | 1.50M | if (c == 'r' || c == 'R') { |
5910 | 4.92k | if (nextchar('"')) |
5911 | 967 | return RawStringValue(c, '"'); |
5912 | 3.96k | else if (nextchar('\'')) |
5913 | 321 | return RawStringValue(c, '\''); |
5914 | 4.92k | } |
5915 | | |
5916 | | /* literal strings */ |
5917 | | |
5918 | 1.50M | if (c == '\"' || c == '\'') |
5919 | 12.5k | return StringValue(c, false); |
5920 | | |
5921 | | /* special functions */ |
5922 | | |
5923 | 1.48M | if (c == '%') |
5924 | 1.20k | return SpecialValue(c); |
5925 | | |
5926 | | /* functions, constants and variables */ |
5927 | | |
5928 | 1.48M | if (c == '`') |
5929 | 3.30k | return StringValue(c, true); |
5930 | 1.49M | symbol: |
5931 | | |
5932 | 1.49M | if (c == '.') return SymbolValue(c); |
5933 | 1.48M | if (c == '_') return Placeholder(c); |
5934 | 1.46M | if(mbcslocale) { |
5935 | | // FIXME potentially need R_wchar_t with UTF-8 Windows. |
5936 | 0 | if (mbcs_get_next(c, &wc) == -1) |
5937 | 0 | return END_OF_INPUT; /* EOF whilst reading MBCS char */ |
5938 | 0 | if (iswalpha(wc)) return SymbolValue(c); |
5939 | 0 | } else |
5940 | 1.46M | if (isalpha(c)) return SymbolValue(c); |
5941 | | |
5942 | | /* compound tokens */ |
5943 | | |
5944 | 1.07M | switch (c) { |
5945 | 6.01k | case '<': |
5946 | 6.01k | if (nextchar('=')) { |
5947 | 131 | yylval = install_and_save("<="); |
5948 | 131 | return LE; |
5949 | 131 | } |
5950 | 5.88k | if (nextchar('-')) { |
5951 | 4.46k | yylval = install_and_save("<-"); |
5952 | 4.46k | return LEFT_ASSIGN; |
5953 | 4.46k | } |
5954 | 1.42k | if (nextchar('<')) { |
5955 | 673 | if (nextchar('-')) { |
5956 | 671 | yylval = install_and_save("<<-"); |
5957 | 671 | return LEFT_ASSIGN; |
5958 | 671 | } |
5959 | 2 | else |
5960 | 2 | return ERROR; |
5961 | 673 | } |
5962 | 747 | yylval = install_and_save("<"); |
5963 | 747 | return LT; |
5964 | 13.2k | case '-': |
5965 | 13.2k | if (nextchar('>')) { |
5966 | 1.02k | if (nextchar('>')) { |
5967 | 146 | yylval = install_and_save2("<<-", "->>"); |
5968 | 146 | return RIGHT_ASSIGN; |
5969 | 146 | } |
5970 | 883 | else { |
5971 | 883 | yylval = install_and_save2("<-", "->"); |
5972 | 883 | return RIGHT_ASSIGN; |
5973 | 883 | } |
5974 | 1.02k | } |
5975 | 12.2k | yylval = install_and_save("-"); |
5976 | 12.2k | return '-'; |
5977 | 1.37k | case '>': |
5978 | 1.37k | if (nextchar('=')) { |
5979 | 227 | yylval = install_and_save(">="); |
5980 | 227 | return GE; |
5981 | 227 | } |
5982 | 1.14k | yylval = install_and_save(">"); |
5983 | 1.14k | return GT; |
5984 | 1.71k | case '!': |
5985 | 1.71k | if (nextchar('=')) { |
5986 | 296 | yylval = install_and_save("!="); |
5987 | 296 | return NE; |
5988 | 296 | } |
5989 | 1.42k | yylval = install_and_save("!"); |
5990 | 1.42k | return '!'; |
5991 | 156k | case '=': |
5992 | 156k | if (nextchar('=')) { |
5993 | 1.12k | yylval = install_and_save("=="); |
5994 | 1.12k | return EQ; |
5995 | 1.12k | } |
5996 | 155k | else if (nextchar('>')) { |
5997 | 718 | yylval = install_and_save("=>"); |
5998 | 718 | HavePipeBind = true; |
5999 | 718 | return PIPEBIND; |
6000 | 718 | } |
6001 | 154k | yylval = install_and_save("="); |
6002 | 154k | return EQ_ASSIGN; |
6003 | 20.5k | case ':': |
6004 | 20.5k | if (nextchar(':')) { |
6005 | 2.15k | if (nextchar(':')) { |
6006 | 302 | yylval = install_and_save(":::"); |
6007 | 302 | return NS_GET_INT; |
6008 | 302 | } |
6009 | 1.84k | else { |
6010 | 1.84k | yylval = install_and_save("::"); |
6011 | 1.84k | return NS_GET; |
6012 | 1.84k | } |
6013 | 2.15k | } |
6014 | 18.4k | if (nextchar('=')) { |
6015 | 251 | yylval = install_and_save(":="); |
6016 | 251 | return LEFT_ASSIGN; |
6017 | 251 | } |
6018 | 18.1k | yylval = install_and_save(":"); |
6019 | 18.1k | return ':'; |
6020 | 1.42k | case '&': |
6021 | 1.42k | if (nextchar('&')) { |
6022 | 730 | yylval = install_and_save("&&"); |
6023 | 730 | return AND2; |
6024 | 730 | } |
6025 | 698 | yylval = install_and_save("&"); |
6026 | 698 | return AND; |
6027 | 2.57k | case '|': |
6028 | 2.57k | if (nextchar('|')) { |
6029 | 126 | yylval = install_and_save("||"); |
6030 | 126 | return OR2; |
6031 | 126 | } |
6032 | 2.45k | else if (nextchar('>')) { |
6033 | 1.27k | yylval = install_and_save("|>"); |
6034 | 1.27k | return PIPE; |
6035 | 1.27k | } |
6036 | 1.17k | yylval = install_and_save("|"); |
6037 | 1.17k | return OR; |
6038 | 2.32k | case LBRACE: |
6039 | 2.32k | yylval = install_and_save("{"); |
6040 | 2.32k | return c; |
6041 | 1.65k | case RBRACE: |
6042 | 1.65k | strcpy(yytext, "}"); |
6043 | 1.65k | return c; |
6044 | 60.2k | case '(': |
6045 | 60.2k | yylval = install_and_save("("); |
6046 | 60.2k | return c; |
6047 | 55.4k | case ')': |
6048 | 55.4k | strcpy(yytext, ")"); |
6049 | 55.4k | return c; |
6050 | 4.10k | case '[': |
6051 | 4.10k | if (nextchar('[')) { |
6052 | 351 | yylval = install_and_save("[["); |
6053 | 351 | return LBB; |
6054 | 351 | } |
6055 | 3.74k | yylval = install_and_save("["); |
6056 | 3.74k | return c; |
6057 | 4.07k | case ']': |
6058 | 4.07k | strcpy(yytext, "]"); |
6059 | 4.07k | return c; |
6060 | 307k | case '?': |
6061 | 307k | yylval = install_and_save("?"); |
6062 | 307k | return c; |
6063 | 2.63k | case '*': |
6064 | | /* Replace ** by ^. This has been here since 1998, but is |
6065 | | undocumented (at least in the obvious places). It is in |
6066 | | the index of the Blue Book with a reference to p. 431, the |
6067 | | help for 'Deprecated'. S-PLUS 6.2 still allowed this, so |
6068 | | presumably it was for compatibility with S. */ |
6069 | 2.63k | if (nextchar('*')) { |
6070 | 200 | yylval = install_and_save2("^", "**"); |
6071 | 200 | return '^'; |
6072 | 200 | } else |
6073 | 2.43k | yylval = install_and_save("*"); |
6074 | 2.43k | return c; |
6075 | 10.3k | case '+': |
6076 | 11.8k | case '/': |
6077 | 22.6k | case '^': |
6078 | 72.8k | case '~': |
6079 | 75.0k | case '$': |
6080 | 76.0k | case '@': |
6081 | 76.6k | case '\\': |
6082 | 76.6k | yytext[0] = (char) c; |
6083 | 76.6k | yytext[1] = '\0'; |
6084 | 76.6k | yylval = install(yytext); |
6085 | 76.6k | return c; |
6086 | 336k | case '\n': |
6087 | 349k | case ',': |
6088 | 353k | case ';': |
6089 | 353k | yytext[0] = (char) c; |
6090 | 353k | yytext[1] = '\0'; |
6091 | 353k | return c; |
6092 | 502 | default: |
6093 | 502 | clen = 1; |
6094 | 502 | if (mbcslocale) { |
6095 | | // FIXME potentially need R_wchar_t with UTF-8 Windows. |
6096 | 0 | clen = mbcs_get_next(c, &wc); |
6097 | 0 | if (clen == -1) |
6098 | 0 | return END_OF_INPUT; /* EOF whilst reading MBCS char */ |
6099 | 0 | } |
6100 | 502 | DECLARE_YYTEXT_BUFP(yyp); |
6101 | 502 | YYTEXT_PUSH(c, yyp); |
6102 | 502 | for(i = 1; i < clen ; i++) |
6103 | 0 | YYTEXT_PUSH(xxgetc(), yyp); |
6104 | 502 | YYTEXT_PUSH('\0', yyp); |
6105 | 502 | return (clen == 1) ? c : ERROR; |
6106 | 1.07M | } |
6107 | 1.07M | } |
6108 | | |
6109 | | /** |
6110 | | * Sets the first elements of the yyloc structure with current |
6111 | | * information |
6112 | | */ |
6113 | | static void setfirstloc(void) |
6114 | 1.69M | { |
6115 | 1.69M | yylloc.first_line = ParseState.xxlineno; |
6116 | 1.69M | yylloc.first_column = ParseState.xxcolno; |
6117 | 1.69M | yylloc.first_byte = ParseState.xxbyteno; |
6118 | 1.69M | yylloc.first_parsed = ParseState.xxparseno; |
6119 | 1.69M | } |
6120 | | |
6121 | | static void setlastloc(void) |
6122 | 1.68M | { |
6123 | 1.68M | yylloc.last_line = ParseState.xxlineno; |
6124 | 1.68M | yylloc.last_column = ParseState.xxcolno; |
6125 | 1.68M | yylloc.last_byte = ParseState.xxbyteno; |
6126 | 1.68M | yylloc.last_parsed = ParseState.xxparseno; |
6127 | 1.68M | } |
6128 | | |
6129 | | /** |
6130 | | * Wrap around the token function. Returns the same result |
6131 | | * but increments the identifier, after a call to token_, |
6132 | | * the identifier variable contains the id of the token |
6133 | | * just returned |
6134 | | * |
6135 | | * @return the same as token |
6136 | | */ |
6137 | | |
6138 | 1.69M | static int token_(void){ |
6139 | | // capture the position before retrieving the token |
6140 | 1.69M | setfirstloc( ) ; |
6141 | | |
6142 | | // get the token |
6143 | 1.69M | int res = token( ) ; |
6144 | | |
6145 | | // capture the position after |
6146 | 1.69M | int _last_col = ParseState.xxcolno ; |
6147 | 1.69M | int _last_parsed = ParseState.xxparseno ; |
6148 | | |
6149 | 1.69M | _current_token = res ; |
6150 | 1.69M | incrementId( ) ; |
6151 | 1.69M | yylloc.id = identifier ; |
6152 | | |
6153 | | // record the position |
6154 | 1.69M | if( res != '\n' && res != END_OF_INPUT) |
6155 | 1.35M | record_( yylloc.first_parsed, yylloc.first_column, |
6156 | 1.35M | _last_parsed, _last_col, |
6157 | 1.35M | res, identifier, yytext ); |
6158 | | |
6159 | 1.69M | return res; |
6160 | 1.69M | } |
6161 | | |
6162 | | |
6163 | | static int yylex(void) |
6164 | 1.68M | { |
6165 | 1.68M | int tok; |
6166 | | |
6167 | 1.69M | again: |
6168 | | |
6169 | 1.69M | tok = token_(); |
6170 | | |
6171 | | /* Newlines must be handled in a context */ |
6172 | | /* sensitive way. The following block of */ |
6173 | | /* deals directly with newlines in the */ |
6174 | | /* body of "if" statements. */ |
6175 | | |
6176 | 1.69M | if (tok == '\n') { |
6177 | | |
6178 | 336k | if (EatLines || *contextp == '[' || *contextp == '(') |
6179 | 9.19k | goto again; |
6180 | | |
6181 | | /* The essence of this is that in the body of */ |
6182 | | /* an "if", any newline must be checked to */ |
6183 | | /* see if it is followed by an "else". */ |
6184 | | /* such newlines are discarded. */ |
6185 | | |
6186 | 327k | if (*contextp == 'i') { |
6187 | | |
6188 | | /* Find the next non-newline token */ |
6189 | | |
6190 | 2.94k | while(tok == '\n') |
6191 | 1.70k | tok = token_(); |
6192 | | |
6193 | | /* If we encounter "}", ")" or "]" then */ |
6194 | | /* we know that all immediately preceding */ |
6195 | | /* "if" bodies have been terminated. */ |
6196 | | /* The corresponding "i" values are */ |
6197 | | /* popped off the context stack. */ |
6198 | | |
6199 | 1.24k | if (tok == RBRACE || tok == ')' || tok == ']' ) { |
6200 | 572 | while (*contextp == 'i') |
6201 | 342 | ifpop(); |
6202 | 230 | *contextp-- = 0; |
6203 | 230 | setlastloc(); |
6204 | 230 | return tok; |
6205 | 230 | } |
6206 | | |
6207 | | /* When a "," is encountered, it terminates */ |
6208 | | /* just the immediately preceding "if" body */ |
6209 | | /* so we pop just a single "i" of the */ |
6210 | | /* context stack. */ |
6211 | | |
6212 | 1.01k | if (tok == ',') { |
6213 | 68 | ifpop(); |
6214 | 68 | setlastloc(); |
6215 | 68 | return tok; |
6216 | 68 | } |
6217 | | |
6218 | | /* Tricky! If we find an "else" we must */ |
6219 | | /* ignore the preceding newline. Any other */ |
6220 | | /* token means that we must return the newline */ |
6221 | | /* to terminate the "if" and "push back" that */ |
6222 | | /* token so that we will obtain it on the next */ |
6223 | | /* call to token. In either case sensitivity */ |
6224 | | /* is lost, so we pop the "i" from the context */ |
6225 | | /* stack. */ |
6226 | | |
6227 | 948 | if(tok == ELSE) { |
6228 | 587 | EatLines = 1; |
6229 | 587 | ifpop(); |
6230 | 587 | setlastloc(); |
6231 | 587 | return ELSE; |
6232 | 587 | } |
6233 | 361 | else { |
6234 | 361 | ifpop(); |
6235 | 361 | SavedToken = tok; |
6236 | 361 | xxlinesave = yylloc.first_line; |
6237 | 361 | xxcolsave = yylloc.first_column; |
6238 | 361 | xxbytesave = yylloc.first_byte; |
6239 | 361 | xxparsesave = yylloc.first_parsed; |
6240 | 361 | SavedLval = yylval; |
6241 | 361 | setlastloc(); |
6242 | 361 | if (ParseState.keepSrcRefs && ParseState.keepParseData && |
6243 | 35 | yytext[0]) |
6244 | | |
6245 | | /* unrecord the pushed back token if not null */ |
6246 | 35 | ParseState.data_count--; |
6247 | 361 | return '\n'; |
6248 | 361 | } |
6249 | 948 | } |
6250 | 326k | else { |
6251 | 326k | setlastloc(); |
6252 | 326k | return '\n'; |
6253 | 326k | } |
6254 | 327k | } |
6255 | | |
6256 | | /* Additional context sensitivities */ |
6257 | | |
6258 | 1.35M | switch(tok) { |
6259 | | |
6260 | | /* Any newlines immediately following the */ |
6261 | | /* the following tokens are discarded. The */ |
6262 | | /* expressions are clearly incomplete. */ |
6263 | | |
6264 | 10.3k | case '+': |
6265 | 22.5k | case '-': |
6266 | 24.9k | case '*': |
6267 | 26.4k | case '/': |
6268 | 37.4k | case '^': |
6269 | 38.2k | case LT: |
6270 | 38.3k | case LE: |
6271 | 38.5k | case GE: |
6272 | 39.7k | case GT: |
6273 | 40.8k | case EQ: |
6274 | 41.1k | case NE: |
6275 | 42.3k | case OR: |
6276 | 43.0k | case AND: |
6277 | 43.1k | case OR2: |
6278 | 43.8k | case AND2: |
6279 | 45.1k | case PIPE: |
6280 | 45.8k | case PIPEBIND: |
6281 | 47.0k | case SPECIAL: |
6282 | 49.0k | case FUNCTION: |
6283 | 49.6k | case WHILE: |
6284 | 50.0k | case REPEAT: |
6285 | 50.4k | case FOR: |
6286 | 50.7k | case IN: |
6287 | 358k | case '?': |
6288 | 359k | case '!': |
6289 | 359k | case '=': |
6290 | 377k | case ':': |
6291 | 427k | case '~': |
6292 | 430k | case '$': |
6293 | 431k | case '@': |
6294 | 436k | case LEFT_ASSIGN: |
6295 | 437k | case RIGHT_ASSIGN: |
6296 | 591k | case EQ_ASSIGN: |
6297 | 591k | EatLines = 1; |
6298 | 591k | break; |
6299 | | |
6300 | | /* Push any "if" statements found and */ |
6301 | | /* discard any immediately following newlines. */ |
6302 | | |
6303 | 3.64k | case IF: |
6304 | 3.64k | IfPush(); |
6305 | 3.64k | EatLines = 1; |
6306 | 3.64k | break; |
6307 | | |
6308 | | /* Terminate any immediately preceding "if" */ |
6309 | | /* statements and discard any immediately */ |
6310 | | /* following newlines. */ |
6311 | | |
6312 | 845 | case ELSE: |
6313 | 845 | ifpop(); |
6314 | 845 | EatLines = 1; |
6315 | 845 | break; |
6316 | | |
6317 | | /* These tokens terminate any immediately */ |
6318 | | /* preceding "if" statements. */ |
6319 | | |
6320 | 3.48k | case ';': |
6321 | 16.0k | case ',': |
6322 | 16.0k | ifpop(); |
6323 | 16.0k | break; |
6324 | | |
6325 | | /* Any newlines following these tokens can */ |
6326 | | /* indicate the end of an expression. */ |
6327 | | |
6328 | 385k | case SYMBOL: |
6329 | 408k | case PLACEHOLDER: |
6330 | 421k | case STR_CONST: |
6331 | 607k | case NUM_CONST: |
6332 | 607k | case NULL_CONST: |
6333 | 609k | case NEXT: |
6334 | 609k | case BREAK: |
6335 | 609k | EatLines = 0; |
6336 | 609k | break; |
6337 | | |
6338 | | /* Handle brackets, braces and parentheses */ |
6339 | | |
6340 | 351 | case LBB: |
6341 | 351 | if(contextp - contextstack >= CONTEXTSTACK_SIZE - 2) |
6342 | 0 | raiseLexError("contextstackOverflow", NO_VALUE, NULL, |
6343 | 0 | _("contextstack overflow (%s:%d:%d)")); |
6344 | 351 | *++contextp = '['; |
6345 | 351 | *++contextp = '['; |
6346 | 351 | break; |
6347 | | |
6348 | 3.74k | case '[': |
6349 | 3.74k | if(contextp - contextstack >= CONTEXTSTACK_SIZE - 1) |
6350 | 1 | raiseLexError("contextstackOverflow", NO_VALUE, NULL, |
6351 | 1 | _("contextstack overflow (%s:%d:%d)")); |
6352 | 3.74k | *++contextp = (char) tok; |
6353 | 3.74k | break; |
6354 | | |
6355 | 2.32k | case LBRACE: |
6356 | 2.32k | if(contextp - contextstack >= CONTEXTSTACK_SIZE - 1) |
6357 | 3 | raiseLexError("contextstackOverflow", NO_VALUE, NULL, |
6358 | 3 | _("contextstack overflow (%s:%d:%d)")); |
6359 | 2.32k | *++contextp = (char) tok; |
6360 | 2.32k | EatLines = 1; |
6361 | 2.32k | break; |
6362 | | |
6363 | 60.2k | case '(': |
6364 | 60.2k | if(contextp - contextstack >= CONTEXTSTACK_SIZE - 1) |
6365 | 23 | raiseLexError("contextstackOverflow", NO_VALUE, NULL, |
6366 | 23 | _("contextstack overflow (%s:%d:%d)")); |
6367 | 60.2k | *++contextp = (char) tok; |
6368 | 60.2k | break; |
6369 | | |
6370 | 4.07k | case ']': |
6371 | 4.15k | while (*contextp == 'i') |
6372 | 82 | ifpop(); |
6373 | 4.07k | *contextp-- = 0; |
6374 | 4.07k | EatLines = 0; |
6375 | 4.07k | break; |
6376 | | |
6377 | 1.43k | case RBRACE: |
6378 | 1.54k | while (*contextp == 'i') |
6379 | 103 | ifpop(); |
6380 | 1.43k | *contextp-- = 0; |
6381 | 1.43k | break; |
6382 | | |
6383 | 55.4k | case ')': |
6384 | 55.6k | while (*contextp == 'i') |
6385 | 179 | ifpop(); |
6386 | 55.4k | *contextp-- = 0; |
6387 | 55.4k | EatLines = 0; |
6388 | 55.4k | break; |
6389 | | |
6390 | 1.35M | } |
6391 | 1.35M | setlastloc(); |
6392 | 1.35M | return tok; |
6393 | 1.35M | } |
6394 | | /** |
6395 | | * Records location information about a symbol. The information is |
6396 | | * used to fill the data |
6397 | | * |
6398 | | */ |
6399 | | static void record_( int first_parsed, int first_column, int last_parsed, int last_column, |
6400 | 2.83M | int token, int id, char* text_in ){ |
6401 | | |
6402 | 2.83M | if (!ParseState.keepSrcRefs || !ParseState.keepParseData |
6403 | 1.76M | || id == NA_INTEGER) return; |
6404 | | |
6405 | | // don't care about zero sized things |
6406 | 1.07M | if( !yytext[0] ) return ; |
6407 | | |
6408 | 1.07M | if (ParseState.data_count == DATA_COUNT) |
6409 | 3 | growData(); |
6410 | | |
6411 | 1.07M | _FIRST_COLUMN( ParseState.data_count ) = first_column; |
6412 | 1.07M | _FIRST_PARSED( ParseState.data_count ) = first_parsed; |
6413 | 1.07M | _LAST_COLUMN( ParseState.data_count ) = last_column; |
6414 | 1.07M | _LAST_PARSED( ParseState.data_count ) = last_parsed; |
6415 | 1.07M | _TOKEN( ParseState.data_count ) = token; |
6416 | 1.07M | _ID( ParseState.data_count ) = id ; |
6417 | 1.07M | _PARENT(ParseState.data_count) = 0 ; |
6418 | 1.07M | if ( text_in ) |
6419 | 660k | SET_STRING_ELT(PS_TEXT, ParseState.data_count, mkChar2(text_in)); |
6420 | 411k | else |
6421 | 411k | SET_STRING_ELT(PS_TEXT, ParseState.data_count, mkChar("")); |
6422 | | |
6423 | 1.07M | if( id > ID_COUNT ) |
6424 | 2 | growID(id) ; |
6425 | | |
6426 | 1.07M | ID_ID( id ) = ParseState.data_count ; |
6427 | | |
6428 | 1.07M | ParseState.data_count++ ; |
6429 | 1.07M | } |
6430 | | |
6431 | | /** |
6432 | | * records parent as the parent of all its childs. This grows the |
6433 | | * parents list with a new vector. The first element of the new |
6434 | | * vector is the parent id, and other elements are childs id |
6435 | | * |
6436 | | * @param parent id of the parent expression |
6437 | | * @param childs array of location information for all child symbols |
6438 | | * @param nchilds number of childs |
6439 | | */ |
6440 | 954k | static void recordParents( int parent, yyltype * childs, int nchilds){ |
6441 | | |
6442 | 954k | if( parent > ID_COUNT ){ |
6443 | 2 | growID(parent) ; |
6444 | 2 | } |
6445 | | |
6446 | | /* some of the childs might be an empty token (like cr) |
6447 | | which we do not want to track */ |
6448 | 954k | int ii; /* loop index */ |
6449 | 954k | yyltype loc ; |
6450 | 2.32M | for( ii=0; ii<nchilds; ii++){ |
6451 | 1.37M | loc = childs[ii] ; |
6452 | 1.37M | if( loc.id == NA_INTEGER || (loc.first_line == loc.last_line && loc.first_byte > loc.last_byte) ) |
6453 | 2.40k | continue ; |
6454 | | /* This shouldn't happen... */ |
6455 | 1.37M | if (loc.id < 0 || loc.id > identifier) { |
6456 | 0 | raiseLexError("internalError", NO_VALUE, NULL, |
6457 | 0 | _("internal parser error (%s:%d:%d)")); |
6458 | 0 | } |
6459 | 1.37M | ID_PARENT( loc.id ) = parent; |
6460 | 1.37M | } |
6461 | | |
6462 | 954k | } |
6463 | | |
6464 | | /** |
6465 | | * The token pointed by the location has the wrong token type, |
6466 | | * This updates the type |
6467 | | * |
6468 | | * @param loc location information for the token to track |
6469 | | */ |
6470 | 63.1k | static void modif_token( yyltype* loc, int tok ){ |
6471 | | |
6472 | 63.1k | int id = loc->id ; |
6473 | | |
6474 | 63.1k | if (!ParseState.keepSrcRefs || !ParseState.keepParseData |
6475 | 59.9k | || id < 0 || id > ID_COUNT) return; |
6476 | | |
6477 | 3.20k | if( tok == SYMBOL_FUNCTION_CALL ){ |
6478 | | // looking for first child of id |
6479 | 1.62k | int j = ID_ID( id ) ; |
6480 | 1.62k | int parent = id ; |
6481 | | |
6482 | 1.62k | if (j < 0 || j > ID_COUNT) |
6483 | 0 | return; |
6484 | | |
6485 | 4.50k | while( ID_PARENT( _ID(j) ) != parent ){ |
6486 | 2.88k | j-- ; |
6487 | 2.88k | if (j < 0) |
6488 | 0 | return; |
6489 | 2.88k | } |
6490 | | |
6491 | 1.62k | if( _TOKEN(j) == SYMBOL ){ |
6492 | 695 | _TOKEN(j) = SYMBOL_FUNCTION_CALL ; |
6493 | 695 | } |
6494 | | |
6495 | 1.62k | } else{ |
6496 | 1.57k | _TOKEN( ID_ID(id) ) = tok ; |
6497 | 1.57k | } |
6498 | | |
6499 | 3.20k | } |
6500 | | |
6501 | | /* this local version of lengthgets() always copies and doesn't fill with NA */ |
6502 | 2.53k | static SEXP lengthgets2(SEXP x, int len) { |
6503 | 2.53k | SEXP result; |
6504 | 2.53k | PROTECT(result = allocVector( TYPEOF(x), len )); |
6505 | | |
6506 | 2.53k | len = (len < length(x)) ? len : length(x); |
6507 | 2.53k | switch(TYPEOF(x)) { |
6508 | 1.26k | case INTSXP: |
6509 | 7.71M | for (int i = 0; i < len; i++) |
6510 | 7.71M | INTEGER(result)[i] = INTEGER(x)[i]; |
6511 | 476k | for (int i = len; i < length(result); i++) |
6512 | 475k | INTEGER(result)[i] = 0; |
6513 | 1.26k | break; |
6514 | 1.26k | case STRSXP: |
6515 | 959k | for (int i = 0; i < len; i++) |
6516 | 957k | SET_STRING_ELT(result, i, STRING_ELT(x, i)); |
6517 | 1.26k | break; |
6518 | 0 | default: |
6519 | 0 | UNIMPLEMENTED_TYPE("lengthgets2", x); |
6520 | 2.53k | } |
6521 | 2.53k | UNPROTECT(1); /* result */ |
6522 | 2.53k | return result; |
6523 | 2.53k | } |
6524 | | |
6525 | 1.29k | static void finalizeData(void){ |
6526 | | |
6527 | 1.29k | int nloc = ParseState.data_count ; |
6528 | | |
6529 | 1.29k | int i, j, id ; |
6530 | 1.29k | int parent ; |
6531 | | |
6532 | | /* store parents in the data */ |
6533 | 942k | for( i=0; i<nloc; i++){ |
6534 | 941k | id = _ID(i); |
6535 | 941k | parent = ID_PARENT( id ) ; |
6536 | 1.43M | while( parent != 0 && ID_ID(parent) == 0 ) |
6537 | 497k | parent = ID_PARENT( parent ) ; |
6538 | 941k | _PARENT(i) = parent ; |
6539 | | |
6540 | 941k | #define FD_FAST_UPDATE_PARENTS |
6541 | 941k | #ifdef FD_FAST_UPDATE_PARENTS |
6542 | | /* |
6543 | | With long generated expressions, updating the parents can take |
6544 | | a lot of time due to long chains of nodes not represented in the |
6545 | | parse data. To reduce the overhead somewhat, we create shortcuts |
6546 | | in the IDS array to point directly to the parent that is in the |
6547 | | parse data. |
6548 | | */ |
6549 | 941k | int data_parent = parent; |
6550 | 941k | parent = ID_PARENT( id ) ; |
6551 | 1.43M | while( parent != data_parent ){ |
6552 | 497k | ID_PARENT( id ) = data_parent; /* set shortcut */ |
6553 | 497k | id = parent; |
6554 | 497k | parent = ID_PARENT( parent ); |
6555 | 497k | } |
6556 | 941k | #endif |
6557 | 941k | } |
6558 | | |
6559 | | /* attach comments to closest enclosing symbol */ |
6560 | | /* not updating ID_PARENT anymore */ |
6561 | | |
6562 | 1.29k | #define FD_FAST_ASSIGN_COMMENTS |
6563 | 1.29k | #ifdef FD_FAST_ASSIGN_COMMENTS |
6564 | | /* |
6565 | | All terminals (tokens) are ordered by start and end location, including |
6566 | | the comments, in the data. |
6567 | | |
6568 | | All non-terminals, including to be found parents of the comments, are |
6569 | | ordered by their end location. When they have the same end location |
6570 | | in the code, they are ordered by their decreasing start location |
6571 | | (children before parents). |
6572 | | |
6573 | | All terminals and non-terminals are also before their parents (if any), |
6574 | | so a comment is also befor its parent in the data. |
6575 | | |
6576 | | Consequently: the first non-terminal after a comment that encloses the |
6577 | | comment is its (immediate) parent. The original algorithm for every |
6578 | | comment linearly searches for the first enclosing non-terminal and |
6579 | | returns it, but it has quadratic complexity and dominates the whole |
6580 | | parsing for long inputs (used when FD_FAST_ASSIGN_COMMENTS is not |
6581 | | defined). |
6582 | | |
6583 | | This algorithm uses the parental information available on nodes that |
6584 | | follow the comments. That information has been filled by the parser |
6585 | | during reductions (but not for comments, because those are not in the |
6586 | | grammar). A node following a comment is either the parent of the |
6587 | | comment, or some of its parents are, or is an orphan. |
6588 | | |
6589 | | Note that a non-terminal may end before a terminal (e.g. comment) in the |
6590 | | code but be after the terminal in the data (due to look-ahead). It seems |
6591 | | that the parent of the comment has to be within parents of the |
6592 | | non-terminal as well, but I am not sure how to prove it, so the algorithm |
6593 | | just skips non-terminals preceding the comment in the code (so is not |
6594 | | strictly linear). |
6595 | | */ |
6596 | | |
6597 | 942k | for(i = nloc-1; i >= 0; i--) { |
6598 | 941k | if (isCommentLike(_TOKEN(i))) { |
6599 | 233k | int orphan = 1; |
6600 | 233k | int istartl = _FIRST_PARSED(i); |
6601 | 233k | int istartc = _FIRST_COLUMN(i); |
6602 | | |
6603 | | /* look for first node j that does not end before the comment i */ |
6604 | 441k | for(j = i + 1; j < nloc && _LAST_PARSED(j) <= istartl; j++); |
6605 | | |
6606 | 233k | if (j < nloc) { |
6607 | 436k | for(;;) { |
6608 | 436k | int jstartl = _FIRST_PARSED(j); |
6609 | 436k | int jstartc = _FIRST_COLUMN(j); |
6610 | | |
6611 | 436k | if (jstartl < istartl || (jstartl == istartl |
6612 | 1.77k | && jstartc <= istartc)) { |
6613 | | /* j starts before or at the comment */ |
6614 | 1.77k | _PARENT(i) = _ID(j); |
6615 | 1.77k | orphan = 0; |
6616 | 1.77k | break; |
6617 | 1.77k | } |
6618 | | /* find parent of j */ |
6619 | 434k | int jparent = _PARENT(j); |
6620 | 434k | if (jparent == 0) |
6621 | 230k | break; /* orphan */ |
6622 | 203k | j = ID_ID(jparent); |
6623 | 203k | } |
6624 | 232k | } |
6625 | 233k | if (orphan) |
6626 | 231k | _PARENT(i) = 0; |
6627 | 233k | } |
6628 | 941k | } |
6629 | | #else |
6630 | | /* the original algorithm, which is slow for large inputs */ |
6631 | | |
6632 | | int comment_line, comment_first_col; |
6633 | | int this_first_parsed, this_last_parsed, this_first_col ; |
6634 | | int orphan ; |
6635 | | |
6636 | | for( i=0; i<nloc; i++){ |
6637 | | if( isCommentLike(_TOKEN(i)) ){ |
6638 | | comment_line = _FIRST_PARSED( i ) ; |
6639 | | comment_first_col = _FIRST_COLUMN( i ) ; |
6640 | | |
6641 | | orphan = 1 ; |
6642 | | for( j=i+1; j<nloc; j++){ |
6643 | | this_first_parsed = _FIRST_PARSED( j ) ; |
6644 | | this_first_col = _FIRST_COLUMN( j ) ; |
6645 | | this_last_parsed = _LAST_PARSED( j ) ; |
6646 | | |
6647 | | /* the comment needs to start after the current symbol */ |
6648 | | if( comment_line < this_first_parsed ) continue ; |
6649 | | if( (comment_line == this_first_parsed) & (comment_first_col < this_first_col) ) continue ; |
6650 | | |
6651 | | /* the current symbol must finish after the comment */ |
6652 | | if( this_last_parsed <= comment_line ) continue ; |
6653 | | |
6654 | | /* we have a match, record the parent and stop looking */ |
6655 | | _PARENT(i) = _ID(j); |
6656 | | orphan = 0; |
6657 | | break ; |
6658 | | } |
6659 | | if(orphan){ |
6660 | | _PARENT(i) = 0 ; |
6661 | | } |
6662 | | } |
6663 | | } |
6664 | | #endif |
6665 | | |
6666 | | |
6667 | | /* now rework the parents of comments, we try to attach |
6668 | | comments that are not already attached (parent=0) to the next |
6669 | | enclosing top-level expression */ |
6670 | | |
6671 | 942k | for( i=0; i<nloc; i++){ |
6672 | 941k | int token = _TOKEN(i); |
6673 | 941k | if( isCommentLike(token) && _PARENT(i) == 0 ){ |
6674 | 578k | for( j=i; j<nloc; j++){ |
6675 | 578k | if( isCommentLike(_TOKEN(j)) ) continue ; |
6676 | 275k | if( _PARENT(j) != 0 ) continue ; |
6677 | 230k | _PARENT(i) = - _ID(j) ; |
6678 | 230k | break ; |
6679 | 275k | } |
6680 | 231k | } |
6681 | 941k | } |
6682 | | |
6683 | | /* attach the token names as an attribute so we don't need to switch to a dataframe, and decide on terminals */ |
6684 | 1.29k | SEXP tokens; |
6685 | 1.29k | PROTECT(tokens = allocVector( STRSXP, nloc ) ); |
6686 | 942k | for (int i=0; i<nloc; i++) { |
6687 | 941k | int token = _TOKEN(i); |
6688 | 941k | int xlat = YYTRANSLATE(token); |
6689 | 941k | if (xlat == 2) /* "unknown" */ |
6690 | 347k | xlat = token; |
6691 | 941k | if (xlat >= 0 && xlat < YYNTOKENS + YYNNTS) |
6692 | 941k | SET_STRING_ELT(tokens, i, mkChar(yytname[xlat])); |
6693 | 44 | else { /* we have a token which doesn't have a name, e.g. an illegal character as in PR#15518 */ |
6694 | 44 | char name[2]; |
6695 | 44 | name[0] = (char) xlat; |
6696 | 44 | name[1] = 0; |
6697 | 44 | SET_STRING_ELT(tokens, i, mkChar(name)); |
6698 | 44 | } |
6699 | 941k | _TERMINAL(i) = xlat < YYNTOKENS; |
6700 | 941k | } |
6701 | 1.29k | SEXP dims, newdata, newtext; |
6702 | 1.29k | if (nloc) { |
6703 | 1.26k | PROTECT( newdata = lengthgets2(PS_DATA, nloc * DATA_ROWS)); |
6704 | 1.26k | PROTECT( newtext = lengthgets2(PS_TEXT, nloc)); |
6705 | 1.26k | } else { |
6706 | 38 | PROTECT( newdata = allocVector( INTSXP, 0)); |
6707 | 38 | PROTECT( newtext = allocVector( STRSXP, 0)); |
6708 | 38 | } |
6709 | 1.29k | PROTECT( dims = allocVector( INTSXP, 2 ) ) ; |
6710 | 1.29k | INTEGER(dims)[0] = DATA_ROWS ; |
6711 | 1.29k | INTEGER(dims)[1] = nloc ; |
6712 | 1.29k | setAttrib( newdata, install( "dim" ), dims ) ; |
6713 | 1.29k | setAttrib( newdata, install("tokens"), tokens ); |
6714 | 1.29k | setAttrib( newdata, install("text"), newtext ); |
6715 | | |
6716 | 1.29k | setAttrib(newdata, R_ClassSymbol, mkString("parseData")); |
6717 | | |
6718 | | /* Put it into the original or srcfile environment */ |
6719 | 1.29k | if (isEnvironment(PS_ORIGINAL)) |
6720 | 1.29k | defineVar(install("parseData"), newdata, PS_ORIGINAL); |
6721 | 0 | else |
6722 | 0 | if (isEnvironment(PS_SRCFILE)) |
6723 | 0 | defineVar(install("parseData"), newdata, PS_SRCFILE); |
6724 | 1.29k | UNPROTECT(4); /* tokens, newdata, newtext, dims */ |
6725 | 1.29k | } |
6726 | | |
6727 | | /** |
6728 | | * Grows the data |
6729 | | */ |
6730 | 3 | static void growData(void){ |
6731 | | |
6732 | 3 | int new_data_count; |
6733 | 3 | if (PS_DATA == R_NilValue) { |
6734 | 2 | new_data_count = INIT_DATA_COUNT; |
6735 | 2 | PS_SET_DATA(allocVector(INTSXP, 0)); |
6736 | 2 | PS_SET_TEXT(allocVector(STRSXP, 0)); |
6737 | 2 | } else |
6738 | 1 | new_data_count = 2*DATA_COUNT; |
6739 | | |
6740 | 3 | PS_SET_DATA(lengthgets2(PS_DATA, new_data_count * DATA_ROWS)); |
6741 | 3 | PS_SET_TEXT(lengthgets2(PS_TEXT, new_data_count)); |
6742 | 3 | } |
6743 | | |
6744 | | /** |
6745 | | * Grows the ids vector so that ID_ID(target) can be called |
6746 | | */ |
6747 | 4 | static void growID( int target ){ |
6748 | | |
6749 | 4 | int new_count; |
6750 | 4 | if (PS_IDS == R_NilValue) { |
6751 | 2 | new_count = INIT_DATA_COUNT/2 - 1; |
6752 | 2 | PS_SET_IDS(allocVector(INTSXP, 0)); |
6753 | 2 | } else |
6754 | 2 | new_count = ID_COUNT; |
6755 | | |
6756 | 6 | while (target > new_count) |
6757 | 2 | new_count = 2*new_count + 1; |
6758 | | |
6759 | 4 | if (new_count <= ID_COUNT) |
6760 | 0 | return; |
6761 | | |
6762 | 4 | int new_size = (1 + new_count)*2; |
6763 | 4 | PS_SET_IDS(lengthgets2(PS_IDS, new_size)); |
6764 | 4 | } |
6765 | | |
6766 | | static bool checkForPlaceholder(SEXP placeholder, SEXP arg) |
6767 | 1.25M | { |
6768 | 1.25M | if (! HavePlaceholder) |
6769 | 2.19k | return false; |
6770 | 1.25M | else if (arg == placeholder) |
6771 | 755 | return true; |
6772 | 1.25M | else if (TYPEOF(arg) == LANGSXP) |
6773 | 1.22M | for (SEXP cur = arg; cur != R_NilValue; cur = CDR(cur)) |
6774 | 982k | if (checkForPlaceholder(placeholder, CAR(cur))) |
6775 | 191k | return true; |
6776 | 1.06M | return false; |
6777 | 1.25M | } |
6778 | | |
6779 | 3.93k | static const char* getFilename(void) { |
6780 | 3.93k | SEXP srcfile = PS_SRCFILE; |
6781 | 3.93k | if (!srcfile || TYPEOF(srcfile) != ENVSXP) |
6782 | 2.81k | return "<input>"; |
6783 | 1.12k | srcfile = R_findVar(install("filename"), srcfile); |
6784 | 1.12k | if (TYPEOF(srcfile) != STRSXP || !strlen(CHAR(STRING_ELT(srcfile, 0)))) |
6785 | 0 | return "<input>"; |
6786 | 1.12k | else |
6787 | 1.12k | return CHAR(STRING_ELT(srcfile, 0)); |
6788 | 1.12k | } |
6789 | | |
6790 | | /* raiseParseError creates a "parseError: condition object and |
6791 | | signals an error. |
6792 | | "value" is optional; use valuetype = NO_VALUE to skip |
6793 | | other args will always be passed. |
6794 | | Args appear in the order |
6795 | | [value], filename, lineno, colno |
6796 | | in the sprintf call for the format. |
6797 | | */ |
6798 | | NORET static void raiseParseError(const char *subclassname, |
6799 | | SEXP call, |
6800 | | int valuetype, |
6801 | | const void *value, |
6802 | | YYLTYPE *lloc, |
6803 | | const char *format) |
6804 | 1.96k | { |
6805 | 1.96k | int nextra = 4, |
6806 | 1.96k | lineno = lloc->first_line, |
6807 | 1.96k | colno = lloc->first_column; |
6808 | 1.96k | const char *filename = getFilename(); |
6809 | | |
6810 | 1.96k | SEXP cond; |
6811 | 1.96k | switch(valuetype) { |
6812 | 1.63k | case NO_VALUE: |
6813 | 1.63k | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6814 | 1.63k | nextra, format, |
6815 | 1.63k | filename, lineno, colno); |
6816 | 1.63k | break; |
6817 | 0 | case CHAR_VALUE: |
6818 | 0 | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6819 | 0 | nextra, format, |
6820 | 0 | *(const char *)value, |
6821 | 0 | filename, lineno, colno); |
6822 | 0 | break; |
6823 | 297 | case STRING_VALUE: |
6824 | 297 | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6825 | 297 | nextra, format, |
6826 | 297 | (const char *)value, |
6827 | 297 | filename, lineno, colno); |
6828 | 297 | break; |
6829 | 34 | case INT_VALUE: |
6830 | 34 | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6831 | 34 | nextra, format, |
6832 | 34 | *(const int *)value, |
6833 | 34 | filename, lineno, colno); |
6834 | 34 | break; |
6835 | 0 | case UINT_VALUE: |
6836 | 0 | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6837 | 0 | nextra, format, |
6838 | 0 | *(const unsigned int *)value, |
6839 | 0 | filename, lineno, colno); |
6840 | 0 | break; |
6841 | 0 | case UCS_VALUE: |
6842 | 0 | cond = R_makeErrorCondition(call, "parseError", subclassname, |
6843 | 0 | nextra, format, |
6844 | 0 | *(const ucs_t *)value, |
6845 | 0 | filename, lineno, colno); |
6846 | 0 | break; |
6847 | 1.96k | } |
6848 | | |
6849 | 1.96k | PROTECT(cond); |
6850 | 1.96k | switch(valuetype) { |
6851 | 1.63k | case NO_VALUE: |
6852 | 1.63k | R_setConditionField(cond, 2, "value", R_NilValue); |
6853 | 1.63k | break; |
6854 | 297 | case STRING_VALUE: |
6855 | 297 | R_setConditionField(cond, 2, "value", mkString((const char *)value)); |
6856 | 297 | break; |
6857 | 34 | case INT_VALUE: |
6858 | 34 | R_setConditionField(cond, 2, "value", ScalarInteger(*(int*)value)); |
6859 | 34 | break; |
6860 | 0 | case UINT_VALUE: |
6861 | 0 | R_setConditionField(cond, 2, "value", ScalarInteger(*(unsigned int*)value)); |
6862 | 0 | break; |
6863 | 0 | case CHAR_VALUE: { |
6864 | 0 | char c[2]; |
6865 | 0 | c[0] = *(char *)value; |
6866 | 0 | c[1] = '\0'; |
6867 | 0 | R_setConditionField(cond, 2, "value", mkString(c)); |
6868 | 0 | break; |
6869 | 0 | } |
6870 | 0 | case UCS_VALUE: { |
6871 | 0 | ucs_t wc[2]; |
6872 | 0 | wc[0] = *(ucs_t *)value; |
6873 | 0 | wc[1] = '\0'; |
6874 | 0 | R_setConditionField(cond, 2, "value", mkStringUTF8(wc, 1)); |
6875 | 0 | break; |
6876 | 0 | } |
6877 | 1.96k | } |
6878 | | |
6879 | 1.96k | R_setConditionField(cond, 3, "filename", mkString(getFilename())); |
6880 | 1.96k | R_setConditionField(cond, 4, "lineno", ScalarInteger(lineno)); |
6881 | 1.96k | R_setConditionField(cond, 5, "colno", ScalarInteger(colno)); |
6882 | | |
6883 | 1.96k | R_signalErrorCondition(cond, call); |
6884 | 1.96k | UNPROTECT(1); /* cond; not reached */ |
6885 | 1.96k | } |
6886 | | |
6887 | | /* This function is for lexer errors; it gets the location |
6888 | | from the ParseState, but is otherwise the same as |
6889 | | raiseParseError. |
6890 | | */ |
6891 | | NORET static void raiseLexError(const char *subclassname, |
6892 | | int valuetype, |
6893 | | const void *value, |
6894 | | const char *format) |
6895 | 684 | { |
6896 | 684 | YYLTYPE lloc; |
6897 | 684 | lloc.first_line = ParseState.xxlineno; |
6898 | 684 | lloc.first_column = ParseState.xxcolno; |
6899 | 684 | raiseParseError(subclassname, R_NilValue, |
6900 | 684 | valuetype, value, |
6901 | 684 | &lloc, format); |
6902 | 684 | } |