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