Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
%types%
32
 
33
StringT;
34
CCodeP;
35
BoolT;
36
 
37
%terminals%
38
 
39
blt-prefixes;		// %prefixes% 
40
blt-maps;		// %maps% 
41
blt-assignments;	// %assignments% 
42
blt-terminals;		// %terminals%
43
blt-header;		// %header% 
44
blt-actions;		// %actions% 
45
blt-trailer;		// %trailer% 
46
blt-result-assign;	// %result-assignments%
47
sid-identifier: () -> (: StringT);
48
c-identifier: () -> (: StringT);
49
separator;		// ,
50
typemark;		// :
51
terminator;		// ; 
52
begin-action;		// <
53
define;			// =
54
end-action;		// >
55
code: () -> (: CCodeP);	// @{ ... @}
56
arrow;			// ->
57
open-tuple;		// (
58
close-tuple;		// )
59
blt-param-assign;	// %parameter-assignments%
60
reference;		// &
61
eof;
62
 
63
%productions%
64
 
65
<set-prefix>: (: StringT &) -> ();
66
<x-set-prefix>: (: StringT &) -> ();
67
<set-map>: (: StringT &) -> ();
68
<x-set-map>: (: StringT &) -> ();
69
<init-tuple>;
70
<tuple-type>: (: StringT &, : StringT &) -> ();
71
<tuple-ref-type>: (: StringT &, : StringT &) -> ();
72
<tuple-name>: (: StringT &) -> ();
73
<save-tuple>;
74
<null-type>;
75
<assign>: (: StringT &) -> ();
76
<x-assign>: (: CCodeP) -> ();
77
<passign>: (: StringT &) -> ();
78
<x-passign>: (: CCodeP) -> ();
79
<rassign>: (: StringT &) -> ();
80
<x-rassign>: (: CCodeP) -> ();
81
<set-terminal>: (: StringT &) -> ();
82
<x-set-terminal>: (: CCodeP) -> ();
83
<set-action>: (: StringT &) -> ();
84
<x-set-action>: (: CCodeP) -> ();
85
<set-header1>: (: CCodeP) -> ();
86
<set-header2>: (: CCodeP) -> ();
87
<set-trailer1>: (: CCodeP) -> ();
88
<set-trailer2>: (: CCodeP) -> ();
89
 
90
<unhandled-syntax-error>;
91
 
92
<expected-identifier>;
93
<expected-c-identifier>;
94
<expected-separator>;
95
<expected-open-tuple>;
96
<expected-close-tuple>;
97
<expected-arrow>;
98
<expected-terminator>;
99
<expected-end-action>;
100
<expected-define>;
101
<expected-code>;
102
<expected-blt-header>;
103
<expected-blt-terminals>;
104
<expected-blt-actions>;
105
<expected-blt-trailer>;
106
<expected-eof>;
107
 
108
<destroy-string>: (: StringT &) -> ();
109
 
110
<skip-to-end-of-tuple-defn>;
111
<skip-to-end-of-prefix>;
112
<skip-to-end-of-map>;
113
<skip-to-end-of-assignment>;
114
<skip-to-end-of-result-assign>;
115
<skip-to-end-of-param-assign>;
116
<skip-to-end-of-terminal>;
117
<skip-to-end-of-action>;
118
<skip-recover>;
119
 
120
<is-close-tuple-or-skipped-or-eof>: () -> (: BoolT);
121
 
