Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5/src/utilities/sid/c-parser.act – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
// -*- C -*-
2
%prefixes%
3
 
4
%maps%
5
 
6
StringT		-> NStringT;
7
CCodeP		-> CCodeP;
8
BoolT		-> BoolT;
9
c-parse-grammar	-> c_parse_grammar;
10
 
11
%header% @{
12
/*
13
    		 Crown Copyright (c) 1997
14
 
15
    This TenDRA(r) Computer Program is subject to Copyright
16
    owned by the United Kingdom Secretary of State for Defence
17
    acting through the Defence Evaluation and Research Agency
18
    (DERA).  It is made available to Recipients with a
19
    royalty-free licence for its use, reproduction, transfer
20
    to other parties and amendment for any purpose not excluding
21
    product development provided that any such use et cetera
22
    shall be deemed to be acceptance of the following conditions:-
23
 
24
        (1) Its Recipients shall ensure that this Notice is
25
        reproduced upon any copies or amended versions of it;
26
 
27
        (2) Any amended version of it shall be clearly marked to
28
        show both the nature of and the organisation responsible
29
        for the relevant amendment or amendments;
30
 
31
        (3) Its onward transfer from a recipient to another
32
        party shall be deemed to be that party's acceptance of
33
        these conditions;
34
 
35
        (4) DERA gives no warranty or assurance as to its
36
        quality or suitability for any purpose and DERA accepts
37
        no liability whatsoever in relation to any use to which
38
        it may be put.
39
*/
40
 
41
 
42
#include "c-parser.h"
43
#include "action.h"
44
#include "c-code.h"
45
#include "c-out-info.h"
46
#include "basic.h"
47
#include "entry.h"
48
#include "gen-errors.h"
49
#include "type.h"
50
#include "types.h"
51
 
52
/*--------------------------------------------------------------------------*/
53
 
54
#define CURRENT_TERMINAL c_lexer_get_terminal (c_current_stream)
55
#define ADVANCE_LEXER c_lexer_next_token (c_current_stream)
56
#define SAVE_LEXER(x) (c_lexer_save_terminal (c_current_stream, (CTokenT) (x)))
57
#define RESTORE_LEXER (c_lexer_restore_terminal (c_current_stream))
58
 
59
/*--------------------------------------------------------------------------*/
60
 
61
static NStringT		c_prefix_names [CPFX_NUM_PREFIXES];
62
static BoolT		c_inited_prefix_names = FALSE;
63
static CPrefixT		c_current_prefix;
64
static EntryP		c_current_entry;
65
static TypeTupleT	c_saved_type;
66
static TypeTupleT	c_current_type;
67
static BoolT		c_propagating_error = FALSE;
68
 
69
/*--------------------------------------------------------------------------*/
70
 
71
CLexerStreamP		c_current_stream;
72
COutputInfoP		c_current_out_info;
73
TableP			c_current_table;
74
@}, @{
75
/*
76
    		 Crown Copyright (c) 1997
77
 
78
    This TenDRA(r) Computer Program is subject to Copyright
79
    owned by the United Kingdom Secretary of State for Defence
80
    acting through the Defence Evaluation and Research Agency
81
    (DERA).  It is made available to Recipients with a
82
    royalty-free licence for its use, reproduction, transfer
83
    to other parties and amendment for any purpose not excluding
84
    product development provided that any such use et cetera
85
    shall be deemed to be acceptance of the following conditions:-
86
 
87
        (1) Its Recipients shall ensure that this Notice is
88
        reproduced upon any copies or amended versions of it;
89
 
90
        (2) Any amended version of it shall be clearly marked to
91
        show both the nature of and the organisation responsible
92
        for the relevant amendment or amendments;
93
 
94
        (3) Its onward transfer from a recipient to another
95
        party shall be deemed to be that party's acceptance of
96
        these conditions;
97
 
98
        (4) DERA gives no warranty or assurance as to its
99
        quality or suitability for any purpose and DERA accepts
100
        no liability whatsoever in relation to any use to which
101
        it may be put.
102
*/
103
 
104
 
105
@};
106
 
107
%assignments%
108
 
109
StringT: (a) -> (b) = @{
110
    nstring_assign (&@b, @&a);
111
@};
112
 
113
%parameter-assignments%
114
 
115
StringT: (a) -> (b) = @{
116
    nstring_assign (&@b, @a);
117
@};
118
 
119
%result-assignments%
120
 
121
StringT: (a) -> (b) = @{
122
    nstring_assign (@b, @&a);
123
@};
124
 
