]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/core/lex-asn1.l
Security-54.1.7.tar.gz
[apple/security.git] / SecuritySNACCRuntime / compiler / core / lex-asn1.l
1 %START MACRO_DEF BRACE_BAL
2 %a 14000
3 %p 12000
4 %e 2000
5 %n 1000
6 %o 20000
7
8
9
10 /* compiler/core/lex-asn1.l */
11 /* AUTHOR: Mike Sample */
12 /* DATE: 91/92 */
13
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. */
20
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 $ */
24
25 /* This lex spec should compile under either lex or flex. */
26
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. */
32
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. */
35
36
37 WHITESPC [ \t\n\r]
38
39
40 %{
41
42 #include "asn-incl.h"
43 #include "mem.h"
44 #include "asn1module.h"
45 #include "exports.h"
46 #include "parse-asn1.h" /* defines the returned token values */
47 #include "parser.h"
48 #include "lex-stuff.h"
49 #include "errno.h"
50
51 unsigned long int myLineNoG = 0;
52
53 %}
54
55 %%
56
57 <INITIAL>"[C]" return BOXC_SYM;
58 <INITIAL>"[S]" return BOXS_SYM;
59
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;
119
120
121
122 <MACRO_DEF>(.|\n) {
123 int i;
124 char *buf;
125 int bufSize;
126 int inComment;
127 int inStr;
128 unsigned int c, c1, c2;
129
130 /*
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.
136 *
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
140 */
141
142 unput (yytext[0]);
143
144 bufSize = 1024;
145 buf = Malloc (1024);
146
147 i = 0; /* put BEGIN str at beginning */
148 buf[i++] = 'B';
149 buf[i++] = 'E';
150 buf[i++] = 'G';
151 buf[i++] = 'I';
152 buf[i++] = 'N';
153 buf[i++] = '\n';
154
155 inStr = FALSE;
156 inComment = FALSE;
157 for ( ; ; i++)
158 {
159 c = input();
160
161 if (i >= (bufSize - 4))
162 {
163 bufSize += 512;
164 buf = (char*) Realloc (buf, bufSize);
165 }
166
167 buf[i] = c;
168
169 if ((inComment) && (c == '\n'))
170 inComment = FALSE;
171 else if (!(inStr) && (c == '-'))
172 {
173 c = input();
174 if (c == '-')
175 {
176 buf[++i] = c;
177 inComment = !inComment;
178 }
179 else
180 unput (c);
181 }
182 else if (inComment)
183 continue;
184 else if (c == '"')
185 inStr = !inStr;
186 else if (inStr)
187 continue;
188 else if (c == 'E')
189 {
190 c1 = input();
191 c2 = input();
192 if ((c1 == 'N') && (c2 == 'D'))
193 {
194 buf[++i] = 'N';
195 buf[++i] = 'D';
196 buf[++i] = '\0';
197 yylval.charPtr = buf;
198 COUNT_NEWLINES (myLineNoG, buf);
199 myLineNoG -=1; /* take off 1 added after "BEGIN" */
200 return MACRODEFBODY_SYM;
201 }
202 else
203 {
204 unput (c2);
205 unput (c1);
206 }
207 }
208 }
209 /* not reached */
210 }
211
212
213
214 <INITIAL>[A-Z](-[A-Z0-9]|[A-Z0-9])*{WHITESPC}*MACRO {
215 int i;
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; }
226
227
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;
233
234 <INITIAL>ERROR return ERROR_SYM;
235 <INITIAL>PARAMETER return PARAMETER_SYM;
236
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;
241
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;}
250
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;}
256
257 <INITIAL>SUPPLIER{WHITESPC}*INVOKES {
258 COUNT_NEWLINES (myLineNoG, yytext);
259 return SUPPLIERINVOKES_SYM;}
260
261 <INITIAL>EXTENSION-ATTRIBUTE return EXTENSIONATTRIBUTE_SYM;
262 <INITIAL>EXTENSIONS return EXTENSIONS_SYM;
263 <INITIAL>CHOSEN return CHOSEN_SYM;
264
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;
271
272 <INITIAL>OBJECT return OBJECT_SYM;
273 <INITIAL>PORTS return PORTS_SYM;
274
275 <INITIAL>PORT return PORT_SYM;
276 <INITIAL>ABSTRACT{WHITESPC}*OPERATIONS {
277 COUNT_NEWLINES (myLineNoG, yytext);
278 return ABSTRACTOPS_SYM;}
279
280
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;
286
287 <INITIAL>ABSTRACT-BIND return ABSTRACTBIND_SYM;
288 <INITIAL>TO return TO_SYM;
289
290 <INITIAL>ABSTRACT-UNBIND return ABSTRACTUNBIND_SYM;
291
292 <INITIAL>ABSTRACT-ERROR return ABSTRACTERROR_SYM;
293
294 <INITIAL>ABSTRACT-OPERATION return ABSTRACTOPERATION_SYM;
295
296 <INITIAL>TOKEN return TOKEN_SYM;
297
298 <INITIAL>TOKEN-DATA return TOKENDATA_SYM;
299
300 <INITIAL>SECURITY-CATEGORY return SECURITYCATEGORY_SYM;
301
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;
307
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;
316
317
318
319 <BRACE_BAL>(.|\n) {
320 int i;
321 char *buf;
322 int bufSize;
323 int inComment;
324 int inStr;
325 int braceDepth;
326 char c, c1, c2;
327
328 /*
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
333 */
334 unput (yytext[0]);
335
336 bufSize = 256;
337 buf = Malloc (256);
338
339 i = 0; /* put openning brace at beginning */
340 buf[i++] = '{';
341 buf[i++] = ' ';
342
343 inStr = FALSE;
344 inComment = FALSE;
345 braceDepth = 1;
346 for ( ; ; i++)
347 {
348 c = input();
349
350 if (i >= (bufSize - 2))
351 {
352 bufSize += 256;
353 buf = (char*) Realloc (buf, bufSize);
354 }
355
356 buf[i] = c;
357
358 if ((inComment) && (c == '\n'))
359 inComment = FALSE;
360 else if (!(inStr) && (c == '-'))
361 {
362 c = input();
363 if (c == '-')
364 {
365 buf[++i] = c;
366 inComment = !inComment;
367 }
368 else
369 unput (c);
370 }
371 else if (inComment)
372 continue;
373 else if (c == '"')
374 inStr = !inStr;
375 else if (inStr)
376 continue;
377 else if (c == '{')
378 braceDepth++;
379 else if (c == '}')
380 {
381 braceDepth--;
382 if (braceDepth == 0)
383 {
384 buf[++i] = '\0';
385 yylval.charPtr = buf;
386 COUNT_NEWLINES (myLineNoG, buf);
387 return BRACEBAL_SYM;
388 }
389 }
390 }
391 /* not reached */
392 }
393
394
395
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';
401 return BSTRING_SYM;}
402
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';
408 return HSTRING_SYM;}
409
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 */
415 return CSTRING_SYM;}
416
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;}
422
423
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;}
429
430 <INITIAL>[1-9][0-9]* { /*first digit cannot be zero on multi-digit #'s*/
431 errno = 0;
432 {
433 unsigned long ul = (unsigned long) strtol(yytext,NULL,10);
434 if (!errno && ul>(unsigned long)0xFFFFFFFF) {
435 errno = ERANGE;
436 }
437 if (!errno) {
438 yylval.uintVal = (unsigned int) ul;
439 return NUMBER_SYM;
440 }
441 }
442 yylval.charPtr = (char*)Malloc (yyleng+1);
443 strcpy (yylval.charPtr, yytext);
444 yylval.charPtr[yyleng] = '\0';
445 return NUMBER_ERANGE;}
446
447 <INITIAL>0 { /*allow zero as first digit on single digit #'s*/
448 yylval.uintVal = 0;
449 return NUMBER_SYM;}
450
451
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
455 */
456 /* eat comments, update line no */
457 int len;
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';
466 else
467 yylval.charPtr[len-2] = '\0';
468 return SNACC_ATTRIBUTES; }
469
470
471 <INITIAL>"--"(-[^\-\n]|[^\-\n])*("--"|\n|"-\n") {
472 /* eat comments, update line no */
473 COUNT_NEWLINES (myLineNoG, yytext);}
474
475
476 %%
477
478
479 /*
480 * these "LexBegin..." routines are used by yacc for (ack!)
481 * lexical tie ins
482 */
483
484 int
485 LexBeginMacroDefContext()
486 {
487 BEGIN (MACRO_DEF);
488 }
489
490 int
491 LexBeginBraceBalContext()
492 {
493 BEGIN (BRACE_BAL);
494 }
495
496 int
497 LexBeginInitialContext()
498 {
499 BEGIN (INITIAL);
500 }
501
502 /*
503 * $Log: lex-asn1.l,v $
504 * Revision 1.1 2001/06/20 21:27:57 dmitch
505 * Adding missing snacc compiler files.
506 *
507 * Revision 1.1.1.1 1999/03/16 18:06:49 aram
508 * Originals from SMIME Free Library.
509 *
510 * Revision 1.5 1997/08/28 09:46:41 wan
511 * Reworked number range checking, only gives warning now.
512 *
513 * Revision 1.4 1997/06/19 09:17:17 wan
514 * Added isPdu flag to tables. Added value range checks during parsing.
515 *
516 * Revision 1.3 1995/07/25 19:41:30 rj
517 * changed `_' to `-' in file names.
518 *
519 * Revision 1.2 1994/09/01 00:37:12 rj
520 * snacc_config.h removed.
521 *
522 * for a list of changes relative to the 1.1 distribution, please refer to the ChangeLog.
523 */