|
|
1.1 ! root 1: /* lex.l - lex ASN.1 analyzer */ ! 2: /* %WARNING% */ ! 3: ! 4: %{ ! 5: #ifndef lint ! 6: static char *RCSid = "$Header: /f/osi/pepsy/RCS/lex.l.gnrc,v 7.0 90/07/01 19:54:35 mrose Exp $"; ! 7: #endif ! 8: ! 9: /* ! 10: * $Header: /f/osi/pepsy/RCS/lex.l.gnrc,v 7.0 90/07/01 19:54:35 mrose Exp $ ! 11: * ! 12: * ! 13: * $Log: lex.l.gnrc,v $ ! 14: * Revision 7.0 90/07/01 19:54:35 mrose ! 15: * *** empty log message *** ! 16: * ! 17: * Revision 7.1 90/05/21 17:08:26 mrose ! 18: * yyporting ! 19: * ! 20: * Revision 7.0 89/11/23 22:11:40 mrose ! 21: * Release 6.0 ! 22: * ! 23: */ ! 24: ! 25: /* ! 26: * NOTICE ! 27: * ! 28: * Acquisition, use, and distribution of this module and related ! 29: * materials are subject to the restrictions of a license agreement. ! 30: * Consult the Preface in the User's Manual for the full terms of ! 31: * this agreement. ! 32: * ! 33: * ! 34: */ ! 35: ! 36: ! 37: struct table { ! 38: char *t_keyword; ! 39: int t_value; ! 40: int t_porting; ! 41: }; ! 42: ! 43: static struct table reserved[] = { ! 44: "ABSENT", ABSENT, 0, ! 45: "ANY", ANY, 0, ! 46: "APPLICATION", APPLICATION, 0, ! 47: "BEGIN", BGIN, 0, ! 48: "BIT", BIT, 0, ! 49: "BITSTRING", BITSTRING, 0, ! 50: "BOOLEAN", BOOLEAN, 0, ! 51: "BY", BY, 0, ! 52: "CHOICE", CHOICE, 0, ! 53: "COMPONENT", COMPONENT, 0, ! 54: "COMPONENTS", COMPONENTS, 0, ! 55: "COMPONENTSOF", COMPONENTSOF, 0, ! 56: "DECODER", DECODER, 0, ! 57: "DEFAULT", DEFAULT, 0, ! 58: "DEFINED", DEFINED, 0, ! 59: "DEFINITIONS", DEFINITIONS, 0, ! 60: "ENCODER", ENCODER, 0, ! 61: "ENCRYPTED", ENCRYPTED, 0, ! 62: "END", END, 0, ! 63: "ENUMERATED", ENUMERATED, 0, ! 64: "EXPLICIT", EXPLICIT, 0, ! 65: "EXPORTS", EXPORTS, 0, ! 66: "FALSE", FALSE, 0, ! 67: "FROM", FROM, 0, ! 68: "IDENTIFIER", IDENTIFIER, 0, ! 69: "IMPLICIT", IMPLICIT, 0, ! 70: "IMPORTS", IMPORTS, 0, ! 71: "INCLUDE", INCLUDES, 0, ! 72: "INTEGER", INTEGER, 0, ! 73: "MIN", MIN, 0, ! 74: "MAX", MAX, 0, ! 75: "NULL", NIL, 0, ! 76: "OBJECT", OBJECT, 0, ! 77: "OCTET", OCTET, 0, ! 78: "OCTETSTRING", OCTETSTRING, 0, ! 79: "OF", OF, 0, ! 80: "OPTIONAL", OPTIONAL, 0, ! 81: "PREFIXES", PREFIXES, 0, ! 82: "PRESENT", PRESENT, 0, ! 83: "PRINTER", PRINTER, 0, ! 84: "PRIVATE", PRIVATE, 0, ! 85: "REAL", REAL, 0, ! 86: "SECTIONS", SECTIONS, 0, ! 87: "SEQUENCE", SEQUENCE, 0, ! 88: "SEQUENCEOF", SEQUENCEOF, 0, ! 89: "SET", SET, 0, ! 90: "SETOF", SETOF, 0, ! 91: "SIZE", SIZE, 0, ! 92: "STRING", STRING, 0, ! 93: "TAGS", TAGS, 0, ! 94: "TRUE", TRUE, 0, ! 95: "UNIVERSAL", UNIVERSAL, 0, ! 96: "WITH", WITH, 0, ! 97: "PLUS-INFINITY", PLUSINFINITY, 0, ! 98: "MINUS-INFINITY", MINUSINFINITY, 0, ! 99: %BEGIN(ROSY)% ! 100: "OPERATION", OPERATION, 1, ! 101: "ARGUMENT", ARGUMENT, 0, ! 102: "RESULT", RESULT, 0, ! 103: "ERRORS", ERRORS, 0, ! 104: "LINKED", LINKED, 0, ! 105: "ERROR", ERROR, 1, ! 106: "PARAMETER", PARAMETER, 0, ! 107: /* start new stuff */ ! 108: "ABSTRACT-OPERATION", OPERATION, 0, ! 109: "ABSTRACT-ERROR", ERROR, 0, ! 110: "ABSTRACT", ABSTRACT, 0, ! 111: "OPERATIONS", OPERATIONS, 0, ! 112: "CONSUMER", CONSUMER, 0, ! 113: "SUPPLIER", SUPPLIER, 0, ! 114: "INVOKES", INVOKES, 0, ! 115: "PORT", PORT, 0, ! 116: "PORTS", PORTS, 0, ! 117: /* refine is beyond me! (JPO) ! 118: "REFINE", REFINE, 0, ! 119: "AS", AS, 0, ! 120: "RECURRING", RECURRING, 0, ! 121: "VISIBLE", VISIBLE, 0, ! 122: "PAIRED", PAIRED, 0, ! 123: */ ! 124: /* end new stuff */ ! 125: %END(ROSY)% ! 126: %BEGIN(MOSY)% ! 127: "OBJECT-TYPE", OBJECTYPE, 1, ! 128: "SYNTAX", SYNTAX, 0, ! 129: "ACCESS", ACCESS, 0, ! 130: "STATUS", STATUS, 0, ! 131: %END(MOSY)% ! 132: NULL, 0 ! 133: }; ! 134: %} ! 135: ! 136: %% ! 137: ! 138: "--" { register int c, d; ! 139: ! 140: for (d = 0; c = input (); d = c == '-') ! 141: if (c == '\n' || (d && c == '-')) ! 142: break; ! 143: } ! 144: [ \t]* { ! 145: if (yydebug) ! 146: fprintf (stderr, "WT\n"); ! 147: } ! 148: \n { ! 149: if (yydebug) ! 150: fprintf (stderr, "NL\n"); ! 151: } ! 152: "::=" { ! 153: if (yydebug) ! 154: fprintf (stderr, "SY: CCE\n"); ! 155: return CCE; ! 156: } ! 157: "..." { ! 158: if (yydebug) ! 159: fprintf (stderr, "SY: DOTDOTDOT\n"); ! 160: return DOTDOTDOT; ! 161: } ! 162: ".." { ! 163: if (yydebug) ! 164: fprintf (stderr, "SY: DOTDOT\n"); ! 165: return DOTDOT; ! 166: } ! 167: "." { ! 168: if (yydebug) ! 169: fprintf (stderr, "SY: DOT\n"); ! 170: return DOT; ! 171: } ! 172: ";" { ! 173: if (yydebug) ! 174: fprintf (stderr, "SY: SEMICOLON"); ! 175: return SEMICOLON; ! 176: } ! 177: "," { ! 178: if (yydebug) ! 179: fprintf (stderr, "SY: COMMA\n"); ! 180: return COMMA; ! 181: } ! 182: "{" { ! 183: if (yydebug) ! 184: fprintf (stderr, "SY: LBRACE\n"); ! 185: return LBRACE; ! 186: } ! 187: "}" { ! 188: if (yydebug) ! 189: fprintf (stderr, "SY: RBRACE\n"); ! 190: return RBRACE; ! 191: } ! 192: "|" { ! 193: if (yydebug) ! 194: fprintf (stderr, "SY: BAR\n"); ! 195: return BAR; ! 196: } ! 197: %BEGIN(ROSY)% ! 198: "[S]" { ! 199: if (yydebug) ! 200: fprintf (stderr, "SY: OBJECTSUPPLIER\n"); ! 201: return OBJECTSUPPLIER; ! 202: } ! 203: "[C]" { ! 204: if (yydebug) ! 205: fprintf (stderr, "SY: OBJECTCONSUMER\n"); ! 206: return OBJECTCONSUMER; ! 207: } ! 208: %END(ROSY)% ! 209: "[["|"$"|"<<" { register int tok, c, d, len; ! 210: register char *cp, *ep, *pp; ! 211: ! 212: if (*yytext == '$') ! 213: tok = VLENGTH; ! 214: else ! 215: if (*yytext == '<') ! 216: tok = CONTROL; ! 217: else { ! 218: while((c = input()) == ' ' || c =='\t') ! 219: continue; ! 220: switch (c) { ! 221: case 'a': tok = VALA; ! 222: break; ! 223: case 'b': tok = VALB; ! 224: break; ! 225: case 'i': tok = VALI; ! 226: break; ! 227: case 's': tok = VALS; ! 228: break; ! 229: case 'o': tok = VALO; ! 230: break; ! 231: case 'x': tok = VALX; ! 232: break; ! 233: case 'p': tok = VALP; ! 234: break; ! 235: case 'q': tok = VALQ; ! 236: break; ! 237: case 'r': tok = VALR; ! 238: break; ! 239: case 'O': tok = VALOID; ! 240: break; ! 241: case 'P': tok = PARAMETERTYPE; ! 242: break; ! 243: default : myyerror ("unknown token: \"%s\"", yytext); ! 244: break; ! 245: } ! 246: if ((c = input()) != ' ' && c != '\t' ! 247: && c != '\n') ! 248: yyerror ("syntax error in [[ ... ]]"); ! 249: } ! 250: ! 251: if ((pp = malloc ((unsigned) (len = BUFSIZ))) ! 252: == NULL) ! 253: yyerror ("out of memory"); ! 254: ! 255: for (ep = (cp = pp) + len - 1, d = NULL;; d = c) { ! 256: if ((c = input ()) == NULL) ! 257: yyerror ("end-of-file while reading value"); ! 258: if ((d == ']' && c == ']' && tok !=CONTROL) || ! 259: (c == '$' && (tok ==VALX || tok ==VALO)) || ! 260: (d == '>' && c == '>' && tok ==CONTROL)) { ! 261: if ((tok == VALX || tok == VALO) && ! 262: (c != '$')) ! 263: yyerror("Missing '$' in [[ - ]]"); ! 264: if (c == '$') {unput(c); *cp = NULL;} ! 265: else *--cp = NULL; ! 266: yylval.yy_string = pp; ! 267: if (yydebug) ! 268: fprintf (stderr, "VAL: \"%s\"\n", ! 269: yylval.yy_string); ! 270: return tok; ! 271: } ! 272: if (cp >= ep) { ! 273: register int curlen = cp - pp; ! 274: register char *dp; ! 275: ! 276: if ((dp = realloc (pp, ! 277: (unsigned) (len += BUFSIZ))) ! 278: == NULL) ! 279: yyerror ("out of memory"); ! 280: cp = dp + curlen; ! 281: ep = (pp = dp) + len - 1; ! 282: } ! 283: *cp++ = c; ! 284: } ! 285: } ! 286: "[" { ! 287: if (yydebug) ! 288: fprintf (stderr, "SY: LBRACKET\n"); ! 289: return LBRACKET; ! 290: } ! 291: "]" { ! 292: if (yydebug) ! 293: fprintf (stderr, "SY: RBRACKET\n"); ! 294: return RBRACKET; ! 295: } ! 296: "<" { ! 297: if (yydebug) ! 298: fprintf (stderr, "SY: LANGLE\n"); ! 299: return LANGLE; ! 300: } ! 301: "(" { ! 302: if (yydebug) ! 303: fprintf (stderr, "SY: LPAREN\n"); ! 304: return LPAREN; ! 305: } ! 306: ")" { ! 307: if (yydebug) ! 308: fprintf (stderr, "SY: RPAREN\n"); ! 309: return RPAREN; ! 310: } ! 311: [0-9]+ { ! 312: (void) sscanf (yytext, "%d", &yylval.yy_number); ! 313: if (yydebug) ! 314: fprintf (stderr, "LIT: 0x%x\n", yylval.yy_number); ! 315: return LITNUMBER; ! 316: } ! 317: -[0-9]+ { ! 318: (void) sscanf (yytext, "%d", &yylval.yy_number); ! 319: if (yydebug) ! 320: fprintf (stderr, "LIT: 0x%x\n", yylval.yy_number); ! 321: return LITNUMBER; ! 322: } ! 323: '[^'$]*'[BbHh] { register char *cp; register int i; ! 324: ! 325: switch (*(cp = yytext + strlen (yytext) - 1)) { ! 326: case 'H': ! 327: case 'h': ! 328: *cp = NULL; ! 329: (void) sscanf (yytext + 1, "%x", ! 330: &yylval.yy_number); ! 331: break; ! 332: ! 333: case 'B': ! 334: case 'b': ! 335: *cp-- = NULL, *cp = NULL; ! 336: for (i = 0, cp = yytext + 1; *cp; ) { ! 337: i <<= 1; ! 338: i += *cp++ - '0'; ! 339: } ! 340: yylval.yy_number = i; ! 341: break; ! 342: } ! 343: if (yydebug) ! 344: fprintf (stderr, "LIT: 0x%x\n", yylval.yy_number); ! 345: return LITNUMBER; ! 346: } ! 347: \"[^\"$]*\" { ! 348: yytext[strlen (yytext) - 1] = NULL; ! 349: yylval.yy_string = new_string (yytext + 1); ! 350: if (yydebug) ! 351: fprintf (stderr, "LIT: \"%s\"\n", yylval.yy_string); ! 352: return LITSTRING; ! 353: } ! 354: [A-Z][A-Za-z0-9-]* { register struct table *t; ! 355: ! 356: for (t = reserved; t -> t_keyword; t++) ! 357: if (strcmp (t -> t_keyword, yytext) == 0) { ! 358: if (yyporting && t -> t_porting) ! 359: break; ! 360: if (yydebug) ! 361: fprintf (stderr, ! 362: "KE: \"%s\"\n", yytext); ! 363: return t -> t_value; ! 364: } ! 365: yylval.yy_string = new_string (yytext); ! 366: if (yydebug) ! 367: fprintf (stderr, "ID: \"%s\"\n", yylval.yy_string); ! 368: return ID; ! 369: } ! 370: [a-z][A-Za-z0-9-]* { yylval.yy_string = new_string (yytext); ! 371: if (yydebug) ! 372: fprintf (stderr, "NAME: \"%s\"\n", yylval.yy_string); ! 373: return NAME; ! 374: } ! 375: "%[" { register int c, d, len; ! 376: register char *cp, *ep, *pp; ! 377: ! 378: if ((pp = malloc ((unsigned) (len = BUFSIZ))) ! 379: == NULL) ! 380: yyerror ("out of memory"); ! 381: ! 382: for (ep = (cp = pp) + len - 1, d = NULL;; d = c) { ! 383: if ((c = input ()) == NULL) ! 384: yyerror ("end-of-file while reading value"); ! 385: if (d == '%' && c == ']' ) { ! 386: *--cp = NULL; ! 387: yylval.yy_string = pp; ! 388: if (yydebug) ! 389: fprintf (stderr, "VAL: \"%s\"\n", ! 390: yylval.yy_string); ! 391: return SCTRL; ! 392: } ! 393: if (d == '\n') ! 394: yyerror ("newline in %[ %] construct"); ! 395: if (cp >= ep) { ! 396: register int curlen = cp - pp; ! 397: register char *dp; ! 398: ! 399: if ((dp = realloc (pp, ! 400: (unsigned) (len += BUFSIZ))) ! 401: == NULL) ! 402: yyerror ("out of memory"); ! 403: cp = dp + curlen; ! 404: ep = (pp = dp) + len - 1; ! 405: } ! 406: *cp++ = c; ! 407: } ! 408: } ! 409: "%{" { register int c, d, len; ! 410: int mylineno; ! 411: register char *cp, *ep, *pp; ! 412: ! 413: mylineno = yylineno; ! 414: if ((pp = malloc ((unsigned) (len = BUFSIZ))) ! 415: == NULL) ! 416: yyerror ("out of memory"); ! 417: ! 418: for (ep = (cp = pp) + len - 1, d = NULL;; d = c) { ! 419: if ((c = input ()) == NULL) ! 420: yyerror ("end-of-file while reading action"); ! 421: if (d == '%' && c == '}') { ! 422: *--cp = NULL; ! 423: yylval.yy_action = new_action (pp, mylineno);; ! 424: if (yydebug) ! 425: fprintf (stderr, "ACTION: \"%s\", %d\n", ! 426: yylval.yy_action -> ya_text, ! 427: yylval.yy_action -> ya_lineno); ! 428: return ACTION; ! 429: } ! 430: if (cp >= ep) { ! 431: register int curlen = cp - pp; ! 432: register char *dp; ! 433: ! 434: if ((dp = realloc (pp, ! 435: (unsigned) (len += BUFSIZ))) ! 436: == NULL) ! 437: yyerror ("out of memory"); ! 438: cp = dp + curlen; ! 439: ep = (pp = dp) + len - 1; ! 440: } ! 441: *cp++ = c; ! 442: } ! 443: } ! 444: . { ! 445: myyerror ("unknown token: \"%s\"", yytext); ! 446: } ! 447: ! 448: %%
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.