~ubuntu-branches/ubuntu/vivid/libdap/vivid

« back to all changes in this revision

Viewing changes to dds.yy

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-10-17 22:12:11 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131017221211-re1r37k4d6wrtmeq
Tags: 3.12.0-1
* New upstream release.
  - No longer need curl-types-remove.patch 
* Add debian/watch file.
* Fix typo in hardening flags; Change  to =all,-pie ; 
  Use DEB_LDFLAGS_MAINT_APPEND. Closes: #697387.
* Enable parallel build. Closes: #723938.
* Depend on libcurl4-gnutls-dev | libcurl-dev. Closes: #722701.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// -*- mode: c++; c-basic-offset:4 -*-
 
3
 
 
4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
 
5
// Access Protocol.
 
6
 
 
7
// Copyright (c) 2002,2003 OPeNDAP, Inc.
 
8
// Author: James Gallagher <jgallagher@opendap.org>
 
9
//
 
10
// This library is free software; you can redistribute it and/or
 
11
// modify it under the terms of the GNU Lesser General Public
 
12
// License as published by the Free Software Foundation; either
 
13
// version 2.1 of the License, or (at your option) any later version.
 
14
// 
 
15
// This library is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
// Lesser General Public License for more details.
 
19
// 
 
20
// You should have received a copy of the GNU Lesser General Public
 
21
// License along with this library; if not, write to the Free Software
 
22
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
//
 
24
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
 
25
 
 
26
// (c) COPYRIGHT URI/MIT 1994-1999
 
27
// Please read the full copyright statement in the file COPYRIGHT_URI.
 
28
//
 
29
// Authors:
 
30
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
 
31
 
 
32
/*
 
33
   Grammar for the DDS. This grammar can be used with the bison parser
 
34
   generator to build a parser for the DDS. It assumes that a scanner called
 
35
   `ddslex()' exists and returns several token types (see das.tab.h)
 
36
   in addition to several single character token types. The matched lexeme
 
37
   for an ID is stored by the scanner in a global char * `ddslval'.
 
38
   Because the scanner returns a value via this global and because the parser
 
39
   stores ddslval (not the information pointed to), the values of rule
 
40
   components must be stored as they are parsed and used once accumulated at
 
41
   or near the end of a rule. If ddslval returned a value (instead of a
 
42
   pointer to a value) this would not be necessary.
 
43
 
 
44
   jhrg 8/29/94 
 
45
*/
 
46
 
 
47
%code requires {
 
48
 
 
49
#include "config_dap.h"
 
50
 
 
51
#include <cstring>
 
52
#include <cassert>
 
53
#include <iostream>
 
54
#include <stack>
 
55
#include <sstream>
 
56
 
 
57
#include "Byte.h"
 
58
#include "Int16.h"
 
59
#include "UInt16.h"
 
60
#include "Int32.h"
 
61
#include "UInt32.h"
 
62
#include "Float32.h"
 
63
#include "Float64.h"
 
64
#include "Str.h"
 
65
#include "Url.h"
 
66
#include "Array.h"
 
67
#include "Structure.h"
 
68
#include "Sequence.h"
 
69
#include "Grid.h"
 
70
 
 
71
#include "DDS.h"
 
72
#include "Error.h"
 
73
#include "parser.h"
 
74
#include "util.h"
 
75
 
 
76
using namespace std;
 
77
using namespace libdap;
 
78
 
 
79
// These macros are used to access the `arguments' passed to the parser. A
 
80
// pointer to an error object and a pointer to an integer status variable are
 
81
// passed in to the parser within a structure (which itself is passed as a
 
82
// pointer). Note that the ERROR macro explicitly casts OBJ to an ERROR *. 
 
83
// ERROR is no longer used. These parsers now signal problems by throwing
 
84
// exceptions. 5/22/2002 jhrg
 
85
#define DDS_OBJ(arg) ((DDS *)((parser_arg *)(arg))->_object)
 
86
 
 
87
// #define YYPARSE_PARAM arg
 
88
 
 
89
extern int dds_line_num;        /* defined in dds.lex */
 
90
 
 
91
} // code requires
 
