blob: ff8a82a9db328c200de29fe09028aabc8988ecc5 (
plain)
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
%pure-parser
%parse-param {FitsFile* nrrd}
%lex-param {nrrdFlexLexer* ll}
%parse-param {nrrdFlexLexer* ll}
%{
#define YYDEBUG 1
#define DISCARD_(x) {yyclearin; nrrdDiscard(x);}
#include "file.h"
#undef yyFlexLexer
#define yyFlexLexer nrrdFlexLexer
#include <FlexLexer.h>
extern int nrrdlex(void*, nrrdFlexLexer*);
extern void nrrderror(FitsFile*, nrrdFlexLexer*, const char*);
extern void nrrdDiscard(int);
int dim;
%}
%union {
#define NRRDPARSERSIZE 256
float real;
int integer;
char str[NRRDPARSERSIZE];
}
%type <real> numeric
// Basic
%token EOF_
%token <integer> INT
%token <real> REAL
%token <str> STRING
%token DEBUG_
%token ON_
%token OFF_
// Magic
%token NRRD0001_
%token NRRD0002_
%token NRRD0003_
%token NRRD0004_
%token NRRD0005_
// 3. Headers
%token DATA_
%token FILE_
// 4. Space
%token SPACE_
%token UNITS_
%token DIMENSIONS_
%token ORIGIN_
%token DIRECTIONS_
// 5.1 Dimension
%token DIMENSION_
// 5.2 Type
%token TYPE_
%token SIGNED_
%token UNSIGNED_
%token CHAR_
%token INT8_
%token INT8_T_
%token UCHAR_
%token UINT8_
%token UINT8_T_
%token SHORT_
%token INT_
%token INT16_
%token INT16_T_
%token USHORT_
%token UINT16_
%token UINT16_T_
%token INT32_
%token INT32_T_
%token UINT_
%token UINT32_
%token UINT32_T_
%token LONG_
%token LONGLONG_
%token INT64_
%token INT64_T_
%token ULONGLONG_
%token UINT64_
%token UINT64_T_
%token FLOAT_
%token DOUBLE_
// 5.3 Block
%token BLOCK_
%token SIZE_
%token BLOCKSIZE_
// 5.4 ENCODING
%token ENCODING_
%token RAW_
%token TXT_
%token TEXT_
%token ASCII_
%token HEX_
%token GZ_
%token GZIP_
%token BZ2_
%token BZIP2_
// 5.5 Endian
%token ENDIAN_
%token BIG_
%token LITTLE_
// 5.6 Content
%token CONTENT_
// 5.7 MinMax
%token OLD_
%token MIN_
%token OLDMIN_
%token MAX_
%token OLDMAX_
// 5.8 Skip
%token SKIP_
%token LINE_
%token LINESKIP_
%token BYTE_
%token BYTESKIP_
// 5.9 Number
%token NUMBER_
// 5.10 Sample
%token SAMPLE_
%token SAMPLEUNITS_
// 6 Per Axis
%token SIZES_
%token SPACINGS_
%token THICKNESSES_
%token AXIS_
%token MINS_
%token AXISMINS_
%token MAXS_
%token AXISMAXS_
%token CENTERS_
%token CENTERINGS_
%token CELL_
%token NODE_
%token NONE_
%token LABELS_
%token KINDS_
%token DOMAINS_
%%
start : {dim=0; nrrd->setpArch(FitsFile::BIG);} commands
;
commands: commands command terminator
| command terminator
;
command : /* empty */
| DEBUG_ debug
| magic
| comment
| DATA_ FILE_ ':' STRING
| SPACE_ space
| DIMENSION_ ':' INT
| TYPE_ ':' type
| block
| ENCODING_ ':' encoding
| ENDIAN_ ':' endian
| CONTENT_ ':' {DISCARD_(1)} STRING
| MIN_ ':' numeric
| MAX_ ':' numeric
| oldmin
| oldmax
| lineskip
| byteskip
| NUMBER_ ':' STRING
| SIZES_ ':' sizes
| SPACINGS_ ':' spacings
| THICKNESSES_ ':' thicknesses
| AXIS_ MINS_ ':' axismins
| AXISMINS_ ':' axismins
| AXIS_ MAXS_ ':' axismaxs
| AXISMAXS_ ':' axismaxs
| CENTERS_ ':' centers
| CENTERINGS_ ':' centers
| LABELS_ ':' labels
| UNITS_ ':' units
| KINDS_ ':' kinds
;
magic : NRRD0001_
| NRRD0002_
| NRRD0003_
| NRRD0004_
| NRRD0005_
;
comment : '#' {DISCARD_(1)} STRING
;
terminator: '\n'
| EOF_ {YYACCEPT;}
;
numeric : REAL {$$=$1;}
| INT {$$=$1;}
;
debug : ON_ {yydebug=1;}
| OFF_ {yydebug=0;}
;
space : ':' {DISCARD_(1)} STRING
| DIMENSION_ ':' INT
| UNITS_ ':' {DISCARD_(1)} STRING
| ORIGIN_ ':' {DISCARD_(1)} STRING
| DIRECTIONS_ ':' {DISCARD_(1)} STRING
;
type : char {nrrd->setpBitpix(8);}
| uchar {nrrd->setpBitpix(8);}
| short {nrrd->setpBitpix(16);}
| ushort {nrrd->setpBitpix(16);}
| int {nrrd->setpBitpix(32);}
| uint {nrrd->setpBitpix(32);}
| long {nrrd->setpBitpix(64);}
| ulong {nrrd->setpBitpix(64);}
| FLOAT_ {nrrd->setpBitpix(-32);}
| DOUBLE_ {nrrd->setpBitpix(-64);}
| BLOCK_
;
char : CHAR_
| SIGNED_ CHAR_
| INT8_
| INT8_T_
;
uchar : UCHAR_
| UNSIGNED_ CHAR_
| UINT8_
| UINT8_T_
;
short : SHORT_
| SHORT_ INT_
| SIGNED_ SHORT_
| SIGNED_ SHORT_ INT_
| INT16_
| INT16_T_
;
ushort : USHORT_
| UNSIGNED_ SHORT_
| UNSIGNED_ SHORT_ INT_
| UINT16_
| UINT16_T_
;
int : INT_
| SIGNED_ INT_
| INT32_
| INT32_T_
;
uint : UINT_
| UNSIGNED_ INT_
| UINT32_
| UINT32_T_
;
long : LONGLONG_
| LONG_ LONG_
| LONG_ LONG_ INT_
| SIGNED_ LONG_ LONG_
| SIGNED_ LONG_ LONG_ INT_
| INT64_
| INT64_T_
;
ulong : ULONGLONG_
| UNSIGNED_ LONG_ LONG_
| UNSIGNED_ LONG_ LONG_ INT_
| UINT64_
| UINT64_T_
;
block : BLOCK_ SIZE_ ':' INT
| BLOCKSIZE_ ':' INT
;
encoding : RAW_ {nrrd->setpEncoding(FitsFile::RAW);}
| TXT_ {nrrd->setpEncoding(FitsFile::ASCII);}
| TEXT_ {nrrd->setpEncoding(FitsFile::ASCII);}
| ASCII_ {nrrd->setpEncoding(FitsFile::ASCII);}
| HEX_ {nrrd->setpEncoding(FitsFile::HEX);}
| GZ_ {nrrd->setpEncoding(FitsFile::GZIP);}
| GZIP_ {nrrd->setpEncoding(FitsFile::GZIP);}
| BZ2_ {nrrd->setpEncoding(FitsFile::BZ2);}
| BZIP2_ {nrrd->setpEncoding(FitsFile::BZ2);}
;
endian : BIG_ {nrrd->setpArch(FitsFile::BIG);}
| LITTLE_ {nrrd->setpArch(FitsFile::LITTLE);}
;
oldmin : OLD_ MIN_ ':' numeric
| OLDMIN_ ':' numeric
;
oldmax : OLD_ MAX_ ':' numeric
| OLDMAX_ ':' numeric
;
lineskip : LINE_ SKIP_ ':' INT
| LINESKIP_ ':' INT
;
byteskip : BYTE_ SKIP_ ':' INT
| BYTESKIP_ ':' INT
;
sizes : sizes size
| size
;
size : INT
{
switch (dim) {
case 0:
nrrd->setpWidth($1);
break;
case 1:
nrrd->setpHeight($1);
break;
case 2:
nrrd->setpDepth($1);
break;
}
dim++;
}
;
spacings : spacings numeric
| numeric
;
thicknesses : thicknesses numeric
| numeric
;
axismins : axismins numeric
| numeric
;
axismaxs : axismaxs numeric
| numeric
;
centers : centers center
| center
;
center : CELL_
| NODE_
| NONE_
;
labels : labels STRING
| STRING
;
units : units STRING
| STRING
;
kinds : kinds STRING
| STRING
;
%%
|