Imported Upstream version 0.4.8
[platform/upstream/libsmi.git] / lib / parser-sming.y
1 /*
2  * parser-sming.y --
3  *
4  *      Syntax rules for parsing the SMIng MIB module language.
5  *
6  * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
7  *
8  * See the file "COPYING" for information on usage and redistribution
9  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10  *
11  * @(#) $Id: parser-sming.y 7966 2008-03-27 21:25:52Z schoenw $
12  */
13
14 %{
15
16 #include <config.h>
17     
18 #ifdef BACKEND_SMING
19
20 #define _ISOC99_SOURCE
21 #include <stdio.h>
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <time.h>
27 #include <limits.h>
28 #include <float.h>
29
30 #if defined(_MSC_VER)
31 #include <malloc.h>
32 #endif
33
34 #ifdef HAVE_WIN_H
35 #include "win.h"
36 #endif
37
38 #include "smi.h"
39 #include "error.h"
40 #include "parser-sming.h"
41 #include "scanner-sming.h"
42 #include "data.h"
43 #include "check.h"
44 #include "util.h"
45     
46 #ifdef HAVE_DMALLOC_H
47 #include <dmalloc.h>
48 #endif
49
50
51 /*
52  * These arguments are passed to yyparse() and yylex().
53  */
54 #define YYPARSE_PARAM parserPtr
55 #define YYLEX_PARAM   parserPtr
56
57     
58     
59 #define thisParserPtr      ((Parser *)parserPtr)
60 #define thisModulePtr     (((Parser *)parserPtr)->modulePtr)
61
62
63     
64 /*
65  * NOTE: The argument lvalp ist not really a void pointer. Unfortunately,
66  * we don't know it better at this point. bison generated C code declares
67  * YYSTYPE just a few lines below based on the `%union' declaration.
68  */
69 extern int yylex(void *lvalp, Parser *parserPtr);
70
71
72
73 static char *typeIdentifier, *macroIdentifier, *identityIdentifier, 
74             *classIdentifier, *attributeIdentifier;
75 static char *importModulename = NULL;
76 static Type *typePtr = NULL;
77 static Macro *macroPtr = NULL;
78 static Identity *identityPtr = NULL;
79 static Class    *classPtr = NULL;
80 static Attribute *attributePtr = NULL;
81 static Event *eventPtr = NULL;
82 static SmiBasetype defaultBasetype = SMI_BASETYPE_UNKNOWN;
83 static NamedNumber *namedNumberPtr = NULL;
84 static int bitsFlag = 0; /* used to differentiate bits definition from enum*/
85 static int attributeFlag = 0; /* 
86                                                            *Used to differentiate between attribute and
87                                                            *and typedef to tie the type statement
88                                                            *respectively to class or module.
89                                                            */
90
91
92 #define SMI_EPOCH       631152000       /* 01 Jan 1990 00:00:00 */ 
93  
94
95 static Type *
96 findType(char *spec, Parser *parserPtr, Module *modulePtr)
97 {
98     Type *typePtr;
99     Import *importPtr;
100     char *module, *type;
101
102     type = strstr(spec, "::");
103     if (!type) {
104         typePtr = findTypeByModuleAndName(modulePtr, spec);
105         if (!typePtr) {
106             importPtr = findImportByName(spec, modulePtr);
107             if (importPtr) {
108                 typePtr = findTypeByModulenameAndName(importPtr->export.module,
109                                                       spec);
110             }
111         }
112     } else {
113         module = strtok(spec, ":");
114         type = &type[2];
115         typePtr = findTypeByModulenameAndName(module, type);
116     }
117     return typePtr;
118 }
119  
120  
121 static Identity *
122 findIdentity(char *spec, Parser *parserPtr, Module *modulePtr)
123 {
124     Identity *identityPtr;
125     Import *importPtr;
126     char *module, *identity;
127
128     identity = strstr(spec, "::");
129     if (!identity) {
130         identityPtr = findIdentityByModuleAndName(modulePtr, spec);
131         if (!identityPtr) {
132             importPtr = findImportByName(spec, modulePtr);
133             if (importPtr) {
134                 identityPtr = findIdentityByModulenameAndName(importPtr->export.module,
135                                                       spec);
136             }
137         }
138     } else {
139         module = strtok(spec, ":");
140         identity = &identity[2];
141         identityPtr = findIdentityByModulenameAndName(module, identity);
142     }
143     return identityPtr;
144 }
145
146 static Class *
147 findClass(char *spec, Parser *parserPtr, Module *modulePtr)
148 {
149     Class *classPtr;
150     Import *importPtr;
151     char *module, *class;
152
153     class = strstr(spec, "::");
154     if (!class) {
155         classPtr = findClassByModuleAndName(modulePtr, spec);
156         if (!classPtr) {
157             importPtr = findImportByName(spec, modulePtr);
158             if (importPtr) {
159                 classPtr = findClassByModulenameAndName(importPtr->export.module,
160                                                       spec);
161             }
162         }
163     } else {
164         module = strtok(spec, ":");
165         class = &class[2];
166         classPtr = findClassByModulenameAndName(module, class);
167     }
168     return classPtr;
169 }
170
171 static void
172 checkTypes(Parser *parserPtr, Module *modulePtr)
173 {
174     Type *typePtr;
175     
176     for(typePtr = modulePtr->firstTypePtr;
177         typePtr; typePtr = typePtr->nextPtr) {
178
179         /*
180          * Complain about empty description clauses.
181          */
182
183         if (! parserPtr->flags & SMI_FLAG_NODESCR
184             && (! typePtr->export.description
185                 || ! typePtr->export.description[0])) {
186             smiPrintErrorAtLine(parserPtr, ERR_EMPTY_DESCRIPTION,
187                                 typePtr->line, typePtr->export.name);
188         }
189         
190         smiCheckNamedNumberRedefinition(parserPtr, typePtr);
191         smiCheckNamedNumberSubtyping(parserPtr, typePtr);
192     }
193 }
194
195
196
197 static time_t
198 checkDate(Parser *parserPtr, char *date)
199 {
200     struct tm   tm;
201     time_t      anytime;
202     int         i, len;
203     char        *p;
204
205     memset(&tm, 0, sizeof(tm));
206     anytime = 0;
207
208     len = strlen(date);
209     if (len == 10 || len == 16) {
210         for (i = 0; i < len; i++) {
211             if (((i < 4 || i == 5 || i == 6 || i == 8 || i == 9 || i == 11
212                   || i == 12 || i == 14 || i == 15) && ! isdigit((int)date[i]))
213                 || ((i == 4 || i == 7) && date[i] != '-')
214                 || (i == 10 && date[i] != ' ')
215                 || (i == 13 && date[i] != ':')) {
216                 smiPrintError(parserPtr, ERR_DATE_CHARACTER, date);
217                 anytime = (time_t) -1;
218                 break;
219             }
220         }
221     } else {
222         smiPrintError(parserPtr, ERR_DATE_LENGTH, date);
223         anytime = (time_t) -1;
224     }
225     
226     if (anytime == 0) {
227         for (i = 0, p = date, tm.tm_year = 0; i < 4; i++, p++) {
228             tm.tm_year = tm.tm_year * 10 + (*p - '0');
229         }
230         p++;
231         tm.tm_mon = (p[0]-'0') * 10 + (p[1]-'0');
232         p += 3;
233         tm.tm_mday = (p[0]-'0') * 10 + (p[1]-'0');
234         p += 2;
235         if (len == 16) {
236             p++;
237             tm.tm_hour = (p[0]-'0') * 10 + (p[1]-'0');
238             p += 3;
239             tm.tm_min = (p[0]-'0') * 10 + (p[1]-'0');
240         }
241         
242         if (tm.tm_mon < 1 || tm.tm_mon > 12) {
243             smiPrintError(parserPtr, ERR_DATE_MONTH, date);
244         }
245         if (tm.tm_mday < 1 || tm.tm_mday > 31) {
246             smiPrintError(parserPtr, ERR_DATE_DAY, date);
247         }
248         if (tm.tm_hour < 0 || tm.tm_hour > 23) {
249             smiPrintError(parserPtr, ERR_DATE_HOUR, date);
250         }
251         if (tm.tm_min < 0 || tm.tm_min > 59) {
252             smiPrintError(parserPtr, ERR_DATE_MINUTES, date);
253         }
254         
255         tm.tm_year -= 1900;
256         tm.tm_mon -= 1;
257         tm.tm_isdst = 0;
258
259         anytime = timegm(&tm);
260
261         if (anytime == (time_t) -1) {
262             smiPrintError(parserPtr, ERR_DATE_VALUE, date);
263         } else {
264             if (anytime < SMI_EPOCH) {
265                 smiPrintError(parserPtr, ERR_DATE_IN_PAST, date);
266             }
267             if (anytime > time(NULL)) {
268                 smiPrintError(parserPtr, ERR_DATE_IN_FUTURE, date);
269             }
270         }
271     }
272     
273     return (anytime == (time_t) -1) ? 0 : anytime;
274 }
275
276 static char *hexToStr(char *hexStr, int len)
277 {
278    union{
279         char ch;
280         long l;
281    } hex2char;
282    
283    char* res =(char*)malloc(sizeof(char)*len/2+1);
284    char* tmp =(char*)malloc(sizeof(char)*3);
285    int i,j = 0;
286
287    tmp[2]=0;
288    for(i=2; i+1<len; i+=2)
289    {
290         tmp[0]= hexStr[i];
291         tmp[1]= hexStr[i+1];
292         
293         hex2char.l = strtol(tmp,NULL,16);
294         res[j] = hex2char.ch;
295         
296         j++;
297    }
298    
299    smiFree(tmp);
300    
301    res[j]=0;
302    return res;
303 }
304
305 static void createBitsValue(SmiValue *valuePtr, Type *typePtr)
306 {
307     List *bitsListPtr, *valueListPtr, *p, *pp, *nextPtr;
308     int nBits, bit;
309     
310     if (valuePtr->basetype != SMI_BASETYPE_BITS)
311         return;
312         
313         bitsListPtr = typePtr->listPtr;
314         valueListPtr = (void *)valuePtr->value.ptr;
315         for (nBits = 0, p = bitsListPtr; p; p = p->nextPtr) {
316             if (nBits < 1+((NamedNumber *)(p->ptr))->export.value.value.unsigned64) {
317                 nBits = 1+((NamedNumber *)(p->ptr))->export.value.value.unsigned64;
318             }
319         }
320         valuePtr->value.ptr = smiMalloc((nBits+7)/8);
321         memset(valuePtr->value.ptr, 0, (nBits+7)/8);
322         valuePtr->len = (nBits+7)/8;
323         for (p = valueListPtr; p;) {
324             for (pp = bitsListPtr; pp; pp = pp->nextPtr) {
325                 if (!strcmp(p->ptr,
326                             ((NamedNumber *)(pp->ptr))->export.name)) {
327                     bit = (int)(((NamedNumber *)(pp->ptr))->export.value.value.unsigned64);
328                     valuePtr->value.ptr[bit/8] |=
329                         1 << (7-(bit%8));
330                 }
331             }
332             smiFree(p->ptr);
333             nextPtr = p->nextPtr;
334             smiFree(p);
335             p = nextPtr;
336         }
337 }
338
339                             
340 %}
341
342 /*
343  * The grammars start symbol.
344  */
345 %start smingFile
346
347
348
349 /*
350  * We call the parser from within the parser when IMPORTing modules,
351  * hence we need reentrant parser code. This is a bison feature.
352  */
353 %pure_parser
354
355
356
357 /*
358  * The attributes.
359  */
360 %union {
361     char           *id;                         /* identifier name           */
362     int            rc;                          /* >=0: ok, <0: error        */
363     time_t         date;                        /* a date value              */
364     char           *text;
365     Module         *modulePtr;
366     Node           *nodePtr;
367     Object         *objectPtr;
368     Identity   *identityPtr;
369     Macro          *macroPtr;
370     Type           *typePtr;
371     Class          *classPtr;
372     Attribute  *attributePtr;
373     Event          *eventPtr;
374     Index          index;
375     Option         *optionPtr;
376     Refinement     *refinementPtr;
377     SmiStatus      status;
378     SmiAccess      access;
379     NamedNumber    *namedNumberPtr;
380     Range          *rangePtr;
381     SmiValue       *valuePtr;
382     List           *listPtr;
383     Revision       *revisionPtr;
384 }
385
386
387
388 /*
389  * Tokens and their attributes.
390  */
391 %token DOT
392 %token DOT_DOT
393 %token COLON_COLON
394
395 %token <text>ucIdentifier
396 %token <text>lcIdentifier
397
398 %token <text>floatValue
399 %token <text>textSegment
400 %token <text>decimalNumber
401 %token <text>hexadecimalNumber
402 %token <text>OID
403
404 %token <rc>moduleKeyword
405 %token <rc>importKeyword
406 %token <rc>revisionKeyword
407 %token <rc>identityKeyword
408 %token <rc>oidKeyword
409 %token <rc>dateKeyword
410 %token <rc>organizationKeyword
411 %token <rc>contactKeyword
412 %token <rc>descriptionKeyword
413 %token <rc>referenceKeyword
414 %token <rc>extensionKeyword
415 %token <rc>typedefKeyword
416 %token <rc>typeKeyword
417 %token <rc>formatKeyword
418 %token <rc>unitsKeyword
419 %token <rc>statusKeyword
420 %token <rc>accessKeyword
421 %token <rc>defaultKeyword
422 %token <rc>impliedKeyword
423 %token <rc>indexKeyword
424 %token <rc>augmentsKeyword
425 %token <rc>reordersKeyword
426 %token <rc>sparseKeyword
427 %token <rc>expandsKeyword
428 %token <rc>createKeyword
429 %token <rc>membersKeyword
430 %token <rc>objectsKeyword
431 %token <rc>mandatoryKeyword
432 %token <rc>optionalKeyword
433 %token <rc>refineKeyword
434 %token <rc>abnfKeyword
435 %token <rc>OctetStringKeyword
436 %token <rc>ObjectIdentifierKeyword
437 %token <rc>Integer32Keyword
438 %token <rc>Unsigned32Keyword
439 %token <rc>Integer64Keyword
440 %token <rc>Unsigned64Keyword
441 %token <rc>Float32Keyword
442 %token <rc>Float64Keyword
443 %token <rc>Float128Keyword
444 %token <rc>BitsKeyword
445 %token <rc>EnumerationKeyword
446 %token <rc>currentKeyword
447 %token <rc>deprecatedKeyword
448 %token <rc>obsoleteKeyword
449 %token <rc>readonlyKeyword
450 %token <rc>readwriteKeyword
451
452 %token <rc>parentKeyword
453 %token <rc>classKeyword
454 %token <rc>extendsKeyword
455 %token <rc>attributeKeyword
456 %token <rc>uniqueKeyword
457 %token <rc>eventKeyword
458 %token <rc>PointerKeyword
459 %token <rc>eventonlyKeyword
460 %token <rc>neginfKeyword
461 %token <rc>posinfKeyword
462 %token <rc>snanKeyword
463 %token <rc>qnanKeyword
464
465
466 /*
467  * Types of non-terminal symbols.
468  */
469
470 %type <rc>smingFile
471 %type <rc>moduleStatement_optsep_0n
472 %type <rc>moduleStatement_optsep_1n
473 %type <rc>moduleStatement_optsep
474 %type <modulePtr>moduleStatement
475 %type <rc>extensionStatement_stmtsep_0n
476 %type <rc>extensionStatement_stmtsep_1n
477 %type <rc>extensionStatement_stmtsep
478 %type <macroPtr>extensionStatement
479 %type <rc>identityStatement_stmtsep_0n
480 %type <rc>identityStatement_stmtsep_1n
481 %type <rc>identityStatement_stmtsep
482 %type <identityPtr>identityStatement
483 %type <identityPtr>parentStatement_stmtsep_01
484 %type <identityPtr>parentStatement
485 %type <rc>typedefStatement_stmtsep_0n
486 %type <rc>typedefStatement_stmtsep_1n
487 %type <rc>typedefStatement_stmtsep
488 %type <typePtr>typedefStatement
489 %type <rc>attributeStatement_stmtsep_0n
490 %type <rc>attributeStatement_stmtsep_1n
491 %type <rc>attributeStatement_stmtsep
492 %type <attributePtr>attributeStatement
493 %type <rc>eventStatement_stmtsep_0n
494 %type <rc>eventStatement_stmtsep_1n
495 %type <rc>eventStatement_stmtsep
496 %type <eventPtr>eventStatement
497 %type <rc>classStatement_stmtsep_0n
498 %type <rc>classStatement_stmtsep_1n
499 %type <rc>classStatement_stmtsep
500 %type <classPtr>classStatement
501 %type <classPtr>extendsStatement_stmtsep_01
502 %type <classPtr>extendsStatement
503 %type <rc>importStatement_stmtsep_0n
504 %type <rc>importStatement_stmtsep_1n
505 %type <rc>importStatement_stmtsep
506 %type <listPtr>importStatement
507 %type <rc>revisionStatement_stmtsep_0n
508 %type <rc>revisionStatement_stmtsep_1n
509 %type <rc>revisionStatement_stmtsep
510 %type <revisionPtr>revisionStatement
511 %type <typePtr>typedefTypeStatement
512 %type <attributePtr>attributeTypeStatement
513 %type <date>dateStatement
514 %type <text>organizationStatement
515 %type <text>contactStatement
516 %type <text>formatStatement_stmtsep_01
517 %type <text>formatStatement
518 %type <text>unitsStatement_stmtsep_01
519 %type <text>unitsStatement
520 %type <status>statusStatement_stmtsep_01
521 %type <status>statusStatement
522 %type <valuePtr>defaultStatement_stmtsep_01
523 %type <valuePtr>defaultStatement
524 %type <access>accessStatement_stmtsep_01
525 %type <access>accessStatement
526 %type <access>access
527 %type <text>descriptionStatement_stmtsep_01
528 %type <text>descriptionStatement
529 %type <text>referenceStatement_stmtsep_01
530 %type <text>referenceStatement
531 %type <text>abnfStatement_stmtsep_01
532 %type <text>abnfStatement
533 %type <typePtr>refinedBaseType_refinedType
534 %type <typePtr>refinedBaseType
535 %type <typePtr>refinedType
536 %type <attributePtr>attribute_refinedBaseType_refinedType
537 %type <attributePtr>attribute_refinedBaseType
538 %type <attributePtr>attribute_refinedType
539 %type <listPtr>optsep_anySpec_01
540 %type <listPtr>anySpec
541 %type <listPtr>optsep_numberSpec_01
542 %type <listPtr>numberSpec
543 %type <listPtr>furtherNumberElement_0n
544 %type <listPtr>furtherNumberElement_1n
545 %type <rangePtr>furtherNumberElement
546 %type <rangePtr>numberElement
547 %type <valuePtr>numberUpperLimit_01
548 %type <valuePtr>numberUpperLimit
549 %type <listPtr>optsep_floatSpec_01
550 %type <listPtr>floatSpec
551 %type <listPtr>furtherFloatElement_0n
552 %type <listPtr>furtherFloatElement_1n
553 %type <rangePtr>furtherFloatElement
554 %type <rangePtr>floatElement
555 %type <text>floatUpperLimit_01
556 %type <text>floatUpperLimit
557 %type <text>specialFloatValue
558 %type <listPtr>optsep_pointerRestr_01
559 %type <text>pointerRestr
560 %type <listPtr>bitsOrEnumerationSpec
561 %type <listPtr>bitsOrEnumerationList
562 %type <listPtr>furtherBitsOrEnumerationItem_0n
563 %type <listPtr>furtherBitsOrEnumerationItem_1n
564 %type <namedNumberPtr>furtherBitsOrEnumerationItem
565 %type <namedNumberPtr>bitsOrEnumerationItem
566 %type <listPtr>identifierList
567 %type <listPtr>furtherIdentifier_0n
568 %type <listPtr>furtherIdentifier_1n
569 %type <text>furtherIdentifier
570 %type <listPtr>uniqueStatement_stmtsep_01
571 %type <listPtr>uniqueStatement
572 %type <listPtr>uniqueSpec
573 %type <listPtr>bitsValue
574 %type <listPtr>bitsList
575 %type <listPtr>furtherLcIdentifier_0n
576 %type <listPtr>furtherLcIdentifier_1n
577 %type <text>furtherLcIdentifier
578 %type <text>identifier
579 %type <text>qucIdentifier
580 %type <text>qlcIdentifier
581 %type <text>text
582 %type <text>optsep_textSegment_0n
583 %type <text>optsep_textSegment_1n
584 %type <text>optsep_textSegment
585 %type <date>date
586 %type <text>format
587 %type <text>units
588 %type <valuePtr>anyValue
589 %type <status>status
590 %type <valuePtr>number
591 %type <valuePtr>negativeNumber
592 %type <valuePtr>signedNumber
593 %type <rc>optsep_comma_01
594 %type <rc>sep
595 %type <rc>optsep
596 %type <rc>stmtsep
597 %type <text>qOID
598
599 %%
600
601 /*
602  * Yacc rules.
603  *
604  */
605
606
607 /*
608  * One mibFile may contain multiple MIB modules.
609  * It's also possible that there's no module in a file.
610  */
611 smingFile:              optsep moduleStatement_optsep_0n
612                         {
613                             /*
614                              * Return the number of successfully
615                              * parsed modules.
616                              */
617                             $$ = $2;
618                         }
619         ;
620
621 moduleStatement_optsep_0n:      /* empty */
622                         {
623                             $$ = 0;
624                         }
625         |               moduleStatement_optsep_1n
626                         {
627                             $$ = $1;
628                         }
629         ;
630
631 moduleStatement_optsep_1n:      moduleStatement_optsep
632                         {
633                             $$ = $1;
634                         }
635         |               moduleStatement_optsep_1n moduleStatement_optsep
636                         {
637                             /*
638                              * Sum up the number of successfully parsed
639                              * modules or return -1, if at least one
640                              * module failed.
641                              */
642                             if (($1 >= 0) && ($2 >= 0)) {
643                                 $$ = $1 + $2;
644                             } else {
645                                 $$ = -1;
646                             }
647                         }
648         ;
649
650 moduleStatement_optsep: moduleStatement optsep
651                         {
652                             /*
653                              * If we got a (Module *) return rc == 1,
654                              * otherwise parsing failed (rc == -1).
655                              */
656                             if ($1 != NULL) {
657                                 $$ = 1;
658                             } else {
659                                 $$ = -1;
660                             }
661                         }
662         ;
663
664 moduleStatement:        moduleKeyword sep ucIdentifier
665                         {
666                             thisParserPtr->modulePtr = findModuleByName($3);
667                             if (!thisParserPtr->modulePtr) {
668                                 thisParserPtr->modulePtr =
669                                     addModule($3,
670                                               smiStrdup(thisParserPtr->path),
671                                               0,
672                                               thisParserPtr);
673                             } else {
674                                 smiPrintError(thisParserPtr,
675                                               ERR_MODULE_ALREADY_LOADED,
676                                               $3);
677                                 free($3);
678                                 /*
679                                  * this aborts parsing the whole file,
680                                  * not only the current module.
681                                  */
682                                 YYABORT;
683                             }
684                             thisModulePtr->export.language = SMI_LANGUAGE_SMING;
685                             thisParserPtr->modulePtr->numImportedIdentifiers
686                                                                            = 0;
687                             thisParserPtr->modulePtr->numStatements = 0;
688                             thisParserPtr->modulePtr->numModuleIdentities = 0;
689                             thisParserPtr->firstIndexlabelPtr = NULL;
690                             thisParserPtr->identityObjectName = NULL;
691                         }
692                         optsep '{' stmtsep
693                         importStatement_stmtsep_0n
694                         organizationStatement stmtsep
695                         {
696                             if ($9) {
697                                 setModuleOrganization(thisParserPtr->modulePtr,
698                                                       $9);
699                             }
700                         }
701                         contactStatement stmtsep
702                         {
703                             if ($12) {
704                                 setModuleContactInfo(thisParserPtr->modulePtr,
705                                                      $12);
706                             }
707                         }
708                         descriptionStatement stmtsep
709                         {
710                             if ($15) {
711                                 setModuleDescription(thisParserPtr->modulePtr,
712                                                      $15, thisParserPtr);
713                             }
714                         }
715                         referenceStatement_stmtsep_01
716                         {
717                             if ($18) {
718                                 setModuleReference(thisParserPtr->modulePtr,
719                                                    $18, thisParserPtr);
720                             }
721                         }
722                         revisionStatement_stmtsep_0n
723                         extensionStatement_stmtsep_0n
724                         identityStatement_stmtsep_0n
725                         typedefStatement_stmtsep_0n
726                         classStatement_stmtsep_0n                       
727                         '}' optsep ';'
728                         {
729                             checkTypes(thisParserPtr, thisModulePtr);
730                             
731                             $$ = thisModulePtr;
732                         }
733         ;
734
735 extensionStatement_stmtsep_0n: /* empty */
736                         {
737                             $$ = 0;
738                         }
739         |               extensionStatement_stmtsep_1n
740                         {
741                             /*
742                              * Return the number of successfully
743                              * parsed extension statements.
744                              */
745                             $$ = $1;
746                         }
747         ;
748
749 extensionStatement_stmtsep_1n: extensionStatement_stmtsep
750                         {
751                             $$ = $1;
752                         }
753         |               extensionStatement_stmtsep_1n
754                         extensionStatement_stmtsep
755                         {
756                             /*
757                              * Sum up the number of successfully parsed
758                              * extensions or return -1, if at least one
759                              * failed.
760                              */
761                             if (($1 >= 0) && ($2 >= 0)) {
762                                 $$ = $1 + $2;
763                             } else {
764                                 $$ = -1;
765                             }
766                         }
767         ;
768
769 extensionStatement_stmtsep: extensionStatement stmtsep
770                         {
771                             /*
772                              * If we got a (Type *) return rc == 1,
773                              * otherwise parsing failed (rc == -1).
774                              */
775                             if ($1) {
776                                 $$ = 1;
777                             } else {
778                                 $$ = -1;
779                             }
780                         }
781         ;
782
783 extensionStatement:     extensionKeyword sep lcIdentifier
784                         {
785                             macroIdentifier = $3;
786                             macroPtr = addMacro(macroIdentifier,
787                                                 0,
788                                                 thisParserPtr);
789                             setMacroDecl(macroPtr, SMI_DECL_EXTENSION);
790                         }
791                         optsep '{' stmtsep
792                         statusStatement_stmtsep_01
793                         {
794                             if (macroPtr && $8) {
795                                 setMacroStatus(macroPtr, $8);
796                             }
797                         }
798                         descriptionStatement_stmtsep_01
799                         {
800                             if (macroPtr && $10) {
801                                 setMacroDescription(macroPtr, $10,
802                                                     thisParserPtr);
803                             }
804                         }
805                         referenceStatement_stmtsep_01
806                         {
807                             if (macroPtr && $12) {
808                                 setMacroReference(macroPtr, $12,
809                                                   thisParserPtr);
810                             }
811                         }
812                         abnfStatement_stmtsep_01
813                         {
814                            if (macroPtr && $14) {
815                                 setMacroAbnf(macroPtr, $14,
816                                                   thisParserPtr);
817                            }
818                         }
819                         '}' optsep ';'
820                         {
821                             $$ = 0;
822                             macroPtr = NULL;
823                         }
824         ;
825
826 typedefStatement_stmtsep_0n: /* empty */
827                         {
828                             $$ = 0;
829                         }
830         |               typedefStatement_stmtsep_1n
831                         {
832                             /*
833                              * Return the number of successfully
834                              * parsed typedef statements.
835                              */
836                             $$ = $1;
837                         }
838         ;
839
840 typedefStatement_stmtsep_1n: typedefStatement_stmtsep
841                         {
842                             $$ = $1;
843                         }
844         |               typedefStatement_stmtsep_1n
845                         typedefStatement_stmtsep
846                         {
847                             /*
848                              * Sum up the number of successfully parsed
849                              * typedefs or return -1, if at least one
850                              * failed.
851                              */
852                             if (($1 >= 0) && ($2 >= 0)) {
853                                 $$ = $1 + $2;
854                             } else {
855                                 $$ = -1;
856                             }
857                         }
858         ;
859
860 typedefStatement_stmtsep: typedefStatement stmtsep
861                         {
862                             /*
863                              * If we got a (Type *) return rc == 1,
864                              * otherwise parsing failed (rc == -1).
865                              */
866                             if ($1) {
867                                 $$ = 1;
868                             } else {
869                                 $$ = -1;
870                             }
871                         }
872         ;
873
874 typedefStatement:       typedefKeyword sep ucIdentifier
875                         {
876                             typeIdentifier = $3;
877                             /* 
878                              *check for duplicate names in the module 
879                              */
880                             if(typePtr = 
881                                 findType(typeIdentifier, thisParserPtr,thisModulePtr)) 
882                                         if( typePtr->modulePtr == thisParserPtr->modulePtr)
883                                                smiPrintError(thisParserPtr,
884                                                                                 ERR_DUPLICATE_TYPE_NAME,
885                                                                         typeIdentifier);
886                         }
887                         optsep '{' stmtsep
888                         typedefTypeStatement stmtsep
889                         {
890                             if ($8) {
891                                 if ($8->export.name) {
892                                     /*
893                                      * If the exact type has been found
894                                      * and no new Type structure has been
895                                      * created, we have to create a
896                                      * duplicate now.
897                                      */
898                                     typePtr = duplicateType($8, 0,
899                                                             thisParserPtr);
900                                 } else {
901                                     typePtr = $8;
902                                 }
903                                 typePtr = setTypeName(typePtr, typeIdentifier);
904                                 setTypeDecl(typePtr, SMI_DECL_TYPEDEF);
905                             }
906                             defaultBasetype = typePtr->export.basetype;
907                         }
908                         defaultStatement_stmtsep_01
909                         {
910                             if (typePtr && $11) {
911                                 if(typePtr->export.basetype == 
912                                                                 SMI_BASETYPE_ENUM) 
913                                                                 //check ENUM value for correctness
914                                 {
915                                         if($11->len)
916                                         if(namedNumberPtr = findNamedNumberByName(typePtr,
917                                                                                                          $11->value.ptr)){
918                                                 smiFree($11);
919                                                 $11 = &namedNumberPtr->export.value;
920                                         }
921                                         else{ smiPrintError(thisParserPtr,
922                                                         ERR_ENUM_NAME_NOT_DEFINED,
923                                                         $11->value.ptr);
924                                             }
925                                 }
926                                 //NOTE that the bits default value is set in the anyval
927                                 //rule
928                                 setTypeValue(typePtr, $11);
929                             }
930                         }
931                         formatStatement_stmtsep_01
932                         {
933                             if (typePtr && $13
934                                 && smiCheckFormat(thisParserPtr,
935                                                   typePtr->export.basetype,
936                                                   $13, 0)) {
937                                 setTypeFormat(typePtr, $13);
938                             }
939                         }
940                         unitsStatement_stmtsep_01
941                         {
942                             if (typePtr && $15) {
943                                 setTypeUnits(typePtr, $15);
944                             }
945                         }
946                         statusStatement_stmtsep_01
947                         {
948                             if (typePtr && $17) {
949                                 setTypeStatus(typePtr, $17);
950                             }
951                         }
952                         descriptionStatement_stmtsep_01
953                         {
954                             if (typePtr && $19) {
955                                 setTypeDescription(typePtr, $19,
956                                                    thisParserPtr);
957                             }
958                         }
959                         referenceStatement_stmtsep_01
960                         {
961                             if (typePtr && $21) {
962                                 setTypeReference(typePtr, $21, thisParserPtr);
963                             }
964                         }
965                         '}' optsep ';'
966                         {
967                             smiCheckNamedNumberSubtyping(thisParserPtr , typePtr);
968                             smiCheckNamedNumbersOrder(thisParserPtr , typePtr);
969                             smiCheckNamedNumberRedefinition(thisParserPtr , typePtr);
970                             $$ = 0;
971                             typePtr = NULL;
972                             free(typeIdentifier);
973                             defaultBasetype = SMI_BASETYPE_UNKNOWN;
974                         }
975         ;
976         
977 classStatement_stmtsep_0n: /* empty */
978                         {
979                             $$ = 0;
980                         }
981         |               classStatement_stmtsep_1n
982                         {
983                             /*
984                              * Return the number of successfully
985                              * parsed typedef statements.
986                              */
987                             $$ = $1;
988                         }
989         ;
990
991 classStatement_stmtsep_1n: classStatement_stmtsep
992                         {
993                             $$ = $1;
994                         }
995         |               classStatement_stmtsep_1n
996                         classStatement_stmtsep
997                         {
998                             /*
999                              * Sum up the number of successfully parsed
1000                              * classes or return -1, if at least one
1001                              * failed.
1002                              */
1003                             if (($1 >= 0) && ($2 >= 0)) {
1004                                 $$ = $1 + $2;
1005                             } else {
1006                                 $$ = -1;
1007                             }
1008                         }
1009         ;
1010
1011 classStatement_stmtsep: classStatement stmtsep
1012                         {
1013                             /*
1014                              * If we got a (Type *) return rc == 1,
1015                              * otherwise parsing failed (rc == -1).
1016                              */
1017                             if ($1) {
1018                                 $$ = 1;
1019                             } else {
1020                                 $$ = -1;
1021                             }
1022                         }
1023         ;
1024
1025 classStatement: classKeyword sep ucIdentifier
1026                         {
1027                             classIdentifier = $3;
1028                             if(findClassByModuleAndName(thisModulePtr, classIdentifier))
1029                             {
1030                                 smiPrintError(thisParserPtr,
1031                                                                                 ERR_DUPLICATE_CLASS_NAME,
1032                                                                         attributeIdentifier);
1033                             }
1034                             else{
1035                             classPtr = addClass(classIdentifier,
1036                                                 thisParserPtr);
1037                             setClassDecl(classPtr, SMI_DECL_CLASS);
1038                             }
1039                         }
1040                         optsep '{' stmtsep
1041                         extendsStatement_stmtsep_01
1042                         {
1043                                 if(classPtr && $8)
1044                                         classPtr->parentPtr = $8;
1045                         }
1046                         attributeStatement_stmtsep_0n
1047                         uniqueStatement_stmtsep_01
1048                         {
1049                                 List *tmpList;
1050                                 Attribute *tmpAttribute;
1051                                 if(classPtr && $11)
1052                                 {
1053                                         
1054                                         //Check for "magic" value #@# that defines
1055                                         //scalar class. See NOTE after Class definitino in data.h
1056                                         if(!strcmp((char*)($11->ptr),"#@#"))
1057                                         {       
1058                                                 classPtr->uniqueList = (List*)malloc(sizeof(List));
1059                                                 classPtr->uniqueList->ptr = classPtr;
1060                                                 classPtr->uniqueList->nextPtr = NULL;
1061                                                 smiFree($11);
1062                                         }
1063                                         else
1064                                         {
1065                                                 tmpList = $11;
1066                                                 //convert  all attribute names to atributes
1067                                                 for(tmpList; tmpList; tmpList=tmpList->nextPtr)
1068                                                 {
1069                                                         if(tmpAttribute = 
1070                                                         (Attribute*)smiGetAttribute(&(classPtr->export),(char*)(tmpList->ptr)))
1071                                                         {
1072                                                                 smiFree(tmpList->ptr);
1073                                                                 tmpList->ptr = tmpAttribute;
1074                                                         }
1075                                                         else
1076                                                         {
1077                                                                 smiFree(tmpList->ptr);
1078                                                                 tmpList->ptr = NULL;
1079                                                                 smiPrintError(thisParserPtr,
1080                                                                                 ERR_ATTRIBUTE_NOT_FOUND,
1081                                                                         attributeIdentifier);
1082                                                         }
1083                                                 }
1084                                                 
1085                                                 classPtr->uniqueList = $11;
1086                                         }
1087                                 }
1088                         }
1089                         eventStatement_stmtsep_0n
1090                         statusStatement_stmtsep_01
1091                         {
1092                             if (classPtr && $14) {
1093                                 setClassStatus(classPtr, $14);
1094                             }
1095                         }
1096                         descriptionStatement_stmtsep_01
1097                         {
1098                             if (classPtr && $16) {
1099                                 setClassDescription(classPtr, $16,
1100                                                     thisParserPtr);
1101                             }
1102                         }
1103                         referenceStatement_stmtsep_01
1104                         {
1105                             if (classPtr && $18) {
1106                                 setClassReference(classPtr, $18,
1107                                                   thisParserPtr);
1108                             }
1109                         }
1110                         '}' optsep ';'
1111                         {
1112                             $$ = 0;
1113                             classPtr = NULL;
1114                         }
1115         ;
1116                 
1117 attributeStatement_stmtsep_0n: /* empty */
1118                         {
1119                             $$ = 0;
1120                         }
1121         |               attributeStatement_stmtsep_1n
1122                         {
1123                             /*
1124                              * Return the number of successfully
1125                              * parsed typedef statements.
1126                              */
1127                             $$ = $1;
1128                         }
1129         ;
1130
1131 attributeStatement_stmtsep_1n: attributeStatement_stmtsep
1132                         {
1133                             $$ = $1;
1134                         }
1135         |               attributeStatement_stmtsep_1n
1136                         attributeStatement_stmtsep
1137                         {
1138                             /*
1139                              * Sum up the number of successfully parsed
1140                              * attributes or return -1, if at least one
1141                              * failed.
1142                              */
1143                             if (($1 >= 0) && ($2 >= 0)) {
1144                                 $$ = $1 + $2;
1145                             } else {
1146                                 $$ = -1;
1147                             }
1148                         }
1149         ;
1150
1151 attributeStatement_stmtsep: attributeStatement stmtsep
1152                         {
1153                             /*
1154                              * If we got a (Type *) return rc == 1,
1155                              * otherwise parsing failed (rc == -1).
1156                              */
1157                             if ($1) {
1158                                 $$ = 1;
1159                             } else {
1160                                 $$ = -1;
1161                             }
1162                         }
1163         ;
1164
1165 attributeStatement: attributeKeyword sep lcIdentifier
1166                                         {
1167                                                 attributeIdentifier = $3;
1168                                                 attributePtr = (Attribute*)smiGetAttribute(&(classPtr->export),
1169                                                                                                 attributeIdentifier);
1170                                                 if(attributePtr)
1171                                                 {
1172                                                         smiPrintError(thisParserPtr,
1173                                                                                 ERR_DUPLICATE_ATTRIBUTE_NAME,
1174                                                                         attributeIdentifier);
1175                                                 attributePtr = NULL;
1176                                                 }                                       
1177                                         }
1178                                         optsep '{' stmtsep
1179                                         attributeTypeStatement
1180                                         {
1181                                         if ($8) {
1182                                                 attributePtr = $8;
1183                                                         setAttributeName(attributePtr, 
1184                                                                                         attributeIdentifier);
1185                                                         setAttributeDecl(attributePtr, 
1186                                                                                                 SMI_DECL_ATTRIBUTE);
1187                                                         defaultBasetype = attributePtr->export.basetype;
1188                                         }
1189                                         }
1190                                         accessStatement_stmtsep_01
1191                                         {
1192                                                 if($10 && attributePtr){
1193                                                 /* check whether there's access for class reference, 
1194                                                    which is not allowed */
1195                                                         if(attributePtr->parentClassPtr)
1196                                                                 smiPrintError(thisParserPtr,
1197                                                                                 ERR_ATTRIBUTE_CLASS_ACCESS,
1198                                                                                                 attributeIdentifier);
1199                                                 else {
1200                                                         setAttributeAccess(attributePtr,$10);
1201                                                 }
1202                                                 }
1203                                                 else if(attributePtr && attributePtr->parentTypePtr)
1204                                                 {
1205                                                         smiPrintError(thisParserPtr,
1206                                                                                 ERR_ATTRIBUTE_MISSING_ACCESS,
1207                                                                                                 attributeIdentifier);
1208                                                 }
1209                                         }
1210                                         defaultStatement_stmtsep_01
1211                                         {
1212                                                 if($12 && attributePtr){
1213                                                         if(attributePtr->parentClassPtr)
1214                                                                 smiPrintError(thisParserPtr,
1215                                                                                 ERR_ATTRIBUTE_CLASS_DEFAULT,
1216                                                                                                 attributeIdentifier);
1217                                                 else{
1218                                                         attributePtr->export.value = *$12;
1219                                                 }
1220                                                 }
1221                                                 else if(attributePtr)
1222                                                 {
1223                                                         attributePtr->export.value.basetype = 
1224                                                                                                         SMI_BASETYPE_UNKNOWN;
1225                                                 }
1226                                         }
1227                                         formatStatement_stmtsep_01
1228                                         {
1229                                                 if($14 && attributePtr){
1230                                                         if(attributePtr->parentClassPtr)
1231                                                                 smiPrintError(thisParserPtr,
1232                                                                                 ERR_ATTRIBUTE_CLASS_FORMAT,
1233                                                                                                 attributeIdentifier);
1234                                                 else{
1235                                                         if (smiCheckFormat(thisParserPtr,
1236                                                                                 attributePtr->export.basetype,$14, 0)) 
1237                                                                 {
1238                                                                         attributePtr->export.format = $14;
1239                                                         }
1240                                                 }
1241                                                 }
1242                                 }
1243                                         unitsStatement_stmtsep_01
1244                                         {
1245                                         if($16 && attributePtr){
1246                                                         if(attributePtr->parentClassPtr)
1247                                                                 smiPrintError(thisParserPtr,
1248                                                                                 ERR_ATTRIBUTE_CLASS_UNITS,
1249                                                                                                 attributeIdentifier);
1250                                                 else{
1251                                                                         attributePtr->export.units = $16;
1252                                                 }
1253                                                 }
1254                                         }
1255                                         statusStatement_stmtsep_01
1256                                         {
1257                                                 if (attributePtr && $18) 
1258                                                         attributePtr->export.status = $18;
1259                                         }
1260                                         descriptionStatement_stmtsep_01
1261                                         {
1262                                                 if (attributePtr && $20) 
1263                                                         attributePtr->export.description = $20;
1264                                         }
1265                                         referenceStatement_stmtsep_01
1266                                         {
1267                                                 if (attributePtr && $22) 
1268                                                         attributePtr->export.reference = $22;
1269                                 }
1270                                         '}' optsep ';'
1271                                         {
1272                                                 $$ = attributePtr;
1273                                                 attributePtr = NULL;
1274                                                 defaultBasetype = SMI_BASETYPE_UNKNOWN;
1275                                         }
1276                 ;
1277
1278 eventStatement_stmtsep_0n: /* empty */
1279                         {
1280                             $$ = 0;
1281                         }
1282         |               eventStatement_stmtsep_1n
1283                         {
1284                             /*
1285                              * Return the number of successfully
1286                              * parsed event statements.
1287                              */
1288                             $$ = $1;
1289                         }
1290         ;
1291
1292 eventStatement_stmtsep_1n: eventStatement_stmtsep
1293                         {
1294                             $$ = $1;
1295                         }
1296         |               eventStatement_stmtsep_1n
1297                         eventStatement_stmtsep
1298                         {
1299                             /*
1300                              * Sum up the number of successfully parsed
1301                              * events or return -1, if at least one
1302                              * failed.
1303                              */
1304                             if (($1 >= 0) && ($2 >= 0)) {
1305                                 $$ = $1 + $2;
1306                             } else {
1307                                 $$ = -1;
1308                             }
1309                         }
1310         ;
1311
1312 eventStatement_stmtsep: eventStatement stmtsep
1313                         {
1314                             /*
1315                              * If we got a (Type *) return rc == 1,
1316                              * otherwise parsing failed (rc == -1).
1317                              */
1318                             if ($1) {
1319                                 $$ = 1;
1320                             } else {
1321                                 $$ = -1;
1322                             }
1323                         }
1324         ;
1325
1326 eventStatement: eventKeyword sep lcIdentifier
1327                         {
1328                                 //TODO check for repeated names
1329                                 eventPtr=addEvent($3,classPtr,thisParserPtr);
1330                         }
1331                         optsep '{' stmtsep
1332                         statusStatement_stmtsep_01
1333                         {
1334                                 if($8 && eventPtr)
1335                                 eventPtr->export.status = $8;
1336                         }
1337                         descriptionStatement_stmtsep_01
1338                         {
1339                                 if($10 && eventPtr)
1340                                 eventPtr->export.description = $10;
1341                         }
1342                         referenceStatement_stmtsep_01
1343                         {
1344                                 if($12 && eventPtr)
1345                                 eventPtr->export.reference = $12;
1346                         }
1347                         '}' optsep ';'
1348                         {
1349                                 $$ = eventPtr;
1350                                 eventPtr = NULL;
1351                         }
1352                 ;
1353
1354 importStatement_stmtsep_0n: /* empty */
1355                         {
1356                             $$ = 0;
1357                         }
1358         |               importStatement_stmtsep_1n
1359                         {
1360                             $$ = $1;
1361                         }
1362         ;
1363
1364 importStatement_stmtsep_1n: importStatement_stmtsep
1365                         {
1366                             $$ = $1;
1367                         }
1368         |               importStatement_stmtsep_1n importStatement_stmtsep
1369                         {
1370                             /*
1371                              * Sum up the number of successfully parsed
1372                              * imports or return -1, if at least one
1373                              * module failed.
1374                              */
1375                             if (($1 >= 0) && ($2 >= 0)) {
1376                                 $$ = $1 + $2;
1377                             } else {
1378                                 $$ = -1;
1379                             }
1380                         }
1381         ;
1382
1383 importStatement_stmtsep: importStatement stmtsep
1384                         {
1385                             /*
1386                              * If we got an (Object *) return rc == 1,
1387                              * otherwise parsing failed (rc == -1).
1388                              */
1389                             if ($1) {
1390                                 $$ = 1;
1391                             } else {
1392                                 $$ = -1;
1393                             }
1394                         }
1395         ;
1396
1397 importStatement:        importKeyword sep ucIdentifier
1398                         {
1399                             importModulename = smiStrdup($3);
1400                         }
1401                         optsep '(' optsep
1402                         identifierList
1403                         {
1404                             List *listPtr, *nextPtr;
1405                             
1406                             for (listPtr = $8; listPtr; listPtr = nextPtr) {
1407                                 addImport(listPtr->ptr, thisParserPtr);
1408                                 thisParserPtr->modulePtr->
1409                                                       numImportedIdentifiers++;
1410                                 nextPtr = listPtr->nextPtr;
1411                                 free(listPtr);
1412                             }
1413                         }
1414                         optsep ')' optsep ';'
1415                         {
1416                             Module *modulePtr;
1417                             char *s = importModulename;
1418
1419                             modulePtr = findModuleByName(s);
1420                             if (!modulePtr) {
1421                                 modulePtr = loadModule(s, thisParserPtr);
1422                             }
1423                             checkImports(modulePtr, thisParserPtr);
1424                             free(s);
1425                             $$ = NULL;
1426                         }
1427         ;
1428
1429 revisionStatement_stmtsep_0n: /* empty */
1430                         {
1431                             $$ = 0;
1432                         }
1433         |               revisionStatement_stmtsep_1n
1434                         {
1435                             $$ = $1;
1436                         }
1437         ;
1438
1439 revisionStatement_stmtsep_1n: revisionStatement_stmtsep
1440                         {
1441                             $$ = $1;
1442                         }
1443         |               revisionStatement_stmtsep_1n revisionStatement_stmtsep
1444                         {
1445                             /*
1446                              * Sum up the number of successfully parsed
1447                              * revisions or return -1, if at least one
1448                              * module failed.
1449                              */
1450                             if (($1 >= 0) && ($2 >= 0)) {
1451                                 $$ = $1 + $2;
1452                             } else {
1453                                 $$ = -1;
1454                             }
1455                         }
1456         ;
1457
1458 revisionStatement_stmtsep: revisionStatement stmtsep
1459                            {
1460                                /*
1461                                 * If we got a (Revision *) return rc == 1,
1462                                 * otherwise parsing failed (rc == -1).
1463                                 */
1464                                if ($1) {
1465                                 $$ = 1;
1466                                } else {
1467                                    $$ = -1;
1468                                }
1469                            }
1470         ;
1471
1472 revisionStatement:      revisionKeyword optsep '{' stmtsep
1473                         dateStatement stmtsep
1474                         descriptionStatement stmtsep
1475                         '}' optsep ';'
1476                         {
1477                             $$ = addRevision($5, $7, thisParserPtr);
1478                         }
1479         ;
1480
1481 identityStatement_stmtsep_0n: /* empty */
1482                         {
1483                             $$ = 0;
1484                         }
1485         |               identityStatement_stmtsep_1n
1486                         {
1487                             /*
1488                              * Return the number of successfully
1489                              * parsed identity statements.
1490                              */
1491                             $$ = $1;
1492                         }
1493         ;
1494
1495 identityStatement_stmtsep_1n: identityStatement_stmtsep
1496                         {
1497                             $$ = $1;
1498                         }
1499         |               identityStatement_stmtsep_1n
1500                         identityStatement_stmtsep
1501                         {
1502                             /*
1503                              * Sum up the number of successfully parsed
1504                              * identities or return -1, if at least one
1505                              * failed.
1506                              */
1507                             if (($1 >= 0) && ($2 >= 0)) {
1508                                 $$ = $1 + $2;
1509                             } else {
1510                                 $$ = -1;
1511                             }
1512                         }
1513         ;
1514
1515 identityStatement_stmtsep: identityStatement stmtsep
1516                         {
1517                             /*
1518                              * If we got a (Type *) return rc == 1,
1519                              * otherwise parsing failed (rc == -1).
1520                              */
1521                             if ($1) {
1522                                 $$ = 1;
1523                             } else {
1524                                 $$ = -1;
1525                             }
1526                         }
1527         ;
1528
1529 identityStatement:      identityKeyword sep lcIdentifier
1530                         {
1531                                 identityIdentifier = $3;
1532                                 identityPtr = addIdentity(identityIdentifier,
1533                                                 thisParserPtr);
1534                             setIdentityDecl(identityPtr, SMI_DECL_IDENTITY);
1535                         }
1536                         optsep '{' stmtsep
1537                         parentStatement_stmtsep_01
1538                         {
1539                                 if(identityPtr && $8) {
1540                                         setIdentityParent(identityPtr,$8);
1541                                 }
1542                         }
1543                         statusStatement_stmtsep_01
1544                         {
1545                             if (identityPtr && $10) {
1546                                 setIdentityStatus(identityPtr, $10);
1547                             }
1548                         }
1549                         descriptionStatement_stmtsep_01
1550                         {
1551                                 if (identityPtr && $12) {
1552                                 setIdentityDescription(identityPtr, $12,
1553                                                                         thisParserPtr);
1554                             }
1555                         }
1556                         referenceStatement_stmtsep_01
1557                         {
1558                                 setIdentityReference(identityPtr, $14, 
1559                                                                          thisParserPtr)
1560                         }
1561                         '}' optsep ';'
1562                         {
1563                             $$ = 0;
1564                             identityPtr = NULL;
1565                         }
1566         ;
1567
1568 typedefTypeStatement:   typeKeyword sep refinedBaseType_refinedType optsep ';'
1569                         {
1570                             $$ = $3;
1571                         }
1572         ;
1573
1574 attributeTypeStatement: typeKeyword sep attribute_refinedBaseType_refinedType optsep ';'
1575                         {
1576                             $$ = $3;
1577                         }
1578         ;
1579
1580 dateStatement:          dateKeyword sep date optsep ';'
1581                         {
1582                             $$ = $3;
1583                         }
1584         ;
1585
1586 organizationStatement:  organizationKeyword sep text optsep ';'
1587                         {
1588                             $$ = $3;
1589                         }
1590         ;
1591
1592 contactStatement:       contactKeyword sep text optsep ';'
1593                         {
1594                             $$ = $3;
1595                         }
1596         ;
1597
1598 formatStatement_stmtsep_01: /* empty */
1599                         {
1600                             $$ = NULL;
1601                         }
1602         |               formatStatement stmtsep
1603                         {
1604                             $$ = $1;
1605                         }
1606         ;
1607
1608 formatStatement:        formatKeyword sep format optsep ';'
1609                         {
1610                             $$ = $3;
1611                         }
1612         ;
1613
1614 unitsStatement_stmtsep_01: /* empty */
1615                         {
1616                             $$ = NULL;
1617                         }
1618         |               unitsStatement stmtsep
1619                         {
1620                             $$ = $1;
1621                         }
1622         ;
1623
1624 unitsStatement:         unitsKeyword sep units optsep ';'
1625                         {
1626                             $$ = $3;
1627                         }
1628         ;
1629
1630 statusStatement_stmtsep_01: /* empty */
1631                         {
1632                             $$ = SMI_STATUS_CURRENT;
1633                         }
1634         |               statusStatement stmtsep
1635                         {
1636                             $$ = $1;
1637                         }
1638         ;
1639
1640 statusStatement:        statusKeyword sep status optsep ';'
1641                         {
1642                             $$ = $3;
1643                         }
1644         ;
1645
1646 uniqueStatement_stmtsep_01:
1647                 {
1648                             $$ = NULL;
1649                         }
1650         |               uniqueStatement stmtsep
1651                         {
1652                             $$ = $1;
1653                         }
1654                 ;
1655                 
1656 uniqueStatement:        uniqueKeyword sep '(' uniqueSpec ')' optsep ';'
1657                         {
1658                             $$ = $4;
1659                         }
1660         ;
1661
1662 uniqueSpec:     optsep_comma_01
1663                         {
1664                                 $$ = smiMalloc(sizeof(List));
1665                             $$->ptr = "#@#"; //used to indicate that unique
1666                                                          //statement is present and empty
1667                                                          //i.e. the class is scalar
1668                             $$->nextPtr = NULL;
1669                         }
1670                 |               lcIdentifier furtherLcIdentifier_0n optsep_comma_01
1671                         {
1672                             $$ = smiMalloc(sizeof(List));
1673                             $$->ptr = $1;
1674                             $$->nextPtr = $2;
1675                         }
1676                 ;
1677
1678
1679                 
1680                 
1681 extendsStatement_stmtsep_01: /* empty */
1682                         {
1683                             $$ = NULL;
1684                         }
1685         |               extendsStatement stmtsep
1686                         {
1687                             $$ = $1;
1688                         }
1689                 ;
1690
1691 extendsStatement:       extendsKeyword sep ucIdentifier optsep ';'
1692                         {
1693                             $$ = findClass($3, thisParserPtr,thisModulePtr);
1694                             if(!$$)smiPrintError(thisParserPtr,
1695                                               ERR_UNKNOWN_CLASS,
1696                                               $3);
1697                             
1698                         }
1699         ;
1700
1701 defaultStatement_stmtsep_01: /* empty */
1702                         {
1703                             $$ = NULL;
1704                         }
1705         |               defaultStatement stmtsep
1706                         {
1707                             $$ = $1;
1708                         }
1709         ;
1710
1711 defaultStatement:       defaultKeyword sep anyValue optsep ';'
1712                         {
1713                             $$ = $3;
1714                         }
1715         ;
1716         
1717 accessStatement_stmtsep_01: /* empty */
1718                         {
1719                             $$ = SMI_ACCESS_UNKNOWN;
1720                         }
1721         |               accessStatement stmtsep
1722                         {
1723                             $$ = $1;
1724                         }
1725         ;
1726
1727 accessStatement:        accessKeyword sep access optsep ';'
1728                         {
1729                             $$ = $3;
1730                         }
1731         ;
1732         
1733 access:         readonlyKeyword
1734                         {
1735                                 $$ = SMI_ACCESS_READ_ONLY;
1736                         }
1737                 |               readwriteKeyword
1738                         {
1739                                 $$ = SMI_ACCESS_READ_WRITE;
1740                         }
1741                 |               eventonlyKeyword
1742                         {
1743                                 $$ = SMI_ACCESS_EVENT_ONLY;
1744                         }
1745                 ;
1746         
1747 parentStatement_stmtsep_01: /* empty */
1748                         {
1749                             $$ = NULL;
1750                         }
1751         |               parentStatement stmtsep
1752                         {
1753                             $$ = $1;
1754                         }
1755         ;
1756
1757 parentStatement:        parentKeyword sep lcIdentifier optsep ';'
1758                         {
1759                             $$ = findIdentity($3, thisParserPtr, thisModulePtr);
1760                             if(!$$)smiPrintError(thisParserPtr,
1761                                               ERR_IDENTITY_PARENT_NOT_FOUND,
1762                                               $3);
1763                         }
1764         ;
1765
1766 descriptionStatement_stmtsep_01: /* empty */
1767                         {
1768                             $$ = NULL;
1769                         }
1770         |               descriptionStatement stmtsep
1771                         {
1772                             $$ = $1;
1773                         }
1774         ;
1775
1776 descriptionStatement:   descriptionKeyword sep text optsep ';'
1777                         {
1778                             $$ = $3;
1779                         }
1780         ;
1781
1782 referenceStatement_stmtsep_01: /* empty */
1783                         {
1784                             $$ = NULL;
1785                         }
1786         |               referenceStatement stmtsep
1787                         {
1788                             $$ = $1;
1789                         }
1790         ;
1791
1792 referenceStatement:     referenceKeyword sep text optsep ';'
1793                         {
1794                             $$ = $3;
1795                         }
1796         ;
1797
1798 abnfStatement_stmtsep_01: /* empty */
1799                         {
1800                             $$ = NULL;
1801                         }
1802         |               abnfStatement stmtsep
1803                         {
1804                             $$ = $1;
1805                         }
1806         ;
1807
1808 abnfStatement:          abnfKeyword sep text optsep ';'
1809                         {
1810                             $$ = $3;
1811                         }
1812         ;
1813
1814
1815
1816 refinedBaseType_refinedType: refinedBaseType
1817                         {
1818                             $$ = $1;
1819                         }
1820         |               refinedType
1821                         {
1822                             $$ = $1;
1823                         }
1824         ;
1825         
1826 attribute_refinedBaseType_refinedType: attribute_refinedBaseType
1827                         {
1828                             $$ = $1;
1829                         }
1830         |               attribute_refinedType
1831                         {
1832                             $$ = $1;
1833                         }
1834         ;
1835         
1836
1837 refinedBaseType:        OctetStringKeyword optsep_numberSpec_01
1838                         {
1839                             List *p;
1840                             
1841                             if (!$2) {
1842                                 $$ = smiHandle->typeOctetStringPtr;
1843                             } else {
1844                                 $$ = duplicateType(smiHandle->typeOctetStringPtr, 0,
1845                                                    thisParserPtr);
1846                                 setTypeParent($$, smiHandle->typeOctetStringPtr);
1847                                 setTypeList($$, $2);
1848                                 for (p = $2; p; p = p->nextPtr)
1849                                     ((Range *)p->ptr)->typePtr = $$;
1850                             }
1851                         }
1852         |               ObjectIdentifierKeyword
1853                         {
1854                             $$ = smiHandle->typeObjectIdentifierPtr;
1855                         }
1856         |               Integer32Keyword optsep_numberSpec_01
1857                         {
1858                             List *p;
1859                             
1860                             if (!$2) {
1861                                 $$ = smiHandle->typeInteger32Ptr;
1862                             } else {
1863                                 $$ = duplicateType(smiHandle->typeInteger32Ptr, 0,
1864                                                    thisParserPtr);
1865                                 setTypeParent($$, smiHandle->typeInteger32Ptr);
1866                                 setTypeList($$, $2);
1867                                 for (p = $2; p; p = p->nextPtr)
1868                                     ((Range *)p->ptr)->typePtr = $$;
1869                             }
1870                         }
1871         |               Unsigned32Keyword optsep_numberSpec_01
1872                         {
1873                             List *p;
1874                             
1875                             if (!$2) {
1876                                 $$ = smiHandle->typeUnsigned32Ptr;
1877                             } else {
1878                                 $$ = duplicateType(smiHandle->typeUnsigned32Ptr, 0,
1879                                                    thisParserPtr);
1880                                 setTypeParent($$, smiHandle->typeUnsigned32Ptr);
1881                                 setTypeList($$, $2);
1882                                 for (p = $2; p; p = p->nextPtr)
1883                                     ((Range *)p->ptr)->typePtr = $$;
1884                             }
1885                         }
1886         |               Integer64Keyword optsep_numberSpec_01
1887                         {
1888                             List *p;
1889                             
1890                             if (!$2) {
1891                                 $$ = smiHandle->typeInteger64Ptr;
1892                             } else {
1893                                 $$ = duplicateType(smiHandle->typeInteger64Ptr, 0,
1894                                                    thisParserPtr);
1895                                 setTypeParent($$, smiHandle->typeInteger64Ptr);
1896                                 setTypeList($$, $2);
1897                                 for (p = $2; p; p = p->nextPtr)
1898                                     ((Range *)p->ptr)->typePtr = $$;
1899                             }
1900                         }
1901         |               Unsigned64Keyword optsep_numberSpec_01
1902                         {
1903                             List *p;
1904                             
1905                             if (!$2) {
1906                                 $$ = smiHandle->typeUnsigned64Ptr;
1907                             } else {
1908                                 $$ = duplicateType(smiHandle->typeUnsigned64Ptr, 0,
1909                                                    thisParserPtr);
1910                                 setTypeParent($$, smiHandle->typeUnsigned64Ptr);
1911                                 setTypeList($$, $2);
1912                                 for (p = $2; p; p = p->nextPtr)
1913                                     ((Range *)p->ptr)->typePtr = $$;
1914                             }
1915                         }
1916         |               Float32Keyword optsep_floatSpec_01
1917                         {
1918                             List *p;
1919                             
1920                             if (!$2) {
1921                                 $$ = smiHandle->typeFloat32Ptr;
1922                             } else {
1923                                 $$ = duplicateType(smiHandle->typeFloat32Ptr, 0,
1924                                                    thisParserPtr);
1925                                 setTypeParent($$, smiHandle->typeFloat32Ptr);
1926                                 setTypeList($$, $2);
1927                                 for (p = $2; p; p = p->nextPtr)
1928                                     ((Range *)p->ptr)->typePtr = $$;
1929                             }
1930                         }
1931         |               Float64Keyword optsep_floatSpec_01
1932                         {
1933                             List *p;
1934                             
1935                             if (!$2) {
1936                                 $$ = smiHandle->typeFloat64Ptr;
1937                             } else {
1938                                 $$ = duplicateType(smiHandle->typeFloat64Ptr, 0,
1939                                                    thisParserPtr);
1940                                 setTypeParent($$, smiHandle->typeFloat64Ptr);
1941                                 setTypeList($$, $2);
1942                                 for (p = $2; p; p = p->nextPtr)
1943                                     ((Range *)p->ptr)->typePtr = $$;
1944                             }
1945                         }
1946         |               Float128Keyword optsep_floatSpec_01
1947                         {
1948                             List *p;
1949                             
1950                             if (!$2) {
1951                                 $$ = smiHandle->typeFloat128Ptr;
1952                             } else {
1953                                 $$ = duplicateType(smiHandle->typeFloat128Ptr, 0,
1954                                                    thisParserPtr);
1955                                 setTypeParent($$, smiHandle->typeFloat128Ptr);
1956                                 setTypeList($$, $2);
1957                                 for (p = $2; p; p = p->nextPtr)
1958                                     ((Range *)p->ptr)->typePtr = $$;
1959                             }
1960                         }
1961         |               PointerKeyword optsep_pointerRestr_01
1962                         {
1963                             if (!$2) {
1964                                 $$ = smiHandle->typePointerPtr;
1965                             } else {
1966                                 $$ = duplicateType(smiHandle->typePointerPtr, 0,
1967                                                    thisParserPtr);
1968                                 setTypeParent($$, smiHandle->typePointerPtr);
1969                                 setTypeList($$, $2);                            
1970                                 }
1971                         }
1972         |               EnumerationKeyword bitsOrEnumerationSpec
1973                         {
1974                             List *p;
1975                             
1976                             if (!$2) {
1977                                 $$ = smiHandle->typeEnumPtr;
1978                             } else {
1979                                 $$ = duplicateType(smiHandle->typeEnumPtr, 0,
1980                                                    thisParserPtr);
1981                                 setTypeParent($$, smiHandle->typeEnumPtr);
1982                                 setTypeList($$, $2);
1983                                 for (p = $2; p; p = p->nextPtr)
1984                                     ((NamedNumber *)p->ptr)->typePtr = $$;
1985                             }
1986                         }
1987         |               BitsKeyword 
1988                         {
1989                                 bitsFlag = 1; //Since Enum elements can be 
1990                                                           //negative we must make sure
1991                                                           //that bits is not negative,
1992                                                           //so we raise bitsFlag and
1993                                                           //give error if there is
1994                                                           //negative value 
1995                         }
1996                         bitsOrEnumerationSpec
1997                         {
1998                             List *p;
1999                             
2000                             if (!$3) {
2001                                 $$ = smiHandle->typeBitsPtr;
2002                             } else {
2003                                 $$ = duplicateType(smiHandle->typeBitsPtr, 0,
2004                                                    thisParserPtr);
2005                                 setTypeParent($$, smiHandle->typeBitsPtr);
2006                                 setTypeList($$, $3);
2007                                 for (p = $3; p; p = p->nextPtr)
2008                                     ((NamedNumber *)p->ptr)->typePtr = $$;
2009                             }
2010                             
2011                             bitsFlag = 0;//reset flag
2012                         }
2013         ;
2014         
2015         
2016 attribute_refinedBaseType:      OctetStringKeyword optsep_numberSpec_01
2017                         {
2018                             List *p;
2019                             $$ = duplicateTypeToAttribute(smiHandle->typeOctetStringPtr,
2020                                                                                                 classPtr, thisParserPtr);
2021                                 setAttributeParentType($$, smiHandle->typeOctetStringPtr);
2022                             if ($2) {
2023                                         setAttributeList($$, $2);
2024                                         for (p = $2; p; p = p->nextPtr)
2025                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2026                             }
2027                         }
2028         |               ObjectIdentifierKeyword
2029                         {
2030                             $$ = duplicateTypeToAttribute(
2031                                 smiHandle->typeObjectIdentifierPtr, classPtr, thisParserPtr);
2032                                 setAttributeParentType($$, smiHandle->typeObjectIdentifierPtr);
2033                         }
2034         |               Integer32Keyword optsep_numberSpec_01
2035                         {
2036                             List *p;
2037                             
2038                                 $$ = duplicateTypeToAttribute(smiHandle->typeInteger32Ptr,
2039                                                                                                         classPtr, thisParserPtr);
2040                                 setAttributeParentType($$, smiHandle->typeInteger32Ptr);
2041                             if ($2) {
2042                                         setAttributeList($$, $2);
2043                                         for (p = $2; p; p = p->nextPtr)
2044                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2045                             }
2046                         }
2047         |               Unsigned32Keyword optsep_numberSpec_01
2048                         {
2049                             List *p;
2050                             
2051                                 $$ = duplicateTypeToAttribute(smiHandle->typeUnsigned32Ptr,
2052                                                                                                         classPtr, thisParserPtr);
2053                                 setAttributeParentType($$, smiHandle->typeUnsigned32Ptr);
2054                             if ($2) {
2055                                         setAttributeList($$, $2);
2056                                         for (p = $2; p; p = p->nextPtr)
2057                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2058                             }
2059                         }
2060         |               Integer64Keyword optsep_numberSpec_01
2061                         {
2062                            List *p;
2063                             
2064                                 $$ = duplicateTypeToAttribute(smiHandle->typeInteger64Ptr,
2065                                                                                                         classPtr, thisParserPtr);
2066                                 setAttributeParentType($$, smiHandle->typeInteger64Ptr);
2067                             if ($2) {
2068                                         setAttributeList($$, $2);
2069                                         for (p = $2; p; p = p->nextPtr)
2070                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2071                             }
2072                         }
2073         |               Unsigned64Keyword optsep_numberSpec_01
2074                         {
2075                            List *p;
2076                             
2077                                 $$ = duplicateTypeToAttribute(smiHandle->typeUnsigned64Ptr,
2078                                                                                                         classPtr, thisParserPtr);
2079                                 setAttributeParentType($$, smiHandle->typeUnsigned64Ptr);
2080                             if ($2) {
2081                                         setAttributeList($$, $2);
2082                                         for (p = $2; p; p = p->nextPtr)
2083                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2084                             }
2085                         }
2086         |               Float32Keyword optsep_floatSpec_01
2087                         {
2088                             List *p;
2089                             
2090                                 $$ = duplicateTypeToAttribute(smiHandle->typeFloat32Ptr,
2091                                                                                                         classPtr, thisParserPtr);
2092                                 setAttributeParentType($$, smiHandle->typeFloat32Ptr);
2093                             if ($2) {
2094                                         setAttributeList($$, $2);
2095                                         for (p = $2; p; p = p->nextPtr)
2096                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2097                             }
2098                         }
2099         |               Float64Keyword optsep_floatSpec_01
2100                         {
2101                            List *p;
2102                             
2103                                 $$ = duplicateTypeToAttribute(smiHandle->typeFloat64Ptr,
2104                                                                                                         classPtr, thisParserPtr);
2105                                 setAttributeParentType($$, smiHandle->typeFloat64Ptr);
2106                             if ($2) {
2107                                         setAttributeList($$, $2);
2108                                         for (p = $2; p; p = p->nextPtr)
2109                                         ((Range *)p->ptr)->typePtr = (Type*)$$;
2110                             }
2111                         }
2112         |               Float128Keyword optsep_floatSpec_01
2113                         {
2114                             List *p;
2115                             
2116                             $$ = duplicateTypeToAttribute(smiHandle->typeFloat128Ptr,
2117                                                           classPtr, thisParserPtr);
2118                             setAttributeParentType($$, smiHandle->typeFloat128Ptr);
2119                             if ($2) {
2120                                 setAttributeList($$, $2);
2121                                 for (p = $2; p; p = p->nextPtr)
2122                                     ((Range *)p->ptr)->typePtr = (Type*)$$;
2123                             }
2124                         }
2125         |               PointerKeyword optsep_pointerRestr_01
2126                         {
2127                             $$ = duplicateTypeToAttribute(smiHandle->typePointerPtr,
2128                                                           classPtr, thisParserPtr);
2129                             setAttributeParentType($$, smiHandle->typePointerPtr);
2130                             if ($2) {
2131                                 setAttributeList($$, $2);
2132                             }
2133                         }
2134         |               EnumerationKeyword bitsOrEnumerationSpec
2135                         {
2136                             List *p;
2137                             
2138                             $$ = duplicateTypeToAttribute(smiHandle->typeEnumPtr,
2139                                                                                                         classPtr, thisParserPtr);
2140                                 setAttributeParentType($$, smiHandle->typeEnumPtr);
2141                             if ($2) {
2142                                         setAttributeList($$, $2);
2143                                         for (p = $2; p; p = p->nextPtr)
2144                                         ((NamedNumber *)p->ptr)->typePtr = (Type*)$$;
2145                             }
2146                         }
2147         |               BitsKeyword 
2148                         {
2149                                 bitsFlag = 1; //Since Enum elements can be 
2150                                                           //negative we must make sure
2151                                                           //that bits is not negative,
2152                                                           //so we raise bitsFlag and
2153                                                           //give error if there is
2154                                                           //negative value 
2155                         }
2156                         bitsOrEnumerationSpec
2157                         {
2158                             List *p;
2159                             
2160                             $$ = duplicateTypeToAttribute(smiHandle->typeBitsPtr,
2161                                                           classPtr, thisParserPtr);
2162                             setAttributeParentType($$, smiHandle->typeBitsPtr);
2163                             if ($1) {
2164                                 setAttributeList($$, $1);
2165                                 for (p = $1; p; p = p->nextPtr)
2166                                     ((NamedNumber *)(p->ptr))->typePtr = (Type*)$$;
2167                             }
2168                             
2169                             bitsFlag = 0; /* reset flag */
2170                         }
2171         ;
2172
2173 refinedType:            qucIdentifier optsep_anySpec_01
2174                         {
2175                             typePtr = findType($1, thisParserPtr,
2176                                                thisModulePtr);
2177                             if (typePtr && $2) {
2178                                 typePtr = duplicateType(typePtr, 0,
2179                                                         thisParserPtr);
2180                                 setTypeList(typePtr, $2);
2181                             }
2182
2183                             $$ = typePtr;
2184                         }
2185         ;
2186         
2187 attribute_refinedType:          qucIdentifier optsep_anySpec_01
2188                         {
2189                             Class *tmp;
2190                             typePtr = findType($1, thisParserPtr,
2191                                                thisModulePtr);
2192                             if (typePtr && $2) {
2193                                 attributePtr = duplicateTypeToAttribute(typePtr,
2194                                                                                         classPtr, thisParserPtr);
2195                                 setAttributeList(attributePtr, $2);
2196                                 setAttributeParentType(attributePtr, typePtr);
2197                             } else if( typePtr ){
2198                                 attributePtr = duplicateTypeToAttribute(typePtr,
2199                                                                                         classPtr, thisParserPtr);
2200                                         setAttributeParentType(attributePtr, typePtr);
2201                                 } else if($2){
2202                                         smiPrintError(thisParserPtr, ERR_UNKNOWN_TYPE, $1);
2203                                         attributePtr = NULL;
2204                                 } else if (tmp = findClass($1,
2205                                                                                  thisParserPtr,thisModulePtr)){
2206                                         attributePtr = addAttribute($1, classPtr, thisParserPtr);
2207                                         setAttributeParentClass(attributePtr, tmp);
2208                                 } else {
2209                                         attributePtr = NULL;
2210                                         smiPrintError(thisParserPtr, 
2211                                                                                         ERR_UNKNOWN_TYPE_OR_CLASS, $1);
2212                                 }
2213                                 
2214
2215                             $$ = attributePtr;
2216                         }
2217         ;
2218
2219 optsep_anySpec_01:      /* empty */
2220                         {
2221                             $$ = NULL;
2222                         }
2223         |               optsep anySpec
2224                         {
2225                             $$ = $2;
2226                         }
2227         ;
2228
2229 anySpec:                numberSpec
2230                         {
2231                             $$ = $1;
2232                         }
2233         |               floatSpec
2234                         {
2235                             $$ = $1;
2236                         }
2237         ;
2238
2239 optsep_numberSpec_01:   /* empty */
2240                         {
2241                             $$ = NULL;
2242                         }
2243         |               optsep numberSpec
2244                         {
2245                             $$ = $2;
2246                         }
2247         ;
2248
2249 numberSpec:             '(' optsep numberElement furtherNumberElement_0n
2250                         optsep ')'
2251                         {
2252                             $$ = smiMalloc(sizeof(List));
2253                             $$->ptr = $3;
2254                             $$->nextPtr = $4;
2255                         }
2256         ;
2257
2258 furtherNumberElement_0n:        /* empty */
2259                         {
2260                             $$ = NULL;
2261                         }
2262         |               furtherNumberElement_1n
2263                         {
2264                             $$ = $1;
2265                         }
2266         ;
2267
2268 furtherNumberElement_1n:        furtherNumberElement
2269                         {
2270                             $$ = smiMalloc(sizeof(List));
2271                             $$->ptr = $1;
2272                             $$->nextPtr = NULL;
2273                         }
2274         |               furtherNumberElement_1n furtherNumberElement
2275                         {
2276                             List *p, *pp;
2277                             
2278                             p = smiMalloc(sizeof(List));
2279                             p->ptr = $2;
2280                             p->nextPtr = NULL;
2281                             for (pp = $1; pp->nextPtr; pp = pp->nextPtr);
2282                             pp->nextPtr = p;
2283                             $$ = $1;
2284                         }
2285         ;
2286
2287 furtherNumberElement:   optsep '|' optsep numberElement
2288                         {
2289                             $$ = $4;
2290                         }
2291         ;
2292
2293 numberElement:          signedNumber numberUpperLimit_01
2294                         {
2295                             $$ = smiMalloc(sizeof(Range));
2296                             $$->export.minValue = *$1;
2297                             if ($2) {
2298                                 $$->export.maxValue = *$2;
2299                                 smiFree($2);
2300                             } else {
2301                                 $$->export.maxValue = *$1;
2302                             }
2303                             smiFree($1);
2304                         }
2305         ;
2306
2307 numberUpperLimit_01:    /* empty */
2308                         {
2309                             $$ = NULL;
2310                         }
2311         |               numberUpperLimit
2312                         {
2313                             $$ = $1;
2314                         }
2315         ;
2316
2317 numberUpperLimit:       optsep DOT_DOT optsep signedNumber
2318                         {
2319                             $$ = $4;
2320                         }
2321         ;
2322
2323 optsep_floatSpec_01:    /* empty */
2324                         {
2325                             $$ = NULL;
2326                         }
2327         |               optsep floatSpec
2328                         {
2329                             $$ = $2;
2330                         }
2331         ;
2332
2333 floatSpec:              '(' optsep floatElement furtherFloatElement_0n
2334                         optsep ')'
2335                         {
2336                             $$ = smiMalloc(sizeof(List));
2337                             $$->ptr = $3;
2338                             $$->nextPtr = $4;
2339                         }
2340         ;
2341
2342 furtherFloatElement_0n: /* empty */
2343                         {
2344                             $$ = NULL;
2345                         }
2346         |               furtherFloatElement_1n
2347                         {
2348                             $$ = $1;
2349                         }
2350         ;
2351
2352 furtherFloatElement_1n: furtherFloatElement
2353                         {
2354                             $$ = smiMalloc(sizeof(List));
2355                             $$->ptr = $1;
2356                             $$->nextPtr = NULL;
2357                         }
2358         |               furtherFloatElement_1n furtherFloatElement
2359                         {
2360                             List *p, *pp;
2361                             
2362                             p = smiMalloc(sizeof(List));
2363                             p->ptr = $2;
2364                             p->nextPtr = NULL;
2365                             for (pp = $1; pp->nextPtr; pp = pp->nextPtr);
2366                             pp->nextPtr = p;
2367                             $$ = $1;
2368                         }
2369         ;
2370
2371 furtherFloatElement:    optsep '|' optsep floatElement
2372                         {
2373                             $$ = $4;
2374                         }
2375         ;
2376
2377 floatElement:           floatValue floatUpperLimit_01
2378                         {
2379                             $$ = smiMalloc(sizeof(Range));
2380                             $$->export.minValue.basetype = SMI_BASETYPE_FLOAT64;
2381                             $$->export.minValue.value.float64 = strtod($1, NULL);
2382                             if ($2) {
2383                                 $$->export.maxValue.basetype =
2384                                                           SMI_BASETYPE_FLOAT64;
2385                                 $$->export.maxValue.value.float64 =
2386                                                               strtod($2, NULL);
2387                             } else {
2388                                 $$->export.maxValue = $$->export.minValue;
2389                             }
2390                         }
2391         ;
2392
2393 floatUpperLimit_01:     /* empty */
2394                         {
2395                             $$ = NULL;
2396                         }
2397         |               floatUpperLimit
2398                         {
2399                             $$ = $1;
2400                         }
2401         ;
2402
2403 floatUpperLimit:        optsep DOT_DOT optsep floatValue
2404                         {
2405                             $$ = $4;
2406                         }
2407         ;
2408
2409 specialFloatValue:
2410                         neginfKeyword
2411                         {
2412                                 $$="-inf";
2413                         }
2414                 |       posinfKeyword
2415                         {
2416                                 $$="+inf";
2417                         }
2418                 |       qnanKeyword
2419                         {
2420                                 $$="nan";
2421                         }
2422                 |       snanKeyword
2423                         {
2424                                 $$="nan";
2425                         }
2426         ;               
2427         
2428 optsep_pointerRestr_01: /* empty */
2429                         {
2430                             $$ = NULL;
2431                         }
2432         |               optsep pointerRestr
2433                         {
2434                             NamedNumber *nn =(NamedNumber*)smiMalloc(sizeof(NamedNumber));
2435                             $$ = smiMalloc(sizeof(List));
2436                             $$->ptr = nn;
2437                             nn->export.name = $2;
2438                         }
2439         ;
2440
2441 pointerRestr:           '(' optsep qlcIdentifier optsep ')'
2442                         {
2443                             $$ = $3;
2444                         }
2445     ;
2446
2447 bitsOrEnumerationSpec:  '(' optsep bitsOrEnumerationList optsep ')'
2448                         {
2449                             $$ = $3;
2450                         }
2451         ;
2452
2453 bitsOrEnumerationList:  bitsOrEnumerationItem furtherBitsOrEnumerationItem_0n
2454                         optsep_comma_01
2455                         {
2456                             $$ = smiMalloc(sizeof(List));
2457                             $$->ptr = $1;
2458                             $$->nextPtr = $2;
2459                         }
2460         ;
2461
2462 furtherBitsOrEnumerationItem_0n: /* empty */
2463                         {
2464                             $$ = NULL;
2465                         }
2466         |               furtherBitsOrEnumerationItem_1n
2467                         {
2468                             $$ = $1;
2469                         }
2470         ;
2471
2472 furtherBitsOrEnumerationItem_1n: furtherBitsOrEnumerationItem
2473                         {
2474                             $$ = smiMalloc(sizeof(List));
2475                             $$->ptr = $1;
2476                             $$->nextPtr = NULL;
2477                         }
2478         |               furtherBitsOrEnumerationItem_1n
2479                         furtherBitsOrEnumerationItem
2480                         {
2481                             List *p, *pp;
2482                             
2483                             p = smiMalloc(sizeof(List));
2484                             p->ptr = $2;
2485                             p->nextPtr = NULL;
2486                             for (pp = $1; pp->nextPtr; pp = pp->nextPtr);
2487                             pp->nextPtr = p;
2488                             $$ = $1;
2489                         }
2490         ;
2491
2492         
2493 furtherBitsOrEnumerationItem: optsep ',' optsep bitsOrEnumerationItem
2494                         {
2495                             $$ = $4;
2496                         }
2497         ;
2498
2499 bitsOrEnumerationItem:  lcIdentifier optsep '(' optsep signedNumber optsep ')'
2500                         {
2501                             $$ = smiMalloc(sizeof(NamedNumber));
2502                             $$->export.name = $1;
2503                             $$->export.value = *$5;
2504                         }
2505         ;
2506
2507 identifierList:         identifier furtherIdentifier_0n optsep_comma_01
2508                         {
2509                             $$ = smiMalloc(sizeof(List));
2510                             $$->ptr = $1;
2511                             $$->nextPtr = $2;
2512                         }
2513         ;
2514
2515 furtherIdentifier_0n:   /* empty */
2516                         {
2517                             $$ = NULL;
2518                         }
2519         |               furtherIdentifier_1n
2520                         {
2521                             $$ = $1;
2522                         }
2523         ;
2524
2525 furtherIdentifier_1n:   furtherIdentifier
2526                         {
2527                             $$ = smiMalloc(sizeof(List));
2528                             $$->ptr = $1;
2529                             $$->nextPtr = NULL;
2530                         }
2531         |               furtherIdentifier_1n furtherIdentifier
2532                         {
2533                             List *p, *pp;
2534                             
2535                             p = smiMalloc(sizeof(List));
2536                             p->ptr = $2;
2537                             p->nextPtr = NULL;
2538                             for (pp = $1; pp->nextPtr; pp = pp->nextPtr);
2539                             pp->nextPtr = p;
2540                             $$ = $1;
2541                         }
2542         ;
2543
2544 furtherIdentifier:      optsep ',' optsep identifier
2545                         {
2546                             $$ = $4;
2547                         }
2548         ;
2549
2550 bitsValue:              '(' optsep bitsList optsep ')'
2551                         {
2552                             $$ = $3;
2553                         }
2554         ;
2555
2556 bitsList:               optsep_comma_01
2557                         {
2558                             $$ = NULL;
2559                         }
2560         |               lcIdentifier furtherLcIdentifier_0n optsep_comma_01
2561                         {
2562                             $$ = smiMalloc(sizeof(List));
2563                             $$->ptr = $1;
2564                             $$->nextPtr = $2;
2565                         }
2566         ;
2567
2568 //NOTE used also for unique statement
2569 furtherLcIdentifier_0n: /* empty */
2570                         {
2571                             $$ = NULL;
2572                         }
2573         |               furtherLcIdentifier_1n
2574                         {
2575                             $$ = $1;
2576                         }
2577         ;
2578
2579 furtherLcIdentifier_1n: furtherLcIdentifier
2580                         {
2581                             $$ = smiMalloc(sizeof(List));
2582                             $$->ptr = $1;
2583                             $$->nextPtr = NULL;
2584                         }
2585         |               furtherLcIdentifier_1n furtherLcIdentifier
2586                         {
2587                             List *p, *pp;
2588                             
2589                             p = smiMalloc(sizeof(List));
2590                             p->ptr = $2;
2591                             p->nextPtr = NULL;
2592                             for (pp = $1; pp->nextPtr; pp = pp->nextPtr);
2593                             pp->nextPtr = p;
2594                             $$ = $1;
2595                         }
2596         ;
2597
2598 furtherLcIdentifier:    optsep ',' optsep lcIdentifier
2599                         {
2600                             $$ = $4;
2601                         }
2602         ;
2603
2604 identifier:             ucIdentifier
2605                         {
2606                             $$ = $1;
2607                         }
2608         |               lcIdentifier
2609                         {
2610                             $$ = $1;
2611                         }
2612         ;
2613
2614 qucIdentifier:          ucIdentifier COLON_COLON ucIdentifier
2615                         {
2616                             char *s;
2617
2618                             s = smiMalloc(strlen($1) +
2619                                             strlen($3) + 3);
2620                             sprintf(s, "%s::%s", $1, $3);
2621                             $$ = s;
2622                             free($1);
2623                             free($3);
2624                         }
2625         |               ucIdentifier
2626                         {
2627                             $$ = $1;
2628                         }
2629         ;
2630
2631 qlcIdentifier:          ucIdentifier COLON_COLON lcIdentifier
2632                         {
2633                             char *s;
2634
2635                             s = smiMalloc(strlen($1) +
2636                                           strlen($3) + 3);
2637                             sprintf(s, "%s::%s", $1, $3);
2638                             $$ = s;
2639                         }
2640         |               lcIdentifier
2641                         {
2642                             $$ = $1;
2643                         }
2644         ;
2645
2646 text:                   textSegment optsep_textSegment_0n
2647                         {
2648                             int len;
2649                             if ($2) {
2650                                 $$ = smiMalloc(strlen($1) + strlen($2) + 1);
2651                                 strcpy($$, $1);
2652                                 strcat($$, $2);
2653                                 free($1);
2654                                 free($2);
2655                             } else {
2656                                 $$ = smiStrdup($1);
2657                             }
2658                             len = strlen($$);
2659                             while (len > 0 && $$[len-1] == '\n') {
2660                                 $$[--len] = 0;
2661                             }
2662                         }
2663         ;
2664
2665 optsep_textSegment_0n:  /* empty */
2666                         {
2667                             $$ = NULL;
2668                         }
2669         |               optsep_textSegment_1n
2670                         {
2671                             $$ = $1;
2672                         }
2673         ;
2674
2675 optsep_textSegment_1n:  optsep_textSegment
2676                         {
2677                             $$ = $1;
2678                         }
2679         |               optsep_textSegment_1n optsep_textSegment
2680                         {
2681                             $$ = smiMalloc(strlen($1) + strlen($2) + 1);
2682                             strcpy($$, $1);
2683                             strcat($$, $2);
2684                             free($1);
2685                             free($2);
2686                         }
2687         ;
2688
2689 optsep_textSegment:     optsep textSegment
2690                         {
2691                             $$ = smiStrdup($2);
2692                         }
2693         ;
2694
2695 date:                   textSegment
2696                         {
2697                             $$ = checkDate(thisParserPtr, $1);
2698                         }
2699         ;
2700
2701 format:                 textSegment
2702                         {
2703                             $$ = smiStrdup($1);
2704                         }
2705         ;
2706
2707 units:                  textSegment
2708                         {
2709                             $$ = smiStrdup($1);
2710                         }
2711         ;
2712
2713 /*
2714  * The type of `anyValue' must be determined from the
2715  * context. `anyValue' appears only in default value clauses. Hence,
2716  * we set a global variable defaultBasetype in the object type
2717  * declaring clause to remember the expected type.  Here, we use this
2718  * variable to build an SmiValue with the appropriate base type.
2719  */
2720 anyValue:               bitsValue
2721                         {
2722                             if (defaultBasetype == SMI_BASETYPE_BITS) {
2723                                 $$ = smiMalloc(sizeof(SmiValue));
2724                                 $$->basetype = SMI_BASETYPE_BITS;
2725                                 $$->value.ptr = (void*)($1);
2726                                 //set the bits value in the value.integer32
2727                                 if(typePtr){
2728                                         createBitsValue($$,typePtr);
2729                                 }
2730                                 else if(attributePtr){
2731                                 createBitsValue($$,
2732                                         (Type*)smiGetAttributeParentType(&(attributePtr->export)));
2733                                 }
2734                             } else {
2735                                 smiPrintError(thisParserPtr,
2736                                               ERR_UNEXPECTED_VALUETYPE);
2737                                 $$ = NULL;
2738                             }
2739                         }
2740         |               decimalNumber
2741                         {
2742                             /* Note: might also be an OID or signed */
2743                             switch (defaultBasetype) {
2744                             case SMI_BASETYPE_UNSIGNED32:
2745                                 $$ = smiMalloc(sizeof(SmiValue));
2746                                 $$->basetype = SMI_BASETYPE_UNSIGNED32;
2747                                 $$->value.unsigned32 = strtoul($1, NULL, 10);
2748                                 break;
2749                             case SMI_BASETYPE_UNSIGNED64:
2750                                 $$ = smiMalloc(sizeof(SmiValue));
2751                                 $$->basetype = SMI_BASETYPE_UNSIGNED64;
2752                                 $$->value.unsigned64 = strtoull($1, NULL, 10);
2753                                 break;
2754                             case SMI_BASETYPE_INTEGER32:
2755                                 $$ = smiMalloc(sizeof(SmiValue));
2756                                 $$->basetype = SMI_BASETYPE_INTEGER32;
2757                                 $$->value.integer32 = strtol($1, NULL, 10);
2758                                 break;
2759                             case SMI_BASETYPE_INTEGER64:
2760                                 $$ = smiMalloc(sizeof(SmiValue));
2761                                 $$->basetype = SMI_BASETYPE_INTEGER64;
2762                                 $$->value.integer64 = strtoll($1, NULL, 10);
2763                                 break;
2764                             case SMI_BASETYPE_OBJECTIDENTIFIER:
2765                                 $$ = smiMalloc(sizeof(SmiValue));
2766                                 $$->basetype = SMI_BASETYPE_OBJECTIDENTIFIER;
2767                                 $$->len = strlen($1);
2768                                 $$->value.ptr = smiStrdup($1);
2769                                 /* TODO */
2770                                 break;
2771                             default:
2772                                 smiPrintError(thisParserPtr,
2773                                               ERR_UNEXPECTED_VALUETYPE);
2774                                 $$ = NULL;
2775                                 break;
2776                             }
2777                         }
2778         |               '-' decimalNumber
2779                         {
2780                             switch (defaultBasetype) {
2781                             case SMI_BASETYPE_INTEGER32:
2782                                 $$ = smiMalloc(sizeof(SmiValue));
2783                                 $$->basetype = SMI_BASETYPE_INTEGER32;
2784                                 $$->value.integer32 = - strtol($2, NULL, 10);
2785                                 break;
2786                             case SMI_BASETYPE_INTEGER64:
2787                                 $$ = smiMalloc(sizeof(SmiValue));
2788                                 $$->basetype = SMI_BASETYPE_INTEGER64;
2789                                 $$->value.integer64 = - strtoll($2, NULL, 10);
2790                                 break;
2791                             default:
2792                                 smiPrintError(thisParserPtr,
2793                                               ERR_UNEXPECTED_VALUETYPE);
2794                                 $$ = NULL;
2795                                 break;
2796                             }
2797                         }
2798         |               hexadecimalNumber
2799                         {
2800                             /* Note: might also be an octet string */
2801                             switch (defaultBasetype) {
2802                             case SMI_BASETYPE_UNSIGNED32:
2803                                 $$ = smiMalloc(sizeof(SmiValue));
2804                                 $$->basetype = SMI_BASETYPE_UNSIGNED32;
2805                                 $$->value.unsigned32 = strtoul($1, NULL, 16);
2806                                 break;
2807                             case SMI_BASETYPE_UNSIGNED64:
2808                                 $$ = smiMalloc(sizeof(SmiValue));
2809                                 $$->basetype = SMI_BASETYPE_UNSIGNED64;
2810                                 $$->value.unsigned64 = strtoull($1, NULL, 16);
2811                                 break;
2812                             case SMI_BASETYPE_INTEGER32:
2813                                 $$ = smiMalloc(sizeof(SmiValue));
2814                                 $$->basetype = SMI_BASETYPE_INTEGER32;
2815                                 $$->value.integer32 = strtol($1, NULL, 16);
2816                                 break;
2817                             case SMI_BASETYPE_INTEGER64:
2818                                 $$ = smiMalloc(sizeof(SmiValue));
2819                                 $$->basetype = SMI_BASETYPE_INTEGER64;
2820                                 $$->value.integer64 = strtoll($1, NULL, 16);
2821                                 break;
2822                             case SMI_BASETYPE_OCTETSTRING:
2823                                 $$ = smiMalloc(sizeof(SmiValue));
2824                                 $$->basetype = SMI_BASETYPE_OCTETSTRING;
2825                                 $$->value.ptr = hexToStr($1,strlen($1));
2826                                 $$->len = strlen($$->value.ptr);
2827                                 break;
2828                             default:
2829                                 smiPrintError(thisParserPtr,
2830                                               ERR_UNEXPECTED_VALUETYPE);
2831                                 $$ = NULL;
2832                                 break;
2833                             }
2834                         }
2835         |               floatValue
2836                         {
2837                             /* Note: might also be an OID */
2838                             switch (defaultBasetype) {
2839                             case SMI_BASETYPE_FLOAT32:
2840                                 $$ = smiMalloc(sizeof(SmiValue));
2841                                 $$->basetype = SMI_BASETYPE_FLOAT32;
2842                                 $$->value.float32 = strtof($1,NULL);
2843                                 if(errno == ERANGE){
2844                                         smiPrintError(thisParserPtr, 
2845                                         ERR_FLOAT_OVERFLOW, $1);
2846                                         errno = 0;
2847                                 }
2848                                 break;
2849                             case SMI_BASETYPE_FLOAT64:
2850                                 $$ = smiMalloc(sizeof(SmiValue));
2851                                 $$->basetype = SMI_BASETYPE_FLOAT64;
2852                                 $$->value.float64 = strtod($1,NULL);
2853                                 if(errno == ERANGE){
2854                                         smiPrintError(thisParserPtr, 
2855                                         ERR_FLOAT_OVERFLOW, $1);
2856                                         errno = 0;
2857                                 }
2858                                 break;
2859                             case SMI_BASETYPE_FLOAT128:
2860                                 $$ = smiMalloc(sizeof(SmiValue));
2861                                 $$->basetype = SMI_BASETYPE_FLOAT128;
2862                                 $$->value.float128 = strtold($1,NULL);
2863                                 if(errno == ERANGE){
2864                                         smiPrintError(thisParserPtr, 
2865                                         ERR_FLOAT_OVERFLOW, $1);
2866                                         errno = 0;
2867                                 }
2868                                 break;          
2869                             case SMI_BASETYPE_OBJECTIDENTIFIER:
2870                                 $$ = smiMalloc(sizeof(SmiValue));
2871                                 $$->basetype = SMI_BASETYPE_OBJECTIDENTIFIER;
2872                                 $$->value.ptr = smiMalloc(strlen($1)+1);
2873                                 strcpy($$->value.ptr,$1);
2874                                 $$->len = strlen($$->value.ptr);
2875                                 break;
2876                             default:
2877                                 smiPrintError(thisParserPtr,
2878                                               ERR_UNEXPECTED_VALUETYPE);
2879                                 $$ = NULL;
2880                                 break;
2881                             }
2882                         }
2883         |               '-' floatValue
2884                         {
2885                 
2886                             switch (defaultBasetype) {
2887                             case SMI_BASETYPE_FLOAT32:
2888                                 $$ = smiMalloc(sizeof(SmiValue));
2889                                 $$->basetype = SMI_BASETYPE_FLOAT32;
2890                                 $$->value.float32 = - strtof($2,NULL);
2891                                 if(errno == ERANGE){
2892                                         smiPrintError(thisParserPtr, 
2893                                         ERR_FLOAT_OVERFLOW, $2);
2894                                         errno = 0;
2895                                 }
2896                                 break;
2897                             case SMI_BASETYPE_FLOAT64:
2898                                 $$ = smiMalloc(sizeof(SmiValue));
2899                                 $$->basetype = SMI_BASETYPE_FLOAT64;
2900                                 $$->value.float64 = - strtof($2,NULL);
2901                                 if(errno == ERANGE){
2902                                         smiPrintError(thisParserPtr, 
2903                                         ERR_FLOAT_OVERFLOW, $2);
2904                                         errno = 0;
2905                                 }
2906                                 break;
2907                             case SMI_BASETYPE_FLOAT128:
2908                                 $$ = smiMalloc(sizeof(SmiValue));
2909                                 $$->basetype = SMI_BASETYPE_FLOAT128;
2910                                 $$->value.float128 = - strtof($2,NULL);
2911                                 if(errno == ERANGE){
2912                                         smiPrintError(thisParserPtr, 
2913                                         ERR_FLOAT_OVERFLOW, $2);
2914                                         errno = 0;
2915                                 }
2916                                 break;          
2917                             default:
2918                                 smiPrintError(thisParserPtr,
2919                                               ERR_UNEXPECTED_VALUETYPE);
2920                                 $$ = NULL;
2921                                 break;
2922                             }
2923                         }
2924         |               specialFloatValue
2925                         {
2926                                   /* Note: might also be an OID */
2927                             switch (defaultBasetype) {
2928                             case SMI_BASETYPE_FLOAT32:
2929                                 $$ = smiMalloc(sizeof(SmiValue));
2930                                 $$->basetype = SMI_BASETYPE_FLOAT32;
2931                                 $$->value.float32 = strtof($1,NULL);
2932                                 if(errno == ERANGE){
2933                                         smiPrintError(thisParserPtr, 
2934                                         ERR_FLOAT_OVERFLOW, $1);
2935                                         errno = 0;
2936                                 }
2937                                 break;
2938                             case SMI_BASETYPE_FLOAT64:
2939                                 $$ = smiMalloc(sizeof(SmiValue));
2940                                 $$->basetype = SMI_BASETYPE_FLOAT64;
2941                                 $$->value.float64 = strtod($1,NULL);
2942                                 if(errno == ERANGE){
2943                                         smiPrintError(thisParserPtr, 
2944                                         ERR_FLOAT_OVERFLOW, $1);
2945                                         errno = 0;
2946                                 }
2947                                 break;
2948                             case SMI_BASETYPE_FLOAT128:
2949                                 $$ = smiMalloc(sizeof(SmiValue));
2950                                 $$->basetype = SMI_BASETYPE_FLOAT128;
2951                                 $$->value.float128 = strtold($1,NULL);
2952                                 if(errno == ERANGE){
2953                                         smiPrintError(thisParserPtr, 
2954                                         ERR_FLOAT_OVERFLOW, $1);
2955                                         errno = 0;
2956                                 }
2957                                 break;
2958                                 default:
2959                                 smiPrintError(thisParserPtr,
2960                                               ERR_UNEXPECTED_VALUETYPE);
2961                                 $$ = NULL;
2962                                 break;
2963                             }   
2964                         }
2965         |               text
2966                         {
2967                             if (defaultBasetype == SMI_BASETYPE_OCTETSTRING) {
2968                                 $$ = smiMalloc(sizeof(SmiValue));
2969                                 $$->basetype = SMI_BASETYPE_OCTETSTRING;
2970                                 $$->value.ptr = $1;
2971                                 $$->len = strlen($1);
2972                             } else {
2973                                 smiPrintError(thisParserPtr,
2974                                               ERR_UNEXPECTED_VALUETYPE);
2975                                 $$ = NULL;
2976                             }
2977                         }
2978         |               qlcIdentifier
2979                         {
2980                             /* Note: might be an Enumeration item or OID */
2981                             /* TODO: convert if it's an oid? */
2982                             switch (defaultBasetype) {
2983                             case SMI_BASETYPE_ENUM:
2984                                 $$ = smiMalloc(sizeof(SmiValue));
2985                                 $$->basetype = SMI_BASETYPE_ENUM;
2986                                 $$->value.ptr = $1;
2987                                 $$->len = strlen($1);
2988                                 /* TODO: XXX convert to int */
2989                                 break;
2990                             case SMI_BASETYPE_OBJECTIDENTIFIER:
2991                                 $$ = smiMalloc(sizeof(SmiValue));
2992                                 $$->basetype = SMI_BASETYPE_OBJECTIDENTIFIER;
2993                                 $$->value.ptr = $1;
2994                                 $$->len = strlen($1);
2995                                 /* TODO: XXX convert to oid if found */
2996                                 break;
2997                                 case SMI_BASETYPE_POINTER:
2998                                 $$ = smiMalloc(sizeof(SmiValue));
2999                                 $$->basetype = SMI_BASETYPE_OBJECTIDENTIFIER;
3000                                 $$->value.ptr = $1;
3001                                 $$->len = strlen($1);
3002                                 /* TODO: XXX check if valid reference found */
3003                                 break;
3004                             default:
3005                                 smiPrintError(thisParserPtr,
3006                                               ERR_UNEXPECTED_VALUETYPE);
3007                                 $$ = NULL;
3008                                 break;
3009                             }
3010                         }
3011         |               qOID
3012                         {
3013                             if (defaultBasetype == SMI_BASETYPE_OBJECTIDENTIFIER){
3014                             $$ = smiMalloc(sizeof(SmiValue));
3015                                 $$->basetype = SMI_BASETYPE_OBJECTIDENTIFIER;
3016                                 $$->value.ptr = $1;
3017                                 $$->len = strlen($$->value.ptr);
3018                             }
3019                             else
3020                                 smiPrintError(thisParserPtr,
3021                                               ERR_UNEXPECTED_VALUETYPE);
3022                         }
3023         ;
3024         
3025 qOID:           ucIdentifier COLON_COLON OID
3026                         {
3027                             char *s;
3028
3029                             s = smiMalloc(strlen($1) +
3030                                           strlen($3) + 3);
3031                             sprintf(s, "%s::%s", $1, $3);
3032                             $$ = s;
3033                         }
3034                 |       OID
3035                         {
3036                                 $$ = smiMalloc(strlen($1)+1);
3037                                 strcpy($$,$1);
3038                         }
3039         ;
3040
3041 status:                 currentKeyword
3042                         {
3043                             $$ = SMI_STATUS_CURRENT;
3044                         }
3045         |               deprecatedKeyword
3046                         {
3047                             $$ = SMI_STATUS_DEPRECATED;
3048                         }
3049         |               obsoleteKeyword
3050                         {
3051                             $$ = SMI_STATUS_OBSOLETE;
3052                         }
3053         ;
3054
3055 number:                 hexadecimalNumber
3056                         {
3057                             $$ = smiMalloc(sizeof(SmiValue));
3058                             $$->basetype = SMI_BASETYPE_UNSIGNED64;
3059                             $$->value.unsigned64 = strtoull($1, NULL, 16);
3060                         }
3061         |               decimalNumber
3062                         {
3063                             $$ = smiMalloc(sizeof(SmiValue));
3064                             $$->basetype = SMI_BASETYPE_UNSIGNED64;
3065                             $$->value.unsigned64 = strtoull($1, NULL, 10);
3066                         }
3067         ;
3068
3069 negativeNumber:         '-' decimalNumber
3070                         {
3071                             if(bitsFlag){
3072                             smiPrintError(thisParserPtr,
3073                                               ERR_BITS_NUMBER_NEGATIVE);
3074                             $$ = NULL;
3075                             }
3076                             $$ = smiMalloc(sizeof(SmiValue));
3077                             $$->basetype = SMI_BASETYPE_INTEGER64;
3078                             $$->value.integer64 = - strtoll($2, NULL, 10);
3079                         }
3080         ;
3081
3082 signedNumber:           number
3083                         {
3084                             $$ = $1;
3085                         }
3086         |               negativeNumber
3087                         {
3088                             $$ = $1;
3089                         }
3090         ;
3091
3092 /* decimalNumber, hexadecimalNumber, floatValue */
3093
3094 /* unknown... */
3095
3096 optsep_comma_01:        /* empty */
3097                         {
3098                             $$ = 0;
3099                         }
3100 /*      |               optsep ',' */
3101         ;
3102
3103 sep:                    /* empty, skipped by lexer */
3104                         {
3105                             $$ = 0;
3106                         }
3107         ;                       
3108
3109 optsep:                 /* empty, skipped by lexer */
3110                         {
3111                             $$ = 0;
3112                         }
3113         ;                       
3114
3115 stmtsep:                /* empty, skipped by lexer */
3116                         {
3117                             $$ = 0;
3118                         }
3119         ;                       
3120
3121 %%
3122
3123 #endif
3124