changed `struct fd_set' to `fd_set'
[heimdal.git] / lib / asn1 / parse.y
blob2f55a48046a1402fab2b638e3ad026756c8fb82d
1 /*
2 * Copyright (c) 1997 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
39 /* $Id$ */
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include "symbol.h"
49 #include "lex.h"
50 #include "gen_locl.h"
52 RCSID("$Id$");
54 static Type *new_type (Typetype t);
55 void yyerror (char *);
56 int yylex();
58 static void append (Member *l, Member *r);
62 %union {
63 int constant;
64 char *name;
65 Type *type;
66 Member *member;
69 %token INTEGER SEQUENCE OF OCTET STRING GeneralizedTime GeneralString
70 %token BIT APPLICATION OPTIONAL EEQUAL TBEGIN END DEFINITIONS EXTERNAL
71 %token <name> IDENTIFIER
72 %token <constant> CONSTANT
74 %type <constant> constant optional2
75 %type <type> type
76 %type <member> memberdecls memberdecl bitdecls bitdecl
78 %start envelope
82 envelope : IDENTIFIER DEFINITIONS EEQUAL TBEGIN specification END {}
85 specification :
86 | specification declaration
89 declaration : extern_decl
90 | type_decl
91 | constant_decl
94 extern_decl : IDENTIFIER EXTERNAL
96 Symbol *s = addsym($1);
97 s->stype = Stype;
101 type_decl : IDENTIFIER EEQUAL type
103 Symbol *s = addsym ($1);
104 s->stype = Stype;
105 s->type = $3;
106 generate_type (s);
110 constant_decl : IDENTIFIER type EEQUAL constant
112 Symbol *s = addsym ($1);
113 s->stype = SConstant;
114 s->constant = $4;
115 generate_constant (s);
119 type : INTEGER { $$ = new_type(TInteger); }
120 | OCTET STRING { $$ = new_type(TOctetString); }
121 | GeneralString { $$ = new_type(TGeneralString); }
122 | GeneralizedTime { $$ = new_type(TGeneralizedTime); }
123 | SEQUENCE OF type
125 $$ = new_type(TSequenceOf);
126 $$->subtype = $3;
128 | SEQUENCE '{' memberdecls '}'
130 $$ = new_type(TSequence);
131 $$->members = $3;
133 | BIT STRING '{' bitdecls '}'
135 $$ = new_type(TBitString);
136 $$->members = $4;
138 | IDENTIFIER
140 Symbol *s = addsym($1);
141 $$ = new_type(TType);
142 if(s->stype != Stype)
143 error_message ("%s is not a type\n", $1);
144 else
145 $$->symbol = s;
147 | '[' APPLICATION constant ']' type
149 $$ = new_type(TApplication);
150 $$->subtype = $5;
151 $$->application = $3;
155 memberdecls : { $$ = NULL; }
156 | memberdecl { $$ = $1; }
157 | memberdecls ',' memberdecl { $$ = $1; append($$, $3); }
160 memberdecl : IDENTIFIER '[' constant ']' type optional2
162 $$ = malloc(sizeof(*$$));
163 $$->name = $1;
164 $$->gen_name = strdup($1);
165 output_name ($$->gen_name);
166 $$->val = $3;
167 $$->optional = $6;
168 $$->type = $5;
169 $$->next = $$->prev = $$;
173 optional2 : { $$ = 0; }
174 | OPTIONAL { $$ = 1; }
177 bitdecls : { $$ = NULL; }
178 | bitdecl { $$ = $1; }
179 | bitdecls ',' bitdecl { $$ = $1; append($$, $3); }
182 bitdecl : IDENTIFIER '(' constant ')'
184 $$ = malloc(sizeof(*$$));
185 $$->name = $1;
186 $$->gen_name = strdup($1);
187 output_name ($$->gen_name);
188 $$->val = $3;
189 $$->optional = 0;
190 $$->type = NULL;
191 $$->prev = $$->next = $$;
195 constant : CONSTANT { $$ = $1; }
196 | IDENTIFIER {
197 Symbol *s = addsym($1);
198 if(s->stype != SConstant)
199 error_message ("%s is not a constant\n",
200 s->name);
201 else
202 $$ = s->constant;
207 void
208 yyerror (char *s)
210 error_message ("%s\n", s);
213 static Type *
214 new_type (Typetype tt)
216 Type *t = malloc(sizeof(*t));
217 if (t == NULL) {
218 error_message ("out of memory in malloc(%u)", sizeof(*t));
219 exit (1);
221 t->type = tt;
222 t->application = 0;
223 t->members = NULL;
224 t->subtype = NULL;
225 t->symbol = NULL;
226 return t;
229 static void
230 append (Member *l, Member *r)
232 l->prev->next = r;
233 r->prev = l->prev;
234 l->prev = r;
235 r->next = l;