125
%terminals%
126
 
127
c-identifier: () -> (i) = @{
128
    nstring_assign (&@i, c_lexer_string_value (c_current_stream));
129
@};
130
 
131
sid-identifier: () -> (i) = @{
132
    nstring_assign (&@i, c_lexer_string_value (c_current_stream));
133
@};
134
 
135
code: () -> (c) = @{
136
    @c = c_lexer_code_value (c_current_stream);
137
@};
138
 
139
%actions%
140
 
141
// Prefix section actions:
142
 
143
<set-prefix>: (string) -> () = @{
144
    int prefix;
145
 
146
    if (!c_inited_prefix_names) {
147
	nstring_copy_cstring (&(c_prefix_names [CPFX_TYPE]), "type");
148
	nstring_copy_cstring (&(c_prefix_names [CPFX_FN]), "function");
149
	nstring_copy_cstring (&(c_prefix_names [CPFX_IN]), "input");
150
	nstring_copy_cstring (&(c_prefix_names [CPFX_OUT]), "output");
151
	nstring_copy_cstring (&(c_prefix_names [CPFX_LABEL]), "label");
152
	nstring_copy_cstring (&(c_prefix_names [CPFX_TERMINAL]), "terminal");
153
	c_inited_prefix_names = TRUE;
154
    }
155
    for (prefix = 0; prefix < CPFX_NUM_PREFIXES; prefix ++) {
156
	if (nstring_ci_equal (@&string, &(c_prefix_names [prefix]))) {
157
	    break;
158
	}
159
    }
160
    if ((c_current_prefix = (CPrefixT) prefix) == CPFX_NUM_PREFIXES) {
161
	E_c_unknown_prefix (@&string);
162
    }
163
    nstring_destroy (&@=string);
164
@};
165
 
166
<x-set-prefix>: (string) -> () = @{
167
    if (c_current_prefix == CPFX_NUM_PREFIXES) {
168
	nstring_destroy (&@=string);
169
    } else {
170
	NStringP prefix = c_out_info_prefix (c_current_out_info,
171
					     c_current_prefix);
172
 
173
	nstring_destroy (prefix);
174
	nstring_assign (prefix, &@=string);
175
    }
176
@};
177
 
178
// Mapping section actions:
179
 
180
<set-map>: (string) -> () = @{
181
    if ((c_current_entry = table_get_entry (c_current_table, @&string)) ==
182
	NIL (EntryP)) {
183
	E_c_unknown_identifier (@&string);
184
    } else if (entry_get_mapping (c_current_entry)) {
185
	E_c_remapped_identifier (@&string);
186
	c_current_entry = NIL (EntryP);
187
    } else {
188
	switch (entry_type (c_current_entry)) EXHAUSTIVE {
189
	  case ET_NAME:
190
	  case ET_ACTION:
191
	  case ET_NON_LOCAL:
192
	    E_c_illegal_map (@&string);
193
	    c_current_entry = NIL (EntryP);
194
	    break;
195
	  case ET_RENAME:
196
	  case ET_PREDICATE:
197
	    /* UNREACHED */
198
	    break;
199
	  case ET_TYPE:
200
	  case ET_RULE:
201
	  case ET_BASIC:
202
	    break;
203
	}
204
    }
205
    nstring_destroy (&@=string);
206
@};
207
 
208
<x-set-map>: (string) -> () = @{
209
    if (c_current_entry) {
210
	entry_set_mapping (c_current_entry, &@=string);
211
    } else {
212
	nstring_destroy (&@=string);
213
    }
214
@};
215
 
216
// Header actions:
217
 
218
<set-header1>: (code) -> () = @{
219
    c_code_check (@code, FALSE, FALSE, NIL (TypeTupleP), NIL (TypeTupleP),
220
		  c_current_table);
221
    c_out_info_set_header1 (c_current_out_info, @code);
222
@};
223
 
224
<set-header2>: (code) -> () = @{
225
    c_code_check (@code, FALSE, FALSE, NIL (TypeTupleP), NIL (TypeTupleP),
226
		  c_current_table);
227
    c_out_info_set_header2 (c_current_out_info, @code);
228
@};
229
 
230
// Argument list actions:
231
 
232
<save-tuple> = @{
233
    types_assign (&c_saved_type, &c_current_type);
234
@};
235
 
236
<null-type> = @{
237
    types_init (&c_saved_type);
238
    types_init (&c_current_type);
239
@};
240
 
241
<init-tuple> = @{
242
    types_init (&c_current_type);
243
@};
244
 
