1 /* $NetBSD: lex.l,v 1.1.1.3 2014/04/24 12:45:28 pettai Exp $ */
5 * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 #include "asn1parse.h"
55 static unsigned lineno = 1;
59 static void unterminated(const char *, unsigned);
63 /* This is for broken old lexes (solaris 10 and hpux) */
71 ABSENT { return kw_ABSENT; }
72 ABSTRACT-SYNTAX { return kw_ABSTRACT_SYNTAX; }
73 ALL { return kw_ALL; }
74 APPLICATION { return kw_APPLICATION; }
75 AUTOMATIC { return kw_AUTOMATIC; }
76 BEGIN { return kw_BEGIN; }
77 BIT { return kw_BIT; }
78 BMPString { return kw_BMPString; }
79 BOOLEAN { return kw_BOOLEAN; }
81 CHARACTER { return kw_CHARACTER; }
82 CHOICE { return kw_CHOICE; }
83 CLASS { return kw_CLASS; }
84 COMPONENT { return kw_COMPONENT; }
85 COMPONENTS { return kw_COMPONENTS; }
86 CONSTRAINED { return kw_CONSTRAINED; }
87 CONTAINING { return kw_CONTAINING; }
88 DEFAULT { return kw_DEFAULT; }
89 DEFINITIONS { return kw_DEFINITIONS; }
90 EMBEDDED { return kw_EMBEDDED; }
91 ENCODED { return kw_ENCODED; }
92 END { return kw_END; }
93 ENUMERATED { return kw_ENUMERATED; }
94 EXCEPT { return kw_EXCEPT; }
95 EXPLICIT { return kw_EXPLICIT; }
96 EXPORTS { return kw_EXPORTS; }
97 EXTENSIBILITY { return kw_EXTENSIBILITY; }
98 EXTERNAL { return kw_EXTERNAL; }
99 FALSE { return kw_FALSE; }
100 FROM { return kw_FROM; }
101 GeneralString { return kw_GeneralString; }
102 GeneralizedTime { return kw_GeneralizedTime; }
103 GraphicString { return kw_GraphicString; }
104 IA5String { return kw_IA5String; }
105 IDENTIFIER { return kw_IDENTIFIER; }
106 IMPLICIT { return kw_IMPLICIT; }
107 IMPLIED { return kw_IMPLIED; }
108 IMPORTS { return kw_IMPORTS; }
109 INCLUDES { return kw_INCLUDES; }
110 INSTANCE { return kw_INSTANCE; }
111 INTEGER { return kw_INTEGER; }
112 INTERSECTION { return kw_INTERSECTION; }
113 ISO646String { return kw_ISO646String; }
114 MAX { return kw_MAX; }
115 MIN { return kw_MIN; }
116 MINUS-INFINITY { return kw_MINUS_INFINITY; }
117 NULL { return kw_NULL; }
118 NumericString { return kw_NumericString; }
119 OBJECT { return kw_OBJECT; }
120 OCTET { return kw_OCTET; }
122 OPTIONAL { return kw_OPTIONAL; }
123 ObjectDescriptor { return kw_ObjectDescriptor; }
124 PATTERN { return kw_PATTERN; }
125 PDV { return kw_PDV; }
126 PLUS-INFINITY { return kw_PLUS_INFINITY; }
127 PRESENT { return kw_PRESENT; }
128 PRIVATE { return kw_PRIVATE; }
129 PrintableString { return kw_PrintableString; }
130 REAL { return kw_REAL; }
131 RELATIVE_OID { return kw_RELATIVE_OID; }
132 SEQUENCE { return kw_SEQUENCE; }
133 SET { return kw_SET; }
134 SIZE { return kw_SIZE; }
135 STRING { return kw_STRING; }
136 SYNTAX { return kw_SYNTAX; }
137 T61String { return kw_T61String; }
138 TAGS { return kw_TAGS; }
139 TRUE { return kw_TRUE; }
140 TYPE-IDENTIFIER { return kw_TYPE_IDENTIFIER; }
141 TeletexString { return kw_TeletexString; }
142 UNION { return kw_UNION; }
143 UNIQUE { return kw_UNIQUE; }
144 UNIVERSAL { return kw_UNIVERSAL; }
145 UTCTime { return kw_UTCTime; }
146 UTF8String { return kw_UTF8String; }
147 UniversalString { return kw_UniversalString; }
148 VideotexString { return kw_VideotexString; }
149 VisibleString { return kw_VisibleString; }
150 WITH { return kw_WITH; }
151 [-,;{}()|] { return *yytext; }
152 "[" { return *yytext; }
153 "]" { return *yytext; }
154 ::= { return EEQUAL; }
156 int c, start_lineno = lineno;
158 while((c = input()) != EOF) {
172 unterminated("comment", start_lineno);
175 int c, start_lineno = lineno;
179 while((c = input()) != EOF) {
190 if(seen_star && c == '/') {
199 seen_star = seen_slash = 0;
205 seen_star = seen_slash = 0;
212 unterminated("comment", start_lineno);
215 int start_lineno = lineno;
222 while((c = input()) != EOF) {
223 if(isspace(c) && skip_ws) {
244 while(p > buf && isspace((unsigned char)p[-1]))
252 unterminated("string", start_lineno);
254 fprintf(stderr, "string -- %s\n", buf);
255 yylval.name = estrdup(buf);
259 -?0x[0-9A-Fa-f]+|-?[0-9]+ { char *e, *y = yytext;
260 yylval.constant = strtol((const char *)yytext,
263 lex_error_message("malformed constant (%s)", yytext);
267 [A-Za-z][-A-Za-z0-9_]* {
268 yylval.name = estrdup ((const char *)yytext);
273 \.\.\. { return ELLIPSIS; }
274 \.\. { return RANGE; }
275 . { lex_error_message("Ignoring char(%c)\n", *yytext); }
278 #ifndef yywrap /* XXX */
287 lex_error_message (const char *format, ...)
291 va_start (args, format);
292 fprintf (stderr, "%s:%d: ", get_filename(), lineno);
293 vfprintf (stderr, format, args);
299 unterminated(const char *type, unsigned start_lineno)
301 lex_error_message("unterminated %s, possibly started on line %d\n", type, start_lineno);