-
Notifications
You must be signed in to change notification settings - Fork 16
/
sparse.y
183 lines (158 loc) · 4.1 KB
/
sparse.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
%{
#include <stdio.h>
#include <string.h>
#include "postgres.h"
#include "utils/elog.h"
#include "sbuffer.h"
#define YYMALLOC palloc
#define YYFREE pfree
void sphere_yyerror(const char *str)
{
reset_buffer();
elog(ERROR, "parsing: %s", str);
}
static double human2dec(double d, double m, double s)
{
if (m < 0 || m >= 60 || s < 0 || s >= 60)
{
char err[255];
sprintf(err, "minutes or seconds invalid (min:%f sec:%f)", m, s);
sphere_yyerror(err);
return 0;
}
else
{
if (d < 0)
return (-s / 3600.0 - m / 60.0) + d;
else
return (s / 3600.0 + m / 60.0) + d;
}
}
%}
%token HOUR DEG MIN SEC COMMA
%token OPENCIRC CLOSECIRC OPENPOINT CLOSEPOINT
%token OPENARR CLOSEARR
%union {
int i;
double d;
char c[3];
}
%token <i> SIGN
%token <i> INT
%token <d> FLOAT
%token <c> EULERAXIS
%left COMMA
%type <d> number
%type <i> angle_lat
%type <i> angle_lat_us
%type <i> angle_long
%type <i> angle_long_us
%type <i> spherepoint
%type <i> spherepointlist
%type <i> spherepath
%%
commands:
/* empty */
| command
;
command:
spherepoint { set_spheretype( STYPE_POINT ); }
| spherecircle { set_spheretype( STYPE_CIRCLE ); }
| sphereline { set_spheretype( STYPE_LINE ); }
| eulertrans { set_spheretype( STYPE_EULER ); }
| spherepath { set_spheretype( STYPE_PATH ); }
| sphereellipse { set_spheretype( STYPE_ELLIPSE ); }
| spherebox { set_spheretype( STYPE_BOX ); }
;
/* unsigned number */
number :
FLOAT { $$ = $1; }
| INT { $$ = $1; }
;
/* unsigned longitude */
angle_lat_us :
number { $$ = set_angle(0, $1 ); }
| FLOAT DEG { $$ = set_angle(1, human2dec($1, 0, 0) ); }
| INT DEG { $$ = set_angle(1, human2dec($1, 0, 0) ); }
| INT DEG number { $$ = set_angle(1, human2dec($1, $3, 0) ); }
| INT DEG FLOAT MIN { $$ = set_angle(1, human2dec($1, $3, 0) ); }
| INT DEG INT MIN { $$ = set_angle(1, human2dec($1, $3, 0) ); }
| INT DEG INT MIN number { $$ = set_angle(1, human2dec($1, $3, $5) ); }
| INT DEG INT MIN number SEC { $$ = set_angle(1, human2dec($1, $3, $5) ); }
;
/* unsigned latitude */
angle_long_us :
number { $$ = set_angle(0, $1); }
| FLOAT DEG { $$ = set_angle(1, human2dec($1, 0, 0)); }
| INT DEG { $$ = set_angle(1, human2dec($1, 0, 0)); }
| INT DEG number { $$ = set_angle(1, human2dec($1, $3, 0)); }
| INT DEG FLOAT MIN { $$ = set_angle(1, human2dec($1, $3, 0)); }
| INT DEG INT MIN { $$ = set_angle(1, human2dec($1, $3, 0)); }
| INT DEG INT MIN number { $$ = set_angle(1, human2dec($1, $3, $5)); }
| INT DEG INT MIN number SEC { $$ = set_angle(1, human2dec($1, $3, $5)); }
| INT HOUR number { $$ = set_angle(1, 15 * human2dec($1, $3, 0)); }
| INT HOUR INT MIN number { $$ = set_angle(1, 15 * human2dec($1, $3, $5)); }
| INT HOUR INT MIN number SEC { $$ = set_angle(1, 15 * human2dec($1, $3, $5)); }
;
/* longitude */
angle_long :
angle_long_us { $$ = set_angle_sign($1, 1); }
| SIGN angle_long_us { $$ = set_angle_sign($2, $1); }
;
/* latitude */
angle_lat :
angle_lat_us { $$ = set_angle_sign($1, 1); }
| SIGN angle_lat_us { $$ = set_angle_sign($2, $1); }
;
/* spherical point */
spherepoint:
OPENPOINT angle_long COMMA angle_lat CLOSEPOINT
{
$$ = set_point($2, $4);
}
;
/* spherical circle */
spherecircle:
OPENCIRC spherepoint COMMA angle_lat_us CLOSECIRC
{
set_circle($2, $4);
}
;
/* Euler transformation */
eulertrans :
angle_long COMMA angle_long COMMA angle_long
{
set_euler($1, $3, $5, "ZXZ");
}
| angle_long COMMA angle_long COMMA angle_long COMMA EULERAXIS
{
set_euler($1, $3, $5, $7);
}
;
/* spherical line */
sphereline :
OPENPOINT eulertrans CLOSEPOINT COMMA angle_long_us
{
set_line ($5);
}
;
/* Path and polygons */
spherepointlist :
spherepoint COMMA
| spherepointlist spherepoint COMMA
;
spherepath :
OPENARR spherepointlist spherepoint CLOSEARR { }
;
/* ellipses */
sphereellipse:
OPENCIRC OPENARR angle_lat_us COMMA angle_lat_us CLOSEARR COMMA spherepoint COMMA angle_lat CLOSECIRC
{
set_ellipse($3, $5, $8, $10);
}
;
/* boxes */
spherebox:
OPENPOINT spherepoint COMMA spherepoint CLOSEPOINT { }
| spherepoint COMMA spherepoint { }
;