245
<tuple-type>: (name, type) -> () = @{
246
    if (!types_add_typed_name (&c_current_type, c_current_table, &@=name,
247
			       @&type, FALSE)) {
248
	E_c_unknown_type (@&type);
249
    }
250
    nstring_destroy (&@=type);
251
@};
252
 
253
<tuple-ref-type>: (name, type) -> () = @{
254
    if (!types_add_typed_name (&c_current_type, c_current_table, &@=name,
255
			       @&type, TRUE)) {
256
	E_c_unknown_type (@&type);
257
    }
258
    nstring_destroy (&@=type);
259
@};
260
 
261
<tuple-name>: (string) -> () = @{
262
    types_add_name (&c_current_type, c_current_table, &@=string, FALSE);
263
@};
264
 
265
// Type assignment actions:
266
 
267
<assign>: (string) -> () = @{
268
    if ((c_current_entry = table_get_type (c_current_table, @&string)) ==
269
	NIL (EntryP)) {
270
	E_c_unknown_assign (@&string);
271
    } else if (type_get_assign_code (entry_get_type (c_current_entry))) {
272
	E_c_assign_mult_def (@&string);
273
	c_current_entry = NIL (EntryP);
274
    }
275
    nstring_destroy (&@=string);
276
@};
277
 
278
<x-assign>: (code) -> () = @{
279
    if (c_current_entry) {
280
	BoolT      errored = FALSE;
281
	KeyP       key     = entry_key (c_current_entry);
282
	TypeTupleT tmp;
283
 
284
	types_init (&tmp);
285
	types_add_type_entry (&tmp, c_current_entry, FALSE);
286
	if (!types_disjoint_names (&c_saved_type)) {
287
	    E_c_assign_param_clash (key, &c_saved_type);
288
	    errored = TRUE;
289
	}
290
	if (!types_fillin_types (&c_saved_type, &tmp)) {
291
	    E_c_assign_param_mismatch (key, &tmp, &c_saved_type);
292
	    errored = TRUE;
293
	}
294
	if (!types_disjoint_names (&c_current_type)) {
295
	    E_c_assign_result_clash (key, &c_current_type);
296
	    errored = TRUE;
297
	}
298
	if (!types_fillin_types (&c_current_type, &tmp)) {
299
	    E_c_assign_result_mismatch (key, &tmp, &c_current_type);
300
	    errored = TRUE;
301
	}
302
	if (types_intersect (&c_saved_type, &c_current_type)) {
303
	    E_c_assign_formal_clash (key, &c_saved_type, &c_current_type);
304
	    errored = TRUE;
305
	}
306
	types_destroy (&tmp);
307
	if (errored) {
308
	    types_destroy (&c_saved_type);
309
	    types_destroy (&c_current_type);
310
	    c_code_deallocate (@code);
311
	    c_current_entry = NIL (EntryP);
312
	} else {
313
	    TypeP type = entry_get_type (c_current_entry);
314
 
315
	    c_code_check (@code, FALSE, FALSE, &c_saved_type, &c_current_type,
316
			  c_current_table);
317
	    type_set_assign_code (type, (GenericP) @code);
318
	}
319
    } else {
320
	types_destroy (&c_saved_type);
321
	types_destroy (&c_current_type);
322
	c_code_deallocate (@code);
323
    }
324
@};
325
 
326
<passign>: (string) -> () = @{
327
    if ((c_current_entry = table_get_type (c_current_table, @&string)) ==
328
	NIL (EntryP)) {
329
	E_c_unknown_param_assign (@&string);
330
    } else if (type_get_param_assign_code (entry_get_type (c_current_entry))) {
331
	E_c_param_assign_mult_def (@&string);
332
	c_current_entry = NIL (EntryP);
333
    }
334
    nstring_destroy (&@=string);
335
@};
336
 