122
c-parse-grammar [
123
	// IDENTIFIERS:
124
	identifier: () -> (id: StringT) = {
125
		id = sid-identifier;
126
	    ||
127
		id = c-identifier;
128
	};
129
 
130
	// PREFIX DEFINITIONS:
131
	prefix-list [
132
		prefix = {
133
			prefix = identifier;
134
			<set-prefix> (&prefix);
135
			{
136
				define;
137
			    ##
138
				<expected-define>;
139
			};
140
			{
141
				name = c-identifier;
142
				<x-set-prefix> (&name);
143
				{
144
					terminator;
145
				    ##
146
					<expected-terminator>;
147
				};
148
			    ##
149
				<expected-c-identifier>;
150
				<skip-to-end-of-prefix>;
151
			};
152
		};
153
	] = {
154
		$;
155
	    ||
156
		prefix;
157
		<skip-recover>;
158
		prefix-list;
159
	};
160
 
161
	// IDENTIFIER MAPPING:
162
	map-list [
163
		map = {
164
			from = identifier;
165
			<set-map> (&from);
166
			{
167
				arrow;
168
			    ##
169
				<expected-arrow>;
170
			};
171
			{
172
				to = c-identifier;
173
				<x-set-map> (&to);
174
				{
175
					terminator;
176
				    ##
177
					<expected-terminator>;
178
				};
179
			    ##
180
				<expected-c-identifier>;
181
				<skip-to-end-of-map>;
182
			};
183
		};
184
	] = {
185
		$;
186
	    ||
187
		map;
188
		<skip-recover>;
189
		map-list;
190
	};
191
 
192
	// FUNCTION TYPE SPECIFICATIONS:
193
	function-type-defn [
194
		tuple-defn = {
195
			name = c-identifier;
196
			{
197
				typemark;
198
				{
199
					type = identifier;
200
					{
201
						reference;
202
						<tuple-ref-type> (&name,
203
								  &type);
204
					    ||
205
						<tuple-type> (&name, &type);
206
					};
207
				    ##
208
					<expected-identifier>;
209
					<destroy-string> (&name);
210
					<skip-to-end-of-tuple-defn>;
211
				};
212
			    ||
213
				<tuple-name> (&name);
214
			};
215
		    ##
216
			<expected-identifier>;
217
			<skip-to-end-of-tuple-defn>;
218
		};
219
 
220
		tuple-defn-list-1 = {
221
			tuple-defn;
222
			{
223
				? = <is-close-tuple-or-skipped-or-eof>;
224
			    ||
225
				separator;
226
				tuple-defn-list-1;
227
			    ##
228
				<expected-separator>;
229
				tuple-defn-list-1;
230
			};
231
		};
232
 
233
		tuple-defn-list = {
234
			$;
235
		    ||
236
			tuple-defn-list-1;
237
		};
238
 
239
		type-tuple-defn = {
240
			<init-tuple>;
241
			{
242
				open-tuple;
243
			    ##
244
				<expected-open-tuple>;
245
			};
246
			tuple-defn-list;
247
			<skip-recover>;
248
			{
249
				close-tuple;
250
			    ##
251
				<expected-close-tuple>;
252
			};
253
		};
254
	] = {
255
		typemark;
256
		type-tuple-defn;
257
		<save-tuple>;
258
		{
259
			arrow;
260
		    ##
261
			<expected-arrow>;
262
		};
263
		type-tuple-defn;
264
	    ||
265
		<null-type>;
266
	};
267
 
268
	// ASSIGNMENT DEFINITIONS:
269
	assignment-list [
270
		assignment = {
271
			id = identifier;
272
			<assign> (&id);
273
			function-type-defn;
274
			{
275
				define;
276
			    ##
277
				<expected-define>;
278
			};
279
			{
280
				body = code;
281
				<x-assign> (body);
282
				{
283
					terminator;
284
				    ##
285
					<expected-terminator>;
286
				};
287
			    ##
288
				<expected-code>;
289
				<skip-to-end-of-assignment>;
290
			};
291
		};
292
	] = {
293
		$;
294
	    ||
295
		assignment;
296
		<skip-recover>;
297
		assignment-list;
298
	};
299
 
300
	param-assign-list [
301
		param-assign = {
302
			id = identifier;
303
			<passign> (&id);
304
			function-type-defn;
305
			{
306
				define;
307
			    ##
308
				<expected-define>;
309
			};
310
			{
311
				body = code;
312
				<x-passign> (body);
313
				{
314
					terminator;
315
				    ##
316
					<expected-terminator>;
317
				};
318
			    ##
319
				<expected-code>;
320
				<skip-to-end-of-param-assign>;
321
			};
322
		};
323
	] = {
324
		$;
325
	    ||
326
		param-assign;
327
		<skip-recover>;
328
		param-assign-list;
329
	};
330
 
331
	result-assign-list [
332
		result-assign = {
333
			id = identifier;
334
			<rassign> (&id);
335
			function-type-defn;
336
			{
337
				define;
338
			    ##
339
				<expected-define>;
340
			};
341
			{
342
				body = code;
343
				<x-rassign> (body);
344
				{
345
					terminator;
346
				    ##
347
					<expected-terminator>;
348
				};
349
			    ##
350
				<expected-code>;
351
				<skip-to-end-of-result-assign>;
352
			};
353
		};
354
	] = {
355
		$;
356
	    ||
357
		result-assign;
358
		<skip-recover>;
359
		result-assign-list;
360
	};
361
 
362
	// TERMINAL RESULT EXTRACTION DEFINITIONS:
363
	terminal-list [
364
		terminal = {
365
			id = identifier;
366
			<set-terminal> (&id);
367
			function-type-defn;
368
			{
369
				define;
370
			    ##
371
				<expected-define>;
372
			};
373
			{
374
				body = code;
375
				<x-set-terminal> (body);
376
				{
377
					terminator;
378
				    ##
379
					<expected-terminator>;
380
				};
381
			    ##
382
				<expected-code>;
383
				<skip-to-end-of-terminal>;
384
			};
385
		};
386
	] = {
387
		$;
388
	    ||
389
		terminal;
390
		<skip-recover>;
391
		terminal-list;
392
	};
393
 
394
	// ACTION DEFINITIONS:
395
	action-list [
396
		action = {
397
			begin-action;
398
			{
399
				id = identifier;
400
				<set-action> (&id);
401
				{
402
					end-action;
403
				    ##
404
					<expected-end-action>;
405
				};
406
				function-type-defn;
407
				{
408
					define;
409
				    ##
410
					<expected-define>;
411
				};
412
				{
413
					body = code;
414
					<x-set-action> (body);
415
					{
416
						terminator;
417
					    ##
418
						<expected-terminator>;
419
					};
420
				    ##
421
					<expected-code>;
422
					<skip-to-end-of-action>;
423
				};
424
			    ##
425
				<expected-identifier>;
426
				<skip-to-end-of-action>;
427
			};
428
		};
429
	] = {
430
		$;
431
	    ||
432
		action;
433
		<skip-recover>;
434
		action-list;
435
	};
436
 
437
] /* c-parse-grammar */ = {
438
	{
439
		blt-prefixes;
440
		prefix-list;
441
	    ||
442
		$;
443
	};
444
	{
445
		blt-maps;
446
		map-list;
447
	    ||
448
		$;
449
	};
450
	{
451
		blt-header;
452
	   ##
453
		<expected-blt-header>;
454
	};
455
	{
456
		h1 = code;
457
		<set-header1> (h1);
458
	    ##
459
		<expected-code>;
460
	};
461
	{
462
		separator;
463
	    ##
464
		<expected-separator>;
465
	};
466
	{
467
		h2 = code;
468
		<set-header2> (h2);
469
	    ##
470
		<expected-code>;
471
	};
472
	{
473
		terminator;
474
	    ##
475
		<expected-terminator>;
476
	};
477
	{
478
		blt-assignments;
479
		assignment-list;
480
	    ||
481
		$;
482
	};
483
	{
484
		blt-param-assign;
485
		param-assign-list;
486
	    ||
487
		$;
488
	};
489
	{
490
		blt-result-assign;
491
		result-assign-list;
492
	    ||
493
		$;
494
	};
495
	{
496
		blt-terminals;
497
	    ##
498
		<expected-blt-terminals>;
499
	};
500
	terminal-list;
501
	{
502
		blt-actions;
503
	    ##
504
		<expected-blt-actions>;
505
	};
506
	action-list;
507
	{
508
		blt-trailer;
509
	    ##
510
		<expected-blt-trailer>;
511
	};
512
	{
513
		t1 = code;
514
		<set-trailer1> (t1);
515
	    ##
516
		<expected-code>;
517
	};
518
	{
519
		separator;
520
	    ##
521
		<expected-separator>;
522
	};
523
	{
524
		t2 = code;
525
		<set-trailer2> (t2);
526
	    ##
527
		<expected-code>;
528
	};
529
	{
530
		terminator;
531
	    ##
532
		<expected-terminator>;
533
	};
534
	{
535
		eof;
536
	    ##
537
		<expected-eof>;
538
	};
539
    ##
540
	<unhandled-syntax-error>;
541
};
542
 
543
%entry% c-parse-grammar;