2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 /* $Id: parse.y,v 1.19 2001/09/27 16:21:47 assar Exp $ */
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
);
63 %token INTEGER SEQUENCE OF OCTET STRING GeneralizedTime GeneralString
64 %token BIT APPLICATION OPTIONAL EEQUAL TBEGIN END DEFINITIONS ENUMERATED
68 %token OBJECT IDENTIFIER
70 %token
<constant
> CONSTANT
72 %type
<constant
> constant optional2
74 %type
<member
> memberdecls memberdecl bitdecls bitdecl
80 envelope
: IDENT DEFINITIONS EEQUAL TBEGIN specification END
{}
84 | specification declaration
87 declaration
: imports_decl
92 referencenames
: IDENT
',' referencenames
94 Symbol
*s
= addsym
($1);
99 Symbol
*s
= addsym
($1);
104 imports_decl
: IMPORTS referencenames FROM IDENT
';'
108 type_decl
: IDENT EEQUAL type
110 Symbol
*s
= addsym
($1);
117 constant_decl
: IDENT type EEQUAL constant
119 Symbol
*s
= addsym
($1);
120 s
->stype
= SConstant
;
122 generate_constant
(s
);
126 type
: INTEGER
{ $$
= new_type
(TInteger
); }
127 | INTEGER
'(' constant DOTDOT constant
')' {
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",
133 $$
= new_type
(TUInteger
);
135 | INTEGER
'{' bitdecls
'}'
137 $$
= new_type
(TInteger
);
140 | OBJECT IDENTIFIER
{ $$
= new_type
(TOID
); }
141 | ENUMERATED
'{' bitdecls
'}'
143 $$
= new_type
(TEnumerated
);
146 | OCTET STRING
{ $$
= new_type
(TOctetString
); }
147 | GeneralString
{ $$
= new_type
(TGeneralString
); }
148 | GeneralizedTime
{ $$
= new_type
(TGeneralizedTime
); }
151 $$
= new_type
(TSequenceOf
);
154 | SEQUENCE
'{' memberdecls
'}'
156 $$
= new_type
(TSequence
);
159 | BIT STRING
'{' bitdecls
'}'
161 $$
= new_type
(TBitString
);
166 Symbol
*s
= addsym
($1);
167 $$
= new_type
(TType
);
168 if
(s
->stype
!= Stype
)
169 error_message
("%s is not a type\n", $1);
173 |
'[' APPLICATION constant
']' type
175 $$
= new_type
(TApplication
);
177 $$
->application
= $3;
181 memberdecls
: { $$
= NULL
; }
182 | memberdecl
{ $$
= $1; }
183 | memberdecls
',' memberdecl
{ $$
= $1; append
($$
, $3); }
186 memberdecl
: IDENT
'[' constant
']' type optional2
188 $$
= malloc
(sizeof
(*$$
));
190 $$
->gen_name
= strdup
($1);
191 output_name
($$
->gen_name
);
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
(*$$
));
212 $$
->gen_name
= strdup
($1);
213 output_name
($$
->gen_name
);
217 $$
->prev
= $$
->next
= $$
;
221 constant
: CONSTANT
{ $$
= $1; }
223 Symbol
*s
= addsym
($1);
224 if
(s
->stype
!= SConstant
)
225 error_message
("%s is not a constant\n",
236 error_message
("%s\n", s
);
240 new_type
(Typetype tt
)
242 Type
*t
= malloc
(sizeof
(*t
));
244 error_message
("out of memory in malloc(%lu)",
245 (unsigned long)sizeof
(*t
));
257 append
(Member
*l
, Member
*r
)