337
<x-passign>: (code) -> () = @{
338
    if (c_current_entry) {
339
	BoolT      errored = FALSE;
340
	KeyP       key     = entry_key (c_current_entry);
341
	TypeTupleT tmp;
342
 
343
	types_init (&tmp);
344
	types_add_type_entry (&tmp, c_current_entry, FALSE);
345
	if (!types_disjoint_names (&c_saved_type)) {
346
	    E_c_param_assign_param_clash (key, &c_saved_type);
347
	    errored = TRUE;
348
	}
349
	if (!types_fillin_types (&c_saved_type, &tmp)) {
350
	    E_c_param_assign_param_mismatch (key, &tmp, &c_saved_type);
351
	    errored = TRUE;
352
	}
353
	if (!types_disjoint_names (&c_current_type)) {
354
	    E_c_param_assign_result_clash (key, &c_current_type);
355
	    errored = TRUE;
356
	}
357
	if (!types_fillin_types (&c_current_type, &tmp)) {
358
	    E_c_param_assign_res_mismatch (key, &tmp, &c_current_type);
359
	    errored = TRUE;
360
	}
361
	if (types_intersect (&c_saved_type, &c_current_type)) {
362
	    E_c_param_assign_formal_clash (key, &c_saved_type,
363
					    &c_current_type);
364
	    errored = TRUE;
365
	}
366
	types_destroy (&tmp);
367
	if (errored) {
368
	    types_destroy (&c_saved_type);
369
	    types_destroy (&c_current_type);
370
	    c_code_deallocate (@code);
371
	    c_current_entry = NIL (EntryP);
372
	} else {
373
	    TypeP type = entry_get_type (c_current_entry);
374
 
375
	    c_code_check (@code, FALSE, TRUE, &c_saved_type, &c_current_type,
376
			  c_current_table);
377
	    type_set_param_assign_code (type, (GenericP) @code);
378
	}
379
    } else {
380
	types_destroy (&c_saved_type);
381
	types_destroy (&c_current_type);
382
	c_code_deallocate (@code);
383
    }
384
@};
385
 
386
<rassign>: (string) -> () = @{
387
    if ((c_current_entry = table_get_type (c_current_table, @&string)) ==
388
	NIL (EntryP)) {
389
	E_c_unknown_result_assign (@&string);
390
    } else if (type_get_result_assign_code (entry_get_type (c_current_entry))) {
391
	E_c_result_assign_mult_def (@&string);
392
	c_current_entry = NIL (EntryP);
393
    }
394
    nstring_destroy (&@=string);
395
@};
396
 
397
<x-rassign>: (code) -> () = @{
398
    if (c_current_entry) {
399
	BoolT      errored = FALSE;
400
	KeyP       key     = entry_key (c_current_entry);
401
	TypeTupleT tmp;
402
 
403
	types_init (&tmp);
404
	types_add_type_entry (&tmp, c_current_entry, FALSE);
405
	if (!types_disjoint_names (&c_saved_type)) {
406
	    E_c_result_assign_param_clash (key, &c_saved_type);
407
	    errored = TRUE;
408
	}
409
	if (!types_fillin_types (&c_saved_type, &tmp)) {
410
	    E_c_res_assign_param_mismatch (key, &tmp, &c_saved_type);
411
	    errored = TRUE;
412
	}
413
	if (!types_disjoint_names (&c_current_type)) {
414
	    E_c_result_assign_result_clash (key, &c_current_type);
415
	    errored = TRUE;
416
	}
417
	if (!types_fillin_types (&c_current_type, &tmp)) {
418
	    E_c_res_assign_result_mismatch (key, &tmp, &c_current_type);
419
	    errored = TRUE;
420
	}
421
	if (types_intersect (&c_saved_type, &c_current_type)) {
422
	    E_c_result_assign_formal_clash (key, &c_saved_type,
423
					    &c_current_type);
424
	    errored = TRUE;
425
	}
426
	types_destroy (&tmp);
427
	if (errored) {
428
	    types_destroy (&c_saved_type);
429
	    types_destroy (&c_current_type);
430
	    c_code_deallocate (@code);
431
	    c_current_entry = NIL (EntryP);
432
	} else {
433
	    TypeP type = entry_get_type (c_current_entry);
434
 
435
	    c_code_check (@code, FALSE, FALSE, &c_saved_type, &c_current_type,
436
			  c_current_table);
437
	    type_set_result_assign_code (type, (GenericP) @code);
438
	}
439
    } else {
440
	types_destroy (&c_saved_type);
441
	types_destroy (&c_current_type);
442
	c_code_deallocate (@code);
443
    }
444
@};
445
 
446
// Terminal result extraction actions:
447
 
448
<set-terminal>: (string) -> () = @{
449
    if ((c_current_entry = table_get_basic (c_current_table, @&string)) ==
450
	NIL (EntryP)) {
451
	E_c_unknown_basic (@&string);
452
    } else {
453
	BasicP basic = entry_get_basic (c_current_entry);
454
 
455
	if (basic_get_result_code (basic)) {
456
	    E_c_basic_mult_def (@&string);
457
	    c_current_entry = NIL (EntryP);
458
	} else if (types_equal_zero_tuple (basic_result (basic))) {
459
	    E_c_basic_has_no_result (@&string);
460
	    c_current_entry = NIL (EntryP);
461
	}
462
    }
463
    nstring_destroy (&@=string);
464
@};
465
 
