summaryrefslogtreecommitdiffstats
path: root/fitsy/enviparser.Y
blob: d7256ffd0a75cac59a0df0de866590113d9e1904 (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
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

%pure-parser
%parse-param {FitsFile* envi}
%lex-param {enviFlexLexer* ll}
%parse-param {enviFlexLexer* ll}

%{
#define YYDEBUG 1

#define DISCARD_(x) {yyclearin; enviDiscard(x);}

#include "file.h"

#undef yyFlexLexer
#define yyFlexLexer enviFlexLexer
#include <FlexLexer.h>

extern int envilex(void*, enviFlexLexer*);
extern void envierror(FitsFile*, enviFlexLexer*, const char*);
extern void enviDiscard(int);

static int numWave;
static float wave[MAXWAVES];

%}

%union {
#define ENVIPARSERSIZE 1024
  float real;
  int integer;
  char str[ENVIPARSERSIZE];
}

%type <real> numeric

 // Basic
%token EOF_
%token <integer> INT
%token <real> REAL
%token <str> STRING

%token DEBUG_
%token ON_
%token OFF_

%token AVERAGE_
%token BAND_
%token BANDS_
%token BBL_
%token BIL_
%token BIP_
%token BSQ_
%token BYTE_
%token DATA_
%token DEFAULT_
%token DESCRIPTION_
%token ENVI_
%token FACTOR_
%token FRAME_
%token FILE_
%token FWHM_
%token GAIN_
%token HEADER_
%token INFO_
%token IGNORE_
%token INTERLEAVE_
%token LIMITS_
%token LINES_
%token MAJOR_
%token MAP_
%token MINOR_
%token NAMES_
%token OFFSET_
%token OFFSETS_
%token ORDER_
%token PIXEL_
%token PIXELS_
%token PLOT_
%token PROJECTION_
%token RANGE_
%token REFLECTANCE_
%token SAMPLES_
%token SCALE_
%token SCANNER_
%token SENSOR_
%token SIZE_
%token START_
%token STRETCH_
%token TITLES_
%token TYPE_
%token UNITS_
%token VALUE_
%token VALUES_
%token WAVELENGTH_

%%

 //start	: {yydebug=1;} commands
 start	: {envi->setpArch(FitsFile::BIG)} commands

commands: commands command terminator
	| command terminator
	;

command : /* empty */
	| DEBUG_ debug
	| comment
	| ENVI_
	| DESCRIPTION_ '=' liststr
	| SAMPLES_ '=' INT {envi->setpWidth($3);}
	| LINES_ '=' INT {envi->setpHeight($3);}
	| BANDS_ '=' INT {envi->setpDepth($3);}
        | HEADER_ OFFSET_ '=' INT {envi->setpSkip($4);}
        | MAJOR_ FRAME_ OFFSETS_ '=' listint
        | MINOR_ FRAME_ OFFSETS_ '=' listint
	| FILE_ TYPE_ '=' {DISCARD_(1)} STRING
	| DATA_ TYPE_ '=' bitpix
	| INTERLEAVE_ '=' encoding
	| SENSOR_ TYPE_ '=' {DISCARD_(1)} STRING
	| BYTE_ ORDER_ '=' endian
	| 'X' START_ '=' listint
	| 'Y' START_ '=' listint
	| MAP_ INFO_ '=' listmap
	| PROJECTION_ INFO_ '=' liststr
	| DEFAULT_ BANDS_ '=' listint
	| WAVELENGTH_ UNITS_ '=' STRING
	| REFLECTANCE_ SCALE_ FACTOR_ '=' numeric
	| 'Z' PLOT_ RANGE_ '=' listnum
	| 'Z' PLOT_ AVERAGE_ '=' listnum
	| 'Z' PLOT_ TITLES_ '=' liststr
	| DATA_ IGNORE_ VALUES_ '=' {DISCARD_(1)} STRING
	| PIXEL_ SIZE_ '=' listnum
	| BAND_ NAMES_ '=' liststr
	| WAVELENGTH_ '=' {numWave=0;} listwave
	| FWHM_ '=' liststr
	| BBL_ '=' liststr
	| DATA_ GAIN_ VALUES_ '=' listnum
	| DATA_ OFFSET_ VALUES_ '=' listnum
	| SCANNER_ LIMITS_ '(' PIXELS_ ')' '=' INT INT
	;

comment : ';' {DISCARD_(1)} STRING
	;

terminator: '\n'
	| EOF_ {YYACCEPT;}
	;

numeric	: REAL {$$=$1;}
	| INT {$$=$1;}
	;

debug	: ON_ {yydebug=1;}
	| OFF_ {yydebug=0;}
	;

bitpix  : INT
        {
	  switch($1) {
	  case 1:
	    {envi->setpBitpix(8);}
	    break;
	  case 2:
	    {envi->setpBitpix(16);}
	    break;
	  case 12:
	    {envi->setpBitpix(-16);}
	    break;
	  case 3:
	    {envi->setpBitpix(32);}
	    break;
	  case 14:
	    {envi->setpBitpix(64);}
	    break;
	  case 4:
	    {envi->setpBitpix(-32);}
	    break;
	  case 5:
	    {envi->setpBitpix(-64);}
	    break;
	  default:
	    break;
	  }
	}
        ;

encoding : BSQ_ {envi->setpEncoding(FitsFile::BSQ);}
        | BIP_ {envi->setpEncoding(FitsFile::BIP);}
        | BIL_ {envi->setpEncoding(FitsFile::BIL);}
        ;

endian  : INT
        {
	  switch($1) {
	  case 0:
	    {envi->setpArch(FitsFile::LITTLE);}
	    break;
	  case 1:
	    {envi->setpArch(FitsFile::BIG);}
	    break;
	  }
	}
        ;

liststr : '{' '}'
        | '{' strings '}'
        ;

strings : strings STRING
	| STRING
        ;

listnum : '{' numerics '}'
        ;

numerics: numerics ',' numeric
        | numeric
        ;

listint : '{' ints '}'
        ;

ints    : ints ',' INT
        | INT
        ;

listmap : '{' STRING ',' INT ',' INT ',' numeric ',' numeric ',' numeric ',' numeric ',' INT listmapopt '}'
        ;

listmapopt : /* empty */
        | ',' STRING ',' STRING
        | ',' STRING
        ;

listwave: '{' '}'
        {
	  envi->setpCRPIX3(1);
	  envi->setpCRVAL3(1);
	  envi->setpCDELT3(1);
	}
        | '{' aWaves '}'
        {
	  if (numWave>=2) {
	    envi->setpCRPIX3(1);
	    envi->setpCRVAL3(wave[0]);
	    envi->setpCDELT3((wave[numWave-1]-wave[0])/(numWave-1));
	  }
	  else {
	    envi->setpCRPIX3(1);
	    envi->setpCRVAL3(1);
	    envi->setpCDELT3(1);
	  }
	}
        ;

aWaves  : aWaves ',' aWave
        | aWaves ','
        | aWave
        ;

aWave   : numeric
        {
	  if (numWave < MAXWAVES)
	    wave[numWave++] = $1;
	}
        ;

%%