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 */
54 %token
<text
> SEGFLOAT
57 %token
<text
> EXTENSION
67 boundary PLUMIN deviation
{
68 ((SEG
*)result
)->lower
= $1.val
- $3.val
;
69 ((SEG
*)result
)->upper
= $1.val
+ $3.val
;
70 sprintf
(strbuf
, "%g", ((SEG
*)result
)->lower
);
71 ((SEG
*)result
)->l_sigd
= Max
(Min
(6, significant_digits
(strbuf
)), Max
($1.sigd
, $3.sigd
));
72 sprintf
(strbuf
, "%g", ((SEG
*)result
)->upper
);
73 ((SEG
*)result
)->u_sigd
= Max
(Min
(6, significant_digits
(strbuf
)), Max
($1.sigd
, $3.sigd
));
74 ((SEG
*)result
)->l_ext
= '\0';
75 ((SEG
*)result
)->u_ext
= '\0';
78 boundary RANGE boundary
{
79 ((SEG
*)result
)->lower
= $1.val
;
80 ((SEG
*)result
)->upper
= $3.val
;
81 if
( ((SEG
*)result
)->lower
> ((SEG
*)result
)->upper
) {
83 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
84 errmsg
("swapped boundaries: %g is greater than %g",
85 ((SEG
*)result
)->lower
, ((SEG
*)result
)->upper
)));
89 ((SEG
*)result
)->l_sigd
= $1.sigd
;
90 ((SEG
*)result
)->u_sigd
= $3.sigd
;
91 ((SEG
*)result
)->l_ext
= ( $1.ext ?
$1.ext
: '\0' );
92 ((SEG
*)result
)->u_ext
= ( $3.ext ?
$3.ext
: '\0' );
96 ((SEG
*)result
)->lower
= $1.val
;
97 ((SEG
*)result
)->upper
= HUGE_VAL
;
98 ((SEG
*)result
)->l_sigd
= $1.sigd
;
99 ((SEG
*)result
)->u_sigd
= 0;
100 ((SEG
*)result
)->l_ext
= ( $1.ext ?
$1.ext
: '\0' );
101 ((SEG
*)result
)->u_ext
= '-';
105 ((SEG
*)result
)->lower
= -HUGE_VAL
;
106 ((SEG
*)result
)->upper
= $2.val
;
107 ((SEG
*)result
)->l_sigd
= 0;
108 ((SEG
*)result
)->u_sigd
= $2.sigd
;
109 ((SEG
*)result
)->l_ext
= '-';
110 ((SEG
*)result
)->u_ext
= ( $2.ext ?
$2.ext
: '\0' );
114 ((SEG
*)result
)->lower
= ((SEG
*)result
)->upper
= $1.val
;
115 ((SEG
*)result
)->l_sigd
= ((SEG
*)result
)->u_sigd
= $1.sigd
;
116 ((SEG
*)result
)->l_ext
= ((SEG
*)result
)->u_ext
= ( $1.ext ?
$1.ext
: '\0' );
122 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
123 float val
= seg_atof
($1);
126 $$.sigd
= significant_digits
($1);
131 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
132 float val
= seg_atof
($2);
135 $$.sigd
= significant_digits
($2);
142 /* temp variable avoids a gcc 3.3.x bug on Sparc64 */
143 float val
= seg_atof
($1);
146 $$.sigd
= significant_digits
($1);
155 seg_atof
(char *value
)
159 datum
= DirectFunctionCall1
(float4in
, CStringGetDatum
(value
));
160 return DatumGetFloat4
(datum
);