466
<x-set-terminal>: (code) -> () = @{
467
    if (c_current_entry) {
468
	BasicP     basic   = entry_get_basic (c_current_entry);
469
	TypeTupleP result  = basic_result (basic);
470
	BoolT      errored = FALSE;
471
	KeyP       key     = entry_key (c_current_entry);
472
 
473
	if (!types_disjoint_names (&c_saved_type)) {
474
	    E_c_basic_param_clash (key, &c_saved_type);
475
	    errored = TRUE;
476
	}
477
	if (!types_equal_zero_tuple (&c_saved_type)) {
478
	    E_c_basic_param_mismatch (key, &c_saved_type);
479
	    errored = TRUE;
480
	}
481
	if (!types_disjoint_names (&c_current_type)) {
482
	    E_c_basic_result_clash (key, &c_current_type);
483
	    errored = TRUE;
484
	}
485
	if (!types_fillin_types (&c_current_type, result)) {
486
	    E_c_basic_result_mismatch (key, result, &c_current_type);
487
	    errored = TRUE;
488
	}
489
	if (types_intersect (&c_saved_type, &c_current_type)) {
490
	    E_c_basic_formal_clash (key, &c_saved_type, &c_current_type);
491
	    errored = TRUE;
492
	}
493
	if (errored) {
494
	    types_destroy (&c_saved_type);
495
	    types_destroy (&c_current_type);
496
	    c_code_deallocate (@code);
497
	    c_current_entry = NIL (EntryP);
498
	} else {
499
	    types_destroy (&c_saved_type);
500
	    c_code_check (@code, FALSE, FALSE, NIL (TypeTupleP),
501
			  &c_current_type, c_current_table);
502
	    basic_set_result_code (basic, (GenericP) @code);
503
	}
504
    } else {
505
	types_destroy (&c_saved_type);
506
	types_destroy (&c_current_type);
507
	c_code_deallocate (@code);
508
    }
509
@};
510
 
511
// Action definition actions:
512
 
513
<set-action>: (string) -> () = @{
514
    if ((c_current_entry = table_get_action (c_current_table, @&string)) ==
515
	NIL (EntryP)) {
516
	E_c_unknown_action (@&string);
517
    } else {
518
	ActionP action = entry_get_action (c_current_entry);
519
 
520
	if (action_get_code (action)) {
521
	    E_c_action_mult_def (@&string);
522
	    c_current_entry = NIL (EntryP);
523
	}
524
    }
525
    nstring_destroy (&@=string);
526
@};
527
 
528
<x-set-action>: (code) -> () = @{
529
    if (c_current_entry) {
530
	ActionP    action  = entry_get_action (c_current_entry);
531
	TypeTupleP param   = action_param (action);
532
	TypeTupleP result  = action_result (action);
533
	BoolT      errored = FALSE;
534
	KeyP       key     = entry_key (c_current_entry);
535
 
536
	if (!types_disjoint_names (&c_saved_type)) {
537
	    E_c_action_param_clash (key, &c_saved_type);
538
	    errored = TRUE;
539
	}
540
	if (!types_fillin_types (&c_saved_type, param)) {
541
	    E_c_action_param_mismatch (key, param, &c_saved_type);
542
	    errored = TRUE;
543
	}
544
	if (!types_disjoint_names (&c_current_type)) {
545
	    E_c_action_result_clash (key, &c_current_type);
546
	    errored = TRUE;
547
	}
548
	if (!types_fillin_types (&c_current_type, result)) {
549
	    E_c_action_result_mismatch (key, result, &c_current_type);
550
	    errored = TRUE;
551
	}
552
	if (types_intersect (&c_saved_type, &c_current_type)) {
553
	    E_c_action_formal_clash (key, &c_saved_type, &c_current_type);
554
	    errored = TRUE;
555
	}
556
	if (errored) {
557
	    types_destroy (&c_saved_type);
558
	    types_destroy (&c_current_type);
559
	    c_code_deallocate (@code);
560
	    c_current_entry = NIL (EntryP);
561
	} else {
562
	    c_code_check (@code, TRUE, FALSE, &c_saved_type, &c_current_type,
563
			  c_current_table);
564
	    types_propogate_mutations (param, &c_saved_type);
565
	    action_set_code (action, (GenericP) @code);
566
	}
567
    } else {
568
	types_destroy (&c_saved_type);
569
	types_destroy (&c_current_type);
570
	c_code_deallocate (@code);
571
    }
572
@};
573
 
