4 * Lexical rules for scanning the SMIng MIB module language.
6 * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
8 * See the file "COPYING" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * @(#) $Id: scanner-sming.l 7734 2008-02-15 07:49:14Z schoenw $
27 #if defined(HAVE_WIN_H)
33 #include "parser-sming.h"
34 #include "parser-sming.tab.h"
35 #include "scanner-sming.h"
43 /* we need a reentrant parser, so yylex gets arguments */
45 #define YY_DECL int yylex YY_PROTO((YYSTYPE *lvalp, void *parser))
47 #define YY_DECL int yylex(YYSTYPE *lvalp, void *parser)
52 #define thisParser (*(Parser *) parser)
56 #define MAX_NUMBER "18446744073709551615" /* max Counter64 */
61 * This makes the usual notation when referencing attributes also
62 * work with our pure parser code.
64 #define yylval (*lvalp)
67 static YY_BUFFER_STATE yybuffer[MAX_LEX_DEPTH];
69 static int lexDepth = 0;
73 smingEnterLexRecursion(file)
76 if (lexDepth >= MAX_LEX_DEPTH) {
79 yybuffer[lexDepth++] = YY_CURRENT_BUFFER;
80 yy_switch_to_buffer(yy_create_buffer(file, YY_BUF_SIZE));
87 smingLeaveLexRecursion()
89 yy_delete_buffer(YY_CURRENT_BUFFER);
90 yy_switch_to_buffer(yybuffer[--lexDepth]);
100 * Lex pattern definitions.
102 delim ([^a-zA-Z0-9-])
103 lineBreak ("\n"|"\n\015"|"\015\n")
111 * Lex state definitions.
120 * Lex rules for comments. Do you use {lineBreak} here because it
121 * introduces a trailing context which is (a) slow and (b) causes
125 <INITIAL>"//"({WSP}|{VCHAR})*/"\n" {
128 <INITIAL>"//"({WSP}|{VCHAR})*/"\n\015" {
131 <INITIAL>"//"({WSP}|{VCHAR})*/"\015\n" {
135 * Lex rules for some special tokens.
138 <INITIAL>[\{\}\(\)\;\,\-\.\|] {
155 * Lex rules for separators.
158 <INITIAL>{lineBreak} {
166 * Lex rules for known keywords.
169 <INITIAL>module/{delim} {
171 return moduleKeyword;
174 <INITIAL>import/{delim} {
176 return importKeyword;
179 <INITIAL>revision/{delim} {
181 return revisionKeyword;
184 <INITIAL>date/{delim} {
189 <INITIAL>organization/{delim} {
191 return organizationKeyword;
194 <INITIAL>contact/{delim} {
196 return contactKeyword;
199 <INITIAL>description/{delim} {
201 return descriptionKeyword;
204 <INITIAL>reference/{delim} {
206 return referenceKeyword;
209 <INITIAL>extension/{delim} {
211 return extensionKeyword;
214 <INITIAL>typedef/{delim} {
216 return typedefKeyword;
219 <INITIAL>type/{delim} {
224 <INITIAL>parent/{delim} {
226 return parentKeyword;
229 <INITIAL>identity/{delim} {
231 return identityKeyword;
234 <INITIAL>class/{delim} {
239 <INITIAL>extends/{delim} {
241 return extendsKeyword;
244 <INITIAL>attribute/{delim} {
246 return attributeKeyword;
249 <INITIAL>unique/{delim} {
251 return uniqueKeyword;
254 <INITIAL>event/{delim} {
259 <INITIAL>format/{delim} {
261 return formatKeyword;
264 <INITIAL>units/{delim} {
269 <INITIAL>status/{delim} {
271 return statusKeyword;
274 <INITIAL>access/{delim} {
276 return accessKeyword;
279 <INITIAL>default/{delim} {
281 return defaultKeyword;
284 <INITIAL>abnf/{delim} {
293 <INITIAL>OctetString/{delim} {
295 return OctetStringKeyword;
298 <INITIAL>Pointer/{delim} {
300 return PointerKeyword;
303 <INITIAL>ObjectIdentifier/{delim} {
305 return ObjectIdentifierKeyword;
308 <INITIAL>Integer32/{delim} {
310 return Integer32Keyword;
313 <INITIAL>Integer64/{delim} {
315 return Integer64Keyword;
318 <INITIAL>Unsigned32/{delim} {
320 return Unsigned32Keyword;
323 <INITIAL>Unsigned64/{delim} {
325 return Unsigned64Keyword;
328 <INITIAL>Float32/{delim} {
330 return Float32Keyword;
333 <INITIAL>Float64/{delim} {
335 return Float64Keyword;
338 <INITIAL>Float128/{delim} {
340 return Float128Keyword;
343 <INITIAL>Bits/{delim} {
348 <INITIAL>Enumeration/{delim} {
350 return EnumerationKeyword;
357 <INITIAL>current/{delim} {
359 return currentKeyword;
362 <INITIAL>deprecated/{delim} {
364 return deprecatedKeyword;
367 <INITIAL>obsolete/{delim} {
369 return obsoleteKeyword;
376 <INITIAL>eventonly/{delim} {
378 return eventonlyKeyword;
381 <INITIAL>readonly/{delim} {
383 return readonlyKeyword;
386 <INITIAL>readwrite/{delim} {
388 return readwriteKeyword;
392 *Special floating point values' keywords
395 <INITIAL>neginf/{delim} {
397 return neginfKeyword;
400 <INITIAL>posinf/{delim} {
402 return posinfKeyword;
405 <INITIAL>snan/{delim} {
410 <INITIAL>qnan/{delim} {
418 * Lex rules for identifiers.
421 /* e.g. module names: REF: draft,p.12-13 */
422 <INITIAL>[A-Z](-?[a-zA-Z0-9_]+)*-? {
423 if (yytext[yyleng-1] == '-') {
424 smiPrintError(parser, ERR_ID_ENDS_IN_HYPHEN, yytext);
427 smiPrintError(parser, ERR_UCIDENTIFIER_64, yytext);
429 if (strchr(yytext, '_')) {
430 smiPrintError(parser, ERR_UNDERSCORE_IN_IDENTIFIER, yytext);
432 yylval.text = smiStrdup(yytext);
436 /* same for lowercase names */
437 <INITIAL>[a-z](-?[a-zA-Z0-9_]+)*-? {
438 if (yytext[yyleng-1] == '-') {
439 smiPrintError(parser, ERR_ID_ENDS_IN_HYPHEN, yytext);
442 smiPrintError(parser, ERR_LCIDENTIFIER_64, yytext);
444 if (strchr(yytext, '_')) {
445 smiPrintError(parser, ERR_UNDERSCORE_IN_IDENTIFIER, yytext);
447 yylval.text = smiStrdup(yytext);
452 * Lex rules for numbers.
454 * NOTE: `-' is a separate token. Hence, there are no negative numbers.
458 smiPrintError(parser, ERR_LEADING_ZEROS);
461 <INITIAL>([1-9][0-9]*|0)/[^0-9] {
462 if ((yyleng > sizeof(MAX_NUMBER)-1) ||
463 ((yyleng == sizeof(MAX_NUMBER)-1) &&
464 (strcmp(yytext, MAX_NUMBER) > 0))) {
465 smiPrintError(parser, ERR_NUMBER_TOO_LARGE, yytext);
467 yylval.text = yytext;
468 return decimalNumber;
471 <INITIAL>0x[0-9a-fA-F]+/[^0-9a-fA-F] {
473 smiPrintError(parser, ERR_HEX_STRING_MUL2, yytext);
475 yylval.text = yytext;
476 return hexadecimalNumber;
479 * Lex rules for floating point values.
482 <INITIAL>([0-9]*\.[0-9]+([eE][+-]?[0-9]+)?)/[^0-9] {
483 yylval.text = yytext;
488 * Lex rules for OID's.
491 <INITIAL>([0-9A-Za-z]-?)+\.([0-9A-Za-z]-?)+\.([0-9A-Za-z]-?)+(\.([0-9A-Za-z]-?)+)*/([^0-9A-Za-z]) {
492 yylval.text = yytext;
498 * Lex rules for textSegments.
501 <INITIAL>\"([^\"]|(\\\"))*\" {
502 char *s, *d; /* the source and destination pointer */
503 int column = 0; /* the current column */
504 int newlineflag = 0; /* we have just passed a newline */
505 int cutoffcolumn = 0; /* cut off white space up to this column */
506 /* (computed by caculating the indentation */
507 /* of the first column) */
509 yytext[yyleng-1] = '\0';
510 for (d = yytext, s = yytext+1; s[0]; s++, d++) {
512 if ((s[0] == '\n' && s[1] == '\r') /* newline sequence */
513 || (s[0] == '\r' && s[1] == '\n')) {
514 thisParser.line += 1;
519 if (cutoffcolumn < 0) cutoffcolumn = 0;
520 } else if (s[0] == '\n') { /* simple newline */
521 thisParser.line += 1;
525 if (cutoffcolumn < 0) cutoffcolumn = 0;
527 if (newlineflag && isspace((int)(unsigned char)s[0])) { /* space after newline */
528 if (cutoffcolumn <= 0) {
529 cutoffcolumn -= (s[0] == '\t') ? (8-((column-1) % 8)) : 1;
531 column += (s[0] == '\t') ? (8-((column-1) % 8)) : 1;
532 if (cutoffcolumn <= 0 || column <= cutoffcolumn) {
538 } else { /* everything else */
539 if (! isascii(s[0])) {
540 smiPrintError(parser, ERR_ILLEGAL_CHAR_IN_STRING,
541 s[0], (unsigned char) s[0]);
545 if (cutoffcolumn < 0) {
553 yylval.text = yytext;
558 * Skip the remainder of the line
560 <Skipline>.*{lineBreak} {
570 smiPrintError(parser, ERR_LEX_UNEXPECTED_CHAR);