home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_n_r / draft-perkins-snmpv2-lex-spec-00.txt < prev    next >
Text File  |  1996-07-31  |  46KB  |  1,801 lines

  1.  
  2. INTERNET-DRAFT            Expires January 1997            INTERNET-DRAFT
  3.  
  4. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  5.  
  6.  
  7.                         A Lexical Specification
  8.                              for the SNMPv2
  9.                           MIB Module Language
  10.  
  11.                   <draft-perkins-snmpv2-lex-spec-00.txt>
  12.  
  13.                              July 30, 1996
  14.  
  15.                             David T. Perkins
  16.                          dperkins@scruznet.com
  17.  
  18.  
  19.  
  20. 1. Status of this Memo
  21.  
  22.    This document is an Internet Draft.  Internet Drafts are working
  23.    documents of the Internet Engineering Task Force (IETF), its Areas,
  24.    and its Working Groups. Note that other groups may also distribute
  25.    working documents as Internet Drafts.
  26.  
  27.    Internet Drafts are draft documents valid for a maximum of six
  28.    months.  Internet Drafts may be updated, replaced, or obsoleted by
  29.    other documents at any time.  It is not appropriate to use Internet
  30.    Drafts as reference material or to cite them other than as a
  31.    "working draft" or "work in progress."
  32.  
  33.    To learn the current status of any Internet-Draft, please check the
  34.    "1id-abstracts.txt" listing contained in the internet-drafts Shadow
  35.    Directories on:
  36.  
  37.          ftp.is.co.za (Africa)
  38.          nic.nordu.net (Europe)
  39.          ds.internic.net (US East Coast)
  40.          ftp.isi.edu (US West Coast)
  41.          munnari.oz.au (Pacific Rim)
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. Expires 1/30/1997                                               [Page 1]
  59.  
  60. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  61.  
  62.  
  63.  
  64. 2. Introduction
  65.  
  66. This memo integrates the specifications for the lexical elements of the
  67. MIB module language from section 8 of the ASN.1 specification[4],
  68. augmented by the ASN.1 macros defined for the MIB module language, and
  69. modified by textual descriptions in SMIv2(RFCs 1902[1], 1903[2] and
  70. 1904[3]); and the standard practices found in most of the leading MIB
  71. compilers that are accepted by the SNMP community.  Also include in this
  72. memo is a Lex specification for the tokens of the language.
  73.  
  74. This memo is a rough first draft as requested by the SNMPv2 WG at the
  75. SMI Documentation BOF during the June 1996 IETF.
  76.  
  77.  
  78.  
  79.  
  80. 3. Lexical Elements
  81.  
  82. The source for a MIB module must be contained in a MIB module source
  83. file.  One or more MIB modules may be contained in a source file.  A
  84. source file consists of a sequence of lines, each terminated by an end-
  85. of-line.  ASN.1 has no restrictions on the length of a line or the
  86. number of lines in a MIB module source file.
  87. [??What should the limits be here?]
  88. Conforming MIB module compilers must allow lines to be at least 255
  89. characters long (excluding the end-of-line indicator), and must allow
  90. source files to contain at least 65535 lines.
  91.  
  92.  
  93. 3.1 Characters in a Source File
  94.  
  95. The "normal" characters in a source file are:
  96.      A-Z the uppercase letters
  97.      a-z the lowercase letters
  98.      0-9 the decimal digits
  99.      { left curly brace
  100.      } right curly brace
  101.      ( left parenthesis
  102.      ) right parenthesis
  103.      : colon
  104.      ; semicolon
  105.      , coma
  106.      - hyphen (dash)
  107.      . period
  108.      | vertical bar
  109.      = equal sign
  110.      " quote
  111.      ' apostrophe
  112.      a space
  113.      a tab
  114.  
  115.  
  116. Expires 1/30/1997                                               [Page 2]
  117.  
  118. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  119.  
  120.  
  121.  
  122. The "additional" characters are the remaining printable characters in
  123. the 7-bit ASCII character set. The "normal" and "additional" characters
  124. are only allowed in comments and in quoted strings.  Note that the ASN.1
  125. language includes characters "<", ">", "[", and "]", which are not used
  126. in the MIB module language.
  127.  
  128.  
  129. 3.2 Tokens
  130.  
  131. The characters in a MIB module source file form a stream of tokens. The
  132. tokens are identifiers, keywords, literals (i.e., constants),
  133. punctuation, and white space.  White space consists of space characters,
  134. line terminators, tab characters, and comments.  White space is ignored
  135. other than for use to separate otherwise adjacent identifiers, keywords,
  136. and literals.  If the input has been parsed into tokens up to a given
  137. character, the next token is the longest string of characters that could
  138. possibly constitute a token.
  139.  
  140.  
  141. 3.3 Comments
  142.  
  143. A comment is started with a pair of adjacent hyphens (--) and is ended
  144. with the next pair of adjacent hyphens or the end of the line, whichever
  145. comes first.  A comment may include any of the printable characters in
  146. the 7-bit ASCII character set, and spaces and tabs.  A comment may occur
  147. between any two tokens and functions as white space.
  148.  
  149.  
  150. 3.4 Identifiers
  151.  
  152. An identifier consists of 1 to 64 letters, digits, and hyphens.  The
  153. initial character must be a letter.  A hyphen cannot be the last
  154. character of an identifier.  A hyphen cannot be immediately followed by
  155. another hyphen in an identifier. (NOTE: ASN.1 has no limit on number of
  156. characters in an identifier. Otherwise, the lexical rules for
  157. identifiers are identical.)
  158.  
  159. There are two types of identifiers which are distinguished by the case
  160. of the initial letter.  A "ucName" is an identifier that starts with an
  161. uppercase letter.  A "lcName" is an identifier that starts with a
  162. lowercase letter.  Identifiers whose lengths are greater than 24 may
  163. cause compatibility difficulties with tools that process MIB modules
  164.  
  165. Also note that SMIv2 imposes restrictions on use of hyphens in most
  166. identifiers.  Those restrictions are noted in the grammar description.
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. Expires 1/30/1997                                               [Page 3]
  175.  
  176. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  177.  
  178.  
  179. 3.5 Keywords
  180.  
  181. Some identifiers are reserved for use as keywords.  The keywords can not
  182. be used as ucNames.  The keywords consist of the sub-set of ASN.1
  183. keywords used in the MIB module language, and the elements of the macros
  184. defined for SNMP that conform to the rules for ucNames.
  185.  
  186.      The following are keywords in ASN.1, but are not keywords in the
  187.      MIB module language:
  188.           ABSENT, ANY, APPLICATION, BIT, BOOLEAN, BY, CHOICE,
  189.           COMPONENT, COMPONENTS, DEFAULT, DEFINED, ENUMERATED,
  190.           EXPLICIT, EXPORTS, EXTERNAL, FALSE, IMPLICIT, MAX, MIN,
  191.           MINUS-INFINITY, NULL, OPTIONAL, PLUS-INFINITY, PRESENT,
  192.           PRIVATE, REAL, SET, TAGS, TRUE, UNIVERSAL, and WITH
  193.  
  194.      The following are ASN.1 keywords used in the MIB module language:
  195.           BEGIN, DEFINITIONS, END, FROM, IDENTIFIER, IMPORTS,
  196.           INCLUDES, INTEGER, OBJECT, OCTET, OF, SEQUENCE, SIZE,
  197.           and STRING
  198.  
  199.      The following are keywords only in the MIB module language:
  200.           ACCESS, AGENT-CAPABILITIES, AUGMENTS, BITS,
  201.           CONTACT-INFO, CREATION-REQUIRES, Counter32, Counter64,
  202.           DEFVAL, DESCRIPTION, DISPLAY-HINT, GROUP, Gauge32,
  203.           IMPLIED, INDEX, Integer32, IpAddress, LAST-UPDATED,
  204.           MANDATORY-GROUPS, MIN-ACCESS, MODULE, MODULE-
  205.           COMPLIANCE, MODULE-IDENTITY, NOTIFICATION-GROUP,
  206.           NOTIFICATION-TYPE, OBJECT-GROUP, OBJECT-IDENTITY,
  207.           OBJECT-TYPE, OBJECTS, ORGANIZATION, Opaque,
  208.           PRODUCT-RELEASE, REFERENCE, REVISION, STATUS, SUPPORTS,
  209.           SYNTAX, TEXTUAL-CONVENTION, TimeTicks, UNITS,
  210.           Unsigned32, VARIATION, and WRITE-SYNTAX
  211.  
  212.  
  213. 3.6 Punctuation
  214.  
  215. The following is a list of single characters used as punctuation tokens
  216. in the MIB module language:
  217.      { left curly brace
  218.      } right curly brace
  219.      ( left parenthesis
  220.      ) right parenthesis
  221.      : colon
  222.      ; semicolon
  223.      , coma
  224.      - hyphen (dash)
  225.      . period
  226.      | vertical bar
  227.  
  228.  
  229.  
  230.  
  231.  
  232. Expires 1/30/1997                                               [Page 4]
  233.  
  234. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  235.  
  236.  
  237. The following is a list of character combinations used as punctuation
  238. tokens in the MIB module language:
  239.      .. two periods
  240.      ::= two colons and an equal sign
  241.  
  242.  
  243. 3.7 Literals
  244.  
  245. The literals (or constants) are unsigned integers (called numbers),
  246. character strings, hexadecimal strings, and binary strings. (NOTE: the
  247. character strings in the MIB module language are not ASN.1 "cstrings".)
  248.  
  249.  
  250. 3.7.1 Numbers
  251.  
  252. A number consists of one or more decimal digits. The first digit may not
  253. be zero unless the number is a single digit.  The maximum value of a
  254. number is 4294967295. (NOTE: there is no limit on the maximum value of
  255. numbers in ASN.1.)
  256.  
  257.  
  258. 3.7.2 Binary Strings
  259.  
  260. A binary string consists of an arbitrary number (possibly zero) of zeros
  261. and ones, preceded by a single (') and followed by either the pair ('B)
  262. or ('b).  The maximum length is 128 binary digits. (NOTE: ASN.1
  263. terminates a binary string with only a ('B).  Also, ASN.1 has no limit
  264. on the length of a binary string.)
  265.  
  266.  
  267. 3.7.3 Hexadecimal Strings
  268.  
  269. A hexadecimal string consists of an arbitrary number (possibly zero) of
  270. hexadecimal digits, preceded by a single (') and followed by either the
  271. pair ('H) or ('h).  The maximum length is 128 hexadecimal digits.  The
  272. hexadecimal digits are the characters "0", "1", "2", "3", "4", "5", "6",
  273. "7", "8", "9", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F",
  274. and "f".  (NOTE: ASN.1 terminates a hexadecimal string with only a ('H).
  275. Also, ASN.1 recognizes only the uppercase letters as hexadecimal digits
  276. and has no limit on the length of a hexadecimal string.)
  277.  
  278.  
  279. 3.7.4 Strings
  280.  
  281. A character string consists of an arbitrary number (possibly zero) of
  282. the 7-bit graphic ASCII characters except the quote character ("), tabs,
  283. spaces, and line terminators, preceded and followed by the quote
  284. character ("). A line terminator is encoded in a quoted string as a
  285. newline (i.e., the '\n' character).  The maximum length of a character
  286. string is 8192 characters.
  287.  
  288.  
  289.  
  290. Expires 1/30/1997                                               [Page 5]
  291.  
  292. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  293.  
  294.  
  295. 4. Lex Specification
  296.  
  297. The specification below is the input for the Lex program, a widely used
  298. program to generate lexical analyzers.  The specification can also be
  299. processed by the Flex program from the GNU project, which is a clone of
  300. Lex.
  301.  
  302.  
  303.  
  304. 4.1 File v-scan.l
  305.  
  306. /* file: v-scan.l - scanner for SNMPv1 and SNMPv2
  307.  *
  308.  * Copyright 1996 David T. Perkins. All Rights Reserved.
  309.  *
  310.  * David T. Perkins grants a non-exclusive license to use, copy,
  311.  * modify, and distribute this software for any purpose and
  312.  * without fee, provided that this copyright notice and license
  313.  * appear on all copies and supporting documentation.
  314.  * David T. Perkins makes no representations about the suitability
  315.  * of this software for any particular purpose. The software is
  316.  * supplied "AS IS", and David T. Perkins makes no warranty, either
  317.  * express or implied, as to the use, operation, condition, or
  318.  * performance of the software.
  319.  * David T. Perkins retains all title and ownership in the software.
  320.  *
  321.  *
  322.  * $Revision: 1.0.1 $
  323.  * $Date: 28-jul-96 $
  324.  *
  325. */
  326.  
  327. %{
  328. /* file: v-scan.c - generated scanner for SNMPv1 and SNMPv2
  329.  *                  from v-scan.l
  330.  *
  331. */
  332.  
  333. #include <stdlib.h>
  334. #include <errno.h>
  335. #include <limits.h>
  336.  
  337.  
  338. #include "v-types.h"
  339. #include "v-scan.h"
  340. #include "yystype.h"
  341.  
  342. MIBLOC locCur = { NULL, 1, 1 }; /* current location (line, column) */
  343.  
  344. BOOL fInStr;                    /* flag that in string */
  345. USHORT usType;                  /* token type */
  346.  
  347.  
  348. Expires 1/30/1997                                               [Page 6]
  349.  
  350. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  351.  
  352.  
  353. USHORT usColStart;              /* start column for a string */
  354. BOOL fOk2DropLWS;               /* flag to allow dropping LWS */
  355. BOOL fDropLWS;                  /* flag that dropping leading
  356.                                     white space */
  357.  
  358. #define MAXSZNUM 10             /* max digits in a number */
  359. #define MAXNUMSZ "4294967295"   /* max value for a number */
  360. #define MAXNUMUL  4294967295LU
  361.  
  362. #define MAXSZNA 64              /* max length of a name */
  363. CHAR szNa[MAXSZNA+1];           /* buffer for a name */
  364. USHORT cSzNa;                   /* number of bytes in buffer */
  365.  
  366. #define MAXSZSTR 8192           /* max length of a string */
  367. /* note that MAXSZBSTR and MAXSZHBSTR
  368. *  must be less than or equal to MAXSZSTR */
  369. #define MAXSZBSTR 128           /* max length of a binary string */
  370. #define MAXSZHSTR 128           /* max length of a hex string */
  371. CHAR szStr[MAXSZSTR+1];         /* buffer for a string */
  372. USHORT cSzStr;                  /* number of bytes in buffer */
  373.  
  374. %}
  375.  /* states for scanning: */
  376.    /* in a hex or bin string */
  377. %s InHexOrBinString
  378.    /* in a quoted string */
  379. %s InQuotedString
  380.    /* in a comment */
  381. %s InComment
  382.    /* in a name */
  383. %s InName
  384.    /* in a number */
  385. %s InNumber
  386.    /* leading zeros of a number */
  387. %s LeadingZeros
  388.  
  389.  
  390. %n 800      /* increased number of DFA entries */
  391. %e 1500     /* increased number of NFA entries */
  392.  
  393. %%
  394.  
  395.   /* Comment */
  396. <INITIAL>"--" {
  397.         /* start of a comment */
  398.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  399.         BEGIN InComment;
  400.         }
  401.  
  402. <InComment>"--" {
  403.         /* finished with comment */
  404.  
  405.  
  406. Expires 1/30/1997                                               [Page 7]
  407.  
  408. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  409.  
  410.  
  411.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  412.         BEGIN 0;
  413.         }
  414.  
  415. <InComment>"\n" {
  416.         /* finished with comment */
  417.         locCur.ulLineNo++;
  418.         locCur.usColNo = 1;
  419.         BEGIN 0;
  420.         }
  421.  
  422. <InComment>. {
  423.         /* any other character in the comment */
  424.         locCur.usColNo++;
  425.         }
  426.  
  427.   /* special tokens */
  428. <INITIAL>"{" {
  429.         yylval.usval.loc = locCur;
  430.         locCur.usColNo++;
  431.         return(yylval.usval.us = XchLCB);
  432.         }
  433.  
  434. <INITIAL>"}" {
  435.         yylval.usval.loc = locCur;
  436.         locCur.usColNo++;
  437.         return(yylval.usval.us = XchRCB);
  438.         }
  439.  
  440. <INITIAL>"(" {
  441.         yylval.usval.loc = locCur;
  442.         locCur.usColNo++;
  443.         return(yylval.usval.us = XchLPR);
  444.         }
  445.  
  446. <INITIAL>")" {
  447.         yylval.usval.loc = locCur;
  448.         locCur.usColNo++;
  449.         return(yylval.usval.us = XchRPR);
  450.         }
  451.  
  452. <INITIAL>";" {
  453.         yylval.usval.loc = locCur;
  454.         locCur.usColNo++;
  455.         return(yylval.usval.us = XchSEMI);
  456.         }
  457.  
  458. <INITIAL>"," {
  459.         yylval.usval.loc = locCur;
  460.         locCur.usColNo++;
  461.         return(yylval.usval.us = XchCOMMA);
  462.  
  463.  
  464. Expires 1/30/1997                                               [Page 8]
  465.  
  466. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  467.  
  468.  
  469.         }
  470.  
  471. <INITIAL>"-" {
  472.         yylval.usval.loc = locCur;
  473.         locCur.usColNo++;
  474.         return(yylval.usval.us = XchMINUS);
  475.         }
  476.  
  477. <INITIAL>"." {
  478.         yylval.usval.loc = locCur;
  479.         locCur.usColNo++;
  480.         return(yylval.usval.us = XchDOT);
  481.         }
  482.  
  483. <INITIAL>"|" {
  484.         yylval.usval.loc = locCur;
  485.         locCur.usColNo++;
  486.         return(yylval.usval.us = XchOR);
  487.         }
  488.  
  489. <INITIAL>".." {
  490.         yylval.usval.loc = locCur;
  491.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  492.         return(yylval.usval.us = XtokDOTDOT);
  493.         }
  494.  
  495. <INITIAL>"::=" {
  496.         yylval.usval.loc = locCur;
  497.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  498.         return(yylval.usval.us = XtokIS);
  499.         }
  500.  
  501.  
  502.   /* white space */
  503. <INITIAL>[ \t] {
  504.         /* space or tab */
  505.         locCur.usColNo++;
  506.         }
  507.  
  508. <INITIAL>"\n" {
  509.         /* a newline */
  510.         locCur.ulLineNo++;
  511.         locCur.usColNo = 1;
  512.         }
  513.  
  514.  
  515.   /* Name starting with uppercase letter,
  516.      including keywords for the parser */
  517. <INITIAL>[A-Z] {
  518.         /* ucName (identifier that starts with
  519.            an uppercase letter) */
  520.  
  521.  
  522. Expires 1/30/1997                                               [Page 9]
  523.  
  524. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  525.  
  526.  
  527.         yylval.strval.pStr = NULL;
  528.         yylval.strval.loc = locCur;
  529.         locCur.usColNo++;
  530.         cSzNa = 1;
  531.         szNa[0] = yytext[0];
  532.         usType = XtokUCNAME;
  533.         BEGIN InName;
  534.         }
  535.  
  536.   /* Name starting with lowercase letter */
  537. <INITIAL>[a-z] {
  538.         /* lcName (identifier that starts with
  539.            a lowercase letter) */
  540.         yylval.strval.pStr = NULL;
  541.         yylval.strval.loc = locCur;
  542.         locCur.usColNo++;
  543.         cSzNa = 1;
  544.         szNa[0] = yytext[0];
  545.         usType = XtokLCNAME;
  546.         BEGIN InName;
  547.         }
  548.  
  549.   /* common for ucName and lcName */
  550. <InName>"--" {
  551.         /* a comment terminates a name */
  552.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  553.         BEGIN InComment;
  554.  
  555.         /* terminate saved string and check on size of name */
  556.         if (cSzNa > MAXSZNA) {
  557.             yyerror("Name too big, max size is %d", MAXSZNA);
  558.             szNa[MAXSZNA] = 0;
  559.         } else {
  560.             szNa[cSzNa] = 0;
  561.         }
  562.  
  563.         /* check if keyword */
  564.         if ((cSzNa <= MAXSZNA) &&
  565.                 (usType == XtokUCNAME) &&
  566.                 ((yylval.usval.us = getKwType(&szNa[0])) != 0)) {
  567.             /* was a keyword */
  568.             return(yylval.usval.us);
  569.         }
  570.  
  571.         /* Otherwise, store name in string table */
  572.         yylval.strval.pStr = StrTabInsert(&szNa[0]);
  573.         return(usType);
  574.         }
  575.  
  576. <InName>"-"/([A-Z]|[a-z]|[0-9]) {
  577.         /* a hyphen in name */
  578.  
  579.  
  580. Expires 1/30/1997                                              [Page 10]
  581.  
  582. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  583.  
  584.  
  585.         locCur.usColNo++;
  586.         if (cSzNa < MAXSZNA) {
  587.             szNa[cSzNa++] = yytext[0];
  588.         } else if (cSzNa == MAXSZNA) {
  589.             /* max chars in string */
  590.             cSzNa++;
  591.         } /* else, too many chars, so do nothing */
  592.         }
  593.  
  594. <InName>([A-Z]|[a-z]|[0-9]) {
  595.         /* a letter or digit in name */
  596.         locCur.usColNo++;
  597.         if (cSzNa < MAXSZNA) {
  598.             szNa[cSzNa++] = yytext[0];
  599.         } else if (cSzNa == MAXSZNA) {
  600.             /* max chars in string */
  601.             cSzNa++;
  602.         } /* else, too many chars, so do nothing */
  603.         }
  604.  
  605. <InName>(.|\n) {
  606.         /* anything else or newline terminates the name */
  607.  
  608.         /* pushback input */
  609.         yyless(0);
  610.         BEGIN 0;
  611.  
  612.         /* terminate saved string and check on size of name */
  613.         if (cSzNa > MAXSZNA) {
  614.             yyerror("Name too big, max size is %d", MAXSZNA);
  615.             szNa[MAXSZNA] = 0;
  616.         } else {
  617.             szNa[cSzNa] = 0;
  618.         }
  619.  
  620.         /* check if keyword */
  621.         if ((cSzNa <= MAXSZNA) &&
  622.                 (usType == XtokUCNAME) &&
  623.                 ((yylval.usval.us = getKwType(&szNa[0])) != 0)) {
  624.             /* was a keyword */
  625.             return(yylval.usval.us);
  626.         }
  627.  
  628.         /* Otherwise, store name in string table */
  629.         yylval.strval.pStr = StrTabInsert(&szNa[0]);
  630.         return(usType);
  631.         }
  632.  
  633.  
  634.   /* number */
  635. <INITIAL>0/[1-9] {
  636.  
  637.  
  638. Expires 1/30/1997                                              [Page 11]
  639.  
  640. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  641.  
  642.  
  643.         /* a zero followed by nonzero digit */
  644.         locCur.usColNo++;
  645.         yyerror("A leading zero on a number is illegal");
  646.         }
  647.  
  648. <INITIAL>0/0 {
  649.         /* a zero followed by a zero */
  650.         locCur.usColNo++;
  651.         yyerror("Leading zero(s) on a number are illegal");
  652.         BEGIN LeadingZeros;
  653.         }
  654.  
  655. <LeadingZeros>0/0 {
  656.         /* multiple leading zeros */
  657.         locCur.usColNo++;
  658.         }
  659.  
  660. <LeadingZeros>0 {
  661.         /* zero followed by anything else */
  662.         /* pushback input, and rescan as a number */
  663.         yyless(0);
  664.         BEGIN 0;
  665.         }
  666.  
  667. <INITIAL>[0-9] {
  668.         /* start of a number */
  669.         yylval.ulval.loc = locCur;
  670.         locCur.usColNo++;
  671.         cSzNa = 1;
  672.         szNa[0] = yytext[0];
  673.         BEGIN InNumber;
  674.         }
  675.  
  676. <InNumber>[0-9] {
  677.         /* digits in the number */
  678.         locCur.usColNo++;
  679.         if (cSzNa < MAXSZNUM) {
  680.             /* add char to string */
  681.             szNa[cSzNa++] = yytext[0];
  682.         } else if (cSzNa == MAXSZNUM) {
  683.             /* max chars in string */
  684.             cSzNa++;
  685.         } /* else, too many chars, so do nothing */
  686.         }
  687.  
  688.  
  689. <InNumber>(.|\n) {
  690.         /* anything else in input terminates the number */
  691.  
  692.         /* terminate string */
  693.         szNa[(cSzNa < MAXSZNUM) ? cSzNa : MAXSZNUM] = 0;
  694.  
  695.  
  696. Expires 1/30/1997                                              [Page 12]
  697.  
  698. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  699.  
  700.  
  701.  
  702.         /* check if number is valid, and compute value */
  703.         if ((cSzNa > MAXSZNUM)  ||
  704.                 ((cSzNa == MAXSZNUM) &&
  705.                         ((strcmp(szNa, MAXNUMSZ) > 0)))) {
  706.             yylval.ulval.ul = MAXNUMUL;
  707.             yyerror("Number too big, max value is %lu",
  708.                         MAXNUMUL);
  709.         } else {
  710.             /* compute value of number */
  711.             {
  712.                 CHAR *pch;
  713.  
  714.                 yylval.ulval.ul = 0;
  715.                 for (pch = &szNa[0]; *pch != 0; pch++) {
  716.                     yylval.ulval.ul = yylval.ulval.ul*10 +
  717.                                         (*pch - '0');
  718.                 }
  719.             }
  720.         }
  721.  
  722.         /* check for character */
  723.         if ((('a' <= yytext[0]) && (yytext[0] <= 'z')) ||
  724.                 (('A' <= yytext[0]) && (yytext[0] <= 'Z')))
  725.             yyerror(
  726.                 "Missing separator between number and character");
  727.  
  728.         /* pushback input */
  729.         yyless(0);
  730.         BEGIN 0;
  731.         return(XtokNUMBER);
  732.         }
  733.  
  734.  
  735.   /* Hex or Binary string */
  736. <INITIAL>"'" {
  737.         /* start of a HEX or BINARY string */
  738.         yylval.strval.pStr = NULL;
  739.         yylval.strval.loc = locCur;
  740.         locCur.usColNo++;
  741.         cSzStr = 0;
  742.         fInStr = TRUE;
  743.         BEGIN InHexOrBinString;
  744.         }
  745.  
  746. <InHexOrBinString>[0-9a-fA-F] {
  747.         /* in a HEX or BINARY string */
  748.         locCur.usColNo++;
  749.         if (cSzStr < MAXSZSTR) {
  750.             /* add char to string */
  751.             szStr[cSzStr++] = yytext[0];
  752.  
  753.  
  754. Expires 1/30/1997                                              [Page 13]
  755.  
  756. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  757.  
  758.  
  759.         } else if (cSzStr == MAXSZSTR) {
  760.             /* max chars in string */
  761.             cSzStr++;
  762.         } /* else, too many chars, so do nothing */
  763.         }
  764.  
  765. <InHexOrBinString>"'"[Hh] {
  766.         /* end of HEX string */
  767.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  768.  
  769.         /* terminate string and check on size */
  770.         if (cSzStr > MAXSZHSTR) {
  771.             yyerror(
  772.                 "Hexadecimal string too long, max length is %d",
  773.                 MAXSZHSTR);
  774.             szStr[MAXSZHSTR] = 0;
  775.         } else {
  776.             szStr[cSzStr] = 0;
  777.         }
  778.  
  779.         BEGIN 0;
  780.         fInStr = FALSE;
  781.  
  782.         /* store in string table */
  783.         yylval.strval.pStr = StrTabInsert(&szStr[0]);
  784.         return(XtokHSTR);
  785.         }
  786.  
  787. <InHexOrBinString>"'"[Bb] {
  788.         /* end of BINARY string */
  789.         locCur.usColNo = (USHORT)(locCur.usColNo + yyleng);
  790.  
  791.         /* terminate string and check on size */
  792.         if (cSzStr > MAXSZBSTR) {
  793.             yyerror("Binary string too long, max length is %d",
  794.                         MAXSZBSTR);
  795.             szStr[MAXSZBSTR] = 0;
  796.         } else {
  797.             szStr[cSzStr] = 0;
  798.         }
  799.  
  800.         /* check if all binary digits */
  801.         {   CHAR *pch;
  802.  
  803.             for (pch = &szStr[0]; *pch != 0; pch++) {
  804.                 if ((*pch != '0') && (*pch != '1')) {
  805.                     yyerror("Invalid digit in Binary string");
  806.                     *pch = 0;
  807.                     break;
  808.                 }
  809.             }
  810.  
  811.  
  812. Expires 1/30/1997                                              [Page 14]
  813.  
  814. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  815.  
  816.  
  817.         }
  818.  
  819.         BEGIN 0;
  820.         fInStr = FALSE;
  821.  
  822.         /* store in string table */
  823.         yylval.strval.pStr = StrTabInsert(&szStr[0]);
  824.         return(XtokBSTR);
  825.         }
  826.  
  827. <InHexOrBinString>(.|\n) {
  828.         /* invalid char in HEX or BINARY string */
  829.         /* pushback input */
  830.         yyless(0);
  831.         fInStr = FALSE;
  832.         BEGIN 0;
  833.         yyerror("Invalid Hexadecial or Binary string");
  834.         }
  835.  
  836.   /* quoted string */
  837. <INITIAL>\" {
  838.         /* start of a quoted string */
  839.         yylval.strval.pStr = NULL;
  840.         yylval.strval.loc = locCur;
  841.         usColStart = locCur.usColNo++;
  842.         if (fOk2DropLWS)
  843.             fDropLWS = FALSE;
  844.         cSzStr = 0;
  845.         fInStr = TRUE;
  846.         BEGIN InQuotedString;
  847.         }
  848.  
  849. <InQuotedString>"\n" {
  850.         /* a newline in the quoted string */
  851.         locCur.ulLineNo++;
  852.         locCur.usColNo = 1;
  853.         if (fOk2DropLWS)
  854.             fDropLWS = TRUE;
  855.  
  856.         /* add char to string if room */
  857.         if (cSzStr < MAXSZSTR) {
  858.             /* add char to string */
  859.             szStr[cSzStr++] = yytext[0];
  860.         } else if (cSzStr == MAXSZSTR) {
  861.             /* max chars in string */
  862.             cSzStr++;
  863.         } /* else, too many chars, so do nothing */
  864.         }
  865.  
  866. <InQuotedString>[^"\n] {
  867.         /* a character in a quoted string */
  868.  
  869.  
  870. Expires 1/30/1997                                              [Page 15]
  871.  
  872. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  873.  
  874.  
  875.         locCur.usColNo++;
  876.  
  877.         /* check for leading white space */
  878.         if (fDropLWS) {
  879.             /* check if before start column for string */
  880.             /* and char is white space */
  881.             if ((locCur.usColNo > usColStart) ||
  882.                     ((yytext[0] ^= ' ') && (yytext[0] != '\t')))
  883.                /* stop ignoring leading whitespace */
  884.                fDropLWS = FALSE;
  885.         }
  886.  
  887.         /* add char if not dropping leading white space */
  888.         if (!fDropLWS) {
  889.             /* add char to string if room */
  890.             if (cSzStr < MAXSZSTR) {
  891.                 /* add char to string */
  892.                 szStr[cSzStr++] = yytext[0];
  893.             } else if (cSzStr == MAXSZSTR) {
  894.                 /* max chars in string */
  895.                 cSzStr++;
  896.             } /* else, too many chars, so do nothing */
  897.         }
  898.         }
  899.  
  900. <InQuotedString>\" {
  901.         /* end of quoted string */
  902.         locCur.usColNo++;
  903.  
  904.         /* terminate string and check on size */
  905.         if (cSzStr > MAXSZSTR) {
  906.             yyerror("String too long, max length is %d",
  907.                         MAXSZSTR);
  908.             szStr[MAXSZSTR] = 0;
  909.         } else {
  910.             szStr[cSzStr] = 0;
  911.         }
  912.  
  913.         BEGIN 0;
  914.         fInStr = FALSE;
  915.  
  916.         /* store in string table */
  917.         yylval.strval.pStr = StrTabInsert(&szStr[0]);
  918.         return(XtokSTRING);
  919.         }
  920.  
  921.   /* anything else in the input */
  922. <INITIAL>. {
  923.         /* anything else in the input */
  924.         locCur.usColNo++;
  925.         yyerror("Unrecognized item");
  926.  
  927.  
  928. Expires 1/30/1997                                              [Page 16]
  929.  
  930. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  931.  
  932.  
  933.         }
  934.  
  935.  
  936. %%
  937.  
  938. /* parameters for hash function */
  939. #define HASHSIZE 143
  940. #define HASHBITS (sizeof(USHORT)*8)
  941. #define HASH3_4  ((HASHBITS*3)/4)
  942. #define HASH1_8  (HASHBITS/8)
  943. #define HASH_HI  (~((USHORT)(~0) >> HASH1_8))
  944.  
  945. /* hash list */
  946. KEYWORDNAME *apkwNa[HASHSIZE];
  947.  
  948.  
  949. /** hashNa - hash a name
  950. *
  951. * From Compiler: Principles, Techniques, and Tools,
  952. *       P.J. Weinberger
  953. *
  954. * call with:
  955. *   pszName - name
  956. *
  957. * returns:
  958. *   hash value
  959. */
  960.     USHORT
  961. #ifdef __STDC__
  962. hashNa(PSZ pszName)
  963. #else
  964. hashNa(pszName)
  965.     PSZ pszName;
  966. #endif /* __STDC__ */
  967. {
  968.     register USHORT usVal;
  969.     register USHORT usTmp;
  970.  
  971.     for (usVal = 0; *pszName != 0; pszName++) {
  972.         usVal = (USHORT)((usVal << HASH1_8) + *pszName);
  973.         if ((usTmp = (USHORT)(usVal & HASH_HI)) != 0) {
  974.             usVal = (USHORT)((usVal ^ (usTmp >> HASH3_4))
  975.                         & ~HASH_HI);
  976.         }
  977.     }
  978.  
  979.     return((USHORT)(usVal%HASHSIZE));
  980.  
  981. } /* hashNa */
  982.  
  983.  
  984.  
  985.  
  986. Expires 1/30/1997                                              [Page 17]
  987.  
  988. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  989.  
  990.  
  991. /** bldKwHash - build hash table for keywords
  992. *
  993. */
  994.     VOID
  995. #ifdef __STDC__
  996. bldKwHash(VOID)
  997. #else
  998. bldKwHash()
  999. #endif /* __STDC__ */
  1000. {
  1001.     INT i;
  1002.     USHORT iHash;
  1003.  
  1004.  
  1005.     for (i = 0; i < HASHSIZE; i++) {
  1006.         apkwNa[i] = NULL;
  1007.     }
  1008.  
  1009.     for (i = cKw - 1; i >= 0; i--) {
  1010.         iHash = hashNa(kwNa[i].pszName);
  1011.         kwNa[i].pHashNext = apkwNa[iHash];
  1012.         apkwNa[iHash] = &(kwNa[i]);
  1013.     }
  1014.  
  1015. } /* bldKwHash */
  1016.  
  1017.  
  1018. #define MXFREQ 10
  1019.  
  1020. /** freqKwHash - print frequences of keyword hash collisions
  1021. *
  1022. */
  1023.     VOID
  1024. #ifdef __STDC__
  1025. freqKwHash(VOID)
  1026. #else
  1027. freqKwHash()
  1028. #endif /* __STDC__ */
  1029. {
  1030.     INT i;
  1031.     USHORT iHash;
  1032.     USHORT acFreq[MXFREQ];
  1033.     KEYWORDNAME *pkwNa;
  1034.  
  1035.  
  1036.     for (i = 0; i < MXFREQ; i++) {
  1037.         acFreq[i] = 0;
  1038.     }
  1039.  
  1040.     for (iHash = 0; iHash < HASHSIZE; iHash++) {
  1041.         for (i = 0, pkwNa = apkwNa[iHash];
  1042.  
  1043.  
  1044. Expires 1/30/1997                                              [Page 18]
  1045.  
  1046. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1047.  
  1048.  
  1049.                 (pkwNa != NULL) && (i < (MXFREQ-1)); i++) {
  1050.             pkwNa = pkwNa->pHashNext;
  1051.         }
  1052.         acFreq[i]++;
  1053.         if (i > 1) {
  1054.             fprintf(fhMsg, "Hash: %d, %d hits\n", iHash, i);
  1055.             for (pkwNa = apkwNa[iHash]; pkwNa != NULL;
  1056.                         pkwNa = pkwNa->pHashNext) {
  1057.                 fprintf(fhMsg, "  \"%s\"\n", pkwNa->pszName);
  1058.             }
  1059.         }
  1060.  
  1061.     }
  1062.  
  1063.     for (i = 0; i < MXFREQ; i++) {
  1064.         if (acFreq[i] != 0)
  1065.             fprintf(fhMsg, "%3d: %d\n", i, acFreq[i]);
  1066.     }
  1067.  
  1068. } /* freqKwHash */
  1069.  
  1070.  
  1071. /** getKwType - lookup item to see if keyword
  1072. *
  1073. * call with:
  1074. *   pszNa - name of item
  1075. *
  1076. * returns:
  1077. *   0 - if not a keyword
  1078. *   otherwise, type of keyword
  1079. *
  1080. */
  1081.     USHORT
  1082. #ifdef __STDC__
  1083. getKwType(PSZ pszNa)
  1084. #else
  1085. getKwType(pszNa)
  1086.     PSZ pszNa;
  1087. #endif /* __STDC__ */
  1088. {
  1089.     USHORT ikwNa;
  1090.     KEYWORDNAME *pkwNa;
  1091.  
  1092.  
  1093.     /* hash name */
  1094.     ikwNa = hashNa(pszNa);
  1095.  
  1096.  
  1097.     /* check names on hash chain */
  1098.     for (pkwNa = apkwNa[ikwNa]; pkwNa != NULL;
  1099.                 pkwNa = pkwNa->pHashNext) {
  1100.  
  1101.  
  1102. Expires 1/30/1997                                              [Page 19]
  1103.  
  1104. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1105.  
  1106.  
  1107.         if (strcmp(pszNa, pkwNa->pszName) == 0)
  1108.             /* name matched, so return type */
  1109.             return(pkwNa->usType);
  1110.     }
  1111.  
  1112.     /* no match */
  1113.     return(0);
  1114.  
  1115. } /* getKwType */
  1116.  
  1117.  
  1118. /** yywrap - check for more input since scanner (yylex)
  1119. *            got EOF from yygetc
  1120. *
  1121. * returns:
  1122. *   0 - more input available on yyin
  1123. *   1 - finished with all input
  1124. */
  1125.     INT
  1126. #ifdef __STDC__
  1127. yywrap(VOID)
  1128. #else
  1129. yywrap()
  1130. #endif /* __STDC__ */
  1131. {
  1132.     if (fInStr) {
  1133.         yyerror("EOF in string");
  1134.     }
  1135.     return(1);
  1136.  
  1137. } /* yywrap */
  1138.  
  1139.  
  1140. /* end of file */
  1141.  
  1142.  
  1143. 4.2 File v2c-scan.c
  1144.  
  1145. /* file: v2c-sc.c - scanner data and functions for SNMPv2C
  1146.  *
  1147.  * Copyright 1996 David T. Perkins. All Rights Reserved.
  1148.  *
  1149.  * David T. Perkins grants a non-exclusive license to use, copy,
  1150.  * modify, and distribute this software for any purpose and
  1151.  * without fee, provided that this copyright notice and license
  1152.  * appear on all copies and supporting documentation.
  1153.  * David T. Perkins makes no representations about the suitability
  1154.  * of this software for any particular purpose. The software is
  1155.  * supplied "AS IS", and David T. Perkins makes no warranty, either
  1156.  * express or implied, as to the use, operation, condition, or
  1157.  * performance of the software.
  1158.  
  1159.  
  1160. Expires 1/30/1997                                              [Page 20]
  1161.  
  1162. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1163.  
  1164.  
  1165.  * David T. Perkins retains all title and ownership in the software.
  1166.  *
  1167.  *
  1168.  * $Revision: 1.0.2 $
  1169.  * $Date: 27-jul-96 $
  1170.  *
  1171. */
  1172.  
  1173. #include <stdio.h>
  1174. #include <stdlib.h>
  1175. #include <limits.h>
  1176.  
  1177.  
  1178. #include "v-types.h"
  1179. #include "v-scan.h"
  1180. #include "v2c-prs.h"
  1181.  
  1182.  
  1183. PSZ pszScanNa = "v2c-scan";
  1184. PSZ pszScanVer = "v1.0.2";
  1185. PSZ pszScanCopyright =
  1186.     "Copyright 1996 David T. Perkins. All Rights Reserved.";
  1187.  
  1188. /* items whose value is defined in parser output */
  1189. USHORT XchLCB = chLCB;
  1190. USHORT XchRCB = chRCB;
  1191. USHORT XchLPR = chLPR;
  1192. USHORT XchRPR = chRPR;
  1193. USHORT XchSEMI = chSEMI;
  1194. USHORT XchCOMMA = chCOMMA;
  1195. USHORT XchMINUS = chMINUS;
  1196. USHORT XchDOT = chDOT;
  1197. USHORT XchOR = chOR;
  1198. USHORT XtokDOTDOT = tokDOTDOT;
  1199. USHORT XtokIS = tokIS;
  1200. USHORT XtokUCNAME = tokUCNAME;
  1201. USHORT XtokLCNAME = tokLCNAME;
  1202. USHORT XtokNUMBER = tokNUMBER;
  1203. USHORT XtokBSTR = tokBSTR;
  1204. USHORT XtokHSTR = tokHSTR;
  1205. USHORT XtokSTRING = tokSTRING;
  1206.  
  1207. /* keywords */
  1208. KEYWORDNAME FAR kwNa[] = {
  1209.         { "ACCESS", kwACCESS, NULL },
  1210.         { "AGENT-CAPABILITIES", kwAGENT_CAPABILITIES, NULL },
  1211.         { "AUGMENTS", kwAUGMENTS, NULL },
  1212.         { "BEGIN", kwBEGIN, NULL },
  1213.         { "BITS", kwBITS, NULL },
  1214.         { "CONTACT-INFO", kwCONTACT_INFO, NULL },
  1215.         { "Counter32", kwCOUNTER32, NULL },
  1216.  
  1217.  
  1218. Expires 1/30/1997                                              [Page 21]
  1219.  
  1220. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1221.  
  1222.  
  1223.         { "Counter64", kwCOUNTER64, NULL },
  1224.         { "CREATION-REQUIRES", kwCREATION_REQUIRES, NULL },
  1225.         { "DEFINITIONS", kwDEFINITIONS, NULL },
  1226.         { "DEFVAL", kwDEFVAL, NULL },
  1227.         { "DESCRIPTION", kwDESCRIPTION, NULL },
  1228.         { "DISPLAY-HINT", kwDISPLAY_HINT, NULL },
  1229.         { "END", kwEND, NULL },
  1230.         { "FROM", kwFROM, NULL },
  1231.         { "Gauge32", kwGAUGE32, NULL },
  1232.         { "GROUP", kwGROUP, NULL },
  1233.         { "IDENTIFIER", kwIDENTIFIER, NULL },
  1234.         { "IMPLIED", kwIMPLIED, NULL },
  1235.         { "IMPORTS", kwIMPORTS, NULL },
  1236.         { "INCLUDES", kwINCLUDES, NULL },
  1237.         { "INDEX", kwINDEX, NULL },
  1238.         { "INTEGER", kwINTEGER, NULL },
  1239.         { "Integer32", kwINTEGER32, NULL },
  1240.         { "IpAddress", kwIPADDRESS, NULL },
  1241.         { "LAST-UPDATED", kwLAST_UPDATED, NULL },
  1242.         { "MANDATORY-GROUPS", kwMANDATORY_GROUPS, NULL },
  1243.         { "MAX-ACCESS", kwMAX_ACCESS, NULL },
  1244.         { "MIN-ACCESS", kwMIN_ACCESS, NULL },
  1245.         { "MODULE", kwMODULE, NULL },
  1246.         { "MODULE-COMPLIANCE", kwMODULE_COMPLIANCE, NULL },
  1247.         { "MODULE-IDENTITY", kwMODULE_IDENTITY, NULL },
  1248.         { "NOTIFICATION-GROUP", kwNOTIFICATION_GROUP, NULL },
  1249.         { "NOTIFICATION-TYPE", kwNOTIFICATION_TYPE, NULL },
  1250.         { "NOTIFICATIONS", kwNOTIFICATIONS, NULL },
  1251.         { "OBJECT", kwOBJECT, NULL },
  1252.         { "OBJECT-GROUP", kwOBJECT_GROUP, NULL },
  1253.         { "OBJECT-IDENTITY", kwOBJECT_IDENTITY, NULL },
  1254.         { "OBJECT-TYPE", kwOBJECT_TYPE, NULL },
  1255.         { "OBJECTS", kwOBJECTS, NULL },
  1256.         { "OCTET", kwOCTET, NULL },
  1257.         { "OF", kwOF, NULL },
  1258.         { "Opaque", kwOPAQUE, NULL },
  1259.         { "ORGANIZATION", kwORGANIZATION, NULL },
  1260.         { "PRODUCT-RELEASE", kwPRODUCT_RELEASE, NULL },
  1261.         { "REFERENCE", kwREFERENCE, NULL },
  1262.         { "REVISION", kwREVISION, NULL },
  1263.         { "SEQUENCE", kwSEQUENCE, NULL },
  1264.         { "SIZE", kwSIZE, NULL },
  1265.         { "STATUS", kwSTATUS, NULL },
  1266.         { "STRING", kwSTRING, NULL },
  1267.         { "SUPPORTS", kwSUPPORTS, NULL },
  1268.         { "SYNTAX", kwSYNTAX, NULL },
  1269.         { "TEXTUAL-CONVENTION", kwTEXTUAL_CONVENTION, NULL },
  1270.         { "TimeTicks", kwTIMETICKS, NULL },
  1271.         { "UNITS", kwUNITS, NULL },
  1272.         { "Unsigned32", kwUNSIGNED32, NULL },
  1273.         { "VARIATION", kwVARIATION, NULL },
  1274.  
  1275.  
  1276. Expires 1/30/1997                                              [Page 22]
  1277.  
  1278. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1279.  
  1280.  
  1281.         { "WRITE-SYNTAX", kwWRITE_SYNTAX, NULL }
  1282. };
  1283.  
  1284. /* number of keywords */
  1285. USHORT cKw = sizeof(kwNa)/sizeof(KEYWORDNAME);
  1286.  
  1287.  
  1288. /** printTokType - print type of a token
  1289. *
  1290. * call with:
  1291. *   iTokType - type of token
  1292. *
  1293. */
  1294.     VOID
  1295. #ifdef __STDC__
  1296. printTokType(INT iTokType)
  1297. #else
  1298. printTokType(iTokType)
  1299.     INT iTokType;
  1300. #endif /* __STDC__ */
  1301. {
  1302.     /* check if in a file */
  1303.     if ((yylval.usval.loc.ulLineNo > 0L) &&
  1304.             (yylval.usval.loc.pszFn != NULL)) {
  1305.  
  1306.         /* output in format for editors */
  1307.  
  1308.         /* check if column valid */
  1309.         if (yylval.usval.loc.usColNo != 0) {
  1310.             /* print out file name, line and column number */
  1311.             fprintf(fhOut, "%s(%lu,%u): ",
  1312.                    yylval.usval.loc.pszFn,
  1313.                    yylval.usval.loc.ulLineNo,
  1314.                    yylval.usval.loc.usColNo);
  1315.         } else {
  1316.             /* print out just file name and line */
  1317.             fprintf(fhOut, "%s(%lu): ",
  1318.                    yylval.usval.loc.pszFn,
  1319.                    yylval.usval.loc.ulLineNo);
  1320.         }
  1321.     }
  1322.  
  1323.     fprintf(fhOut, "T: (%d) ", iTokType);
  1324.     switch(iTokType) {
  1325.     case kwACCESS:
  1326.         fprintf(fhOut, "ACCESS\n");
  1327.         break;
  1328.  
  1329.     case kwAGENT_CAPABILITIES:
  1330.         fprintf(fhOut, "AGENT_CAPABILITIES\n");
  1331.         break;
  1332.  
  1333.  
  1334. Expires 1/30/1997                                              [Page 23]
  1335.  
  1336. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1337.  
  1338.  
  1339.  
  1340.     case kwAUGMENTS:
  1341.         fprintf(fhOut, "AUGMENTS\n");
  1342.         break;
  1343.  
  1344.     case kwBEGIN:
  1345.         fprintf(fhOut, "BEGIN\n");
  1346.         break;
  1347.  
  1348.     case kwBITS:
  1349.         fprintf(fhOut, "BITS\n");
  1350.         break;
  1351.  
  1352.     case kwCONTACT_INFO:
  1353.         fprintf(fhOut, "CONTACT_INFO\n");
  1354.         break;
  1355.  
  1356.     case kwCOUNTER32:
  1357.         fprintf(fhOut, "COUNTER32\n");
  1358.         break;
  1359.  
  1360.     case kwCOUNTER64:
  1361.         fprintf(fhOut, "COUNTER64\n");
  1362.         break;
  1363.  
  1364.     case kwCREATION_REQUIRES:
  1365.         fprintf(fhOut, "CREATION_REQUIRES\n");
  1366.         break;
  1367.  
  1368.     case kwDEFINITIONS:
  1369.         fprintf(fhOut, "DEFINITIONS\n");
  1370.         break;
  1371.  
  1372.     case kwDEFVAL:
  1373.         fprintf(fhOut, "DEFVAL\n");
  1374.         break;
  1375.  
  1376.     case kwDESCRIPTION:
  1377.         fprintf(fhOut, "DESCRIPTION\n");
  1378.         break;
  1379.  
  1380.     case kwDISPLAY_HINT:
  1381.         fprintf(fhOut, "DISPLAY_HINT\n");
  1382.         break;
  1383.  
  1384.     case kwEND:
  1385.         fprintf(fhOut, "END\n");
  1386.         break;
  1387.  
  1388.     case kwFROM:
  1389.         fprintf(fhOut, "FROM\n");
  1390.  
  1391.  
  1392. Expires 1/30/1997                                              [Page 24]
  1393.  
  1394. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1395.  
  1396.  
  1397.         break;
  1398.  
  1399.     case kwGAUGE32:
  1400.         fprintf(fhOut, "GAUGE32\n");
  1401.         break;
  1402.  
  1403.     case kwGROUP:
  1404.         fprintf(fhOut, "GROUP\n");
  1405.         break;
  1406.  
  1407.     case kwIDENTIFIER:
  1408.         fprintf(fhOut, "IDENTIFIER\n");
  1409.         break;
  1410.  
  1411.     case kwIMPLIED:
  1412.         fprintf(fhOut, "IMPLIED\n");
  1413.         break;
  1414.  
  1415.     case kwIMPORTS:
  1416.         fprintf(fhOut, "IMPORTS\n");
  1417.         break;
  1418.  
  1419.     case kwINCLUDES:
  1420.         fprintf(fhOut, "INCLUDES\n");
  1421.         break;
  1422.  
  1423.     case kwINDEX:
  1424.         fprintf(fhOut, "INDEX\n");
  1425.         break;
  1426.  
  1427.     case kwINTEGER:
  1428.         fprintf(fhOut, "INTEGER\n");
  1429.         break;
  1430.  
  1431.     case kwINTEGER32:
  1432.         fprintf(fhOut, "INTEGER32\n");
  1433.         break;
  1434.  
  1435.     case kwIPADDRESS:
  1436.         fprintf(fhOut, "IPADDRESS\n");
  1437.         break;
  1438.  
  1439.     case kwLAST_UPDATED:
  1440.         fprintf(fhOut, "LAST_UPDATED\n");
  1441.         break;
  1442.  
  1443.     case kwMANDATORY_GROUPS:
  1444.         fprintf(fhOut, "MANDATORY_GROUPS\n");
  1445.         break;
  1446.  
  1447.     case kwMAX_ACCESS:
  1448.  
  1449.  
  1450. Expires 1/30/1997                                              [Page 25]
  1451.  
  1452. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1453.  
  1454.  
  1455.         fprintf(fhOut, "MAX_ACCESS\n");
  1456.         break;
  1457.  
  1458.     case kwMIN_ACCESS:
  1459.         fprintf(fhOut, "MIN_ACCESS\n");
  1460.         break;
  1461.  
  1462.     case kwMODULE:
  1463.         fprintf(fhOut, "MODULE\n");
  1464.         break;
  1465.  
  1466.     case kwMODULE_COMPLIANCE:
  1467.         fprintf(fhOut, "MODULE_COMPLIANCE\n");
  1468.         break;
  1469.  
  1470.     case kwMODULE_IDENTITY:
  1471.         fprintf(fhOut, "MODULE_IDENTITY\n");
  1472.         break;
  1473.  
  1474.     case kwNOTIFICATION_GROUP:
  1475.         fprintf(fhOut, "NOTIFICATION_GROUP\n");
  1476.         break;
  1477.  
  1478.     case kwNOTIFICATION_TYPE:
  1479.         fprintf(fhOut, "NOTIFICATION_TYPE\n");
  1480.         break;
  1481.  
  1482.     case kwNOTIFICATIONS:
  1483.         fprintf(fhOut, "NOTIFICATIONS\n");
  1484.         break;
  1485.  
  1486.     case kwOBJECT:
  1487.         fprintf(fhOut, "OBJECT\n");
  1488.         break;
  1489.  
  1490.     case kwOBJECT_GROUP:
  1491.         fprintf(fhOut, "OBJECT_GROUP\n");
  1492.         break;
  1493.  
  1494.     case kwOBJECT_IDENTITY:
  1495.         fprintf(fhOut, "OBJECT_IDENTITY\n");
  1496.         break;
  1497.  
  1498.     case kwOBJECT_TYPE:
  1499.         fprintf(fhOut, "OBJECT_TYPE\n");
  1500.         break;
  1501.  
  1502.     case kwOBJECTS:
  1503.         fprintf(fhOut, "OBJECTS\n");
  1504.         break;
  1505.  
  1506.  
  1507.  
  1508. Expires 1/30/1997                                              [Page 26]
  1509.  
  1510. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1511.  
  1512.  
  1513.     case kwOCTET:
  1514.         fprintf(fhOut, "OCTET\n");
  1515.         break;
  1516.  
  1517.     case kwOF:
  1518.         fprintf(fhOut, "OF\n");
  1519.         break;
  1520.  
  1521.     case kwOPAQUE:
  1522.         fprintf(fhOut, "OPAQUE\n");
  1523.         break;
  1524.  
  1525.     case kwORGANIZATION:
  1526.         fprintf(fhOut, "ORGANIZATION\n");
  1527.         break;
  1528.  
  1529.     case kwPRODUCT_RELEASE:
  1530.         fprintf(fhOut, "PRODUCT_RELEASE\n");
  1531.         break;
  1532.  
  1533.     case kwREFERENCE:
  1534.         fprintf(fhOut, "REFERENCE\n");
  1535.         break;
  1536.  
  1537.     case kwREVISION:
  1538.         fprintf(fhOut, "REVISION\n");
  1539.         break;
  1540.  
  1541.     case kwSEQUENCE:
  1542.         fprintf(fhOut, "SEQUENCE\n");
  1543.         break;
  1544.  
  1545.     case kwSIZE:
  1546.         fprintf(fhOut, "SIZE\n");
  1547.         break;
  1548.  
  1549.     case kwSTATUS:
  1550.         fprintf(fhOut, "STATUS\n");
  1551.         break;
  1552.  
  1553.     case kwSTRING:
  1554.         fprintf(fhOut, "STRING\n");
  1555.         break;
  1556.  
  1557.     case kwSUPPORTS:
  1558.         fprintf(fhOut, "SUPPORTS\n");
  1559.         break;
  1560.  
  1561.     case kwSYNTAX:
  1562.         fprintf(fhOut, "SYNTAX\n");
  1563.         break;
  1564.  
  1565.  
  1566. Expires 1/30/1997                                              [Page 27]
  1567.  
  1568. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1569.  
  1570.  
  1571.  
  1572.     case kwTEXTUAL_CONVENTION:
  1573.         fprintf(fhOut, "TEXTUAL_CONVENTION\n");
  1574.         break;
  1575.  
  1576.     case kwTIMETICKS:
  1577.         fprintf(fhOut, "TIMETICKS\n");
  1578.         break;
  1579.  
  1580.     case kwUNITS:
  1581.         fprintf(fhOut, "UNITS\n");
  1582.         break;
  1583.  
  1584.     case kwUNSIGNED32:
  1585.         fprintf(fhOut, "UNSIGNED32\n");
  1586.         break;
  1587.  
  1588.     case kwVARIATION:
  1589.         fprintf(fhOut, "VARIATION\n");
  1590.         break;
  1591.  
  1592.     case kwWRITE_SYNTAX:
  1593.         fprintf(fhOut, "WRITE_SYNTAX\n");
  1594.         break;
  1595.  
  1596.     case chLCB:
  1597.         fprintf(fhOut, "LCB\n");
  1598.         break;
  1599.  
  1600.     case chRCB:
  1601.         fprintf(fhOut, "RCB\n");
  1602.         break;
  1603.  
  1604.     case chLPR:
  1605.         fprintf(fhOut, "LPR\n");
  1606.         break;
  1607.  
  1608.     case chRPR:
  1609.         fprintf(fhOut, "RPR\n");
  1610.         break;
  1611.  
  1612.     case chSEMI:
  1613.         fprintf(fhOut, "SEMI\n");
  1614.         break;
  1615.  
  1616.     case chCOMMA:
  1617.         fprintf(fhOut, "COMMA\n");
  1618.         break;
  1619.  
  1620.     case chMINUS:
  1621.         fprintf(fhOut, "MINUS\n");
  1622.  
  1623.  
  1624. Expires 1/30/1997                                              [Page 28]
  1625.  
  1626. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1627.  
  1628.  
  1629.         break;
  1630.  
  1631.     case chDOT:
  1632.         fprintf(fhOut, "DOT\n");
  1633.         break;
  1634.  
  1635.     case chOR:
  1636.         fprintf(fhOut, "OR\n");
  1637.         break;
  1638.  
  1639.     case tokDOTDOT:
  1640.         fprintf(fhOut, "DOTDOT\n");
  1641.         break;
  1642.  
  1643.     case tokIS:
  1644.         fprintf(fhOut, "IS\n");
  1645.         break;
  1646.  
  1647.     case tokUCNAME:
  1648.         /* name starting with uppercase letter */
  1649.         fprintf(fhOut, "UCNAME - ");
  1650.         if (yylval.strval.pStr == NULL)
  1651.             fprintf(fhOut, "NULL ptr\n");
  1652.         else if (yylval.strval.pStr->pszVal == NULL)
  1653.             fprintf(fhOut, "Value is NULL ptr\n");
  1654.         else
  1655.             fprintf(fhOut, "\"%s\"\n",
  1656.                     yylval.strval.pStr->pszVal);
  1657.         break;
  1658.  
  1659.     case tokLCNAME:
  1660.         /* name starting with lowercase letter */
  1661.         fprintf(fhOut, "LCNAME - ");
  1662.         if (yylval.strval.pStr == NULL)
  1663.             fprintf(fhOut, "NULL ptr\n");
  1664.         else if (yylval.strval.pStr->pszVal == NULL)
  1665.             fprintf(fhOut, "Value is NULL ptr\n");
  1666.         else
  1667.             fprintf(fhOut, "\"%s\"\n",
  1668.                     yylval.strval.pStr->pszVal);
  1669.         break;
  1670.  
  1671.     case tokSTRING:
  1672.         /* string */
  1673.         fprintf(fhOut, "STRING - ");
  1674.         if (yylval.strval.pStr == NULL)
  1675.             fprintf(fhOut, "NULL ptr\n");
  1676.         else if (yylval.strval.pStr->pszVal == NULL)
  1677.             fprintf(fhOut, "Value is NULL ptr\n");
  1678.         else
  1679.             fprintf(fhOut, "\"%s\"\n",
  1680.  
  1681.  
  1682. Expires 1/30/1997                                              [Page 29]
  1683.  
  1684. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1685.  
  1686.  
  1687.                     yylval.strval.pStr->pszVal);
  1688.         break;
  1689.  
  1690.     case tokNUMBER:
  1691.         fprintf(fhOut, "NUMBER, value %lu\n",
  1692.                yylval.ulval.ul);
  1693.         break;
  1694.  
  1695.     case tokBSTR:
  1696.         /* bit string */
  1697.         fprintf(fhOut, "BSTR - ");
  1698.         if (yylval.strval.pStr == NULL)
  1699.             fprintf(fhOut, "NULL ptr\n");
  1700.         else if (yylval.strval.pStr->pszVal == NULL)
  1701.             fprintf(fhOut, "Value is NULL ptr\n");
  1702.         else
  1703.             fprintf(fhOut, "'%s'B\n",
  1704.                     yylval.strval.pStr->pszVal);
  1705.         break;
  1706.  
  1707.     case tokHSTR:
  1708.         /* hex string */
  1709.         fprintf(fhOut, "HSTR - ");
  1710.         if (yylval.strval.pStr == NULL)
  1711.             fprintf(fhOut, "NULL ptr\n");
  1712.         else if (yylval.strval.pStr->pszVal == NULL)
  1713.             fprintf(fhOut, "Value is NULL ptr\n");
  1714.         else
  1715.             fprintf(fhOut, "'%s'H\n",
  1716.                     yylval.strval.pStr->pszVal);
  1717.         break;
  1718.  
  1719.     default:
  1720.         fprintf(fhOut, "unknown type %d\n", iTokType);
  1721.         break;
  1722.     }
  1723.  
  1724. } /* printTokType */
  1725.  
  1726.  
  1727. /* end of file: v2c-sc.c */
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740. Expires 1/30/1997                                              [Page 30]
  1741.  
  1742. Draft                 SNMPv2 Lexical Specification         July 30, 1996
  1743.  
  1744.  
  1745.  
  1746. 5. References
  1747.  
  1748. [1]  J. Case, K. McCloghrie, M. Rose, S. Waldbusser, "Structure of
  1749.      Management Information for Version 2 of the Simple Network
  1750.      Management Protocol (SNMPv2)", RFC 1902, 01/22/1996.
  1751.  
  1752. [2]  J. Case, K. McCloghrie, M. Rose, S. Waldbusser, "Textual
  1753.      Conventions for Version 2 of the Simple Network Management Protocol
  1754.      (SNMPv2)", RFC 1903, 01/22/1996.
  1755.  
  1756. [3]  J. Case, K. McCloghrie, M. Rose, S. Waldbusser, "Conformance
  1757.      Statements for Version 2 of the Simple Network Management Protocol
  1758.      (SNMPv2)", RFC 1904, 01/22/1996.
  1759.      Management Information for version 2 of the Simple Network
  1760.      Management Protocol (SNMPv2)", RFC 1442, 05/03/1993.
  1761.  
  1762. [4]  Information processing systems - Open Systems Interconnection -
  1763.      Specification of Abstract Syntax Notation One (ASN.1),
  1764.      International Organization for Standardization.  International
  1765.      Standard 8824, (December, 1987).
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798. Expires 1/30/1997                                              [Page 31]
  1799.  
  1800.  
  1801.