574
<set-trailer1>: (code) -> () = @{
575
    c_code_check (@code, FALSE, FALSE, NIL (TypeTupleP), NIL (TypeTupleP),
576
		  c_current_table);
577
    c_out_info_set_trailer1 (c_current_out_info, @code);
578
@};
579
 
580
<set-trailer2>: (code) -> () = @{
581
    c_code_check (@code, FALSE, FALSE, NIL (TypeTupleP), NIL (TypeTupleP),
582
		  c_current_table);
583
    c_out_info_set_trailer2 (c_current_out_info, @code);
584
@};
585
 
586
// Error recovery stuff:
587
 
588
<unhandled-syntax-error> = @{
589
    UNREACHED;
590
@};
591
 
592
<expected-identifier> = @{
593
    if (!c_propagating_error) {
594
	E_c_expected_identifier ();
595
    }
596
@};
597
 
598
<expected-c-identifier> = @{
599
    if (!c_propagating_error) {
600
	E_c_expected_c_identifier ();
601
    }
602
@};
603
 
604
<expected-separator> = @{
605
    if (!c_propagating_error) {
606
	E_c_expected_separator ();
607
    }
608
@};
609
 
610
<expected-open-tuple> = @{
611
    if (!c_propagating_error) {
612
	E_c_expected_open_tuple ();
613
    }
614
@};
615
 
616
<expected-close-tuple> = @{
617
    if (!c_propagating_error) {
618
	E_c_expected_close_tuple ();
619
    }
620
@};
621
 
622
<expected-arrow> = @{
623
    if (!c_propagating_error) {
624
	E_c_expected_arrow ();
625
    }
626
@};
627
 
628
<expected-terminator> = @{
629
    if (!c_propagating_error) {
630
	E_c_expected_terminator ();
631
    }
632
@};
633
 
634
<expected-end-action> = @{
635
    if (!c_propagating_error) {
636
	E_c_expected_end_action ();
637
    }
638
@};
639
 
640
<expected-define> = @{
641
    if (!c_propagating_error) {
642
	E_c_expected_define ();
643
    }
644
@};
645
 
646
<expected-code> = @{
647
    if (!c_propagating_error) {
648
	E_c_expected_code ();
649
    }
650
@};
651
 
652
<expected-blt-header> = @{
653
    if (!c_propagating_error) {
654
	E_c_expected_blt_header ();
655
    }
656
@};
657
 
658
<expected-blt-terminals> = @{
659
    if (!c_propagating_error) {
660
	E_c_expected_blt_terminals ();
661
    }
662
@};
663
 
664
<expected-blt-actions> = @{
665
    if (!c_propagating_error) {
666
	E_c_expected_blt_actions ();
667
    }
668
@};
669
 
670
<expected-blt-trailer> = @{
671
    if (!c_propagating_error) {
672
	E_c_expected_blt_trailer ();
673
    }
674
@};
675
 
676
<expected-eof> = @{
677
    if (!c_propagating_error) {
678
	E_c_expected_eof ();
679
    }
680
@};
681
 
682
<destroy-string>: (string) -> () = @{
683
    nstring_destroy (&@=string);
684
@};
685
 
686
<skip-to-end-of-tuple-defn> = @{
687
    while ((@. != C_TOK_EOF) &&
688
	   (@. != C_TOK_DEFINE) &&
689
	   (@. != C_TOK_CODE) &&
690
	   (@. != C_TOK_SEPARATOR) &&
691
	   (@. != C_TOK_CLOSE_TUPLE) &&
692
	   (@. != C_TOK_TERMINATOR) &&
693
	   (@. != C_TOK_BLT_PARAM_ASSIGN) &&
694
	   (@. != C_TOK_BLT_RESULT_ASSIGN) &&
695
	   (@. != C_TOK_BLT_TERMINALS) &&
696
	   (@. != C_TOK_BLT_ACTIONS) &&
697
	   (@. != C_TOK_BLT_TRAILER)) {
698
	if ((@. == C_TOK_SID_IDENTIFIER) ||
699
	    (@. == C_TOK_C_IDENTIFIER)) {
700
	    nstring_destroy (c_lexer_string_value (c_current_stream));
701
	}
702
	@>;
703
    }
704
    if ((@. == C_TOK_SID_IDENTIFIER) ||
705
	(@. == C_TOK_C_IDENTIFIER)) {
706
	nstring_destroy (c_lexer_string_value (c_current_stream));
707
    }
708
    if (@. != C_TOK_EOF) {
709
	@>;
710
    }
711
    c_propagating_error = TRUE;
712
@};
713
 
