1 /* A Bison parser, made by GNU Bison 3.0.4. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43 /* Identify Bison output. */
44 #define YYBISON 1
45
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.4"
48
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers. */
53 #define YYPURE 1
54
55 /* Push parsers. */
56 #define YYPUSH 0
57
58 /* Pull parsers. */
59 #define YYPULL 1
60
61 /* "%code top" blocks. */
62
63
64 /*
65 +----------------------------------------------------------------------+
66 | PHP Version 7 |
67 +----------------------------------------------------------------------+
68 | Copyright (c) 1997-2017 The PHP Group |
69 +----------------------------------------------------------------------+
70 | This source file is subject to version 3.01 of the PHP license, |
71 | that is bundled with this package in the file LICENSE, and is |
72 | available through the world-wide-web at the following url: |
73 | http://www.php.net/license/3_01.txt |
74 | If you did not receive a copy of the PHP license and are unable to |
75 | obtain it through the world-wide-web, please send a note to |
76 | license@php.net so we can mail you a copy immediately. |
77 +----------------------------------------------------------------------+
78 | Author: Jakub Zelenka <bukka@php.net> |
79 +----------------------------------------------------------------------+
80 */
81
82 #include "php.h"
83 #include "php_json.h"
84 #include "php_json_parser.h"
85
86 #define YYDEBUG 0
87
88 #if YYDEBUG
89 int json_yydebug = 1;
90 #endif
91
92 #ifdef _MSC_VER
93 #define YYMALLOC malloc
94 #define YYFREE free
95 #endif
96
97 #define PHP_JSON_USE(uv) ((void) (uv))
98 #define PHP_JSON_USE_1(uvr, uv1) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1)
99 #define PHP_JSON_USE_2(uvr, uv1, uv2) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1); PHP_JSON_USE(uv2)
100
101
102
103
104 /* Substitute the variable and function names. */
105 #define yyparse php_json_yyparse
106 #define yylex php_json_yylex
107 #define yyerror php_json_yyerror
108 #define yydebug php_json_yydebug
109 #define yynerrs php_json_yynerrs
110
111
112 /* Copy the first part of user declarations. */
113
114
115
116 # ifndef YY_NULLPTR
117 # if defined __cplusplus && 201103L <= __cplusplus
118 # define YY_NULLPTR nullptr
119 # else
120 # define YY_NULLPTR 0
121 # endif
122 # endif
123
124 /* Enabling verbose error messages. */
125 #ifdef YYERROR_VERBOSE
126 # undef YYERROR_VERBOSE
127 # define YYERROR_VERBOSE 1
128 #else
129 # define YYERROR_VERBOSE 0
130 #endif
131
132 /* In a future release of Bison, this section will be replaced
133 by #include "json_parser.tab.h". */
134 #ifndef YY_PHP_JSON_YY_HOME_JAKUB_PROG_PHP_MASTER_EXT_JSON_JSON_PARSER_TAB_H_INCLUDED
135 # define YY_PHP_JSON_YY_HOME_JAKUB_PROG_PHP_MASTER_EXT_JSON_JSON_PARSER_TAB_H_INCLUDED
136 /* Debug traces. */
137 #ifndef YYDEBUG
138 # define YYDEBUG 0
139 #endif
140 #if YYDEBUG
141 extern int php_json_yydebug;
142 #endif
143
144 /* Token type. */
145 #ifndef YYTOKENTYPE
146 # define YYTOKENTYPE
147 enum yytokentype
148 {
149 PHP_JSON_T_NUL = 258,
150 PHP_JSON_T_TRUE = 259,
151 PHP_JSON_T_FALSE = 260,
152 PHP_JSON_T_INT = 261,
153 PHP_JSON_T_DOUBLE = 262,
154 PHP_JSON_T_STRING = 263,
155 PHP_JSON_T_ESTRING = 264,
156 PHP_JSON_T_EOI = 265,
157 PHP_JSON_T_ERROR = 266
158 };
159 #endif
160 /* Tokens. */
161 #define PHP_JSON_T_NUL 258
162 #define PHP_JSON_T_TRUE 259
163 #define PHP_JSON_T_FALSE 260
164 #define PHP_JSON_T_INT 261
165 #define PHP_JSON_T_DOUBLE 262
166 #define PHP_JSON_T_STRING 263
167 #define PHP_JSON_T_ESTRING 264
168 #define PHP_JSON_T_EOI 265
169 #define PHP_JSON_T_ERROR 266
170
171 /* Value type. */
172 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
173
174 union YYSTYPE
175 {
176
177
178 zval value;
179 struct {
180 zend_string *key;
181 zval val;
182 } pair;
183
184
185 };
186
187 typedef union YYSTYPE YYSTYPE;
188 # define YYSTYPE_IS_TRIVIAL 1
189 # define YYSTYPE_IS_DECLARED 1
190 #endif
191
192
193
194 int php_json_yyparse (php_json_parser *parser);
195
196 #endif /* !YY_PHP_JSON_YY_HOME_JAKUB_PROG_PHP_MASTER_EXT_JSON_JSON_PARSER_TAB_H_INCLUDED */
197
198 /* Copy the second part of user declarations. */
199
200
201 /* Unqualified %code blocks. */
202
203
204 int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
205 void php_json_yyerror(php_json_parser *parser, char const *msg);
206 void php_json_parser_object_init(php_json_parser *parser, zval *object);
207 int php_json_parser_object_update(php_json_parser *parser, zval *object, zend_string *key, zval *zvalue);
208 void php_json_parser_array_init(zval *object);
209 void php_json_parser_array_append(zval *array, zval *zvalue);
210
211 #define PHP_JSON_DEPTH_DEC --parser->depth
212 #define PHP_JSON_DEPTH_INC \
213 if (parser->max_depth && parser->depth >= parser->max_depth) { \
214 parser->scanner.errcode = PHP_JSON_ERROR_DEPTH; \
215 YYERROR; \
216 } \
217 ++parser->depth
218
219
220
221 #ifdef short
222 # undef short
223 #endif
224
225 #ifdef YYTYPE_UINT8
226 typedef YYTYPE_UINT8 yytype_uint8;
227 #else
228 typedef unsigned char yytype_uint8;
229 #endif
230
231 #ifdef YYTYPE_INT8
232 typedef YYTYPE_INT8 yytype_int8;
233 #else
234 typedef signed char yytype_int8;
235 #endif
236
237 #ifdef YYTYPE_UINT16
238 typedef YYTYPE_UINT16 yytype_uint16;
239 #else
240 typedef unsigned short int yytype_uint16;
241 #endif
242
243 #ifdef YYTYPE_INT16
244 typedef YYTYPE_INT16 yytype_int16;
245 #else
246 typedef short int yytype_int16;
247 #endif
248
249 #ifndef YYSIZE_T
250 # ifdef __SIZE_TYPE__
251 # define YYSIZE_T __SIZE_TYPE__
252 # elif defined size_t
253 # define YYSIZE_T size_t
254 # elif ! defined YYSIZE_T
255 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
256 # define YYSIZE_T size_t
257 # else
258 # define YYSIZE_T unsigned int
259 # endif
260 #endif
261
262 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
263
264 #ifndef YY_
265 # if defined YYENABLE_NLS && YYENABLE_NLS
266 # if ENABLE_NLS
267 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
268 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
269 # endif
270 # endif
271 # ifndef YY_
272 # define YY_(Msgid) Msgid
273 # endif
274 #endif
275
276 #ifndef YY_ATTRIBUTE
277 # if (defined __GNUC__ \
278 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
279 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
280 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
281 # else
282 # define YY_ATTRIBUTE(Spec) /* empty */
283 # endif
284 #endif
285
286 #ifndef YY_ATTRIBUTE_PURE
287 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
288 #endif
289
290 #ifndef YY_ATTRIBUTE_UNUSED
291 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
292 #endif
293
294 #if !defined _Noreturn \
295 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
296 # if defined _MSC_VER && 1200 <= _MSC_VER
297 # define _Noreturn __declspec (noreturn)
298 # else
299 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
300 # endif
301 #endif
302
303 /* Suppress unused-variable warnings by "using" E. */
304 #if ! defined lint || defined __GNUC__
305 # define YYUSE(E) ((void) (E))
306 #else
307 # define YYUSE(E) /* empty */
308 #endif
309
310 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
311 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
312 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
313 _Pragma ("GCC diagnostic push") \
314 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
315 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
316 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
317 _Pragma ("GCC diagnostic pop")
318 #else
319 # define YY_INITIAL_VALUE(Value) Value
320 #endif
321 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
322 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
323 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
324 #endif
325 #ifndef YY_INITIAL_VALUE
326 # define YY_INITIAL_VALUE(Value) /* Nothing. */
327 #endif
328
329
330 #if ! defined yyoverflow || YYERROR_VERBOSE
331
332 /* The parser invokes alloca or malloc; define the necessary symbols. */
333
334 # ifdef YYSTACK_USE_ALLOCA
335 # if YYSTACK_USE_ALLOCA
336 # ifdef __GNUC__
337 # define YYSTACK_ALLOC __builtin_alloca
338 # elif defined __BUILTIN_VA_ARG_INCR
339 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
340 # elif defined _AIX
341 # define YYSTACK_ALLOC __alloca
342 # elif defined _MSC_VER
343 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
344 # define alloca _alloca
345 # else
346 # define YYSTACK_ALLOC alloca
347 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
348 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
349 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
350 # ifndef EXIT_SUCCESS
351 # define EXIT_SUCCESS 0
352 # endif
353 # endif
354 # endif
355 # endif
356 # endif
357
358 # ifdef YYSTACK_ALLOC
359 /* Pacify GCC's 'empty if-body' warning. */
360 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
361 # ifndef YYSTACK_ALLOC_MAXIMUM
362 /* The OS might guarantee only one guard page at the bottom of the stack,
363 and a page size can be as small as 4096 bytes. So we cannot safely
364 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
365 to allow for a few compiler-allocated temporary stack slots. */
366 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
367 # endif
368 # else
369 # define YYSTACK_ALLOC YYMALLOC
370 # define YYSTACK_FREE YYFREE
371 # ifndef YYSTACK_ALLOC_MAXIMUM
372 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
373 # endif
374 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
375 && ! ((defined YYMALLOC || defined malloc) \
376 && (defined YYFREE || defined free)))
377 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
378 # ifndef EXIT_SUCCESS
379 # define EXIT_SUCCESS 0
380 # endif
381 # endif
382 # ifndef YYMALLOC
383 # define YYMALLOC malloc
384 # if ! defined malloc && ! defined EXIT_SUCCESS
385 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
386 # endif
387 # endif
388 # ifndef YYFREE
389 # define YYFREE free
390 # if ! defined free && ! defined EXIT_SUCCESS
391 void free (void *); /* INFRINGES ON USER NAME SPACE */
392 # endif
393 # endif
394 # endif
395 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
396
397
398 #if (! defined yyoverflow \
399 && (! defined __cplusplus \
400 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
401
402 /* A type that is properly aligned for any stack member. */
403 union yyalloc
404 {
405 yytype_int16 yyss_alloc;
406 YYSTYPE yyvs_alloc;
407 };
408
409 /* The size of the maximum gap between one aligned stack and the next. */
410 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
411
412 /* The size of an array large to enough to hold all stacks, each with
413 N elements. */
414 # define YYSTACK_BYTES(N) \
415 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
416 + YYSTACK_GAP_MAXIMUM)
417
418 # define YYCOPY_NEEDED 1
419
420 /* Relocate STACK from its old location to the new one. The
421 local variables YYSIZE and YYSTACKSIZE give the old and new number of
422 elements in the stack, and YYPTR gives the new location of the
423 stack. Advance YYPTR to a properly aligned location for the next
424 stack. */
425 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
426 do \
427 { \
428 YYSIZE_T yynewbytes; \
429 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
430 Stack = &yyptr->Stack_alloc; \
431 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
432 yyptr += yynewbytes / sizeof (*yyptr); \
433 } \
434 while (0)
435
436 #endif
437
438 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
439 /* Copy COUNT objects from SRC to DST. The source and destination do
440 not overlap. */
441 # ifndef YYCOPY
442 # if defined __GNUC__ && 1 < __GNUC__
443 # define YYCOPY(Dst, Src, Count) \
444 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
445 # else
446 # define YYCOPY(Dst, Src, Count) \
447 do \
448 { \
449 YYSIZE_T yyi; \
450 for (yyi = 0; yyi < (Count); yyi++) \
451 (Dst)[yyi] = (Src)[yyi]; \
452 } \
453 while (0)
454 # endif
455 # endif
456 #endif /* !YYCOPY_NEEDED */
457
458 /* YYFINAL -- State number of the termination state. */
459 #define YYFINAL 18
460 /* YYLAST -- Last index in YYTABLE. */
461 #define YYLAST 34
462
463 /* YYNTOKENS -- Number of terminals. */
464 #define YYNTOKENS 18
465 /* YYNNTS -- Number of nonterminals. */
466 #define YYNNTS 16
467 /* YYNRULES -- Number of rules. */
468 #define YYNRULES 36
469 /* YYNSTATES -- Number of states. */
470 #define YYNSTATES 45
471
472 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
473 by yylex, with out-of-bounds checking. */
474 #define YYUNDEFTOK 2
475 #define YYMAXUTOK 266
476
477 #define YYTRANSLATE(YYX) \
478 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
479
480 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
481 as returned by yylex, without out-of-bounds checking. */
482 static const yytype_uint8 yytranslate[] =
483 {
484 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
488 2, 2, 2, 2, 15, 2, 2, 2, 2, 2,
489 2, 2, 2, 2, 2, 2, 2, 2, 16, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 17, 2, 14, 2, 2, 2, 2, 2, 2,
494 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
496 2, 2, 2, 12, 2, 13, 2, 2, 2, 2,
497 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
498 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
499 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
500 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
501 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
502 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
503 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
504 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
505 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
508 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
509 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
510 5, 6, 7, 8, 9, 10, 11
511 };
512
513 #if YYDEBUG
514 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
515 static const yytype_uint8 yyrline[] =
516 {
517 0, 92, 92, 98, 105, 105, 113, 114, 123, 126,
518 130, 136, 142, 149, 154, 161, 161, 169, 170, 179,
519 182, 186, 191, 196, 203, 204, 208, 209, 210, 211,
520 212, 213, 214, 215, 216, 217, 221
521 };
522 #endif
523
524 #if YYDEBUG || YYERROR_VERBOSE || 0
525 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
526 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
527 static const char *const yytname[] =
528 {
529 "$end", "error", "$undefined", "PHP_JSON_T_NUL", "PHP_JSON_T_TRUE",
530 "PHP_JSON_T_FALSE", "PHP_JSON_T_INT", "PHP_JSON_T_DOUBLE",
531 "PHP_JSON_T_STRING", "PHP_JSON_T_ESTRING", "PHP_JSON_T_EOI",
532 "PHP_JSON_T_ERROR", "'{'", "'}'", "']'", "','", "':'", "'['", "$accept",
533 "start", "object", "$@1", "object_end", "members", "member", "pair",
534 "array", "$@2", "array_end", "elements", "element", "key", "value",
535 "errlex", YY_NULLPTR
536 };
537 #endif
538
539 # ifdef YYPRINT
540 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
541 (internal) symbol number NUM (which must be that of a token). */
542 static const yytype_uint16 yytoknum[] =
543 {
544 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
545 265, 266, 123, 125, 93, 44, 58, 91
546 };
547 # endif
548
549 #define YYPACT_NINF -18
550
551 #define yypact_value_is_default(Yystate) \
552 (!!((Yystate) == (-18)))
553
554 #define YYTABLE_NINF -1
555
556 #define yytable_value_is_error(Yytable_value) \
557 0
558
559 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
560 STATE-NUM. */
561 static const yytype_int8 yypact[] =
562 {
563 -2, -18, -18, -18, -18, -18, -18, -18, -18, -18,
564 -18, 11, -18, -18, 9, -18, 21, -2, -18, -18,
565 -18, -18, -18, 18, 1, -18, -3, 20, 6, -18,
566 -18, -18, -18, 21, -18, -2, -18, -18, -18, -18,
567 -2, -18, -18, -18, -18
568 };
569
570 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
571 Performed when YYTABLE does not specify something else to do. Zero
572 means the default is an error. */
573 static const yytype_uint8 yydefact[] =
574 {
575 0, 32, 33, 34, 30, 31, 28, 29, 36, 4,
576 15, 0, 26, 27, 0, 35, 8, 19, 1, 2,
577 3, 24, 25, 0, 9, 10, 0, 0, 20, 21,
578 6, 7, 5, 0, 12, 0, 14, 18, 17, 16,
579 0, 23, 11, 13, 22
580 };
581
582 /* YYPGOTO[NTERM-NUM]. */
583 static const yytype_int8 yypgoto[] =
584 {
585 -18, -18, -18, -18, -18, -18, -18, -11, -18, -18,
586 -18, -18, -18, -18, -17, 0
587 };
588
589 /* YYDEFGOTO[NTERM-NUM]. */
590 static const yytype_int8 yydefgoto[] =
591 {
592 -1, 11, 12, 16, 32, 23, 24, 25, 13, 17,
593 39, 27, 28, 26, 14, 15
594 };
595
596 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
597 positive, shift that token. If negative, reduce the rule whose
598 number is the opposite. If YYTABLE_NINF, syntax error. */
599 static const yytype_uint8 yytable[] =
600 {
601 29, 1, 2, 3, 4, 5, 6, 7, 8, 8,
602 9, 18, 8, 35, 20, 10, 33, 8, 43, 19,
603 8, 40, 42, 44, 34, 0, 36, 0, 41, 21,
604 22, 30, 31, 37, 38
605 };
606
607 static const yytype_int8 yycheck[] =
608 {
609 17, 3, 4, 5, 6, 7, 8, 9, 11, 11,
610 12, 0, 11, 16, 14, 17, 15, 11, 35, 10,
611 11, 15, 33, 40, 24, -1, 26, -1, 28, 8,
612 9, 13, 14, 13, 14
613 };
614
615 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
616 symbol of state STATE-NUM. */
617 static const yytype_uint8 yystos[] =
618 {
619 0, 3, 4, 5, 6, 7, 8, 9, 11, 12,
620 17, 19, 20, 26, 32, 33, 21, 27, 0, 10,
621 33, 8, 9, 23, 24, 25, 31, 29, 30, 32,
622 13, 14, 22, 15, 33, 16, 33, 13, 14, 28,
623 15, 33, 25, 32, 32
624 };
625
626 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
627 static const yytype_uint8 yyr1[] =
628 {
629 0, 18, 19, 19, 21, 20, 22, 22, 23, 23,
630 24, 24, 24, 25, 25, 27, 26, 28, 28, 29,
631 29, 30, 30, 30, 31, 31, 32, 32, 32, 32,
632 32, 32, 32, 32, 32, 32, 33
633 };
634
635 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
636 static const yytype_uint8 yyr2[] =
637 {
638 0, 2, 2, 2, 0, 4, 1, 1, 0, 1,
639 1, 3, 2, 3, 2, 0, 4, 1, 1, 0,
640 1, 1, 3, 2, 1, 1, 1, 1, 1, 1,
641 1, 1, 1, 1, 1, 1, 1
642 };
643
644
645 #define yyerrok (yyerrstatus = 0)
646 #define yyclearin (yychar = YYEMPTY)
647 #define YYEMPTY (-2)
648 #define YYEOF 0
649
650 #define YYACCEPT goto yyacceptlab
651 #define YYABORT goto yyabortlab
652 #define YYERROR goto yyerrorlab
653
654
655 #define YYRECOVERING() (!!yyerrstatus)
656
657 #define YYBACKUP(Token, Value) \
658 do \
659 if (yychar == YYEMPTY) \
660 { \
661 yychar = (Token); \
662 yylval = (Value); \
663 YYPOPSTACK (yylen); \
664 yystate = *yyssp; \
665 goto yybackup; \
666 } \
667 else \
668 { \
669 yyerror (parser, YY_("syntax error: cannot back up")); \
670 YYERROR; \
671 } \
672 while (0)
673
674 /* Error token number */
675 #define YYTERROR 1
676 #define YYERRCODE 256
677
678
679
680 /* Enable debugging if requested. */
681 #if YYDEBUG
682
683 # ifndef YYFPRINTF
684 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
685 # define YYFPRINTF fprintf
686 # endif
687
688 # define YYDPRINTF(Args) \
689 do { \
690 if (yydebug) \
691 YYFPRINTF Args; \
692 } while (0)
693
694 /* This macro is provided for backward compatibility. */
695 #ifndef YY_LOCATION_PRINT
696 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
697 #endif
698
699
700 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
701 do { \
702 if (yydebug) \
703 { \
704 YYFPRINTF (stderr, "%s ", Title); \
705 yy_symbol_print (stderr, \
706 Type, Value, parser); \
707 YYFPRINTF (stderr, "\n"); \
708 } \
709 } while (0)
710
711
712 /*----------------------------------------.
713 | Print this symbol's value on YYOUTPUT. |
714 `----------------------------------------*/
715
716 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,php_json_parser * parser)717 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, php_json_parser *parser)
718 {
719 FILE *yyo = yyoutput;
720 YYUSE (yyo);
721 YYUSE (parser);
722 if (!yyvaluep)
723 return;
724 # ifdef YYPRINT
725 if (yytype < YYNTOKENS)
726 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
727 # endif
728 YYUSE (yytype);
729 }
730
731
732 /*--------------------------------.
733 | Print this symbol on YYOUTPUT. |
734 `--------------------------------*/
735
736 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,php_json_parser * parser)737 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, php_json_parser *parser)
738 {
739 YYFPRINTF (yyoutput, "%s %s (",
740 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
741
742 yy_symbol_value_print (yyoutput, yytype, yyvaluep, parser);
743 YYFPRINTF (yyoutput, ")");
744 }
745
746 /*------------------------------------------------------------------.
747 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
748 | TOP (included). |
749 `------------------------------------------------------------------*/
750
751 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)752 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
753 {
754 YYFPRINTF (stderr, "Stack now");
755 for (; yybottom <= yytop; yybottom++)
756 {
757 int yybot = *yybottom;
758 YYFPRINTF (stderr, " %d", yybot);
759 }
760 YYFPRINTF (stderr, "\n");
761 }
762
763 # define YY_STACK_PRINT(Bottom, Top) \
764 do { \
765 if (yydebug) \
766 yy_stack_print ((Bottom), (Top)); \
767 } while (0)
768
769
770 /*------------------------------------------------.
771 | Report that the YYRULE is going to be reduced. |
772 `------------------------------------------------*/
773
774 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule,php_json_parser * parser)775 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, php_json_parser *parser)
776 {
777 unsigned long int yylno = yyrline[yyrule];
778 int yynrhs = yyr2[yyrule];
779 int yyi;
780 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
781 yyrule - 1, yylno);
782 /* The symbols being reduced. */
783 for (yyi = 0; yyi < yynrhs; yyi++)
784 {
785 YYFPRINTF (stderr, " $%d = ", yyi + 1);
786 yy_symbol_print (stderr,
787 yystos[yyssp[yyi + 1 - yynrhs]],
788 &(yyvsp[(yyi + 1) - (yynrhs)])
789 , parser);
790 YYFPRINTF (stderr, "\n");
791 }
792 }
793
794 # define YY_REDUCE_PRINT(Rule) \
795 do { \
796 if (yydebug) \
797 yy_reduce_print (yyssp, yyvsp, Rule, parser); \
798 } while (0)
799
800 /* Nonzero means print parse trace. It is left uninitialized so that
801 multiple parsers can coexist. */
802 int yydebug;
803 #else /* !YYDEBUG */
804 # define YYDPRINTF(Args)
805 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
806 # define YY_STACK_PRINT(Bottom, Top)
807 # define YY_REDUCE_PRINT(Rule)
808 #endif /* !YYDEBUG */
809
810
811 /* YYINITDEPTH -- initial size of the parser's stacks. */
812 #ifndef YYINITDEPTH
813 # define YYINITDEPTH 200
814 #endif
815
816 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
817 if the built-in stack extension method is used).
818
819 Do not make this value too large; the results are undefined if
820 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
821 evaluated with infinite-precision integer arithmetic. */
822
823 #ifndef YYMAXDEPTH
824 # define YYMAXDEPTH 10000
825 #endif
826
827
828 #if YYERROR_VERBOSE
829
830 # ifndef yystrlen
831 # if defined __GLIBC__ && defined _STRING_H
832 # define yystrlen strlen
833 # else
834 /* Return the length of YYSTR. */
835 static YYSIZE_T
yystrlen(const char * yystr)836 yystrlen (const char *yystr)
837 {
838 YYSIZE_T yylen;
839 for (yylen = 0; yystr[yylen]; yylen++)
840 continue;
841 return yylen;
842 }
843 # endif
844 # endif
845
846 # ifndef yystpcpy
847 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
848 # define yystpcpy stpcpy
849 # else
850 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
851 YYDEST. */
852 static char *
yystpcpy(char * yydest,const char * yysrc)853 yystpcpy (char *yydest, const char *yysrc)
854 {
855 char *yyd = yydest;
856 const char *yys = yysrc;
857
858 while ((*yyd++ = *yys++) != '\0')
859 continue;
860
861 return yyd - 1;
862 }
863 # endif
864 # endif
865
866 # ifndef yytnamerr
867 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
868 quotes and backslashes, so that it's suitable for yyerror. The
869 heuristic is that double-quoting is unnecessary unless the string
870 contains an apostrophe, a comma, or backslash (other than
871 backslash-backslash). YYSTR is taken from yytname. If YYRES is
872 null, do not copy; instead, return the length of what the result
873 would have been. */
874 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)875 yytnamerr (char *yyres, const char *yystr)
876 {
877 if (*yystr == '"')
878 {
879 YYSIZE_T yyn = 0;
880 char const *yyp = yystr;
881
882 for (;;)
883 switch (*++yyp)
884 {
885 case '\'':
886 case ',':
887 goto do_not_strip_quotes;
888
889 case '\\':
890 if (*++yyp != '\\')
891 goto do_not_strip_quotes;
892 /* Fall through. */
893 default:
894 if (yyres)
895 yyres[yyn] = *yyp;
896 yyn++;
897 break;
898
899 case '"':
900 if (yyres)
901 yyres[yyn] = '\0';
902 return yyn;
903 }
904 do_not_strip_quotes: ;
905 }
906
907 if (! yyres)
908 return yystrlen (yystr);
909
910 return yystpcpy (yyres, yystr) - yyres;
911 }
912 # endif
913
914 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
915 about the unexpected token YYTOKEN for the state stack whose top is
916 YYSSP.
917
918 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
919 not large enough to hold the message. In that case, also set
920 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
921 required number of bytes is too large to store. */
922 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)923 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
924 yytype_int16 *yyssp, int yytoken)
925 {
926 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
927 YYSIZE_T yysize = yysize0;
928 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
929 /* Internationalized format string. */
930 const char *yyformat = YY_NULLPTR;
931 /* Arguments of yyformat. */
932 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
933 /* Number of reported tokens (one for the "unexpected", one per
934 "expected"). */
935 int yycount = 0;
936
937 /* There are many possibilities here to consider:
938 - If this state is a consistent state with a default action, then
939 the only way this function was invoked is if the default action
940 is an error action. In that case, don't check for expected
941 tokens because there are none.
942 - The only way there can be no lookahead present (in yychar) is if
943 this state is a consistent state with a default action. Thus,
944 detecting the absence of a lookahead is sufficient to determine
945 that there is no unexpected or expected token to report. In that
946 case, just report a simple "syntax error".
947 - Don't assume there isn't a lookahead just because this state is a
948 consistent state with a default action. There might have been a
949 previous inconsistent state, consistent state with a non-default
950 action, or user semantic action that manipulated yychar.
951 - Of course, the expected token list depends on states to have
952 correct lookahead information, and it depends on the parser not
953 to perform extra reductions after fetching a lookahead from the
954 scanner and before detecting a syntax error. Thus, state merging
955 (from LALR or IELR) and default reductions corrupt the expected
956 token list. However, the list is correct for canonical LR with
957 one exception: it will still contain any token that will not be
958 accepted due to an error action in a later state.
959 */
960 if (yytoken != YYEMPTY)
961 {
962 int yyn = yypact[*yyssp];
963 yyarg[yycount++] = yytname[yytoken];
964 if (!yypact_value_is_default (yyn))
965 {
966 /* Start YYX at -YYN if negative to avoid negative indexes in
967 YYCHECK. In other words, skip the first -YYN actions for
968 this state because they are default actions. */
969 int yyxbegin = yyn < 0 ? -yyn : 0;
970 /* Stay within bounds of both yycheck and yytname. */
971 int yychecklim = YYLAST - yyn + 1;
972 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
973 int yyx;
974
975 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
976 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
977 && !yytable_value_is_error (yytable[yyx + yyn]))
978 {
979 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
980 {
981 yycount = 1;
982 yysize = yysize0;
983 break;
984 }
985 yyarg[yycount++] = yytname[yyx];
986 {
987 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
988 if (! (yysize <= yysize1
989 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
990 return 2;
991 yysize = yysize1;
992 }
993 }
994 }
995 }
996
997 switch (yycount)
998 {
999 # define YYCASE_(N, S) \
1000 case N: \
1001 yyformat = S; \
1002 break
1003 YYCASE_(0, YY_("syntax error"));
1004 YYCASE_(1, YY_("syntax error, unexpected %s"));
1005 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1006 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1007 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1008 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1009 # undef YYCASE_
1010 }
1011
1012 {
1013 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1014 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1015 return 2;
1016 yysize = yysize1;
1017 }
1018
1019 if (*yymsg_alloc < yysize)
1020 {
1021 *yymsg_alloc = 2 * yysize;
1022 if (! (yysize <= *yymsg_alloc
1023 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1024 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1025 return 1;
1026 }
1027
1028 /* Avoid sprintf, as that infringes on the user's name space.
1029 Don't have undefined behavior even if the translation
1030 produced a string with the wrong number of "%s"s. */
1031 {
1032 char *yyp = *yymsg;
1033 int yyi = 0;
1034 while ((*yyp = *yyformat) != '\0')
1035 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1036 {
1037 yyp += yytnamerr (yyp, yyarg[yyi++]);
1038 yyformat += 2;
1039 }
1040 else
1041 {
1042 yyp++;
1043 yyformat++;
1044 }
1045 }
1046 return 0;
1047 }
1048 #endif /* YYERROR_VERBOSE */
1049
1050 /*-----------------------------------------------.
1051 | Release the memory associated to this symbol. |
1052 `-----------------------------------------------*/
1053
1054 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,php_json_parser * parser)1055 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, php_json_parser *parser)
1056 {
1057 YYUSE (yyvaluep);
1058 YYUSE (parser);
1059 if (!yymsg)
1060 yymsg = "Deleting";
1061 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1062
1063 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1064 switch (yytype)
1065 {
1066 case 3: /* PHP_JSON_T_NUL */
1067
1068 { zval_dtor(&((*yyvaluep).value)); }
1069
1070 break;
1071
1072 case 4: /* PHP_JSON_T_TRUE */
1073
1074 { zval_dtor(&((*yyvaluep).value)); }
1075
1076 break;
1077
1078 case 5: /* PHP_JSON_T_FALSE */
1079
1080 { zval_dtor(&((*yyvaluep).value)); }
1081
1082 break;
1083
1084 case 6: /* PHP_JSON_T_INT */
1085
1086 { zval_dtor(&((*yyvaluep).value)); }
1087
1088 break;
1089
1090 case 7: /* PHP_JSON_T_DOUBLE */
1091
1092 { zval_dtor(&((*yyvaluep).value)); }
1093
1094 break;
1095
1096 case 8: /* PHP_JSON_T_STRING */
1097
1098 { zval_dtor(&((*yyvaluep).value)); }
1099
1100 break;
1101
1102 case 9: /* PHP_JSON_T_ESTRING */
1103
1104 { zval_dtor(&((*yyvaluep).value)); }
1105
1106 break;
1107
1108 case 10: /* PHP_JSON_T_EOI */
1109
1110 { zval_dtor(&((*yyvaluep).value)); }
1111
1112 break;
1113
1114 case 11: /* PHP_JSON_T_ERROR */
1115
1116 { zval_dtor(&((*yyvaluep).value)); }
1117
1118 break;
1119
1120 case 19: /* start */
1121
1122 { zval_dtor(&((*yyvaluep).value)); }
1123
1124 break;
1125
1126 case 20: /* object */
1127
1128 { zval_dtor(&((*yyvaluep).value)); }
1129
1130 break;
1131
1132 case 23: /* members */
1133
1134 { zval_dtor(&((*yyvaluep).value)); }
1135
1136 break;
1137
1138 case 24: /* member */
1139
1140 { zval_dtor(&((*yyvaluep).value)); }
1141
1142 break;
1143
1144 case 25: /* pair */
1145
1146 { zend_string_release(((*yyvaluep).pair).key); zval_dtor(&((*yyvaluep).pair).val); }
1147
1148 break;
1149
1150 case 26: /* array */
1151
1152 { zval_dtor(&((*yyvaluep).value)); }
1153
1154 break;
1155
1156 case 29: /* elements */
1157
1158 { zval_dtor(&((*yyvaluep).value)); }
1159
1160 break;
1161
1162 case 30: /* element */
1163
1164 { zval_dtor(&((*yyvaluep).value)); }
1165
1166 break;
1167
1168 case 31: /* key */
1169
1170 { zval_dtor(&((*yyvaluep).value)); }
1171
1172 break;
1173
1174 case 32: /* value */
1175
1176 { zval_dtor(&((*yyvaluep).value)); }
1177
1178 break;
1179
1180 case 33: /* errlex */
1181
1182 { zval_dtor(&((*yyvaluep).value)); }
1183
1184 break;
1185
1186
1187 default:
1188 break;
1189 }
1190 YY_IGNORE_MAYBE_UNINITIALIZED_END
1191 }
1192
1193
1194
1195
1196 /*----------.
1197 | yyparse. |
1198 `----------*/
1199
1200 int
yyparse(php_json_parser * parser)1201 yyparse (php_json_parser *parser)
1202 {
1203 /* The lookahead symbol. */
1204 int yychar;
1205
1206
1207 /* The semantic value of the lookahead symbol. */
1208 /* Default value used for initialization, for pacifying older GCCs
1209 or non-GCC compilers. */
1210 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1211 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1212
1213 /* Number of syntax errors so far. */
1214 int yynerrs;
1215
1216 int yystate;
1217 /* Number of tokens to shift before error messages enabled. */
1218 int yyerrstatus;
1219
1220 /* The stacks and their tools:
1221 'yyss': related to states.
1222 'yyvs': related to semantic values.
1223
1224 Refer to the stacks through separate pointers, to allow yyoverflow
1225 to reallocate them elsewhere. */
1226
1227 /* The state stack. */
1228 yytype_int16 yyssa[YYINITDEPTH];
1229 yytype_int16 *yyss;
1230 yytype_int16 *yyssp;
1231
1232 /* The semantic value stack. */
1233 YYSTYPE yyvsa[YYINITDEPTH];
1234 YYSTYPE *yyvs;
1235 YYSTYPE *yyvsp;
1236
1237 YYSIZE_T yystacksize;
1238
1239 int yyn;
1240 int yyresult;
1241 /* Lookahead token as an internal (translated) token number. */
1242 int yytoken = 0;
1243 /* The variables used to return semantic value and location from the
1244 action routines. */
1245 YYSTYPE yyval;
1246
1247 #if YYERROR_VERBOSE
1248 /* Buffer for error messages, and its allocated size. */
1249 char yymsgbuf[128];
1250 char *yymsg = yymsgbuf;
1251 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1252 #endif
1253
1254 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1255
1256 /* The number of symbols on the RHS of the reduced rule.
1257 Keep to zero when no symbol should be popped. */
1258 int yylen = 0;
1259
1260 yyssp = yyss = yyssa;
1261 yyvsp = yyvs = yyvsa;
1262 yystacksize = YYINITDEPTH;
1263
1264 YYDPRINTF ((stderr, "Starting parse\n"));
1265
1266 yystate = 0;
1267 yyerrstatus = 0;
1268 yynerrs = 0;
1269 yychar = YYEMPTY; /* Cause a token to be read. */
1270 goto yysetstate;
1271
1272 /*------------------------------------------------------------.
1273 | yynewstate -- Push a new state, which is found in yystate. |
1274 `------------------------------------------------------------*/
1275 yynewstate:
1276 /* In all cases, when you get here, the value and location stacks
1277 have just been pushed. So pushing a state here evens the stacks. */
1278 yyssp++;
1279
1280 yysetstate:
1281 *yyssp = yystate;
1282
1283 if (yyss + yystacksize - 1 <= yyssp)
1284 {
1285 /* Get the current used size of the three stacks, in elements. */
1286 YYSIZE_T yysize = yyssp - yyss + 1;
1287
1288 #ifdef yyoverflow
1289 {
1290 /* Give user a chance to reallocate the stack. Use copies of
1291 these so that the &'s don't force the real ones into
1292 memory. */
1293 YYSTYPE *yyvs1 = yyvs;
1294 yytype_int16 *yyss1 = yyss;
1295
1296 /* Each stack pointer address is followed by the size of the
1297 data in use in that stack, in bytes. This used to be a
1298 conditional around just the two extra args, but that might
1299 be undefined if yyoverflow is a macro. */
1300 yyoverflow (YY_("memory exhausted"),
1301 &yyss1, yysize * sizeof (*yyssp),
1302 &yyvs1, yysize * sizeof (*yyvsp),
1303 &yystacksize);
1304
1305 yyss = yyss1;
1306 yyvs = yyvs1;
1307 }
1308 #else /* no yyoverflow */
1309 # ifndef YYSTACK_RELOCATE
1310 goto yyexhaustedlab;
1311 # else
1312 /* Extend the stack our own way. */
1313 if (YYMAXDEPTH <= yystacksize)
1314 goto yyexhaustedlab;
1315 yystacksize *= 2;
1316 if (YYMAXDEPTH < yystacksize)
1317 yystacksize = YYMAXDEPTH;
1318
1319 {
1320 yytype_int16 *yyss1 = yyss;
1321 union yyalloc *yyptr =
1322 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1323 if (! yyptr)
1324 goto yyexhaustedlab;
1325 YYSTACK_RELOCATE (yyss_alloc, yyss);
1326 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1327 # undef YYSTACK_RELOCATE
1328 if (yyss1 != yyssa)
1329 YYSTACK_FREE (yyss1);
1330 }
1331 # endif
1332 #endif /* no yyoverflow */
1333
1334 yyssp = yyss + yysize - 1;
1335 yyvsp = yyvs + yysize - 1;
1336
1337 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1338 (unsigned long int) yystacksize));
1339
1340 if (yyss + yystacksize - 1 <= yyssp)
1341 YYABORT;
1342 }
1343
1344 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1345
1346 if (yystate == YYFINAL)
1347 YYACCEPT;
1348
1349 goto yybackup;
1350
1351 /*-----------.
1352 | yybackup. |
1353 `-----------*/
1354 yybackup:
1355
1356 /* Do appropriate processing given the current state. Read a
1357 lookahead token if we need one and don't already have one. */
1358
1359 /* First try to decide what to do without reference to lookahead token. */
1360 yyn = yypact[yystate];
1361 if (yypact_value_is_default (yyn))
1362 goto yydefault;
1363
1364 /* Not known => get a lookahead token if don't already have one. */
1365
1366 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1367 if (yychar == YYEMPTY)
1368 {
1369 YYDPRINTF ((stderr, "Reading a token: "));
1370 yychar = yylex (&yylval, parser);
1371 }
1372
1373 if (yychar <= YYEOF)
1374 {
1375 yychar = yytoken = YYEOF;
1376 YYDPRINTF ((stderr, "Now at end of input.\n"));
1377 }
1378 else
1379 {
1380 yytoken = YYTRANSLATE (yychar);
1381 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1382 }
1383
1384 /* If the proper action on seeing token YYTOKEN is to reduce or to
1385 detect an error, take that action. */
1386 yyn += yytoken;
1387 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1388 goto yydefault;
1389 yyn = yytable[yyn];
1390 if (yyn <= 0)
1391 {
1392 if (yytable_value_is_error (yyn))
1393 goto yyerrlab;
1394 yyn = -yyn;
1395 goto yyreduce;
1396 }
1397
1398 /* Count tokens shifted since error; after three, turn off error
1399 status. */
1400 if (yyerrstatus)
1401 yyerrstatus--;
1402
1403 /* Shift the lookahead token. */
1404 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1405
1406 /* Discard the shifted token. */
1407 yychar = YYEMPTY;
1408
1409 yystate = yyn;
1410 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1411 *++yyvsp = yylval;
1412 YY_IGNORE_MAYBE_UNINITIALIZED_END
1413
1414 goto yynewstate;
1415
1416
1417 /*-----------------------------------------------------------.
1418 | yydefault -- do the default action for the current state. |
1419 `-----------------------------------------------------------*/
1420 yydefault:
1421 yyn = yydefact[yystate];
1422 if (yyn == 0)
1423 goto yyerrlab;
1424 goto yyreduce;
1425
1426
1427 /*-----------------------------.
1428 | yyreduce -- Do a reduction. |
1429 `-----------------------------*/
1430 yyreduce:
1431 /* yyn is the number of a rule to reduce with. */
1432 yylen = yyr2[yyn];
1433
1434 /* If YYLEN is nonzero, implement the default value of the action:
1435 '$$ = $1'.
1436
1437 Otherwise, the following line sets YYVAL to garbage.
1438 This behavior is undocumented and Bison
1439 users should not rely upon it. Assigning to YYVAL
1440 unconditionally makes the parser a bit smaller, and it avoids a
1441 GCC warning that YYVAL may be used uninitialized. */
1442 yyval = yyvsp[1-yylen];
1443
1444
1445 YY_REDUCE_PRINT (yyn);
1446 switch (yyn)
1447 {
1448 case 2:
1449
1450 {
1451 ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-1].value));
1452 ZVAL_COPY_VALUE(parser->return_value, &(yyvsp[-1].value));
1453 PHP_JSON_USE((yyvsp[0].value)); YYACCEPT;
1454 }
1455
1456 break;
1457
1458 case 3:
1459
1460 {
1461 PHP_JSON_USE_2((yyval.value), (yyvsp[-1].value), (yyvsp[0].value));
1462 }
1463
1464 break;
1465
1466 case 4:
1467
1468 { PHP_JSON_DEPTH_INC; }
1469
1470 break;
1471
1472 case 5:
1473
1474 {
1475 PHP_JSON_DEPTH_DEC;
1476 (yyval.value) = (yyvsp[-1].value);
1477 }
1478
1479 break;
1480
1481 case 7:
1482
1483 {
1484 parser->scanner.errcode = PHP_JSON_ERROR_STATE_MISMATCH;
1485 YYERROR;
1486 }
1487
1488 break;
1489
1490 case 8:
1491
1492 {
1493 php_json_parser_object_init(parser, &(yyval.value));
1494 }
1495
1496 break;
1497
1498 case 10:
1499
1500 {
1501 php_json_parser_object_init(parser, &(yyval.value));
1502 if (php_json_parser_object_update(parser, &(yyval.value), (yyvsp[0].pair).key, &(yyvsp[0].pair).val) == FAILURE)
1503 YYERROR;
1504 }
1505
1506 break;
1507
1508 case 11:
1509
1510 {
1511 if (php_json_parser_object_update(parser, &(yyvsp[-2].value), (yyvsp[0].pair).key, &(yyvsp[0].pair).val) == FAILURE)
1512 YYERROR;
1513 ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-2].value));
1514 }
1515
1516 break;
1517
1518 case 12:
1519
1520 {
1521 PHP_JSON_USE_2((yyval.value), (yyvsp[-1].value), (yyvsp[0].value));
1522 }
1523
1524 break;
1525
1526 case 13:
1527
1528 {
1529 (yyval.pair).key = Z_STR((yyvsp[-2].value));
1530 ZVAL_COPY_VALUE(&(yyval.pair).val, &(yyvsp[0].value));
1531 }
1532
1533 break;
1534
1535 case 14:
1536
1537 {
1538 PHP_JSON_USE_2((yyval.pair), (yyvsp[-1].value), (yyvsp[0].value));
1539 }
1540
1541 break;
1542
1543 case 15:
1544
1545 { PHP_JSON_DEPTH_INC; }
1546
1547 break;
1548
1549 case 16:
1550
1551 {
1552 PHP_JSON_DEPTH_DEC;
1553 ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-1].value));
1554 }
1555
1556 break;
1557
1558 case 18:
1559
1560 {
1561 parser->scanner.errcode = PHP_JSON_ERROR_STATE_MISMATCH;
1562 YYERROR;
1563 }
1564
1565 break;
1566
1567 case 19:
1568
1569 {
1570 php_json_parser_array_init(&(yyval.value));
1571 }
1572
1573 break;
1574
1575 case 21:
1576
1577 {
1578 php_json_parser_array_init(&(yyval.value));
1579 php_json_parser_array_append(&(yyval.value), &(yyvsp[0].value));
1580 }
1581
1582 break;
1583
1584 case 22:
1585
1586 {
1587 php_json_parser_array_append(&(yyvsp[-2].value), &(yyvsp[0].value));
1588 ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-2].value));
1589 }
1590
1591 break;
1592
1593 case 23:
1594
1595 {
1596 PHP_JSON_USE_2((yyval.value), (yyvsp[-1].value), (yyvsp[0].value));
1597 }
1598
1599 break;
1600
1601 case 36:
1602
1603 {
1604 PHP_JSON_USE_1((yyval.value), (yyvsp[0].value));
1605 YYERROR;
1606 }
1607
1608 break;
1609
1610
1611
1612 default: break;
1613 }
1614 /* User semantic actions sometimes alter yychar, and that requires
1615 that yytoken be updated with the new translation. We take the
1616 approach of translating immediately before every use of yytoken.
1617 One alternative is translating here after every semantic action,
1618 but that translation would be missed if the semantic action invokes
1619 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1620 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1621 incorrect destructor might then be invoked immediately. In the
1622 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1623 to an incorrect destructor call or verbose syntax error message
1624 before the lookahead is translated. */
1625 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1626
1627 YYPOPSTACK (yylen);
1628 yylen = 0;
1629 YY_STACK_PRINT (yyss, yyssp);
1630
1631 *++yyvsp = yyval;
1632
1633 /* Now 'shift' the result of the reduction. Determine what state
1634 that goes to, based on the state we popped back to and the rule
1635 number reduced by. */
1636
1637 yyn = yyr1[yyn];
1638
1639 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1640 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1641 yystate = yytable[yystate];
1642 else
1643 yystate = yydefgoto[yyn - YYNTOKENS];
1644
1645 goto yynewstate;
1646
1647
1648 /*--------------------------------------.
1649 | yyerrlab -- here on detecting error. |
1650 `--------------------------------------*/
1651 yyerrlab:
1652 /* Make sure we have latest lookahead translation. See comments at
1653 user semantic actions for why this is necessary. */
1654 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1655
1656 /* If not already recovering from an error, report this error. */
1657 if (!yyerrstatus)
1658 {
1659 ++yynerrs;
1660 #if ! YYERROR_VERBOSE
1661 yyerror (parser, YY_("syntax error"));
1662 #else
1663 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1664 yyssp, yytoken)
1665 {
1666 char const *yymsgp = YY_("syntax error");
1667 int yysyntax_error_status;
1668 yysyntax_error_status = YYSYNTAX_ERROR;
1669 if (yysyntax_error_status == 0)
1670 yymsgp = yymsg;
1671 else if (yysyntax_error_status == 1)
1672 {
1673 if (yymsg != yymsgbuf)
1674 YYSTACK_FREE (yymsg);
1675 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1676 if (!yymsg)
1677 {
1678 yymsg = yymsgbuf;
1679 yymsg_alloc = sizeof yymsgbuf;
1680 yysyntax_error_status = 2;
1681 }
1682 else
1683 {
1684 yysyntax_error_status = YYSYNTAX_ERROR;
1685 yymsgp = yymsg;
1686 }
1687 }
1688 yyerror (parser, yymsgp);
1689 if (yysyntax_error_status == 2)
1690 goto yyexhaustedlab;
1691 }
1692 # undef YYSYNTAX_ERROR
1693 #endif
1694 }
1695
1696
1697
1698 if (yyerrstatus == 3)
1699 {
1700 /* If just tried and failed to reuse lookahead token after an
1701 error, discard it. */
1702
1703 if (yychar <= YYEOF)
1704 {
1705 /* Return failure if at end of input. */
1706 if (yychar == YYEOF)
1707 YYABORT;
1708 }
1709 else
1710 {
1711 yydestruct ("Error: discarding",
1712 yytoken, &yylval, parser);
1713 yychar = YYEMPTY;
1714 }
1715 }
1716
1717 /* Else will try to reuse lookahead token after shifting the error
1718 token. */
1719 goto yyerrlab1;
1720
1721
1722 /*---------------------------------------------------.
1723 | yyerrorlab -- error raised explicitly by YYERROR. |
1724 `---------------------------------------------------*/
1725 yyerrorlab:
1726
1727 /* Pacify compilers like GCC when the user code never invokes
1728 YYERROR and the label yyerrorlab therefore never appears in user
1729 code. */
1730 if (/*CONSTCOND*/ 0)
1731 goto yyerrorlab;
1732
1733 /* Do not reclaim the symbols of the rule whose action triggered
1734 this YYERROR. */
1735 YYPOPSTACK (yylen);
1736 yylen = 0;
1737 YY_STACK_PRINT (yyss, yyssp);
1738 yystate = *yyssp;
1739 goto yyerrlab1;
1740
1741
1742 /*-------------------------------------------------------------.
1743 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1744 `-------------------------------------------------------------*/
1745 yyerrlab1:
1746 yyerrstatus = 3; /* Each real token shifted decrements this. */
1747
1748 for (;;)
1749 {
1750 yyn = yypact[yystate];
1751 if (!yypact_value_is_default (yyn))
1752 {
1753 yyn += YYTERROR;
1754 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1755 {
1756 yyn = yytable[yyn];
1757 if (0 < yyn)
1758 break;
1759 }
1760 }
1761
1762 /* Pop the current state because it cannot handle the error token. */
1763 if (yyssp == yyss)
1764 YYABORT;
1765
1766
1767 yydestruct ("Error: popping",
1768 yystos[yystate], yyvsp, parser);
1769 YYPOPSTACK (1);
1770 yystate = *yyssp;
1771 YY_STACK_PRINT (yyss, yyssp);
1772 }
1773
1774 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1775 *++yyvsp = yylval;
1776 YY_IGNORE_MAYBE_UNINITIALIZED_END
1777
1778
1779 /* Shift the error token. */
1780 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1781
1782 yystate = yyn;
1783 goto yynewstate;
1784
1785
1786 /*-------------------------------------.
1787 | yyacceptlab -- YYACCEPT comes here. |
1788 `-------------------------------------*/
1789 yyacceptlab:
1790 yyresult = 0;
1791 goto yyreturn;
1792
1793 /*-----------------------------------.
1794 | yyabortlab -- YYABORT comes here. |
1795 `-----------------------------------*/
1796 yyabortlab:
1797 yyresult = 1;
1798 goto yyreturn;
1799
1800 #if !defined yyoverflow || YYERROR_VERBOSE
1801 /*-------------------------------------------------.
1802 | yyexhaustedlab -- memory exhaustion comes here. |
1803 `-------------------------------------------------*/
1804 yyexhaustedlab:
1805 yyerror (parser, YY_("memory exhausted"));
1806 yyresult = 2;
1807 /* Fall through. */
1808 #endif
1809
1810 yyreturn:
1811 if (yychar != YYEMPTY)
1812 {
1813 /* Make sure we have latest lookahead translation. See comments at
1814 user semantic actions for why this is necessary. */
1815 yytoken = YYTRANSLATE (yychar);
1816 yydestruct ("Cleanup: discarding lookahead",
1817 yytoken, &yylval, parser);
1818 }
1819 /* Do not reclaim the symbols of the rule whose action triggered
1820 this YYABORT or YYACCEPT. */
1821 YYPOPSTACK (yylen);
1822 YY_STACK_PRINT (yyss, yyssp);
1823 while (yyssp != yyss)
1824 {
1825 yydestruct ("Cleanup: popping",
1826 yystos[*yyssp], yyvsp, parser);
1827 YYPOPSTACK (1);
1828 }
1829 #ifndef yyoverflow
1830 if (yyss != yyssa)
1831 YYSTACK_FREE (yyss);
1832 #endif
1833 #if YYERROR_VERBOSE
1834 if (yymsg != yymsgbuf)
1835 YYSTACK_FREE (yymsg);
1836 #endif
1837 return yyresult;
1838 }
1839
1840 /* Functions */
1841
php_json_parser_init(php_json_parser * parser,zval * return_value,char * str,size_t str_len,int options,int max_depth)1842 void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, size_t str_len, int options, int max_depth)
1843 {
1844 memset(parser, 0, sizeof(php_json_parser));
1845 php_json_scanner_init(&parser->scanner, str, str_len, options);
1846 parser->depth = 1;
1847 parser->max_depth = max_depth;
1848 parser->return_value = return_value;
1849 }
1850
php_json_parser_error_code(php_json_parser * parser)1851 php_json_error_code php_json_parser_error_code(php_json_parser *parser)
1852 {
1853 return parser->scanner.errcode;
1854 }
1855
php_json_parser_object_init(php_json_parser * parser,zval * object)1856 void php_json_parser_object_init(php_json_parser *parser, zval *object)
1857 {
1858 if (parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) {
1859 array_init(object);
1860 } else {
1861 object_init(object);
1862 }
1863 }
1864
php_json_parser_object_update(php_json_parser * parser,zval * object,zend_string * key,zval * zvalue)1865 int php_json_parser_object_update(php_json_parser *parser, zval *object, zend_string *key, zval *zvalue)
1866 {
1867 /* if JSON_OBJECT_AS_ARRAY is set */
1868 if (Z_TYPE_P(object) == IS_ARRAY) {
1869 zend_symtable_update(Z_ARRVAL_P(object), key, zvalue);
1870 } else {
1871 zval zkey;
1872 if (ZSTR_LEN(key) == 0) {
1873 zend_string_release(key);
1874 key = zend_string_init("_empty_", sizeof("_empty_") - 1, 0);
1875 } else if (ZSTR_VAL(key)[0] == '\0') {
1876 parser->scanner.errcode = PHP_JSON_ERROR_INVALID_PROPERTY_NAME;
1877 zend_string_release(key);
1878 zval_dtor(zvalue);
1879 zval_dtor(object);
1880 return FAILURE;
1881 }
1882 ZVAL_NEW_STR(&zkey, key);
1883 zend_std_write_property(object, &zkey, zvalue, NULL);
1884
1885 if (Z_REFCOUNTED_P(zvalue)) {
1886 Z_DELREF_P(zvalue);
1887 }
1888 }
1889 zend_string_release(key);
1890
1891 return SUCCESS;
1892 }
1893
php_json_parser_array_init(zval * array)1894 void php_json_parser_array_init(zval *array)
1895 {
1896 array_init(array);
1897 }
1898
php_json_parser_array_append(zval * array,zval * zvalue)1899 void php_json_parser_array_append(zval *array, zval *zvalue)
1900 {
1901 zend_hash_next_index_insert(Z_ARRVAL_P(array), zvalue);
1902 }
1903
php_json_yylex(union YYSTYPE * value,php_json_parser * parser)1904 int php_json_yylex(union YYSTYPE *value, php_json_parser *parser)
1905 {
1906 int token = php_json_scan(&parser->scanner);
1907 value->value = parser->scanner.value;
1908 return token;
1909 }
1910
php_json_yyerror(php_json_parser * parser,char const * msg)1911 void php_json_yyerror(php_json_parser *parser, char const *msg)
1912 {
1913 if (!parser->scanner.errcode) {
1914 parser->scanner.errcode = PHP_JSON_ERROR_SYNTAX;
1915 }
1916 }
1917