2 #define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
9 #include "utils/builtins.h"
13 * Bison doesn't allocate anything that needs to live across parser calls,
14 * so we can easily have it use palloc instead of malloc. This prevents
15 * memory leaks if we error out during parsing. Note this only works with
16 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
17 * if possible, so there's not really much problem anyhow, at least if
18 * you're building with gcc.
20 #define YYMALLOC palloc
23 extern
int seg_yylex
(void);
25 extern
int significant_digits
(char *str
); /* defined in seg.c */
27 void seg_yyerror
(const char *message
);
28 int seg_yyparse
(void *result
);
30 static float seg_atof
(char *value
);
32 static char strbuf
[25] = {
33 '0', '0', '0', '0', '0',
34 '0', '0', '0', '0', '0',
35 '0', '0', '0', '0', '0',
36 '0', '0', '0', '0', '0',
37 '0', '0', '0', '0', '\0'
42 /* BISON Declarations */
53 %token
<text
> SEGFLOAT
56 %token
<text
> EXTENSION
66 boundary PLUMIN deviation
{
67 ((SEG
*)result
)->lower
= $1.val
- $3.val
;
68 ((SEG
*)result
)->upper
= $1.val
+ $3.val
;
69 sprintf
(strbuf
, "%g", ((SEG
*)result
)->lower
);
70 ((SEG
*)result
)->l_sigd
= Max
(Min
(6, significant_digits
(strbuf
)), Max
($1.sigd
, $3.sigd
));
71 sprintf
(strbuf
, "%g", ((SEG
*)result
)->upper
);
72 ((SEG
*)result
)->u_sigd
= Max
(Min
(6, significant_digits
(strbuf
)), Max
($1.sigd
, $3.sigd
));
73 ((SEG
*)result
)->l_ext
= '\0';
74 ((SEG
*)result
)->u_ext
= '\0';
77 boundary RANGE boundary
{
78 ((SEG
*)result
)->lower
= $1.val
;
79 ((SEG
*)result
)->upper
= $3.val
;
80 if
( ((SEG
*)result
)->lower
> ((SEG
*)result
)->upper
) {
82 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
83 errmsg
("swapped boundaries: %g is greater than %g",
84 ((SEG
*)result
)->lower
, ((SEG
*)result
)->upper
)));
88 ((SEG
*)result
)->l_sigd
= $1.sigd
;
89 ((SEG
*)result
)->u_sigd
= $3.sigd
;
90 ((SEG
*)result
)->l_ext
= ( $1.ext ?
$1.ext
: '\0' );
91 ((SEG
*)result
)->u_ext
= ( $3.ext ?
$3.ext
: '\0' );
95 ((SEG
*)result
)->lower
= $1.val
;
96 ((SEG
*)result
)->upper
= HUGE_VAL
;
97 ((SEG
*)result
)->l_sigd
= $1.sigd
;
98 ((SEG
*)result
)->u_sigd
= 0;
99 ((SEG
*)result
)->l_ext
= ( $1.ext ?
$1.ext
: '\0' );
100 ((SEG
*)result
)->u_ext
= '-';
104 ((SEG
*)result
)->lower
= -HUGE_VAL
;
105 ((SEG
*)result
)->upper
= $2.val
;
106 ((SEG
*)result
)->l_sigd
= 0;
107 ((SEG
*)result
)->u_sigd
= $2.sigd
;
108 ((SEG
*)result
)->l_ext
= '-';
109 ((SEG
*)result
)->u_ext
= ( $2.ext ?
$2.ext
: '\0' );
113 ((SEG
*)result
)->lower
= ((SEG
*)result
)->upper
= $1.val
;
114 ((SEG
*)result
)->l_sigd
= ((SEG
*)result
)->u_sigd
= $1.sigd
;
115 ((SEG
*)result
)->l_ext
= ((SEG
*)result
)->u_ext
= ( $1.ext ?
$1.ext
: '\0' );
121 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
122 float val
= seg_atof
($1);
125 $$.sigd
= significant_digits
($1);
130 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
131 float val
= seg_atof
($2);
134 $$.sigd
= significant_digits
($2);
141 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
142 float val
= seg_atof
($1);
145 $$.sigd
= significant_digits
($1);
154 seg_atof
(char *value
)
158 datum
= DirectFunctionCall1
(float4in
, CStringGetDatum
(value
));
159 return DatumGetFloat4
(datum
);