714
<skip-to-end-of-prefix> = @{
715
    while ((@. != C_TOK_EOF) &&
716
	   (@. != C_TOK_TERMINATOR) &&
717
	   (@. != C_TOK_BLT_MAPS) &&
718
	   (@. != C_TOK_BLT_TERMINALS) &&
719
	   (@. != C_TOK_BLT_ASSIGNMENTS) &&
720
	   (@. != C_TOK_BLT_PARAM_ASSIGN) &&
721
	   (@. != C_TOK_BLT_RESULT_ASSIGN) &&
722
	   (@. != C_TOK_BLT_ACTIONS) &&
723
	   (@. != C_TOK_BLT_TRAILER)) {
724
	if ((@. == C_TOK_SID_IDENTIFIER) ||
725
	    (@. == C_TOK_C_IDENTIFIER)) {
726
	    nstring_destroy (c_lexer_string_value (c_current_stream));
727
	} else if (@. == C_TOK_CODE) {
728
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
729
	}
730
	@>;
731
    }
732
    if ((@. == C_TOK_SID_IDENTIFIER) ||
733
	(@. == C_TOK_C_IDENTIFIER)) {
734
	nstring_destroy (c_lexer_string_value (c_current_stream));
735
    }
736
    if (@. != C_TOK_EOF) {
737
	@>;
738
    }
739
    c_propagating_error = TRUE;
740
@};
741
 
742
<skip-to-end-of-map> = @{
743
    while ((@. != C_TOK_EOF) &&
744
	   (@. != C_TOK_TERMINATOR) &&
745
	   (@. != C_TOK_BLT_ASSIGNMENTS) &&
746
	   (@. != C_TOK_BLT_PARAM_ASSIGN) &&
747
	   (@. != C_TOK_BLT_RESULT_ASSIGN) &&
748
	   (@. != C_TOK_BLT_TERMINALS) &&
749
	   (@. != C_TOK_BLT_ACTIONS) &&
750
	   (@. != C_TOK_BLT_TRAILER)) {
751
	if ((@. == C_TOK_SID_IDENTIFIER) ||
752
	    (@. == C_TOK_C_IDENTIFIER)) {
753
	    nstring_destroy (c_lexer_string_value (c_current_stream));
754
	} else if (@. == C_TOK_CODE) {
755
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
756
	}
757
	@>;
758
    }
759
    if ((@. == C_TOK_SID_IDENTIFIER) ||
760
	(@. == C_TOK_C_IDENTIFIER)) {
761
	nstring_destroy (c_lexer_string_value (c_current_stream));
762
    }
763
    if (@. != C_TOK_EOF) {
764
	@>;
765
    }
766
    c_propagating_error = TRUE;
767
@};
768
 
769
<skip-to-end-of-assignment> = @{
770
    while ((@. != C_TOK_EOF) &&
771
	   (@. != C_TOK_TERMINATOR) &&
772
	   (@. != C_TOK_BLT_PARAM_ASSIGN) &&
773
	   (@. != C_TOK_BLT_RESULT_ASSIGN) &&
774
	   (@. != C_TOK_BLT_TERMINALS) &&
775
	   (@. != C_TOK_BLT_ACTIONS) &&
776
	   (@. != C_TOK_BLT_TRAILER)) {
777
	if ((@. == C_TOK_SID_IDENTIFIER) ||
778
	    (@. == C_TOK_C_IDENTIFIER)) {
779
	    nstring_destroy (c_lexer_string_value (c_current_stream));
780
	} else if (@. == C_TOK_CODE) {
781
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
782
	}
783
	@>;
784
    }
785
    if ((@. == C_TOK_SID_IDENTIFIER) ||
786
	(@. == C_TOK_C_IDENTIFIER)) {
787
	nstring_destroy (c_lexer_string_value (c_current_stream));
788
    }
789
    if (@. != C_TOK_EOF) {
790
	@>;
791
    }
792
    c_propagating_error = TRUE;
793
@};
794
 
