Commit | Line | Data |
---|---|---|
6f374d1e | 1 | %{ |
0f4556f1 C |
2 | #ifndef lint |
3 | static char sccsid[] = "@(#)courier.y 4.2 (Berkeley) 7/7/83"; | |
4 | #endif | |
5 | ||
6f374d1e C |
6 | #include "Courier.h" |
7 | %} | |
8 | ||
9 | %token | |
10 | identifier number | |
11 | ||
12 | %token | |
13 | ARRAY _BEGIN BOOLEAN CARDINAL | |
14 | CHOICE DEPENDS END ERROR | |
15 | INTEGER LONG OF PROCEDURE | |
16 | PROGRAM RECORD REPORTS RETURNS | |
17 | SEQUENCE STRING TYPE UNSPECIFIED | |
18 | UPON VERSION | |
19 | ||
20 | %union { | |
21 | int integer; | |
22 | struct object *object; | |
23 | list list; | |
24 | } | |
25 | ||
26 | %type <object> | |
27 | identifier number | |
28 | ConstructedType DesignatorType MaximumNumber | |
29 | NumericValue PredefinedType ProgramHeader | |
30 | ReferencedConstant ReferencedType Type | |
31 | ||
32 | %type <list> | |
33 | ArgumentList Candidate CandidateList | |
34 | Correspondence CorrespondenceList Designator | |
35 | DesignatorList ErrorList Field | |
36 | FieldList NameList ResultList | |
37 | ||
38 | %start Program | |
39 | ||
40 | %% | |
41 | ||
42 | Program : | |
43 | ProgramHeader ProgramBody | |
44 | = { | |
45 | program($1); | |
46 | } | |
47 | ; | |
48 | ||
49 | ProgramHeader : | |
50 | identifier ':' PROGRAM '=' | |
51 | = { | |
52 | program_header($1); | |
53 | $$ = $1; | |
54 | } | |
55 | | | |
56 | identifier ':' PROGRAM number VERSION number '=' | |
57 | = { | |
58 | program_header($1); | |
59 | $$ = $1; | |
60 | } | |
61 | ; | |
62 | ||
63 | ProgramBody : | |
64 | _BEGIN DependencyList DeclarationList END '.' | |
65 | ; | |
66 | ||
67 | DependencyList : | |
68 | /* empty */ | |
69 | | DEPENDS UPON ReferencedProgramList ';' | |
70 | = { | |
71 | yyerror("Dependencies on other Courier programs are not supported"); | |
72 | } | |
73 | ; | |
74 | ||
75 | ReferencedProgramList : | |
76 | ReferencedProgram | |
77 | | ReferencedProgramList ',' ReferencedProgram | |
78 | ; | |
79 | ||
80 | ReferencedProgram : | |
81 | identifier '(' number ')' VERSION number | |
82 | ; | |
83 | ||
84 | DeclarationList : | |
85 | /* empty */ | |
86 | | DeclarationList Declaration | |
87 | ; | |
88 | ||
89 | Declaration : | |
90 | identifier ':' TYPE '=' Type ';' | |
91 | = { | |
92 | compile_type($1, $5); | |
93 | } | |
94 | | identifier ':' Type '=' NumericValue ';' | |
95 | = { | |
96 | if (type_check($3, $5)) { | |
97 | compile_def($1, $3, $5); | |
98 | } else | |
99 | yyerror("Type clash in declaration of %s", | |
100 | name_of($1)); | |
101 | } | |
102 | ; | |
103 | ||
104 | Type : | |
105 | PredefinedType | |
106 | = { | |
107 | type_functions($1); | |
108 | $$ = $1; | |
109 | } | |
110 | | ConstructedType | |
111 | = { | |
112 | type_functions($1); | |
113 | $$ = $1; | |
114 | } | |
115 | | ReferencedType | |
116 | = { | |
117 | type_functions($1); | |
118 | $$ = $1; | |
119 | } | |
120 | ; | |
121 | ||
122 | PredefinedType : | |
123 | BOOLEAN | |
124 | = { | |
125 | $$ = Boolean_type; | |
126 | } | |
127 | | CARDINAL | |
128 | = { | |
129 | $$ = Cardinal_type; | |
130 | } | |
131 | | LONG CARDINAL | |
132 | = { | |
133 | $$ = LongCardinal_type; | |
134 | } | |
135 | | INTEGER | |
136 | = { | |
137 | $$ = Integer_type; | |
138 | } | |
139 | | LONG INTEGER | |
140 | = { | |
141 | $$ = LongInteger_type; | |
142 | } | |
143 | | STRING | |
144 | = { | |
145 | $$ = String_type; | |
146 | } | |
147 | | UNSPECIFIED | |
148 | = { | |
149 | $$ = Unspecified_type; | |
150 | } | |
151 | | LONG UNSPECIFIED | |
152 | = { | |
153 | $$ = LongUnspecified_type; | |
154 | } | |
155 | ; | |
156 | ||
157 | ConstructedType : | |
158 | '{' CorrespondenceList '}' | |
159 | = { | |
160 | $$ = construct_type1(C_ENUMERATION, $2); | |
161 | } | |
162 | | ARRAY NumericValue OF Type | |
163 | = { | |
164 | $$ = construct_type2(C_ARRAY, $2, $4); | |
165 | } | |
166 | | SEQUENCE MaximumNumber OF Type | |
167 | = { | |
168 | $$ = construct_type2(C_SEQUENCE, $2, $4); | |
169 | } | |
170 | | RECORD ArgumentList | |
171 | = { | |
172 | $$ = construct_type1(C_RECORD, $2); | |
173 | } | |
174 | | CHOICE DesignatorType OF '{' CandidateList '}' | |
175 | = { | |
176 | $$ = construct_choice($2, $5); | |
177 | } | |
178 | | PROCEDURE ArgumentList ResultList ErrorList | |
179 | = { | |
180 | $$ = construct_procedure($2, $3, $4); | |
181 | } | |
182 | | ERROR ArgumentList | |
183 | = { | |
184 | $$ = construct_type1(C_ERROR, $2); | |
185 | } | |
186 | ; | |
187 | ||
188 | ReferencedType : | |
189 | identifier | |
190 | = { | |
191 | if (check_def($1)) | |
192 | $$ = $1; | |
193 | else | |
194 | $$ = Unspecified_type; | |
195 | } | |
196 | | identifier '.' identifier | |
197 | = { | |
198 | yyerror("References to types in other Courier programs are not supported"); | |
199 | $$ = Unspecified_type; | |
200 | } | |
201 | ; | |
202 | ||
203 | CorrespondenceList : | |
204 | Correspondence | |
205 | = { | |
206 | $$ = cons($1, NIL); | |
207 | } | |
208 | | CorrespondenceList ',' Correspondence | |
209 | = { | |
210 | $$ = nconc($1, cons($3, NIL)); | |
211 | } | |
212 | ; | |
213 | ||
214 | Correspondence : | |
215 | identifier '(' NumericValue ')' | |
216 | = { | |
217 | $$ = cons($1, $3); | |
218 | } | |
219 | ; | |
220 | ||
221 | MaximumNumber : | |
222 | NumericValue | |
223 | = { | |
224 | $$ = $1; | |
225 | } | |
226 | | /* empty */ | |
227 | = { | |
228 | $$ = NIL; | |
229 | } | |
230 | ; | |
231 | ||
232 | NumericValue : | |
233 | number | |
234 | = { | |
235 | $$ = $1; | |
236 | } | |
237 | | ReferencedConstant | |
238 | = { | |
239 | $$ = $1; | |
240 | } | |
241 | ; | |
242 | ||
243 | DesignatorType : | |
244 | /* empty */ | |
245 | = { | |
246 | $$ = NIL; | |
247 | } | |
248 | | ReferencedType | |
249 | = { | |
250 | $$ = $1; | |
251 | } | |
252 | ; | |
253 | ||
254 | CandidateList : | |
255 | Candidate | |
256 | = { | |
257 | $$ = cons($1, NIL); | |
258 | } | |
259 | | CandidateList ',' Candidate | |
260 | = { | |
261 | $$ = nconc($1, cons($3, NIL)); | |
262 | } | |
263 | ; | |
264 | ||
265 | Candidate : | |
266 | DesignatorList '=''>' Type | |
267 | = { | |
268 | $$ = cons($1, $4); | |
269 | } | |
270 | ; | |
271 | ||
272 | DesignatorList : | |
273 | Designator | |
274 | = { | |
275 | $$ = cons($1, NIL); | |
276 | } | |
277 | | DesignatorList ',' Designator | |
278 | = { | |
279 | $$ = nconc($1, cons($3, NIL)); | |
280 | } | |
281 | ; | |
282 | ||
283 | Designator : | |
284 | identifier | |
285 | = { | |
286 | $$ = cons($1, NIL); | |
287 | } | |
288 | | Correspondence | |
289 | = { | |
290 | $$ = $1; | |
291 | } | |
292 | ; | |
293 | ||
294 | ArgumentList : | |
295 | /* empty */ | |
296 | = { | |
297 | $$ = NIL; | |
298 | } | |
299 | | '[' FieldList ']' | |
300 | = { | |
301 | $$ = $2; | |
302 | } | |
303 | ; | |
304 | ||
305 | ResultList : | |
306 | /* empty */ | |
307 | = { | |
308 | $$ = NIL; | |
309 | } | |
310 | | RETURNS '[' FieldList ']' | |
311 | = { | |
312 | $$ = $3; | |
313 | } | |
314 | ; | |
315 | ||
316 | ErrorList : | |
317 | /* empty */ | |
318 | = { | |
319 | $$ = NIL; | |
320 | } | |
321 | | REPORTS '[' NameList ']' | |
322 | = { | |
323 | $$ = $3; | |
324 | } | |
325 | ; | |
326 | ||
327 | FieldList : | |
328 | Field | |
329 | = { | |
330 | $$ = cons($1, NIL); | |
331 | } | |
332 | | FieldList ',' Field | |
333 | = { | |
334 | $$ = nconc($1, cons($3, NIL)); | |
335 | } | |
336 | ; | |
337 | ||
338 | Field : | |
339 | NameList ':' Type | |
340 | = { | |
341 | $$ = cons($1, $3); | |
342 | } | |
343 | ; | |
344 | ||
345 | ||
346 | ReferencedConstant : | |
347 | identifier | |
348 | = { | |
349 | if (check_def($1)) | |
350 | $$ = $1; | |
351 | else | |
352 | $$ = Undefined_constant; | |
353 | } | |
354 | | identifier '.' identifier | |
355 | = { | |
356 | yyerror("References to constants in other Courier programs are not supported"); | |
357 | $$ = Undefined_constant; | |
358 | } | |
359 | ; | |
360 | ||
361 | NameList : | |
362 | identifier | |
363 | = { | |
364 | $$ = cons($1, NIL); | |
365 | } | |
366 | | NameList ',' identifier | |
367 | = { | |
368 | $$ = nconc($1, cons($3, NIL)); | |
369 | } | |
370 | ; |