1 %START MACRO_DEF BRACE_BAL
10 /* compiler/core/lex-asn1.l */
11 /* AUTHOR: Mike Sample */
14 /* Copyright (C) 1991, 1992 Michael Sample */
15 /* and the University of British Columbia */
16 /* This program is free software; you can redistribute it and/or modify */
17 /* it under the terms of the GNU General Public License as published by */
18 /* the Free Software Foundation; either version 2 of the License, or */
19 /* (at your option) any later version. */
21 /* these comments must only be a single line each - lex blows it otherwise */
22 /* due to this claim, the rcs log is at the end of this file. */
23 /* $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/core/Attic/lex-asn1.l,v 1.1 2001/06/20 21:27:57 dmitch Exp $ */
25 /* This lex spec should compile under either lex or flex. */
27 /* There are three modes to the lexical analyzer, INITIAL, MACRO_DEF, */
28 /* and BRACE_BAL. INITIAL is the normal mode. MACRO_DEF is used by */
29 /* a lexical tie-in from the yacc code to eat a MACRO DEFINTION as a */
30 /* single blk of text. BRACE_BAL is used to by a lexical tie-in for */
31 /* eating values inside { }'s. */
33 /* if your ASN.1 source file has control characters that cause */
34 /* snacc to choke, use a program like 'tr' to condition them first. */
44 #include "asn1module.h"
46 #include "parse-asn1.h" /* defines the returned token values */
48 #include "lex-stuff.h"
51 unsigned long int myLineNoG = 0;
57 <INITIAL>"[C]" return BOXC_SYM;
58 <INITIAL>"[S]" return BOXS_SYM;
60 <INITIAL>{WHITESPC}+ { COUNT_NEWLINES (myLineNoG, yytext);}
61 <INITIAL>"." return DOT_SYM;
62 <INITIAL>"," return COMMA_SYM;
63 <INITIAL>"{" return LEFTBRACE_SYM;
64 <INITIAL>"}" return RIGHTBRACE_SYM;
65 <INITIAL>"(" return LEFTPAREN_SYM;
66 <INITIAL>")" return RIGHTPAREN_SYM;
67 <INITIAL>"[" return LEFTBRACKET_SYM;
68 <INITIAL>"]" return RIGHTBRACKET_SYM;
69 <INITIAL>"<" return LESSTHAN_SYM;
70 <INITIAL>"-" return MINUS_SYM;
71 <INITIAL>"::=" return GETS_SYM;
72 <INITIAL>"|" return BAR_SYM;
73 <INITIAL>";" return SEMI_COLON_SYM;
74 <INITIAL>TAGS return TAGS_SYM;
75 <INITIAL>BOOLEAN return BOOLEAN_SYM;
76 <INITIAL>INTEGER return INTEGER_SYM;
77 <INITIAL>BIT return BIT_SYM;
78 <INITIAL>STRING return STRING_SYM;
79 <INITIAL>OCTET return OCTET_SYM;
80 <INITIAL>NULL return NULL_SYM;
81 <INITIAL>SEQUENCE return SEQUENCE_SYM;
82 <INITIAL>OF return OF_SYM;
83 <INITIAL>SET return SET_SYM;
84 <INITIAL>IMPLICIT return IMPLICIT_SYM;
85 <INITIAL>CHOICE return CHOICE_SYM;
86 <INITIAL>ANY return ANY_SYM;
87 <INITIAL>OBJECT{WHITESPC}*IDENTIFIER {
88 COUNT_NEWLINES (myLineNoG, yytext);
89 return OBJECT_IDENTIFIER_SYM;}
90 <INITIAL>OPTIONAL return OPTIONAL_SYM;
91 <INITIAL>DEFAULT return DEFAULT_SYM;
92 <INITIAL>COMPONENTS return COMPONENTS_SYM;
93 <INITIAL>UNIVERSAL return UNIVERSAL_SYM;
94 <INITIAL>APPLICATION return APPLICATION_SYM;
95 <INITIAL>PRIVATE return PRIVATE_SYM;
96 <INITIAL>TRUE return TRUE_SYM;
97 <INITIAL>FALSE return FALSE_SYM;
98 <INITIAL>BEGIN return BEGIN_SYM;
99 <INITIAL>END return END_SYM;
100 <INITIAL>DEFINITIONS return DEFINITIONS_SYM;
101 <INITIAL>EXPLICIT return EXPLICIT_SYM;
102 <INITIAL>ENUMERATED return ENUMERATED_SYM;
103 <INITIAL>EXPORTS return EXPORTS_SYM;
104 <INITIAL>IMPORTS return IMPORTS_SYM;
105 <INITIAL>REAL return REAL_SYM;
106 <INITIAL>INCLUDES return INCLUDES_SYM;
107 <INITIAL>MIN return MIN_SYM;
108 <INITIAL>MAX return MAX_SYM;
109 <INITIAL>SIZE return SIZE_SYM;
110 <INITIAL>FROM return FROM_SYM;
111 <INITIAL>WITH return WITH_SYM;
112 <INITIAL>COMPONENT return COMPONENT_SYM;
113 <INITIAL>PRESENT return PRESENT_SYM;
114 <INITIAL>ABSENT return ABSENT_SYM;
115 <INITIAL>DEFINED return DEFINED_SYM;
116 <INITIAL>BY return BY_SYM;
117 <INITIAL>PLUS-INFINITY return PLUS_INFINITY_SYM;
118 <INITIAL>MINUS-INFINITY return MINUS_INFINITY_SYM;
128 unsigned int c, c1, c2;
131 * matches any first char, then
132 * copies everything until an uncommented,
133 * unquoted END. This Lex state is started
134 * from the yacc src (lexical tie in)
135 * from the MACRO_DEF production.
137 * if you don't like realloc and don't care about
138 * macro defs just have this return a constant string
139 * like "BEGIN <not parsed> END" after eating the definition
147 i = 0; /* put BEGIN str at beginning */
161 if (i >= (bufSize - 4))
164 buf = (char*) Realloc (buf, bufSize);
169 if ((inComment) && (c == '\n'))
171 else if (!(inStr) && (c == '-'))
177 inComment = !inComment;
192 if ((c1 == 'N') && (c2 == 'D'))
197 yylval.charPtr = buf;
198 COUNT_NEWLINES (myLineNoG, buf);
199 myLineNoG -=1; /* take off 1 added after "BEGIN" */
200 return MACRODEFBODY_SYM;
214 <INITIAL>[A-Z](-[A-Z0-9]|[A-Z0-9])*{WHITESPC}*MACRO {
216 /* copy and return the Macro's name only */
217 /* doesn't handle comments between macro name and MACRO sym */
218 for (i = 0; (yytext[i] != ' ') &&
219 (yytext[i] != '\t') &&
220 (yytext[i] != '\n') &&
221 (yytext[i] != '\r'); i++);
222 yylval.charPtr = Malloc (i+1);
223 strncpy (yylval.charPtr, yytext, i);
224 yylval.charPtr[i] = '\0';
225 return NAMEDMACRO_SYM; }
228 <INITIAL>OPERATION return OPERATION_SYM;
229 <INITIAL>ARGUMENT return ARGUMENT_SYM;
230 <INITIAL>RESULT return RESULT_SYM;
231 <INITIAL>ERRORS return ERRORS_SYM;
232 <INITIAL>LINKED return LINKED_SYM;
234 <INITIAL>ERROR return ERROR_SYM;
235 <INITIAL>PARAMETER return PARAMETER_SYM;
237 <INITIAL>BIND return BIND_SYM;
238 <INITIAL>BIND-ERROR return BINDERROR_SYM;
239 <INITIAL>UNBIND return UNBIND_SYM;
240 <INITIAL>UNBIND-ERROR return UNBINDERROR_SYM;
242 <INITIAL>APPLICATION-CONTEXT return AC_SYM;
243 <INITIAL>APPLICATION-SERVICE-ELEMENTS return ASES_SYM;
244 <INITIAL>REMOTE return REMOTE_SYM;
245 <INITIAL>INITIATOR return INITIATOR_SYM;
246 <INITIAL>RESPONDER return RESPONDER_SYM;
247 <INITIAL>ABSTRACT{WHITESPC}*SYNTAXES {
248 COUNT_NEWLINES (myLineNoG, yytext);
249 return ABSTRACTSYNTAXES_SYM;}
251 <INITIAL>APPLICATION-SERVICE-ELEMENT return ASE_SYM;
252 <INITIAL>OPERATIONS return OPERATIONS_SYM;
253 <INITIAL>CONSUMER{WHITESPC}*INVOKES {
254 COUNT_NEWLINES (myLineNoG, yytext);
255 return CONSUMERINVOKES_SYM;}
257 <INITIAL>SUPPLIER{WHITESPC}*INVOKES {
258 COUNT_NEWLINES (myLineNoG, yytext);
259 return SUPPLIERINVOKES_SYM;}
261 <INITIAL>EXTENSION-ATTRIBUTE return EXTENSIONATTRIBUTE_SYM;
262 <INITIAL>EXTENSIONS return EXTENSIONS_SYM;
263 <INITIAL>CHOSEN return CHOSEN_SYM;
265 <INITIAL>EXTENSION return EXTENSION_SYM;
266 <INITIAL>CRITICAL return CRITICAL_SYM;
267 <INITIAL>FOR return FOR_SYM;
268 <INITIAL>SUBMISSION return SUBMISSION_SYM;
269 <INITIAL>DELIVERY return DELIVERY_SYM;
270 <INITIAL>TRANSFER return TRANSFER_SYM;
272 <INITIAL>OBJECT return OBJECT_SYM;
273 <INITIAL>PORTS return PORTS_SYM;
275 <INITIAL>PORT return PORT_SYM;
276 <INITIAL>ABSTRACT{WHITESPC}*OPERATIONS {
277 COUNT_NEWLINES (myLineNoG, yytext);
278 return ABSTRACTOPS_SYM;}
281 <INITIAL>REFINE return REFINE_SYM;
282 <INITIAL>AS return AS_SYM;
283 <INITIAL>RECURRING return RECURRING_SYM;
284 <INITIAL>VISIBLE return VISIBLE_SYM;
285 <INITIAL>PAIRED return PAIRED_SYM;
287 <INITIAL>ABSTRACT-BIND return ABSTRACTBIND_SYM;
288 <INITIAL>TO return TO_SYM;
290 <INITIAL>ABSTRACT-UNBIND return ABSTRACTUNBIND_SYM;
292 <INITIAL>ABSTRACT-ERROR return ABSTRACTERROR_SYM;
294 <INITIAL>ABSTRACT-OPERATION return ABSTRACTOPERATION_SYM;
296 <INITIAL>TOKEN return TOKEN_SYM;
298 <INITIAL>TOKEN-DATA return TOKENDATA_SYM;
300 <INITIAL>SECURITY-CATEGORY return SECURITYCATEGORY_SYM;
302 <INITIAL>ALGORITHM return ALGORITHM_SYM;
303 <INITIAL>ENCRYPTED return ENCRYPTED_SYM;
304 <INITIAL>SIGNED return SIGNED_SYM;
305 <INITIAL>SIGNATURE return SIGNATURE_SYM;
306 <INITIAL>PROTECTED return PROTECTED_SYM;
308 <INITIAL>OBJECT-TYPE return OBJECTTYPE_SYM;
309 <INITIAL>SYNTAX return SYNTAX_SYM;
310 <INITIAL>ACCESS return ACCESS_SYM;
311 <INITIAL>STATUS return STATUS_SYM;
312 <INITIAL>DESCRIPTION return DESCRIPTION_SYM;
313 <INITIAL>REFERENCE return REFERENCE_SYM;
314 <INITIAL>INDEX return INDEX_SYM;
315 <INITIAL>DEFVAL return DEFVAL_SYM;
329 * matches any first char, then
330 * copies everything until an ending "}"
331 * Assumes that initially parsed a "{"
332 * and puts one at beg. of returned string
339 i = 0; /* put openning brace at beginning */
350 if (i >= (bufSize - 2))
353 buf = (char*) Realloc (buf, bufSize);
358 if ((inComment) && (c == '\n'))
360 else if (!(inStr) && (c == '-'))
366 inComment = !inComment;
385 yylval.charPtr = buf;
386 COUNT_NEWLINES (myLineNoG, buf);
396 <INITIAL>\'[0-1]*\'B {
397 COUNT_NEWLINES (myLineNoG, yytext);
398 yylval.charPtr = (char*)Malloc (yyleng);
399 strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip "'"s */
400 yylval.charPtr[yyleng-2] = '\0';
403 <INITIAL>\'[0-9A-Fa-f]*\'H {
404 COUNT_NEWLINES (myLineNoG, yytext);
405 yylval.charPtr = (char*)Malloc (yyleng);
406 strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip "'"s */
407 yylval.charPtr[yyleng-2] = '\0';
410 <INITIAL>\"([^\"]|"\"\"")*\" {
411 COUNT_NEWLINES (myLineNoG, yytext);
412 yylval.charPtr = (char*)Malloc (yyleng);
413 strncpy (yylval.charPtr, yytext+1, yyleng -1); /* strip '"'s */
414 yylval.charPtr[yyleng-2] = '\0'; /* 2 quotes == quote in a quote */
417 <INITIAL>[A-Z](-[a-zA-Z0-9]|[a-zA-Z0-9])* {
418 yylval.charPtr = (char*)Malloc (yyleng+1);
419 strcpy (yylval.charPtr, yytext);
420 yylval.charPtr[yyleng] = '\0';
421 return UCASEFIRST_IDENT_SYM;}
424 <INITIAL>[a-z](-[a-zA-Z0-9]|[a-zA-Z0-9])* {
425 yylval.charPtr = (char*)Malloc (yyleng+1);
426 strcpy (yylval.charPtr, yytext);
427 yylval.charPtr[yyleng] = '\0';
428 return LCASEFIRST_IDENT_SYM;}
430 <INITIAL>[1-9][0-9]* { /*first digit cannot be zero on multi-digit #'s*/
433 unsigned long ul = (unsigned long) strtol(yytext,NULL,10);
434 if (!errno && ul>(unsigned long)0xFFFFFFFF) {
438 yylval.uintVal = (unsigned int) ul;
442 yylval.charPtr = (char*)Malloc (yyleng+1);
443 strcpy (yylval.charPtr, yytext);
444 yylval.charPtr[yyleng] = '\0';
445 return NUMBER_ERANGE;}
447 <INITIAL>0 { /*allow zero as first digit on single digit #'s*/
452 <INITIAL>"--snacc"(-[^-\n]|[^\-\n])*("--"|\n) {
453 /* this must be before the normal comment eater so that snacc attribs
454 * are not treated as normal comments
456 /* eat comments, update line no */
458 COUNT_NEWLINES (myLineNoG, yytext);
459 yylval.charPtr = (char*)Malloc (yyleng-4);
460 /* skip first "--snacc" in copy to ret val */
461 strcpy (yylval.charPtr, yytext + 7);
462 len = strlen (yylval.charPtr);
463 /* strip off newline or -- terminator for comment */
464 if (yylval.charPtr[len-1] == '\n')
465 yylval.charPtr[len-1] = '\0';
467 yylval.charPtr[len-2] = '\0';
468 return SNACC_ATTRIBUTES; }
471 <INITIAL>"--"(-[^\-\n]|[^\-\n])*("--"|\n|"-\n") {
472 /* eat comments, update line no */
473 COUNT_NEWLINES (myLineNoG, yytext);}
480 * these "LexBegin..." routines are used by yacc for (ack!)
485 LexBeginMacroDefContext()
491 LexBeginBraceBalContext()
497 LexBeginInitialContext()
503 * $Log: lex-asn1.l,v $
504 * Revision 1.1 2001/06/20 21:27:57 dmitch
505 * Adding missing snacc compiler files.
507 * Revision 1.1.1.1 1999/03/16 18:06:49 aram
508 * Originals from SMIME Free Library.
510 * Revision 1.5 1997/08/28 09:46:41 wan
511 * Reworked number range checking, only gives warning now.
513 * Revision 1.4 1997/06/19 09:17:17 wan
514 * Added isPdu flag to tables. Added value range checks during parsing.
516 * Revision 1.3 1995/07/25 19:41:30 rj
517 * changed `_' to `-' in file names.
519 * Revision 1.2 1994/09/01 00:37:12 rj
520 * snacc_config.h removed.
522 * for a list of changes relative to the 1.1 distribution, please refer to the ChangeLog.