92
 
 
93
%code {
 
94
 
 
95
// No global static objects in the dap library! 1/24/2000 jhrg
 
96
static stack<BaseType *> *ctor;
 
97
static BaseType *current;
 
98
static string *id;
 
99
static Part part = nil;         /* Part is defined in BaseType */
 
100
 
 
101
static const char *NO_DDS_MSG =
 
102
"The descriptor object returned from the dataset was null.\n\
 
103
Check that the URL is correct.";
 
104
 
 
105
static const char *BAD_DECLARATION =
 
106
"In the dataset descriptor object: Expected a variable declaration\n\
 
107
(e.g., Int32 i;). Make sure that the variable name is not the name\n\
 
108
of a datatype and that the Array: and Maps: sections of a Grid are\n\
 
109
labeled properly.";
 
110
 
 
111
int ddslex();
 
112
void ddserror(parser_arg *arg, const string &s /*char *s*/);
 
113
void error_exit_cleanup();
 
114
void add_entry(DDS &table, stack<BaseType *> **ctor, BaseType **current, 
 
115
               Part p);
 
116
void invalid_declaration(parser_arg *arg, string semantic_err_msg, 
 
117
                         char *type, char *name);
 
118
 
 
119
} // code
 
120
 
 
121
%require "2.4"
 
122
 
 
123
%parse-param {parser_arg *arg}
 
124
%name-prefix "dds"
 
125
%defines
 
126
%debug
 
127
%verbose
 
128
 
 
129
%expect 52
 
130
 
 
131
%union {
 
132
    bool boolean;
 
133
    char word[ID_MAX];
 
134
}
 
135
 
 
136
%token <word> SCAN_WORD
 
137
%token <word> SCAN_DATASET
 
138
%token <word> SCAN_LIST
 
139
%token <word> SCAN_SEQUENCE
 
140
%token <word> SCAN_STRUCTURE
 
141
%token <word> SCAN_FUNCTION
 
142
%token <word> SCAN_GRID
 
143
%token <word> SCAN_BYTE
 
144
%token <word> SCAN_INT16
 
145
%token <word> SCAN_UINT16
 
146
%token <word> SCAN_INT32
 
147
%token <word> SCAN_UINT32
 
148
%token <word> SCAN_FLOAT32
 
149
%token <word> SCAN_FLOAT64
 
150
%token <word> SCAN_STRING
 
151
%token <word> SCAN_URL 
 
152
 
 
153
%type <boolean> datasets dataset declarations array_decl
 
154
 
 
155
%type <word> declaration base_type structure sequence grid var var_name name
 
156
 
 
157
%%
 
158
 
 
159
start:
 
160
                {
 
161
                    /* On entry to the parser, make the BaseType stack. */
 
162
                    ctor = new stack<BaseType *>;
 
163
                }
 
164
                datasets
 
165
                {
 
166
                    delete ctor; ctor = 0;
 
167
                }
 
168
;
 
169
 
 
170
datasets:       dataset
 
171
                | datasets dataset
 
172
;
 
173
 
 
174
dataset:        SCAN_DATASET '{' declarations '}' name ';'
 
175
                {
 
176
                    $$ = $3 && $5;
 
177
                }
 
178
                | error
 
179
                {
 
180
                    parse_error((parser_arg *)arg, NO_DDS_MSG,
 
181
                                dds_line_num, $<word>1);
 
182
                    error_exit_cleanup();
 
183
                    YYABORT;
 
184
                }
 
185
;
 
186
 
 
187
declarations:   /* empty */
 
188
                {
 
189
                    $$ = true;
 
190
                }
 
191
 
 
192
                | declaration { $$ = true; }
 
193
                | declarations declaration { $$ = true; }
 
194
;
 
195
 
 
196
/* This non-terminal is here only to keep types like `List List Int32' from
 
197
   parsing. DODS does not allow Lists of Lists. Those types make translation
 
198
   to/from arrays too hard. */
 
199
 
 
200
declaration:  base_type var ';' 
 
