2000-12-12 04:40:33 +08:00
|
|
|
%{
|
|
|
|
#define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
|
|
|
|
|
2002-07-31 01:32:10 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2000-12-12 04:40:33 +08:00
|
|
|
#include <math.h>
|
2002-07-31 01:32:10 +08:00
|
|
|
|
2004-10-25 05:47:07 +08:00
|
|
|
#include "fmgr.h"
|
|
|
|
#include "utils/builtins.h"
|
2002-07-31 01:32:10 +08:00
|
|
|
#include "segdata.h"
|
2001-06-19 05:38:02 +08:00
|
|
|
|
2008-09-03 04:37:55 +08:00
|
|
|
/*
|
|
|
|
* Bison doesn't allocate anything that needs to live across parser calls,
|
|
|
|
* so we can easily have it use palloc instead of malloc. This prevents
|
|
|
|
* memory leaks if we error out during parsing. Note this only works with
|
|
|
|
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
|
|
|
|
* if possible, so there's not really much problem anyhow, at least if
|
|
|
|
* you're building with gcc.
|
|
|
|
*/
|
|
|
|
#define YYMALLOC palloc
|
|
|
|
#define YYFREE pfree
|
|
|
|
|
2006-03-07 09:03:12 +08:00
|
|
|
extern int seg_yylex(void);
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2006-06-01 10:39:59 +08:00
|
|
|
extern int significant_digits(char *str); /* defined in seg.c */
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2003-09-14 10:18:49 +08:00
|
|
|
void seg_yyerror(const char *message);
|
2006-03-07 09:03:12 +08:00
|
|
|
int seg_yyparse(void *result);
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2006-06-01 10:39:59 +08:00
|
|
|
static float seg_atof(char *value);
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2006-06-01 10:39:59 +08:00
|
|
|
static char strbuf[25] = {
|
2000-12-12 04:40:33 +08:00
|
|
|
'0', '0', '0', '0', '0',
|
|
|
|
'0', '0', '0', '0', '0',
|
|
|
|
'0', '0', '0', '0', '0',
|
|
|
|
'0', '0', '0', '0', '0',
|
|
|
|
'0', '0', '0', '0', '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
/* BISON Declarations */
|
2008-11-26 16:45:12 +08:00
|
|
|
%expect 0
|
2006-03-07 09:03:12 +08:00
|
|
|
%name-prefix="seg_yy"
|
|
|
|
|
2000-12-12 04:40:33 +08:00
|
|
|
%union {
|
|
|
|
struct BND {
|
|
|
|
float val;
|
|
|
|
char ext;
|
|
|
|
char sigd;
|
|
|
|
} bnd;
|
|
|
|
char * text;
|
|
|
|
}
|
2004-09-14 12:21:38 +08:00
|
|
|
%token <text> SEGFLOAT
|
2000-12-12 04:40:33 +08:00
|
|
|
%token <text> RANGE
|
|
|
|
%token <text> PLUMIN
|
|
|
|
%token <text> EXTENSION
|
|
|
|
%type <bnd> boundary
|
|
|
|
%type <bnd> deviation
|
|
|
|
%start range
|
|
|
|
|
|
|
|
/* Grammar follows */
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
range:
|
|
|
|
boundary PLUMIN deviation {
|
|
|
|
((SEG *)result)->lower = $1.val - $3.val;
|
|
|
|
((SEG *)result)->upper = $1.val + $3.val;
|
|
|
|
sprintf(strbuf, "%g", ((SEG *)result)->lower);
|
2002-07-31 01:32:10 +08:00
|
|
|
((SEG *)result)->l_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
|
2000-12-12 04:40:33 +08:00
|
|
|
sprintf(strbuf, "%g", ((SEG *)result)->upper);
|
2002-07-31 01:32:10 +08:00
|
|
|
((SEG *)result)->u_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
|
2000-12-12 04:40:33 +08:00
|
|
|
((SEG *)result)->l_ext = '\0';
|
|
|
|
((SEG *)result)->u_ext = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
boundary RANGE boundary {
|
|
|
|
((SEG *)result)->lower = $1.val;
|
|
|
|
((SEG *)result)->upper = $3.val;
|
|
|
|
if ( ((SEG *)result)->lower > ((SEG *)result)->upper ) {
|
2003-07-25 01:52:50 +08:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("swapped boundaries: %g is greater than %g",
|
|
|
|
((SEG *)result)->lower, ((SEG *)result)->upper)));
|
|
|
|
|
2000-12-12 04:40:33 +08:00
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
((SEG *)result)->l_sigd = $1.sigd;
|
|
|
|
((SEG *)result)->u_sigd = $3.sigd;
|
|
|
|
((SEG *)result)->l_ext = ( $1.ext ? $1.ext : '\0' );
|
|
|
|
((SEG *)result)->u_ext = ( $3.ext ? $3.ext : '\0' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
boundary RANGE {
|
|
|
|
((SEG *)result)->lower = $1.val;
|
2004-03-15 11:29:22 +08:00
|
|
|
((SEG *)result)->upper = HUGE_VAL;
|
2000-12-12 04:40:33 +08:00
|
|
|
((SEG *)result)->l_sigd = $1.sigd;
|
|
|
|
((SEG *)result)->u_sigd = 0;
|
|
|
|
((SEG *)result)->l_ext = ( $1.ext ? $1.ext : '\0' );
|
|
|
|
((SEG *)result)->u_ext = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
RANGE boundary {
|
2004-03-15 11:29:22 +08:00
|
|
|
((SEG *)result)->lower = -HUGE_VAL;
|
2000-12-12 04:40:33 +08:00
|
|
|
((SEG *)result)->upper = $2.val;
|
|
|
|
((SEG *)result)->l_sigd = 0;
|
|
|
|
((SEG *)result)->u_sigd = $2.sigd;
|
|
|
|
((SEG *)result)->l_ext = '-';
|
|
|
|
((SEG *)result)->u_ext = ( $2.ext ? $2.ext : '\0' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
boundary {
|
|
|
|
((SEG *)result)->lower = ((SEG *)result)->upper = $1.val;
|
|
|
|
((SEG *)result)->l_sigd = ((SEG *)result)->u_sigd = $1.sigd;
|
|
|
|
((SEG *)result)->l_ext = ((SEG *)result)->u_ext = ( $1.ext ? $1.ext : '\0' );
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
boundary:
|
2004-09-14 12:21:38 +08:00
|
|
|
SEGFLOAT {
|
2006-06-01 10:39:59 +08:00
|
|
|
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
|
|
|
|
float val = seg_atof($1);
|
|
|
|
|
|
|
|
$$.ext = '\0';
|
|
|
|
$$.sigd = significant_digits($1);
|
|
|
|
$$.val = val;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
2004-09-14 12:21:38 +08:00
|
|
|
EXTENSION SEGFLOAT {
|
2006-06-01 10:39:59 +08:00
|
|
|
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
|
|
|
|
float val = seg_atof($2);
|
|
|
|
|
|
|
|
$$.ext = $1[0];
|
|
|
|
$$.sigd = significant_digits($2);
|
|
|
|
$$.val = val;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
deviation:
|
2004-09-14 12:21:38 +08:00
|
|
|
SEGFLOAT {
|
2006-06-01 10:39:59 +08:00
|
|
|
/* temp variable avoids a gcc 3.3.x bug on Sparc64 */
|
|
|
|
float val = seg_atof($1);
|
|
|
|
|
|
|
|
$$.ext = '\0';
|
|
|
|
$$.sigd = significant_digits($1);
|
|
|
|
$$.val = val;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
2006-06-01 10:39:59 +08:00
|
|
|
static float
|
2004-10-25 05:47:07 +08:00
|
|
|
seg_atof(char *value)
|
|
|
|
{
|
|
|
|
Datum datum;
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2004-10-25 05:47:07 +08:00
|
|
|
datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
|
|
|
|
return DatumGetFloat4(datum);
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-02 06:52:34 +08:00
|
|
|
#include "segscan.c"
|