795
<skip-to-end-of-param-assign> = @{
796
    while ((@. != C_TOK_EOF) &&
797
	   (@. != C_TOK_TERMINATOR) &&
798
	   (@. != C_TOK_BLT_RESULT_ASSIGN) &&
799
	   (@. != C_TOK_BLT_TERMINALS) &&
800
	   (@. != C_TOK_BLT_ACTIONS) &&
801
	   (@. != C_TOK_BLT_TRAILER)) {
802
	if ((@. == C_TOK_SID_IDENTIFIER) ||
803
	    (@. == C_TOK_C_IDENTIFIER)) {
804
	    nstring_destroy (c_lexer_string_value (c_current_stream));
805
	} else if (@. == C_TOK_CODE) {
806
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
807
	}
808
	@>;
809
    }
810
    if ((@. == C_TOK_SID_IDENTIFIER) ||
811
	(@. == C_TOK_C_IDENTIFIER)) {
812
	nstring_destroy (c_lexer_string_value (c_current_stream));
813
    }
814
    if (@. != C_TOK_EOF) {
815
	@>;
816
    }
817
    c_propagating_error = TRUE;
818
@};
819
 
820
<skip-to-end-of-result-assign> = @{
821
    while ((@. != C_TOK_EOF) &&
822
	   (@. != C_TOK_TERMINATOR) &&
823
	   (@. != C_TOK_BLT_TERMINALS) &&
824
	   (@. != C_TOK_BLT_ACTIONS) &&
825
	   (@. != C_TOK_BLT_TRAILER)) {
826
	if ((@. == C_TOK_SID_IDENTIFIER) ||
827
	    (@. == C_TOK_C_IDENTIFIER)) {
828
	    nstring_destroy (c_lexer_string_value (c_current_stream));
829
	} else if (@. == C_TOK_CODE) {
830
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
831
	}
832
	@>;
833
    }
834
    if ((@. == C_TOK_SID_IDENTIFIER) ||
835
	(@. == C_TOK_C_IDENTIFIER)) {
836
	nstring_destroy (c_lexer_string_value (c_current_stream));
837
    }
838
    if (@. != C_TOK_EOF) {
839
	@>;
840
    }
841
    c_propagating_error = TRUE;
842
@};
843
 
844
<skip-to-end-of-terminal> = @{
845
    while ((@. != C_TOK_EOF) &&
846
	   (@. != C_TOK_TERMINATOR) &&
847
	   (@. != C_TOK_BLT_ACTIONS) &&
848
	   (@. != C_TOK_BLT_TRAILER)) {
849
	if ((@. == C_TOK_SID_IDENTIFIER) ||
850
	    (@. == C_TOK_C_IDENTIFIER)) {
851
	    nstring_destroy (c_lexer_string_value (c_current_stream));
852
	} else if (@. == C_TOK_CODE) {
853
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
854
	}
855
	@>;
856
    }
857
    if ((@. == C_TOK_SID_IDENTIFIER) ||
858
	(@. == C_TOK_C_IDENTIFIER)) {
859
	nstring_destroy (c_lexer_string_value (c_current_stream));
860
    }
861
    if (@. != C_TOK_EOF) {
862
	@>;
863
    }
864
    c_propagating_error = TRUE;
865
@};
866
 
867
<skip-to-end-of-action> = @{
868
    while ((@. != C_TOK_EOF) &&
869
	   (@. != C_TOK_TERMINATOR) &&
870
	   (@. != C_TOK_BLT_TRAILER)) {
871
	if ((@. == C_TOK_SID_IDENTIFIER) ||
872
	    (@. == C_TOK_C_IDENTIFIER)) {
873
	    nstring_destroy (c_lexer_string_value (c_current_stream));
874
	} else if (@. == C_TOK_CODE) {
875
	    c_code_deallocate (c_lexer_code_value (c_current_stream));
876
	}
877
	@>;
878
    }
879
    if ((@. == C_TOK_SID_IDENTIFIER) ||
880
	(@. == C_TOK_C_IDENTIFIER)) {
881
	nstring_destroy (c_lexer_string_value (c_current_stream));
882
    }
883
    if (@. != C_TOK_EOF) {
884
	@>;
885
    }
886
    c_propagating_error = TRUE;
887
@};
888
 
889
<skip-recover> = @{
890
    c_propagating_error = FALSE;
891
@};
892
 
893
<is-close-tuple-or-skipped-or-eof>: () -> (predicate) = @{
894
    @predicate = ((@. == C_TOK_CLOSE_TUPLE) ||
895
		  (@. == C_TOK_EOF) ||
896
		  (c_propagating_error));
897
@};
898
 
899
%trailer% @{
900
@}, @{
901
@};