%START MACRO_DEF BRACE_BAL %a 14000 %p 12000 %e 2000 %n 1000 %o 20000 /* compiler/core/lex-asn1.l */ /* AUTHOR: Mike Sample */ /* DATE: 91/92 */ /* Copyright (C) 1991, 1992 Michael Sample */ /* and the University of British Columbia */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* these comments must only be a single line each - lex blows it otherwise */ /* due to this claim, the rcs log is at the end of this file. */ /* $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/core/Attic/lex-asn1.l,v 1.1 2001/06/20 21:27:57 dmitch Exp $ */ /* This lex spec should compile under either lex or flex. */ /* There are three modes to the lexical analyzer, INITIAL, MACRO_DEF, */ /* and BRACE_BAL. INITIAL is the normal mode. MACRO_DEF is used by */ /* a lexical tie-in from the yacc code to eat a MACRO DEFINTION as a */ /* single blk of text. BRACE_BAL is used to by a lexical tie-in for */ /* eating values inside { }'s. */ /* if your ASN.1 source file has control characters that cause */ /* snacc to choke, use a program like 'tr' to condition them first. */ WHITESPC [ \t\n\r] %{ #include "asn-incl.h" #include "mem.h" #include "asn1module.h" #include "exports.h" #include "parse-asn1.h" /* defines the returned token values */ #include "parser.h" #include "lex-stuff.h" #include "errno.h" unsigned long int myLineNoG = 0; %} %% "[C]" return BOXC_SYM; "[S]" return BOXS_SYM; {WHITESPC}+ { COUNT_NEWLINES (myLineNoG, yytext);} "." return DOT_SYM; "," return COMMA_SYM; "{" return LEFTBRACE_SYM; "}" return RIGHTBRACE_SYM; "(" return LEFTPAREN_SYM; ")" return RIGHTPAREN_SYM; "[" return LEFTBRACKET_SYM; "]" return RIGHTBRACKET_SYM; "<" return LESSTHAN_SYM; "-" return MINUS_SYM; "::=" return GETS_SYM; "|" return BAR_SYM; ";" return SEMI_COLON_SYM; TAGS return TAGS_SYM; BOOLEAN return BOOLEAN_SYM; INTEGER return INTEGER_SYM; BIT return BIT_SYM; STRING return STRING_SYM; OCTET return OCTET_SYM; NULL return NULL_SYM; SEQUENCE return SEQUENCE_SYM; OF return OF_SYM; SET return SET_SYM; IMPLICIT return IMPLICIT_SYM; CHOICE return CHOICE_SYM; ANY return ANY_SYM; OBJECT{WHITESPC}*IDENTIFIER { COUNT_NEWLINES (myLineNoG, yytext); return OBJECT_IDENTIFIER_SYM;} OPTIONAL return OPTIONAL_SYM; DEFAULT return DEFAULT_SYM; COMPONENTS return COMPONENTS_SYM; UNIVERSAL return UNIVERSAL_SYM; APPLICATION return APPLICATION_SYM; PRIVATE return PRIVATE_SYM; TRUE return TRUE_SYM; FALSE return FALSE_SYM; BEGIN return BEGIN_SYM; END return END_SYM; DEFINITIONS return DEFINITIONS_SYM; EXPLICIT return EXPLICIT_SYM; ENUMERATED return ENUMERATED_SYM; EXPORTS return EXPORTS_SYM; IMPORTS return IMPORTS_SYM; REAL return REAL_SYM; INCLUDES return INCLUDES_SYM; MIN return MIN_SYM; MAX return MAX_SYM; SIZE return SIZE_SYM; FROM return FROM_SYM; WITH return WITH_SYM; COMPONENT return COMPONENT_SYM; PRESENT return PRESENT_SYM; ABSENT return ABSENT_SYM; DEFINED return DEFINED_SYM; BY return BY_SYM; PLUS-INFINITY return PLUS_INFINITY_SYM; MINUS-INFINITY return MINUS_INFINITY_SYM; (.|\n) { int i; char *buf; int bufSize; int inComment; int inStr; unsigned int c, c1, c2; /* * matches any first char, then * copies everything until an uncommented, * unquoted END. This Lex state is started * from the yacc src (lexical tie in) * from the MACRO_DEF production. * * if you don't like realloc and don't care about * macro defs just have this return a constant string * like "BEGIN END" after eating the definition */ unput (yytext[0]); bufSize = 1024; buf = Malloc (1024); i = 0; /* put BEGIN str at beginning */ buf[i++] = 'B'; buf[i++] = 'E'; buf[i++] = 'G'; buf[i++] = 'I'; buf[i++] = 'N'; buf[i++] = '\n'; inStr = FALSE; inComment = FALSE; for ( ; ; i++) { c = input(); if (i >= (bufSize - 4)) { bufSize += 512; buf = (char*) Realloc (buf, bufSize); } buf[i] = c; if ((inComment) && (c == '\n')) inComment = FALSE; else if (!(inStr) && (c == '-')) { c = input(); if (c == '-') { buf[++i] = c; inComment = !inComment; } else unput (c); } else if (inComment) continue; else if (c == '"') inStr = !inStr; else if (inStr) continue; else if (c == 'E') { c1 = input(); c2 = input(); if ((c1 == 'N') && (c2 == 'D')) { buf[++i] = 'N'; buf[++i] = 'D'; buf[++i] = '\0'; yylval.charPtr = buf; COUNT_NEWLINES (myLineNoG, buf); myLineNoG -=1; /* take off 1 added after "BEGIN" */ return MACRODEFBODY_SYM; } else { unput (c2); unput (c1); } } } /* not reached */ } [A-Z](-[A-Z0-9]|[A-Z0-9])*{WHITESPC}*MACRO { int i; /* copy and return the Macro's name only */ /* doesn't handle comments between macro name and MACRO sym */ for (i = 0; (yytext[i] != ' ') && (yytext[i] != '\t') && (yytext[i] != '\n') && (yytext[i] != '\r'); i++); yylval.charPtr = Malloc (i+1); strncpy (yylval.charPtr, yytext, i); yylval.charPtr[i] = '\0'; return NAMEDMACRO_SYM; } OPERATION return OPERATION_SYM; ARGUMENT return ARGUMENT_SYM; RESULT return RESULT_SYM; ERRORS return ERRORS_SYM; LINKED return LINKED_SYM; ERROR return ERROR_SYM; PARAMETER return PARAMETER_SYM; BIND return BIND_SYM; BIND-ERROR return BINDERROR_SYM; UNBIND return UNBIND_SYM; UNBIND-ERROR return UNBINDERROR_SYM; APPLICATION-CONTEXT return AC_SYM; APPLICATION-SERVICE-ELEMENTS return ASES_SYM; REMOTE return REMOTE_SYM; INITIATOR return INITIATOR_SYM; RESPONDER return RESPONDER_SYM; ABSTRACT{WHITESPC}*SYNTAXES { COUNT_NEWLINES (myLineNoG, yytext); return ABSTRACTSYNTAXES_SYM;} APPLICATION-SERVICE-ELEMENT return ASE_SYM; OPERATIONS return OPERATIONS_SYM; CONSUMER{WHITESPC}*INVOKES { COUNT_NEWLINES (myLineNoG, yytext); return CONSUMERINVOKES_SYM;} SUPPLIER{WHITESPC}*INVOKES { COUNT_NEWLINES (myLineNoG, yytext); return SUPPLIERINVOKES_SYM;} EXTENSION-ATTRIBUTE return EXTENSIONATTRIBUTE_SYM; EXTENSIONS return EXTENSIONS_SYM; CHOSEN return CHOSEN_SYM; EXTENSION return EXTENSION_SYM; CRITICAL return CRITICAL_SYM; FOR return FOR_SYM; SUBMISSION return SUBMISSION_SYM; DELIVERY return DELIVERY_SYM; TRANSFER return TRANSFER_SYM; OBJECT return OBJECT_SYM; PORTS return PORTS_SYM; PORT return PORT_SYM; ABSTRACT{WHITESPC}*OPERATIONS { COUNT_NEWLINES (myLineNoG, yytext); return ABSTRACTOPS_SYM;} REFINE return REFINE_SYM; AS return AS_SYM; RECURRING return RECURRING_SYM; VISIBLE return VISIBLE_SYM; PAIRED return PAIRED_SYM; ABSTRACT-BIND return ABSTRACTBIND_SYM; TO return TO_SYM; ABSTRACT-UNBIND return ABSTRACTUNBIND_SYM; ABSTRACT-ERROR return ABSTRACTERROR_SYM; ABSTRACT-OPERATION return ABSTRACTOPERATION_SYM; TOKEN return TOKEN_SYM; TOKEN-DATA return TOKENDATA_SYM; SECURITY-CATEGORY return SECURITYCATEGORY_SYM; ALGORITHM return ALGORITHM_SYM; ENCRYPTED return ENCRYPTED_SYM; SIGNED return SIGNED_SYM; SIGNATURE return SIGNATURE_SYM; PROTECTED return PROTECTED_SYM; OBJECT-TYPE return OBJECTTYPE_SYM; SYNTAX return SYNTAX_SYM; ACCESS return ACCESS_SYM; STATUS return STATUS_SYM; DESCRIPTION return DESCRIPTION_SYM; REFERENCE return REFERENCE_SYM; INDEX return INDEX_SYM; DEFVAL return DEFVAL_SYM; (.|\n) { int i; char *buf; int bufSize; int inComment; int inStr; int braceDepth; char c, c1, c2; /* * matches any first char, then * copies everything until an ending "}" * Assumes that initially parsed a "{" * and puts one at beg. of returned string */ unput (yytext[0]); bufSize = 256; buf = Malloc (256); i = 0; /* put openning brace at beginning */ buf[i++] = '{'; buf[i++] = ' '; inStr = FALSE; inComment = FALSE; braceDepth = 1; for ( ; ; i++) { c = input(); if (i >= (bufSize - 2)) { bufSize += 256; buf = (char*) Realloc (buf, bufSize); } buf[i] = c; if ((inComment) && (c == '\n')) inComment = FALSE; else if (!(inStr) && (c == '-')) { c = input(); if (c == '-') { buf[++i] = c; inComment = !inComment; } else unput (c); } else if (inComment) continue; else if (c == '"') inStr = !inStr; else if (inStr) continue; else if (c == '{') braceDepth++; else if (c == '}') { braceDepth--; if (braceDepth == 0) { buf[++i] = '\0'; yylval.charPtr = buf; COUNT_NEWLINES (myLineNoG, buf); return BRACEBAL_SYM; } } } /* not reached */ } \'[0-1]*\'B { COUNT_NEWLINES (myLineNoG, yytext); yylval.charPtr = (char*)Malloc (yyleng); strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip "'"s */ yylval.charPtr[yyleng-2] = '\0'; return BSTRING_SYM;} \'[0-9A-Fa-f]*\'H { COUNT_NEWLINES (myLineNoG, yytext); yylval.charPtr = (char*)Malloc (yyleng); strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip "'"s */ yylval.charPtr[yyleng-2] = '\0'; return HSTRING_SYM;} \"([^\"]|"\"\"")*\" { COUNT_NEWLINES (myLineNoG, yytext); yylval.charPtr = (char*)Malloc (yyleng); strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip '"'s */ yylval.charPtr[yyleng-2] = '\0'; /* 2 quotes == quote in a quote */ return CSTRING_SYM;} [A-Z](-[a-zA-Z0-9]|[a-zA-Z0-9])* { yylval.charPtr = (char*)Malloc (yyleng+1); strcpy (yylval.charPtr, yytext); yylval.charPtr[yyleng] = '\0'; return UCASEFIRST_IDENT_SYM;} [a-z](-[a-zA-Z0-9]|[a-zA-Z0-9])* { yylval.charPtr = (char*)Malloc (yyleng+1); strcpy (yylval.charPtr, yytext); yylval.charPtr[yyleng] = '\0'; return LCASEFIRST_IDENT_SYM;} [1-9][0-9]* { /*first digit cannot be zero on multi-digit #'s*/ errno = 0; { unsigned long ul = (unsigned long) strtol(yytext,NULL,10); if (!errno && ul>(unsigned long)0xFFFFFFFF) { errno = ERANGE; } if (!errno) { yylval.uintVal = (unsigned int) ul; return NUMBER_SYM; } } yylval.charPtr = (char*)Malloc (yyleng+1); strcpy (yylval.charPtr, yytext); yylval.charPtr[yyleng] = '\0'; return NUMBER_ERANGE;} 0 { /*allow zero as first digit on single digit #'s*/ yylval.uintVal = 0; return NUMBER_SYM;} "--snacc"(-[^-\n]|[^\-\n])*("--"|\n) { /* this must be before the normal comment eater so that snacc attribs * are not treated as normal comments */ /* eat comments, update line no */ int len; COUNT_NEWLINES (myLineNoG, yytext); yylval.charPtr = (char*)Malloc (yyleng-4); /* skip first "--snacc" in copy to ret val */ strcpy (yylval.charPtr, yytext + 7); len = strlen (yylval.charPtr); /* strip off newline or -- terminator for comment */ if (yylval.charPtr[len-1] == '\n') yylval.charPtr[len-1] = '\0'; else yylval.charPtr[len-2] = '\0'; return SNACC_ATTRIBUTES; } "--"(-[^\-\n]|[^\-\n])*("--"|\n|"-\n") { /* eat comments, update line no */ COUNT_NEWLINES (myLineNoG, yytext);} %% /* * these "LexBegin..." routines are used by yacc for (ack!) * lexical tie ins */ int LexBeginMacroDefContext() { BEGIN (MACRO_DEF); } int LexBeginBraceBalContext() { BEGIN (BRACE_BAL); } int LexBeginInitialContext() { BEGIN (INITIAL); } /* * $Log: lex-asn1.l,v $ * Revision 1.1 2001/06/20 21:27:57 dmitch * Adding missing snacc compiler files. * * Revision 1.1.1.1 1999/03/16 18:06:49 aram * Originals from SMIME Free Library. * * Revision 1.5 1997/08/28 09:46:41 wan * Reworked number range checking, only gives warning now. * * Revision 1.4 1997/06/19 09:17:17 wan * Added isPdu flag to tables. Added value range checks during parsing. * * Revision 1.3 1995/07/25 19:41:30 rj * changed `_' to `-' in file names. * * Revision 1.2 1994/09/01 00:37:12 rj * snacc_config.h removed. * * for a list of changes relative to the 1.1 distribution, please refer to the ChangeLog. */