2 /* NdBox = [(lowerleft),(upperright)] */
3 /* [(xLL(1)...xLL(N)),(xUR(1)...xUR(n))] */
5 #define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
13 extern int cube_yylex(void);
16 static int scanbuflen;
18 void cube_yyerror(const char *message);
19 int cube_yyparse(void *result);
21 static int delim_count(char *s, char delim);
22 static NDBOX * write_box(unsigned int dim, char *str1, char *str2);
23 static NDBOX * write_point_as_box(char *s, int dim);
27 /* BISON Declarations */
28 %name-prefix="cube_yy"
30 %token CUBEFLOAT O_PAREN C_PAREN O_BRACKET C_BRACKET COMMA
37 O_BRACKET paren_list COMMA paren_list C_BRACKET {
41 dim = delim_count($2, ',') + 1;
42 if ( (delim_count($4, ',') + 1) != dim ) {
44 (errcode(ERRCODE_SYNTAX_ERROR),
45 errmsg("bad cube representation"),
46 errdetail("Different point dimensions in (%s) and (%s).",
50 if (dim > CUBE_MAX_DIM) {
52 (errcode(ERRCODE_SYNTAX_ERROR),
53 errmsg("bad cube representation"),
54 errdetail("A cube cannot have more than %d dimensions.",
59 *((void **)result) = write_box( dim, $2, $4 );
63 paren_list COMMA paren_list {
66 dim = delim_count($1, ',') + 1;
68 if ( (delim_count($3, ',') + 1) != dim ) {
70 (errcode(ERRCODE_SYNTAX_ERROR),
71 errmsg("bad cube representation"),
72 errdetail("Different point dimensions in (%s) and (%s).",
76 if (dim > CUBE_MAX_DIM) {
78 (errcode(ERRCODE_SYNTAX_ERROR),
79 errmsg("bad cube representation"),
80 errdetail("A cube cannot have more than %d dimensions.",
85 *((void **)result) = write_box( dim, $1, $3 );
92 dim = delim_count($1, ',') + 1;
93 if (dim > CUBE_MAX_DIM) {
95 (errcode(ERRCODE_SYNTAX_ERROR),
96 errmsg("bad cube representation"),
97 errdetail("A cube cannot have more than %d dimensions.",
102 *((void **)result) = write_point_as_box($1, dim);
110 dim = delim_count($1, ',') + 1;
111 if (dim > CUBE_MAX_DIM) {
113 (errcode(ERRCODE_SYNTAX_ERROR),
114 errmsg("bad cube representation"),
115 errdetail("A cube cannot have more than %d dimensions.",
119 *((void **)result) = write_point_as_box($1, dim);
124 O_PAREN list C_PAREN {
131 /* alloc enough space to be sure whole list will fit */
132 $$ = palloc(scanbuflen + 1);
136 list COMMA CUBEFLOAT {
146 delim_count(char *s, char delim)
150 while ((s = strchr(s, delim)) != NULL)
159 write_box(unsigned int dim, char *str1, char *str2)
164 int size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
172 bp->x[i=0] = strtod(s, NULL);
173 while ((s = strchr(s, ',')) != NULL) {
175 bp->x[i] = strtod(s, NULL);
179 bp->x[i=dim] = strtod(s, NULL);
180 while ((s = strchr(s, ',')) != NULL) {
182 bp->x[i] = strtod(s, NULL);
190 write_point_as_box(char *str, int dim)
197 size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
208 while ((s = strchr(s, ',')) != NULL) {
218 #include "cubescan.c"