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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
%pure-parser
%parse-param {Base* fr}
%lex-param {saoFlexLexer* ll}
%parse-param {saoFlexLexer* ll}
%{
#define YYDEBUG 1
#define FITSPTR (fr->findFits())
#define DISCARD_(x) {yyclearin; saoDiscard(x);}
#include <math.h>
#include <string.h>
#include <iostream>
#include "base.h"
#include "fitsimage.h"
#include "basemarker.h"
#undef yyFlexLexer
#define yyFlexLexer saoFlexLexer
#include <FlexLexer.h>
extern int saolex(void*, saoFlexLexer*);
extern void saoerror(Base*, saoFlexLexer*, const char*);
extern void saoDiscard(int);
static unsigned short globalProps;
static unsigned short localProps;
static const char *color = "green";
static int dash[] = {8,3};
static int fill_ =0;
static const char *font = "helvetica 10 normal roman";
static const char *text = "";
static char localComment[80];
static List<Vertex> polylist;
static List<Tag> taglist;
static List<CallBack> cblist;
static double aAnnuli[MAXANNULI];
static Vector aVector[MAXANNULI];
static int aNum;
static int aStatus;
static Vector aCenter;
static double aAngle;
static unsigned short aProps;
static char aComment[80];
static void setProps(unsigned short* props, unsigned short prop, int value);
%}
%union {
#define SAOBUFSIZE 2048
double real;
int integer;
char str[SAOBUFSIZE];
double vector[3];
}
%type <real> numeric
%type <real> angle
%type <real> optangle
%type <real> value
%type <vector> vvalue
%type <vector> coord
%type <integer> numberof
%token <integer> INT
%token <real> REAL
%token <str> STRING
%token EOF_
%token ANNULUS_
%token BOX_
%token CIRCLE_
%token DEBUG_
%token ELLIPSE_
%token N_
%token OFF_
%token ON_
%token POINT_
%token POLYGON_
%token ROTBOX_
%token VERSION_
%%
start : initGlobal commands processAnnulus
;
commands: commands command terminator
| command terminator
;
command : /* empty */
| DEBUG_ debug
| VERSION_ {cerr << "SAOimage" << endl;}
| initLocal include shape
| generalComment
;
terminator: '\n'
| ';'
| EOF_ {YYACCEPT;}
;
numeric : REAL {$$=$1;}
| INT {$$=$1;}
;
debug : ON_ {yydebug=1;}
| OFF_ {yydebug=0;}
;
sp : /* empty */
| ','
;
bp : /* empty */
| '('
;
ep : /* emtpy */
| ')'
;
optangle: /* empty */ {$$ = 0;}
| angle {$$ = $1;}
;
angle : numeric {$$ = degToRad($1);} /* assume degree */
;
value : numeric {$$ = FITSPTR->mapLenToRef($1, Coord::IMAGE);}
;
vvalue : numeric sp numeric
{
Vector r = FITSPTR->mapLenToRef(Vector($1,$3), Coord::IMAGE);
$$[0] = r[0];
$$[1] = r[1];
$$[2] = r[2];
}
;
numberof: N_ '=' INT {$$ = $3;}
;
coord : numeric sp numeric
{
Vector r = FITSPTR->mapToRef(Vector($1,$3), Coord::IMAGE);
$$[0] = r[0];
$$[1] = r[1];
$$[2] = r[2];
}
;
initGlobal:{
globalProps =
Marker::SELECT | Marker::EDIT | Marker::MOVE |
Marker::ROTATE | Marker::DELETE | Marker::HIGHLITE |
Marker::INCLUDE | Marker::SOURCE;
}
;
initLocal : {
// reset maperr flag
maperr =0;
localProps = globalProps;
}
;
include : /* empty */ {setProps(&localProps, Marker::INCLUDE, 1);}
| '+' {setProps(&localProps, Marker::INCLUDE, 1);}
| '-' {setProps(&localProps, Marker::INCLUDE, 0);}
;
shape : CIRCLE_ bp coord sp value ep shapeComment
{fr->createCircleCmd(Vector($3), $5, fill_,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
| ANNULUS_ bp coord sp value sp value ep shapeComment
{fr->createAnnulusCmd(Vector($3),
$5,$7,1,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
| ANNULUS_ bp coord sp value sp value sp {aNum=2;} aRads ep
shapeComment
{
aAnnuli[0] = $5;
aAnnuli[1] = $7;
fr->createAnnulusCmd(Vector($3),
aNum,aAnnuli,
color,dash,1,font,text,localProps,localComment,taglist,cblist);
}
| ANNULUS_ bp coord sp value sp value sp numberof ep shapeComment
{fr->createAnnulusCmd(Vector($3),
$5,$7,$9,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
| ELLIPSE_ bp coord sp vvalue sp optangle ep shapeComment
{
// for ellipse annulus
aStatus = 1;
aCenter = Vector($3);
aAngle = $7;
aVector[0] = Vector($5);
aNum = 1;
strncpy(aComment,localComment,80);
aProps = localProps;
fr->createEllipseCmd(Vector($3), Vector($5), $7, fill_,
color,dash,1,font,text,localProps,localComment,taglist,cblist);
}
| ELLIPSE_ bp coord sp vvalue sp optangle ep '&' '!'
ELLIPSE_ bp coord sp vvalue sp optangle ep
{
aStatus = 2;
aVector[aNum++] = Vector($5);
}
| BOX_ bp coord sp vvalue sp optangle ep shapeComment
{
// for box annulus
aStatus = 3;
aCenter = Vector($3);
aAngle = $7;
aVector[0] = Vector($5);
aNum = 1;
strncpy(aComment,localComment,80);
aProps = localProps;
fr->createBoxCmd(Vector($3), Vector($5), $7, fill_,
color,dash,1,font,text,localProps,localComment,taglist,cblist);
}
| ROTBOX_ bp coord sp vvalue sp optangle ep shapeComment
{fr->createBoxCmd(Vector($3), Vector($5), $7, fill_,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
| BOX_ bp coord sp vvalue sp optangle ep '&' '!'
BOX_ bp coord sp vvalue sp optangle ep
{
aStatus = 4;
aVector[aNum++] = Vector($5);
}
| POINT_ bp coord ep shapeComment
{fr->createPointCmd(Vector($3), Point::BOXCIRCLE, POINTSIZE,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
| POLYGON_ {polylist.deleteAll();} bp polyNodes ep shapeComment
{fr->createPolygonCmd(polylist, fill_,
color,dash,1,font,text,localProps,localComment,taglist,cblist);}
;
polyNodes : polyNodes sp polyNode
| polyNode
;
polyNode : coord {polylist.append(new Vertex($1));}
;
aRads : aRads sp aRad
| aRad
;
aRad : value {aAnnuli[aNum++] = $1;}
;
processAnnulus : /* empty */
{
switch (aStatus) {
case 0: // do nothing
break;
case 1: // we found just an ellipse, do nothing
break;
case 2: // ok we have an ellipse annulus
fr->markerDeleteLastCmd(); // delete the previous ellipse
fr->createEllipseAnnulusCmd(aCenter,
aNum,aVector,
aAngle,
color,dash,1,font,text,aProps,aComment,taglist,cblist);
break;
case 3: // we found just a box, do nothing
break;
case 4: // ok, we have a box annulus
fr->markerDeleteLastCmd(); // delete the previous box
fr->createBoxAnnulusCmd(aCenter,
aNum,aVector,
aAngle,
color,dash,1,font,text,aProps,aComment,taglist,cblist);
break;
}
aStatus = 0;
}
;
generalComment : '#' {DISCARD_(1);} STRING
;
shapeComment : /* empty */ processAnnulus
| '#' {DISCARD_(0);} STRING processAnnulus
{strncpy(localComment,$3,80);}
;
%%
static void setProps(unsigned short* props, unsigned short prop, int value)
{
if (value)
*props |= prop;
else
*props &= ~prop;
}
|