201
                { 
 
202
                    string smsg;
 
203
                    if (current->check_semantics(smsg)) {
 
204
                        /* BaseType *current_save = current ; */
 
205
                        add_entry(*DDS_OBJ(arg), &ctor, &current, part); 
 
206
                        /* FIX
 
207
                        if( current_save == current )
 
208
                        {
 
209
                            delete current ;
 
210
                            current = 0 ;
 
211
                        }
 
212
                        */
 
213
                    } else {
 
214
                      invalid_declaration((parser_arg *)arg, smsg, $1, $2);
 
215
                      error_exit_cleanup();
 
216
                      YYABORT;
 
217
                    }
 
218
                    strncpy($$,$2,ID_MAX);
 
219
                    $$[ID_MAX-1] = '\0';
 
220
                }
 
221
 
 
222
                | structure  '{' declarations '}' 
 
223
                { 
 
224
                    if( current ) delete current ;
 
225
                    current = ctor->top(); 
 
226
                    ctor->pop();
 
227
                } 
 
228
                var ';' 
 
229
                { 
 
230
                    string smsg;
 
231
                    if (current->check_semantics(smsg))
 
232
                        add_entry(*DDS_OBJ(arg), &ctor, &current, part); 
 
233
                    else {
 
234
                      invalid_declaration((parser_arg *)arg, smsg, $1, $6);
 
235
                      error_exit_cleanup();
 
236
                      YYABORT;
 
237
                    }
 
238
                    strncpy($$,$6,ID_MAX);
 
239
                    $$[ID_MAX-1] = '\0';
 
240
                }
 
241
 
 
242
                | sequence '{' declarations '}' 
 
243
                { 
 
244
                    if( current ) delete current ;
 
245
                    current = ctor->top(); 
 
246
                    ctor->pop();
 
247
                } 
 
248
                var ';' 
 
249
                { 
 
250
                    string smsg;
 
251
                    if (current->check_semantics(smsg))
 
252
                        add_entry(*DDS_OBJ(arg), &ctor, &current, part); 
 
253
                    else {
 
254
                      invalid_declaration((parser_arg *)arg, smsg, $1, $6);
 
255
                      error_exit_cleanup();
 
256
                      YYABORT;
 
257
                    }
 
258
                    strncpy($$,$6,ID_MAX);
 
259
                    $$[ID_MAX-1] = '\0';
 
260
                }
 
261
 
 
262
                | grid '{' SCAN_WORD ':'
 
263
                { 
 
264
                    if (is_keyword(string($3), "array"))
 
265
                        part = array; 
 
266
                    else {
 
267
                        ostringstream msg;
 
268
                        msg << BAD_DECLARATION;
 
269
                        parse_error((parser_arg *)arg, msg.str().c_str(),
 
270
                                    dds_line_num, $3);
 
271
                        YYABORT;
 
272
                    }
 
273
                }
 
274
                declaration SCAN_WORD ':'
 
275
                { 
 
276
                    if (is_keyword(string($7), "maps"))
 
277
                        part = maps; 
 
278
                    else {
 
279
                        ostringstream msg;
 
280
                        msg << BAD_DECLARATION;
 
281
                        parse_error((parser_arg *)arg, msg.str().c_str(),
 
282
                                    dds_line_num, $7);
 
283
                        YYABORT;
 
284
                    }
 
285
                }
 
286
                declarations '}' 
 
287
                {
 
288
                    if( current ) delete current ;
 
289
                    current = ctor->top(); 
 
290
                    ctor->pop();
 
291
                }
 
292
                var ';' 
 
293
                {
 
294
                    string smsg;
 
295
                    if (current->check_semantics(smsg)) {
 
296
                        part = nil; 
 
297
                        add_entry(*DDS_OBJ(arg), &ctor, &current, part); 
 
298
                    }
 
299
                    else {
 
300
                      invalid_declaration((parser_arg *)arg, smsg, $1, $13);
 
301
                      error_exit_cleanup();
 
302
                      YYABORT;
 
303
                    }
 
304
                    strncpy($$,$13,ID_MAX);
 
305
                    $$[ID_MAX-1] = '\0';
 
306
                }
 
307
 
 
308
                | error 
 
