remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / asn1 / parse.y
blobfc780860364bfb3ea4950c2b7b26666326247088
1 /*
2 * Copyright (c) 1997 - 2001 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. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* $Id: parse.y,v 1.19 2001/09/27 16:21:47 assar Exp $ */
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include "symbol.h"
44 #include "lex.h"
45 #include "gen_locl.h"
47 RCSID("$Id: parse.y,v 1.19 2001/09/27 16:21:47 assar Exp $");
49 static Type *new_type (Typetype t);
50 void yyerror (char *);
52 static void append (Member *l, Member *r);
56 %union {
57 int constant;
58 char *name;
59 Type *type;
60 Member *member;
63 %token INTEGER SEQUENCE OF OCTET STRING GeneralizedTime GeneralString
64 %token BIT APPLICATION OPTIONAL EEQUAL TBEGIN END DEFINITIONS ENUMERATED
65 %token EXTERNAL
66 %token DOTDOT
67 %token IMPORTS FROM
68 %token OBJECT IDENTIFIER
69 %token <name> IDENT
70 %token <constant> CONSTANT
72 %type <constant> constant optional2
73 %type <type> type
74 %type <member> memberdecls memberdecl bitdecls bitdecl
76 %start envelope
80 envelope : IDENT DEFINITIONS EEQUAL TBEGIN specification END {}
83 specification :
84 | specification declaration
87 declaration : imports_decl
88 | type_decl
89 | constant_decl
92 referencenames : IDENT ',' referencenames
94 Symbol *s = addsym($1);
95 s->stype = Stype;
97 | IDENT
99 Symbol *s = addsym($1);
100 s->stype = Stype;
104 imports_decl : IMPORTS referencenames FROM IDENT ';'
105 { add_import($4); }
108 type_decl : IDENT EEQUAL type
110 Symbol *s = addsym ($1);
111 s->stype = Stype;
112 s->type = $3;
113 generate_type (s);
117 constant_decl : IDENT type EEQUAL constant
119 Symbol *s = addsym ($1);
120 s->stype = SConstant;
121 s->constant = $4;
122 generate_constant (s);
126 type : INTEGER { $$ = new_type(TInteger); }
127 | INTEGER '(' constant DOTDOT constant ')' {
128 if($3 != 0)
129 error_message("Only 0 supported as low range");
130 if($5 != INT_MIN && $5 != UINT_MAX && $5 != INT_MAX)
131 error_message("Only %u supported as high range",
132 UINT_MAX);
133 $$ = new_type(TUInteger);
135 | INTEGER '{' bitdecls '}'
137 $$ = new_type(TInteger);
138 $$->members = $3;
140 | OBJECT IDENTIFIER { $$ = new_type(TOID); }
141 | ENUMERATED '{' bitdecls '}'
143 $$ = new_type(TEnumerated);
144 $$->members = $3;
146 | OCTET STRING { $$ = new_type(TOctetString); }
147 | GeneralString { $$ = new_type(TGeneralString); }
148 | GeneralizedTime { $$ = new_type(TGeneralizedTime); }
149 | SEQUENCE OF type
151 $$ = new_type(TSequenceOf);
152 $$->subtype = $3;
154 | SEQUENCE '{' memberdecls '}'
156 $$ = new_type(TSequence);
157 $$->members = $3;
159 | BIT STRING '{' bitdecls '}'
161 $$ = new_type(TBitString);
162 $$->members = $4;
164 | IDENT
166 Symbol *s = addsym($1);
167 $$ = new_type(TType);
168 if(s->stype != Stype)
169 error_message ("%s is not a type\n", $1);
170 else
171 $$->symbol = s;
173 | '[' APPLICATION constant ']' type
175 $$ = new_type(TApplication);
176 $$->subtype = $5;
177 $$->application = $3;
181 memberdecls : { $$ = NULL; }
182 | memberdecl { $$ = $1; }
183 | memberdecls ',' memberdecl { $$ = $1; append($$, $3); }
186 memberdecl : IDENT '[' constant ']' type optional2
188 $$ = malloc(sizeof(*$$));
189 $$->name = $1;
190 $$->gen_name = strdup($1);
191 output_name ($$->gen_name);
192 $$->val = $3;
193 $$->optional = $6;
194 $$->type = $5;
195 $$->next = $$->prev = $$;
199 optional2 : { $$ = 0; }
200 | OPTIONAL { $$ = 1; }
203 bitdecls : { $$ = NULL; }
204 | bitdecl { $$ = $1; }
205 | bitdecls ',' bitdecl { $$ = $1; append($$, $3); }
208 bitdecl : IDENT '(' constant ')'
210 $$ = malloc(sizeof(*$$));
211 $$->name = $1;
212 $$->gen_name = strdup($1);
213 output_name ($$->gen_name);
214 $$->val = $3;
215 $$->optional = 0;
216 $$->type = NULL;
217 $$->prev = $$->next = $$;
221 constant : CONSTANT { $$ = $1; }
222 | IDENT {
223 Symbol *s = addsym($1);
224 if(s->stype != SConstant)
225 error_message ("%s is not a constant\n",
226 s->name);
227 else
228 $$ = s->constant;
233 void
234 yyerror (char *s)
236 error_message ("%s\n", s);
239 static Type *
240 new_type (Typetype tt)
242 Type *t = malloc(sizeof(*t));
243 if (t == NULL) {
244 error_message ("out of memory in malloc(%lu)",
245 (unsigned long)sizeof(*t));
246 exit (1);
248 t->type = tt;
249 t->application = 0;
250 t->members = NULL;
251 t->subtype = NULL;
252 t->symbol = NULL;
253 return t;
256 static void
257 append (Member *l, Member *r)
259 l->prev->next = r;
260 r->prev = l->prev;
261 l->prev = r;
262 r->next = l;