309
                {
 
310
                    ostringstream msg;
 
311
                    msg << BAD_DECLARATION;
 
312
                    parse_error((parser_arg *)arg, msg.str().c_str(),
 
313
                                dds_line_num, $<word>1);
 
314
                    YYABORT;
 
315
                }
 
316
;
 
317
 
 
318
 
 
319
structure:      SCAN_STRUCTURE
 
320
                { 
 
321
                    ctor->push(DDS_OBJ(arg)->get_factory()->NewStructure()); 
 
322
                }
 
323
;
 
324
 
 
325
sequence:       SCAN_SEQUENCE 
 
326
                { 
 
327
                    ctor->push(DDS_OBJ(arg)->get_factory()->NewSequence()); 
 
328
                }
 
329
;
 
330
 
 
331
grid:           SCAN_GRID 
 
332
                { 
 
333
                    ctor->push(DDS_OBJ(arg)->get_factory()->NewGrid()); 
 
334
                }
 
335
;
 
336
 
 
337
base_type:      SCAN_BYTE { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewByte(); }
 
338
                | SCAN_INT16 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewInt16(); }
 
339
                | SCAN_UINT16 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewUInt16(); }
 
340
                | SCAN_INT32 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewInt32(); }
 
341
                | SCAN_UINT32 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewUInt32(); }
 
342
                | SCAN_FLOAT32 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewFloat32(); }
 
343
                | SCAN_FLOAT64 { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewFloat64(); }
 
344
                | SCAN_STRING { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewStr(); }
 
345
                | SCAN_URL { if( current ) delete current ;current = DDS_OBJ(arg)->get_factory()->NewUrl(); }
 
346
;
 
347
 
 
348
var:            var_name { current->set_name($1); }
 
349
                | var array_decl
 
350
;
 
351
 
 
352
var_name:       SCAN_WORD | SCAN_BYTE | SCAN_INT16 | SCAN_INT32 | SCAN_UINT16
 
353
                | SCAN_UINT32 | SCAN_FLOAT32 | SCAN_FLOAT64 | SCAN_STRING
 
354
                | SCAN_URL | SCAN_STRUCTURE | SCAN_SEQUENCE | SCAN_GRID
 
355
                | SCAN_LIST
 
356
;
 
357
 
 
358
array_decl:     '[' SCAN_WORD ']'
 
359
                 { 
 
360
                     if (!check_int32($2)) {
 
361
                         string msg = "In the dataset descriptor object:\n";
 
362
                         msg += "Expected an array subscript.\n";
 
363
                         parse_error((parser_arg *)arg, msg.c_str(), 
 
364
                                 dds_line_num, $2);
 
365
                     }
 
366
                     if (current->type() == dods_array_c
 
367
                         && check_int32($2)) {
 
368
                         ((Array *)current)->append_dim(atoi($2));
 
369
                     }
 
370
                     else {
 
371
                         Array *a = DDS_OBJ(arg)->get_factory()->NewArray(); 
 
372
                         a->add_var(current); 
 
373
                         a->append_dim(atoi($2));
 
374
                         if( current ) delete current ;
 
375
                         current = a;
 
376
                     }
 
377
 
 
378
                     $$ = true;
 
379
                 }
 
380
 
 
381
                 | '[' SCAN_WORD 
 
382
                 {
 
383
                     id = new string($2);
 
384
                 } 
 
385
                 '=' SCAN_WORD 
 
386
                 { 
 
387
                     if (!check_int32($5)) {
 
388
                         string msg = "In the dataset descriptor object:\n";
 
389
                         msg += "Expected an array subscript.\n";
 
390
                         parse_error((parser_arg *)arg, msg.c_str(), 
 
391
                                 dds_line_num, $5);
 
392
                         error_exit_cleanup();
 
393
                         YYABORT;
 
394
                     }
 
395
                     if (current->type() == dods_array_c) {
 
396
                         ((Array *)current)->append_dim(atoi($5), *id);
 
397
                     }
 
398
                     else {
 
399
                         Array *a = DDS_OBJ(arg)->get_factory()->NewArray(); 
 
400
                         a->add_var(current); 
 
401
                         a->append_dim(atoi($5), *id);
 
402
                         if( current ) delete current ;
 
403
                         current = a;
 
404
                     }
 
405
 
 
406
                     delete id; id = 0;
 
407
                 }
 
408
                 ']'
 
409
                 {
 
410
                     $$ = true;
 
411
                 }
 
412
 
 
413
                 | error
 
414
                 {
 
415
                     ostringstream msg;
 
416
                     msg << "In the dataset descriptor object:" << endl
 
417
                         << "Expected an array subscript." << endl;
 
418
                     parse_error((parser_arg *)arg, msg.str().c_str(), 
 
419
                                 dds_line_num, $<word>1);
 
420
                     YYABORT;
 
421
                 }
 
422
;
 
423
 
 
424
name:           var_name { (*DDS_OBJ(arg)).set_dataset_name($1); }
 
425
                | SCAN_DATASET { (*DDS_OBJ(arg)).set_dataset_name($1); }
 
426
                | error 
 
427
                {
 
428
                  ostringstream msg;
 
429
                  msg << "Error parsing the dataset name." << endl
 
430
                      << "The name may be missing or may contain an illegal character." << endl;
 
431
                     parse_error((parser_arg *)arg, msg.str().c_str(),
 
432
                                 dds_line_num, $<word>1);
 
433
                     YYABORT;
 
434
                }
 
435
;
 
436
 
 
437
%%
 
438
 
 
439
/* 
 
440
 This function must be defined. However, use the error reporting code in
 
441
 parser-utils.cc.
 
442
 */
 
443
 
 
444
void
 
445
ddserror(parser_arg *, const string &)
 
446
{
 
447
}
 
448
 
 
449
/*
 
450
 Error clean up. Call this before calling YYBORT. Don't call this on a
 
451
 normal exit.
 
452
 */
 
453
 
 
454
void error_exit_cleanup()
 
455
{
 
456
    delete id;
 
457
    id = 0;
 
458
    delete current;
 
459
    current = 0;
 
460
    delete ctor;
 
461
    ctor = 0;
 
462
}
 
463
 
 
464
/*
 
465
 Invalid declaration message.
 
466
 */
 
467
 
 
468
void invalid_declaration(parser_arg *arg, string semantic_err_msg, char *type, char *name)
 
469
{
 
470
    ostringstream msg;
 
471
    msg << "In the dataset descriptor object: `" << type << " " << name << "'" << endl << "is not a valid declaration."
 
472
            << endl << semantic_err_msg;
 
473
    parse_error((parser_arg *) arg, msg.str().c_str(), dds_line_num);
 
474
}
 
475
 
 
476
/*
 
477
 Add the variable pointed to by CURRENT to either the topmost ctor object on
 
478
 the stack CTOR or to the dataset variable table TABLE if CTOR is empty.  If
 
479
 it exists, the current ctor object is popped off the stack and assigned to
 
480
 CURRENT.
 
481
 
 
482
 NB: the ctor stack is popped for arrays because they are ctors which
 
483
 contain only a single variable. For other ctor types, several variables may
 
484
 be members and the parse rule (see `declaration' above) determines when to
 
485
 pop the stack.
 
486
 
 
487
 Returns: void 
 
488
 */
 
489
 
 
490
void add_entry(DDS &table, stack<BaseType *> **ctor, BaseType **current, Part part)
 
491
{
 
492
    if (!*ctor)
 
493
        *ctor = new stack<BaseType *> ;
 
494
 
 
495
    if (!(*ctor)->empty()) { /* must be parsing a ctor type */
 
496
        (*ctor)->top()->add_var(*current, part);
 
497
 
 
498
        const Type &ctor_type = (*ctor)->top()->type();
 
499
 
 
500
        if (ctor_type == dods_array_c) {
 
501
            if (*current)
 
502
                delete *current;
 
503
            *current = (*ctor)->top();
 
504
            (*ctor)->pop();
 
505
 
 
506
            // Return here to avoid deleting the new value of 'current.'
 
507
            return;
 
508
        }
 
509
    }
 
510
    else {
 
511
        table.add_var(*current);
 
512
    }
 
513
 
 
514
    if (*current)
 
515
        delete *current;
 
516
    *current = 0;
 
517
}
 
518