Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
%prefixes%
2
 
3
 
4
/*
5
    TERMINAL PREFIX
6
 
7
    This prefix is used to identify lexical token numbers in syntax.h
8
    (see also symbols.h).
9
*/
10
 
11
terminal = lex_ ;
12
 
13
 
14
%maps%
15
 
16
 
17
/*
18
    PARSER ENTRY POINTS
19
 
20
    There are a number of entry points into the parser.  The main ones
21
    are translation-unit which is used to parse an entire translation
22
    unit and hash-if-expression which is used to parse expressions in
23
    #if preprocessing directives.
24
*/
25
 
26
translation-unit -> parse_file ;
27
expression-entry -> parse_exp ;
28
id-entry -> parse_id ;
29
operator-id -> parse_operator ;
30
declaration-entry -> parse_decl ;
31
function-definition-entry -> parse_func ;
32
type-id-entry -> parse_type ;
33
token-type-id -> parse_tok_type ;
34
member-type-id -> parse_mem_type ;
35
parameter-entry -> parse_param ;
36
statement-entry -> parse_stmt ;
37
initialiser-entry -> parse_init ;
38
hash-if-expression -> parse_nat ;
39
template-type-param -> parse_type_param ;
40
constant-offset -> parse_offset ;
41
 
42
 
43
/*
44
    BASIC TYPES
45
 
46
    The type BOOL is used to hold the predicate values, true and false.
47
    The type COUNT is used to hold the various counters maintained (see
48
    predict.c).  The type LEX is used to hold a lexical token number
49
    (i.e.  one of the values defined in syntax.h).  The other types used
50
    in the parser map in a simple fashion to the main program types.
51
    Note that it is necessary to use aliases for compound types because
52
    of the restrictions imposed by sid.
53
*/
54
 
55
BOOL -> int ;
56
BTYPE -> BASE_TYPE ;
57
CONDITION -> unsigned ;
58
COUNT -> int ;
59
CV -> CV_SPEC ;
60
DECL -> IDENTIFIER ;
61
DSPEC -> DECL_SPEC ;
62
EXP -> EXP ;
63
IDENTIFIER -> IDENTIFIER ;
64
KEY -> BASE_TYPE ;
65
LEX -> int ;
66
LIST-EXP -> SID_LIST_EXP ;
67
NAMESPACE -> NAMESPACE ;
68
NUMBER -> int ;
69
OFFSET -> OFFSET ;
70
TYPE -> TYPE ;
71
 
72
 
73
/*
74
    FILE HEADERS
75
 
76
    These headers are prepended to the parser definition and declaration
77
    output files.  Because of the simple file splitting algorithm applied
78
    to the output this should contain only declarations and not definitions.
79
*/
80
 
81
%header% @{
82
/*
83
    		 Crown Copyright (c) 1997, 1998
84
 
85
    This TenDRA(r) Computer Program is subject to Copyright
86
    owned by the United Kingdom Secretary of State for Defence
87
    acting through the Defence Evaluation and Research Agency
88
    (DERA).  It is made available to Recipients with a
89
    royalty-free licence for its use, reproduction, transfer
90
    to other parties and amendment for any purpose not excluding
91
    product development provided that any such use et cetera
92
    shall be deemed to be acceptance of the following conditions:-
93
 
94
        (1) Its Recipients shall ensure that this Notice is
95
        reproduced upon any copies or amended versions of it;
96
 
97
        (2) Any amended version of it shall be clearly marked to
98
        show both the nature of and the organisation responsible
99
        for the relevant amendment or amendments;
100
 
101
        (3) Its onward transfer from a recipient to another
102
        party shall be deemed to be that party's acceptance of
103
        these conditions;
104
 
105
        (4) DERA gives no warranty or assurance as to its
106
        quality or suitability for any purpose and DERA accepts
107
        no liability whatsoever in relation to any use to which
108
        it may be put.
109
*/
110
 
111
 
112
#include "config.h"
113
#include "c_types.h"
114
#include "exp_ops.h"
115
#include "hashid_ops.h"
116
#include "id_ops.h"
117
#include "type_ops.h"
118
#include "error.h"
119
#include "catalog.h"
120
#include "option.h"
121
#include "access.h"
122
#include "allocate.h"
123
#include "assign.h"
124
#include "basetype.h"
125
#include "cast.h"
126
#include "chktype.h"
127
#include "class.h"
128
#include "constant.h"
129
#include "construct.h"
130
#include "convert.h"
131
#include "declare.h"
132
#include "derive.h"
133
#include "dump.h"
134
#include "exception.h"
135
#include "expression.h"
136
#include "function.h"
137
#include "hash.h"
138
#include "identifier.h"
139
#include "initialise.h"
140
#include "inttype.h"
141
#include "label.h"
142
#include "lex.h"
143
#include "literal.h"
144
#include "member.h"
145
#include "namespace.h"
146
#include "parse.h"
147
#include "pragma.h"
148
#include "predict.h"
149
#include "preproc.h"
150
#include "redeclare.h"
151
#include "rewrite.h"
152
#include "statement.h"
153
#include "symbols.h"
154
#include "template.h"
155
#include "tokdef.h"
156
#include "token.h"
157
#include "typeid.h"
158
#include "variable.h"
159
 
160
 
161
/*
162
    COMPOUND TYPE ALIASES
163
 
164
    These are the aliases for the compound types used in the parser.
165
*/
166
 
167
typedef LIST ( EXP ) SID_LIST_EXP ;
168
 
169
 
170
/*
171
    FUNCTION DECLARATIONS
172
 
173
    The function declarations are included at this point so that the
174
    type definitions are in scope.
175
*/
176
 
177
#include "syntax.h"
178
 
179
 
180
/*
181
    COMPILATION MODE
182
 
183
    The output of sid is automatically generated.  Hence it is not
184
    necessarily appropriate to apply the same level of checking to this
185
    as to the rest of the program.  These pragmas describe the relaxations
186
    allowed for the sid output.
187
*/
188
 
189
#if FS_TENDRA
190
#pragma TenDRA begin
191
#pragma TenDRA const conditional allow
192
#pragma TenDRA unreachable code allow
193
#pragma TenDRA variable analysis off
194
#endif
195
 
196
 
197
@}, @{
198
/*
199
    		 Crown Copyright (c) 1997, 1998
200
 
201
    This TenDRA(r) Computer Program is subject to Copyright
202
    owned by the United Kingdom Secretary of State for Defence
203
    acting through the Defence Evaluation and Research Agency
204
    (DERA).  It is made available to Recipients with a
205
    royalty-free licence for its use, reproduction, transfer
206
    to other parties and amendment for any purpose not excluding
207
    product development provided that any such use et cetera
208
    shall be deemed to be acceptance of the following conditions:-
209
 
210
        (1) Its Recipients shall ensure that this Notice is
211
        reproduced upon any copies or amended versions of it;
212
 
213
        (2) Any amended version of it shall be clearly marked to
214
        show both the nature of and the organisation responsible
215
        for the relevant amendment or amendments;
216
 
217
        (3) Its onward transfer from a recipient to another
218
        party shall be deemed to be that party's acceptance of
219
        these conditions;
220
 
221
        (4) DERA gives no warranty or assurance as to its
222
        quality or suitability for any purpose and DERA accepts
223
        no liability whatsoever in relation to any use to which
224
        it may be put.
225
*/
226
 
227
 
228
#ifndef SYNTAX_INCLUDED
229
#define SYNTAX_INCLUDED
230
 
231
@} ;
232
 
233
 
234
%terminals%
235
 
236
 
237
/*
238
    IDENTIFIER TERMINALS
239
 
240
    Identifiers and related terminals (type names, namespace names and
241
    destructor names) are identified by means of an identifier stored in
242
    crt_token by expand_token.
243
*/
244
 
245
identifier : () -> ( id ) = @{
246
    @id = crt_token->pp_data.id.use ;
247
@} ;
248
 
249
type-name : () -> ( id ) = @{
250
    @id = crt_token->pp_data.id.use ;
251
@} ;
252
 
253
namespace-name : () -> ( id ) = @{
254
    @id = crt_token->pp_data.id.use ;
255
@} ;
256
 
257
statement-name : () -> ( id ) = @{
258
    @id = crt_token->pp_data.id.use ;
259
@} ;
260
 
261
destructor-name : () -> ( id ) = @{
262
    @id = crt_token->pp_data.id.use ;
263
@} ;
264
 
265
template-id : () -> ( id ) = @{
266
    IDENTIFIER id = crt_token->pp_data.tok.id ;
267
    PPTOKEN *args = crt_token->pp_data.tok.args ;
268
    @id = parse_id_template ( id, args, 0 ) ;
269
    RESCAN_LEXER ;
270
@} ;
271
 
272
template-type : () -> ( id ) = @{
273
    IDENTIFIER id = crt_token->pp_data.tok.id ;
274
    PPTOKEN *args = crt_token->pp_data.tok.args ;
275
    @id = parse_type_template ( id, args, 0 ) ;
276
    RESCAN_LEXER ;
277
@} ;
278
 
279
 
280
/*
281
    NAMESPACE SPECIFIER TERMINALS
282
 
283
    Namespace specifiers (i.e. sequences of namespace or class names
284
    separated using '::') are identified by expand_token.  The full nested
285
    names are those which begin with the global namespace.
286
*/
287
 
288
nested-name : () -> ( ns ) = @{
289
    @ns = crt_token->pp_data.ns ;
290
@} ;
291
 
292
full-name : () -> ( ns ) = @{
293
    @ns = crt_token->pp_data.ns ;
294
@} ;
295
 
296
 
297
/*
298
    POINTER TO MEMBER TERMINALS
299
 
300
    Pointer to member specifiers (such as 'C::*') are identified by
301
    expand_token.  The identifier corresponding to the given class is
302
    stored in crt_token.
303
*/
304
 
305
nested-name-star : () -> ( id ) = @{
306
    @id = crt_token->pp_data.id.use ;
307
@} ;
308
 
309
full-name-star : () -> ( id ) = @{
310
    @id = crt_token->pp_data.id.use ;
311
@} ;
312
 
313
 
314
/*
315
    INTEGER AND FLOATING-POINT LITERAL TERMINALS
316
 
317
    Integer and floating-point literal tokens have already been transformed
318
    into their corresponding expressions by expand_token, which stores this
319
    information in crt_token.
320
*/
321
 
322
integer-exp : () -> ( e ) = @{
323
    @e = crt_token->pp_data.exp ;
324
@} ;
325
 
326
floating-exp : () -> ( e ) = @{
327
    @e = crt_token->pp_data.exp ;
328
@} ;
329
 
330
 
331
/*
332
    STRING AND CHARACTER LITERAL TERMINALS
333
 
334
    String and character literal tokens have already been transformed
335
    into their corresponding expressions by expand_token, which stores this
336
    information in crt_token.
337
*/
338
 
339
char-exp : () -> ( e ) = @{
340
    @e = crt_token->pp_data.exp ;
341
@} ;
342
 
343
wchar-exp : () -> ( e ) = @{
344
    @e = crt_token->pp_data.exp ;
345
@} ;
346
 
347
string-exp : () -> ( e ) = @{
348
    @e = crt_token->pp_data.exp ;
349
@} ;
350
 
351
wstring-exp : () -> ( e ) = @{
352
    @e = crt_token->pp_data.exp ;
353
@} ;
354
 
355
 
356
/*
357
    CONDITIONAL COMPILATION TERMINALS
358
 
359
    Any target dependent conditional compilation expressions are stored
360
    in crt_token by the preprocessing routines.
361
*/
362
 
363
hash-if : () -> ( e ) = @{
364
    @e = crt_token->pp_data.exp ;
365
@} ;
366
 
367
hash-elif : () -> ( e ) = @{
368
    @e = crt_token->pp_data.exp ;
369
@} ;
370
 
371
 
372
/*
373
    COMPLEX EXPRESSION AND TYPE TERMINALS
374
 
375
    These terminals are used to handle complex expressions and types
376
    such as token applications.
377
*/
378
 
379
complex-exp : () -> ( e ) = @{
380
    IDENTIFIER id = crt_token->pp_data.tok.id ;
381
    PPTOKEN *args = crt_token->pp_data.tok.args ;
382
    @e = parse_exp_token ( id, args ) ;
383
    RESCAN_LEXER ;
384
@} ;
385
 
386
complex-stmt : () -> ( e ) = @{
387
    IDENTIFIER id = crt_token->pp_data.tok.id ;
388
    PPTOKEN *args = crt_token->pp_data.tok.args ;
389
    @e = parse_exp_token ( id, args ) ;
390
    RESCAN_LEXER ;
391
@} ;
392
 
393
complex-type : () -> ( t ) = @{
394
    IDENTIFIER id = crt_token->pp_data.tok.id ;
395
    PPTOKEN *args = crt_token->pp_data.tok.args ;
396
    @t = parse_type_token ( id, args ) ;
397
    have_type_declaration = TYPE_DECL_NONE ;
398
    have_type_specifier = 1 ;
399
    RESCAN_LEXER ;
400
@} ;
401
 
402
 
403
%actions%
404
 
405
 
406
/*
407
    LEXICAL TOKENS
408
 
409
    These actions give the basic values for the type LEX.  They are used
410
    primarily in overloaded operator function names, but they are also used
411
    to distinguish closely related groups of expressions, such as relational
412
    expressions.  Note that the primary form of the token has been given
413
    whenever there is a choice, otherwise the actions are very dull.
414
*/
415
 
416
<lex_crt> : () -> ( t ) = @{ @t = crt_lex_token ; @} ;
417
<lex_open_round> : () -> ( t ) = @{ @t = lex_open_Hround ; @} ;
418
<lex_semicolon> : () -> ( t ) = @{ @t = lex_semicolon ; @} ;
419
<lex_alignof> : () -> ( t ) = @{ @t = lex_alignof ; @} ;
420
<lex_sizeof> : () -> ( t ) = @{ @t = lex_sizeof ; @} ;
421
 
422
 
423
/*
424
    SPECIAL FUNCTION IDENTIFIERS
425
 
426
    These actions are used to construct the identifiers corresponding to
427
    the operator-function-ids and conversion-function-ids.  In addition,
428
    id_none gives the null identifier and id_anon generates a unique
429
    anonymous identifier.
430
*/
431
 
432
<id_none> : () -> ( id ) = @{
433
    @id = NULL_id ;
434
@} ;
435
 
436
<id_anon> : () -> ( id ) = @{
437
    HASHID nm = lookup_anon () ;
438
    @id = DEREF_id ( hashid_id ( nm ) ) ;
439
@} ;
440
 
441
 
442
/*
443
    NAMESPACES AND IDENTIFIER LOOK-UP
444
 
445
    These actions are used to identify namespaces and identifiers within
446
    those namespaces.
447
*/
448
 
449
<rescan_member> : ( ns, id ) -> ( n ) = @{
450
    HASHID nm = DEREF_hashid ( id_name ( @id ) ) ;
451
    @n = find_qual_id ( @ns, nm, 1, 0 ) ;
452
@} ;
453
 
454
 
455
/*
456
    LISTS OF EXPRESSIONS
457
 
458
    These actions give the basic constructs for building up lists of
459
    expressions.  They map directly to the calculus list operations.
460
*/
461
 
462
<list_exp_null> : () -> ( p ) = @{
463
    @p = NULL_list ( EXP ) ;
464
@} ;
465
 
466
<list_exp_cons> : ( e, q ) -> ( p ) = @{
467
    CONS_exp ( @e, @q, @p ) ;
468
@} ;
469
 
470
 
471
/*
472
    EXPRESSION CONSTRUCTORS
473
 
474
    These actions describe how to build up expressions from more primitive
475
    expressions.  The null expression, exp_none, is used to indicate that
476
    an optional expression is absent.  Most of the actions are very
477
    straightforward, either directly calling a calculus EXP constructor
478
    or the appropriate expression construction function.
479
*/
480
 
481
<exp_none> : () -> ( e ) = @{
482
    @e = NULL_exp ;
483
@} ;
484
 
485
<exp_aggregate> : ( p ) -> ( e ) = @{
486
    /* The expression type is a dummy */
487
    MAKE_exp_aggregate ( type_void, @p, NULL_list ( OFFSET ), @e ) ;
488
@} ;
489
 
490
<exp_and> : ( a, b ) -> ( e ) = @{
491
    @e = make_and_exp ( @a, @b ) ;
492
@} ;
493
 
494
<exp_arrow_begin> : ( a ) -> ( e, t, ns ) = @{
495
    @e = begin_field_exp ( lex_arrow, @a, &@t, &@ns ) ;
496
@} ;
497
 
498
<exp_arrow_end> : ( a, t, ns, id ) -> ( e ) = @{
499
    @e = end_field_exp ( lex_arrow, @a, @t, @ns, @id, 0 ) ;
500
@} ;
501
 
502
<exp_assign> : ( a, b ) -> ( e ) = @{
503
    @e = make_assign_exp ( @a, @b, 1 ) ;
504
@} ;
505
 
506
<exp_assign_op> : ( op, a, b ) -> ( e ) = @{
507
    /* op will be in its primary form */
508
    @e = make_become_exp ( @op, @a, @b ) ;
509
@} ;
510
 
511
<exp_cast> : ( t, a, n ) -> ( e ) = @{
512
    /* n is the number of type definitions in t */
513
    @e = make_cast_exp ( @t, @a, @n ) ;
514
@} ;
515
 
516
<exp_comma> : ( p ) -> ( e ) = @{
517
    @e = make_comma_exp ( @p ) ;
518
@} ;
519
 
520
<exp_cond> : ( a, b, c ) -> ( e ) = @{
521
    @e = make_cond_exp ( @a, @b, @c ) ;
522
@} ;
523
 
524
<exp_div> : ( a, b ) -> ( e ) = @{
525
    @e = make_mult_exp ( lex_div, @a, @b ) ;
526
@} ;
527
 
528
<exp_dot_begin> : ( a ) -> ( e, t, ns ) = @{
529
    @e = begin_field_exp ( lex_dot, @a, &@t, &@ns ) ;
530
@} ;
531
 
532
<exp_dot_end> : ( a, t, ns, id ) -> ( e ) = @{
533
    @e = end_field_exp ( lex_dot, @a, @t, @ns, @id, 0 ) ;
534
@} ;
535
 
536
<exp_ellipsis> : () -> ( e ) = @{
537
    @e = make_ellipsis_exp () ;
538
@} ;
539
 
540
<exp_equality> : ( op, a, b ) -> ( e ) = @{
541
    /* op will be in its primary form */
542
    @e = make_equality_exp ( @op, @a, @b ) ;
543
@} ;
544
 
545
<exp_eval> : ( a ) -> ( e ) = @{
546
    @e = convert_reference ( @a, REF_NORMAL ) ;
547
    @e = convert_lvalue ( @e ) ;
548
@} ;
549
 
550
<exp_func> : ( a, p ) -> ( e ) = @{
551
    @e = make_func_exp ( @a, @p, 0 ) ;
552
@} ;
553
 
554
<exp_identifier> : ( id ) -> ( e ) = @{
555
    @e = make_id_exp ( @id ) ;
556
@} ;
557
 
558
<exp_ignore> : ( a ) -> ( e ) = @{
559
    @e = make_cast_exp ( type_void, @a, 0 ) ;
560
@} ;
561
 
562
<exp_index> : ( a, b ) -> ( e ) = @{
563
    @e = make_index_exp ( @a, @b ) ;
564
@} ;
565
 
566
<exp_indir> : ( a ) -> ( e ) = @{
567
    @e = make_indir_exp ( @a ) ;
568
@} ;
569
 
570
<exp_location> : ( a ) -> ( e ) = @{
571
    MAKE_exp_location ( type_void, crt_loc, @a, @e ) ;
572
@} ;
573
 
574
<exp_log_and> : ( a, b ) -> ( e ) = @{
575
    @e = make_log_and_exp ( @a, @b ) ;
576
@} ;
577
 
578
<exp_log_or> : ( a, b ) -> ( e ) = @{
579
    @e = make_log_or_exp ( @a, @b ) ;
580
@} ;
581
 
582
<exp_lshift> : ( a, b ) -> ( e ) = @{
583
    @e = make_shift_exp ( lex_lshift, @a, @b ) ;
584
@} ;
585
 
586
<exp_maxmin> : ( op, a, b ) -> ( e ) = @{
587
    @e = make_mult_exp ( @op, @a, @b ) ;
588
@} ;
589
 
590
<exp_minus> : ( a, b ) -> ( e ) = @{
591
    @e = make_minus_exp ( @a, @b ) ;
592
@} ;
593
 
594
<exp_mult> : ( a, b ) -> ( e ) = @{
595
    @e = make_mult_exp ( lex_star, @a, @b ) ;
596
@} ;
597
 
598
<exp_not> : ( a ) -> ( e ) = @{
599
    @e = make_not_exp ( @a ) ;
600
@} ;
601
 
602
<exp_or> : ( a, b ) -> ( e ) = @{
603
    @e = make_or_exp ( @a, @b ) ;
604
@} ;
605
 
606
<exp_paren_begin> : () -> () = @{
607
    IGNORE incr_value ( OPT_VAL_paren_depth ) ;
608
@} ;
609
 
610
<exp_paren_end> : ( a ) -> ( e ) = @{
611
    @e = make_paren_exp ( @a ) ;
612
    decr_value ( OPT_VAL_paren_depth ) ;
613
@} ;
614
 
615
<exp_plus> : ( a, b ) -> ( e ) = @{
616
    @e = make_plus_exp ( @a, @b ) ;
617
@} ;
618
 
619
<exp_postdec> : ( a ) -> ( e ) = @{
620
    @e = make_postfix_exp ( lex_minus_Hminus, @a ) ;
621
@} ;
622
 
623
<exp_postinc> : ( a ) -> ( e ) = @{
624
    @e = make_postfix_exp ( lex_plus_Hplus, @a ) ;
625
@} ;
626
 
627
<exp_predec> : ( a ) -> ( e ) = @{
628
    @e = make_prefix_exp ( lex_minus_Hminus, @a ) ;
629
@} ;
630
 
631
<exp_preinc> : ( a ) -> ( e ) = @{
632
    @e = make_prefix_exp ( lex_plus_Hplus, @a ) ;
633
@} ;
634
 
635
<exp_ref> : ( a ) -> ( e ) = @{
636
    @e = make_ref_exp ( @a, 0 ) ;
637
@} ;
638
 
639
<exp_relation> : ( op, a, b ) -> ( e ) = @{
640
    /* op will be in its primary form */
641
    @e = make_relation_exp ( @op, @a, @b ) ;
642
@} ;
643
 
644
<exp_rem> : ( a, b ) -> ( e ) = @{
645
    @e = make_rem_exp ( @a, @b ) ;
646
@} ;
647
 
648
<exp_rshift> : ( a, b ) -> ( e ) = @{
649
    @e = make_shift_exp ( lex_rshift, @a, @b ) ;
650
@} ;
651
 
652
<exp_set> : ( a ) -> ( e ) = @{
653
    @e = make_set_exp ( @a ) ;
654
@} ;
655
 
656
<exp_sizeof> : ( op, t, a, n ) -> ( e ) = @{
657
    @e = make_sizeof_exp ( @t, @a, @n, @op ) ;
658
@} ;
659
 
660
<exp_unary> : ( op, a ) -> ( e ) = @{
661
    @e = make_uminus_exp ( @op, @a ) ;
662
@} ;
663
 
664
<exp_unused> : ( a ) -> ( e ) = @{
665
    @e = make_unused_exp ( @a ) ;
666
@} ;
667
 
668
<exp_xor> : ( a, b ) -> ( e ) = @{
669
    @e = make_xor_exp ( @a, @b ) ;
670
@} ;
671
 
672
 
673
/*
674
    STATEMENT CONSTRUCTORS
675
 
676
    These actions describe how to build up statements from expressions,
677
    declarations, and more primitive statements.  The empty statement is
678
    represented by the null expression, stmt_none.  The other statement
679
    constructors map directly onto constructor functions.
680
*/
681
 
682
<stmt_none> : () -> ( e ) = @{
683
    @e = NULL_exp ;
684
@} ;
685
 
686
<stmt_break> : () -> ( e ) = @{
687
    @e = make_break_stmt () ;
688
@} ;
689
 
690
<stmt_case_begin> : ( a ) -> ( e ) = @{
691
    @e = begin_case_stmt ( @a, 0 ) ;
692
@} ;
693
 
694
<stmt_case_end> : ( a, b ) -> ( e ) = @{
695
    @e = end_case_stmt ( @a, @b ) ;
696
@} ;
697
 
698
<stmt_compound_begin> : () -> ( e ) = @{
699
    @e = begin_compound_stmt ( 1 ) ;
700
@} ;
701
 
702
<stmt_compound_mark> : ( a ) -> () = @{
703
    mark_compound_stmt ( @a ) ;
704
@} ;
705
 
706
<stmt_compound_block> : ( a ) -> ( b ) = @{
707
    COPY_int ( exp_sequence_block ( @a ), 2 ) ;
708
    @b = 1 ;
709
@} ;
710
 
711
<stmt_compound_add> : ( a, b ) -> ( e ) = @{
712
    @e = add_compound_stmt ( @a, @b ) ;
713
@} ;
714
 
715
<stmt_compound_end> : ( a ) -> ( e ) = @{
716
    @e = end_compound_stmt ( @a ) ;
717
@} ;
718
 
719
<stmt_continue> : () -> ( e ) = @{
720
    @e = make_continue_stmt () ;
721
@} ;
722
 
723
<stmt_decl> : () -> ( e ) = @{
724
    in_declaration-- ;
725
    @e = NULL_exp ;
726
@} ;
727
 
728
<stmt_default_begin> : () -> ( e ) = @{
729
    @e = begin_default_stmt ( 0 ) ;
730
@} ;
731
 
732
<stmt_default_end> : ( a, b ) -> ( e ) = @{
733
    @e = end_default_stmt ( @a, @b ) ;
734
@} ;
735
 
736
<stmt_do_begin> : () -> ( e ) = @{
737
    @e = begin_do_stmt () ;
738
@} ;
739
 
740
<stmt_do_end> : ( a, b, c ) -> ( e ) = @{
741
    @e = end_do_stmt ( @a, @b, @c ) ;
742
@} ;
743
 
744
<stmt_exp> : ( a ) -> ( e ) = @{
745
    @e = make_exp_stmt ( @a ) ;
746
@} ;
747
 
748
<stmt_for_begin> : () -> ( e ) = @{
749
    @e = begin_for_stmt () ;
750
@} ;
751
 
752
<stmt_for_init> : ( a, b ) -> ( e ) = @{
753
    @e = init_for_stmt ( @a, &@b ) ;
754
@} ;
755
 
756
<stmt_for_cond> : ( a, b, c ) -> ( e ) = @{
757
    @e = cond_for_stmt ( @a, @b, @c ) ;
758
@} ;
759
 
760
<stmt_for_end> : ( a, b ) -> ( e ) = @{
761
    @e = end_for_stmt ( @a, @b ) ;
762
@} ;
763
 
764
<stmt_goto> : ( id ) -> ( e ) = @{
765
    @e = make_goto_stmt ( @id ) ;
766
@} ;
767
 
768
<stmt_goto_case> : ( a ) -> ( e ) = @{
769
    report ( crt_loc, ERR_stmt_goto_case ( lex_case ) ) ;
770
    @e = begin_case_stmt ( @a, 1 ) ;
771
@} ;
772
 
773
<stmt_goto_default> : () -> ( e ) = @{
774
    report ( crt_loc, ERR_stmt_goto_case ( lex_default ) ) ;
775
    @e = begin_default_stmt ( 1 ) ;
776
@} ;
777
 
778
<stmt_if_begin> : ( a ) -> ( e ) = @{
779
    @e = begin_if_stmt ( @a ) ;
780
@} ;
781
 
782
<stmt_if_cont> : ( a, b ) -> ( e ) = @{
783
    @e = cont_if_stmt ( @a, @b ) ;
784
@} ;
785
 
786
<stmt_if_end> : ( a, b ) -> ( e ) = @{
787
    @e = end_if_stmt ( @a, @b ) ;
788
@} ;
789
 
790
<stmt_else> : () -> () = @{
791
    check_empty_stmt ( lex_else ) ;
792
@} ;
793
 
794
<stmt_no_else> : () -> ( e ) = @{
795
    report ( crt_loc, ERR_stmt_if_no_else () ) ;
796
    @e = NULL_exp ;
797
@} ;
798
 
799
<stmt_label_begin> : ( id ) -> ( e ) = @{
800
    @e = begin_label_stmt ( @id, lex_identifier ) ;
801
@} ;
802
 
803
<stmt_label_end> : ( a, b ) -> ( e ) = @{
804
    @e = end_label_stmt ( @a, @b ) ;
805
@} ;
806
 
807
<stmt_label_set> : () -> () = @{
808
    unreached_fall = 0 ;
809
@} ;
810
 
811
<stmt_label_clear> : () -> () = @{
812
    unreached_fall = 1 ;
813
@} ;
814
 
815
<stmt_label_mod> : () -> () = @{
816
    if ( unreached_code ) unreached_fall = 0 ;
817
@} ;
818
 
819
<stmt_return> : ( a ) -> ( e ) = @{
820
    @e = make_return_stmt ( @a, lex_return ) ;
821
@} ;
822
 
823
<stmt_return_fall> : () -> ( e ) = @{
824
    @e = fall_return_stmt () ;
825
@} ;
826
 
827
<stmt_switch_begin> : ( a ) -> ( e ) = @{
828
    @e = begin_switch_stmt ( @a ) ;
829
@} ;
830
 
831
<stmt_switch_end> : ( a, b, ex ) -> ( e ) = @{
832
    @e = end_switch_stmt ( @a, @b, @ex ) ;
833
@} ;
834
 
835
<stmt_while_begin> : ( a ) -> ( e ) = @{
836
    @e = begin_while_stmt ( @a ) ;
837
@} ;
838
 
839
<stmt_while_end> : ( a, b ) -> ( e ) = @{
840
    @e = end_while_stmt ( @a, @b ) ;
841
@} ;
842
 
843
<stmt_hash_if> : ( a, b ) -> ( e ) = @{
844
    @e = begin_hash_if_stmt ( @a, @b ) ;
845
@} ;
846
 
847
<stmt_hash_elif> : ( a, b, c ) -> ( e ) = @{
848
    @e = cont_hash_if_stmt ( @a, @b, @c ) ;
849
@} ;
850
 
851
<stmt_hash_endif> : ( a, b ) -> ( e ) = @{
852
    @e = end_hash_if_stmt ( @a, @b ) ;
853
@} ;
854
 
855
<stmt_reach> : ( a ) -> ( e ) = @{
856
    @e = make_reach_stmt ( @a, 1 ) ;
857
@} ;
858
 
859
<stmt_unreach> : ( a ) -> ( e ) = @{
860
    @e = make_reach_stmt ( @a, 0 ) ;
861
@} ;
862
 
863
<bind_temporary> : ( a ) -> ( e ) = @{
864
    @e = bind_temporary ( @a ) ;
865
@} ;
866
 
867
 
868
/*
869
    FLOW ANALYSIS
870
 
871
    These actions are concerned with flow and variable analysis.
872
*/
873
 
874
<reach_check> : () -> ( r ) = @{
875
    @r = unreached_code ;
876
    if ( @r ) {
877
	if ( !unreached_last ) {
878
	    report ( crt_loc, ERR_stmt_stmt_unreach () ) ;
879
	    unreached_last = 1 ;
880
	}
881
    } else {
882
	unreached_last = 0 ;
883
    }
884
@} ;
885
 
886
<reach_prev> : ( r ) -> () = @{ unreached_prev = @r ; @} ;
887
<reach_set> : () -> () = @{ unreached_code = 0 ; @} ;
888
<reach_unset> : () -> () = @{ unreached_code = 1 ; @} ;
889
 
890
<condition_get> : () -> ( c ) = @{ @c = crt_condition ; @} ;
891
<condition_set> : ( c ) -> () = @{ crt_condition = @c ; @} ;
892
 
893
 
894
/*
895
    FUNCTION DEFINITIONS CONSTRUCTORS
896
 
897
    These actions are called at the start and the end of a function
898
    definition.  Most of the work is done by construction functions, but
899
    the flags have_type_declaration and in_function_defn are handled
900
    locally.
901
*/
902
 
903
<function_begin> : ( d ) -> ( b ) = @{
904
    @b = in_class_defn ;
905
    in_class_defn = 0 ;
906
    in_function_defn++ ;
907
    really_in_function_defn++ ;
908
    begin_function ( @d ) ;
909
@} ;
910
 
911
<function_end> : ( d, a, b ) -> () = @{
912
    IGNORE end_function ( @d, @a ) ;
913
    in_class_defn = @b ;
914
    in_function_defn-- ;
915
    really_in_function_defn-- ;
916
@} ;
917
 
918
<param_begin> : ( id ) -> () = @{
919
    func_type_defn ( 0 ) ;
920
    begin_param ( @id ) ;
921
    have_type_declaration = TYPE_DECL_NONE ;
922
    have_func_declarator = 0 ;
923
@} ;
924
 
925
<param_end> : () -> () = @{
926
    end_param () ;
927
    have_type_declaration = TYPE_DECL_NONE ;
928
    have_func_declarator = 1 ;
929
@} ;
930
 
931
 
932
/*
933
    CONST-VOLATILE QUALIFIERS
934
 
935
    These actions describe how to construct and combine the const and
936
    volatile type qualifiers.  The main action is cv_join which combines
937
    two CV bitmasks by bitwise or'ing them.  It also checks for
938
    duplicate qualifiers.
939
*/
940
 
941
<cv_none> : () -> ( cv ) = @{ @cv = cv_none ; @} ;
942
<cv_const> : () -> ( cv ) = @{ @cv = cv_const ; @} ;
943
<cv_volatile> : () -> ( cv ) = @{ @cv = cv_volatile ; @} ;
944
 
945
<cv_join> : ( a, b ) -> ( cv ) = @{
946
    CV_SPEC c = ( @a & @b ) ;
947
    if ( c ) report ( crt_loc, ERR_dcl_type_cv_dup ( c ) ) ;
948
    @cv = ( @a | @b ) ;
949
@} ;
950
 
951
 
952
/*
953
    BASIC TYPES
954
 
955
    These actions describe the basic type specifiers, char, short, int,
956
    and so on.  This is a simple map onto the calculus type BTYPE.
957
*/
958
 
959
<btype_char> : () -> ( bt ) = @{ @bt = btype_char ; @} ;
960
<btype_short> : () -> ( bt ) = @{ @bt = btype_short ; @} ;
961
<btype_int> : () -> ( bt ) = @{ @bt = btype_int ; @} ;
962
<btype_long> : () -> ( bt ) = @{ @bt = btype_long ; @} ;
963
<btype_signed> : () -> ( bt ) = @{ @bt = btype_signed ; @} ;
964
<btype_unsigned> : () -> ( bt ) = @{ @bt = btype_unsigned ; @} ;
965
<btype_float> : () -> ( bt ) = @{ @bt = btype_float ; @} ;
966
<btype_double> : () -> ( bt ) = @{ @bt = btype_double ; @} ;
967
<btype_wchar_t> : () -> ( bt ) = @{ @bt = btype_wchar_t ; @} ;
968
<btype_size_t> : () -> ( bt ) = @{ @bt = btype_size_t ; @} ;
969
<btype_ptrdiff_t> : () -> ( bt ) = @{ @bt = btype_ptrdiff_t ; @} ;
970
<btype_void> : () -> ( bt ) = @{ @bt = btype_void ; @} ;
971
<btype_bottom> : () -> ( bt ) = @{ @bt = btype_bottom ; @} ;
972
<btype_none> : () -> ( bt ) = @{ @bt = btype_none ; @} ;
973
 
974
<btype_join> : ( b1, b2 ) -> ( bt ) = @{
975
    if ( @b1 & @b2 ) {
976
	@bt = join_pre_types ( @b1, @b2 ) ;
977
    } else {
978
	@bt = ( @b1 | @b2 ) ;
979
    }
980
@} ;
981
 
982
 
983
/*
984
    BASIC TYPE CONSTRUCTORS
985
 
986
    These actions describe how to combine the basic types into real type
987
    descriptors.  The null type, type_none, is used to indicate the absence
988
    of an optional type.  A base type specifier can be transformed into a
989
    partial type by type_pre, and a type name by type_name.  Two partial
990
    types may be combined using type_join.  A partial type may be turned
991
    into a real type by type_complete, which also checks that the resultant
992
    type is not an inferred type (also see dspec_complete).
993
*/
994
 
995
<type_none> : () -> ( t ) = @{
996
    @t = NULL_type ;
997
@} ;
998
 
999
<type_pre> : () -> ( t ) = @{
1000
    @t = NULL_type ;
1001
    have_type_specifier = 1 ;
1002
@} ;
1003
 
1004
<type_name> : ( id ) -> ( t ) = @{
1005
    MAKE_type_pre ( cv_none, btype_alias, qual_none, @t ) ;
1006
    COPY_id ( type_name ( @t ), @id ) ;
1007
    have_type_specifier = 1 ;
1008
@} ;
1009
 
1010
<type_elaborate> : ( id, k ) -> ( t ) = @{
1011
    MAKE_type_pre ( cv_none, @k, qual_none, @t ) ;
1012
    COPY_id ( type_name ( @t ), @id ) ;
1013
    if ( have_type_declaration == TYPE_DECL_NONE ) {
1014
	have_type_declaration = TYPE_DECL_ELABORATE ;
1015
    }
1016
    have_type_specifier = 1 ;
1017
@} ;
1018
 
1019
<type_join> : ( a, b ) -> ( t ) = @{
1020
    /* Join two partial types */
1021
    if ( IS_NULL_type ( @a ) ) {
1022
	@t = @b ;
1023
    } else if ( IS_NULL_type ( @b ) ) {
1024
	@t = @a ;
1025
    } else {
1026
	report ( crt_loc, ERR_dcl_type_simple_many ( @a, @b ) ) ;
1027
	@t = @b ;
1028
    }
1029
@} ;
1030
 
1031
<type_complete> : ( bt, t, cv ) -> ( c ) = @{
1032
    @c = complete_pre_type ( @bt, @t, @cv, 1 ) ;
1033
    have_type_specifier = 0 ;
1034
@} ;
1035
 
1036
<type_of> : ( op, e, n ) -> ( t ) = @{
1037
    @t = typeof_exp ( &@e, @n, @op ) ;
1038
@} ;
1039
 
1040
<type_check> : ( t ) -> () = @{
1041
    object_type ( @t, null_tag ) ;
1042
@} ;
1043
 
1044
 
1045
/*
1046
    COMPOSITE TYPE CONSTRUCTORS
1047
 
1048
    These actions describe how to build up composite types from simpler
1049
    types.  Except in bitfield types, the type formed is, for example,
1050
    pointer to null type, the type being pointed to only being filled in
1051
    later by type_inject.  Note that type_new_array differs from type_array
1052
    in that the bound expression does not need to be constant.
1053
*/
1054
 
1055
<type_ptr> : ( cv ) -> ( p ) = @{
1056
    MAKE_type_ptr ( @cv, NULL_type, @p ) ;
1057
@} ;
1058
 
1059
<type_func> : ( e ) -> ( f ) = @{
1060
    @f = make_func_type ( NULL_type, @e, cv_c, empty_type_set ) ;
1061
@} ;
1062
 
1063
<type_func_weak> : ( e ) -> ( f ) = @{
1064
    @f = make_func_type ( NULL_type, ( @e | FUNC_WEAK ), cv_c, empty_type_set ) ;
1065
@} ;
1066
 
1067
<type_func_old> : () -> ( f ) = @{
1068
    @f = make_func_type ( NULL_type, FUNC_PARAMS, cv_c, empty_type_set ) ;
1069
@} ;
1070
 
1071
<type_func_none> : () -> ( f ) = @{
1072
    @f = make_func_type ( NULL_type, FUNC_NO_PARAMS, cv_c, empty_type_set ) ;
1073
@} ;
1074
 
1075
<type_array> : ( e ) -> ( a ) = @{
1076
    NAT n = make_array_dim ( @e ) ;
1077
    MAKE_type_array ( cv_none, NULL_type, n, @a ) ;
1078
@} ;
1079
 
1080
<type_bitfield> : ( p, q, e ) -> ( a ) = @{
1081
    @a = make_bitfield_type ( @p, @q, @e, 0 ) ;
1082
@} ;
1083
 
1084
<type_bitfield_mem> : ( p, q, e, id ) -> ( a ) = @{
1085
    /* Check for anonymous bitfields */
1086
    HASHID nm = DEREF_hashid ( id_name ( @id ) ) ;
1087
    int z = IS_hashid_anon ( nm ) ;
1088
    @a = make_bitfield_type ( @p, @q, @e, z ) ;
1089
@} ;
1090
 
1091
<type_inject> : ( p, t ) -> ( c ) = @{
1092
    @c = ( IS_NULL_type ( @p ) ? @t : inject_pre_type ( @p, @t, 1 ) ) ;
1093
@} ;
1094
 
1095
<type_build> : ( p, t ) -> ( c ) = @{
1096
    @c = ( IS_NULL_type ( @p ) ? @t : inject_pre_type ( @p, @t, 0 ) ) ;
1097
@} ;
1098
 
1099
 
1100
/*
1101
    CLASS KEYS
1102
 
1103
    These actions describe the class key qualifiers, class, struct, union
1104
    and enum.  These are representing by the corresponding lexical token
1105
    numbers.
1106
*/
1107
 
1108
<key_struct> : () -> ( key ) = @{ @key = btype_struct ; @} ;
1109
<key_union> : () -> ( key ) = @{ @key = btype_union ; @} ;
1110
<key_enum> : () -> ( key ) = @{ @key = btype_enum ; @} ;
1111
 
1112
 
1113
/*
1114
    CLASS AND ENUMERATION TYPE CONSTRUCTORS
1115
 
1116
    These actions describe how to build up class and enumeration types.
1117
    They also include the elaborated type specifiers.  Note that the value
1118
    of have_type_declaration is set according to the declaration processed.
1119
*/
1120
 
1121
<type_class_begin> : ( id, k ) -> ( t, b ) = @{
1122
    @t = begin_class_defn ( @id, @k, cinfo_none, NULL_type ) ;
1123
    @b = in_function_defn ;
1124
    in_function_defn = 0 ;
1125
    in_class_defn++ ;
1126
    really_in_class_defn++ ;
1127
    no_type_defns++ ;
1128
    end_base_class ( crt_class, 1 ) ;
1129
@} ;
1130
 
1131
<type_class_end> : ( p, b ) -> ( t ) = @{
1132
    @t = end_class_defn ( @p ) ;
1133
    in_function_defn = @b ;
1134
    in_class_defn-- ;
1135
    really_in_class_defn-- ;
1136
@} ;
1137
 
1138
<type_enum_begin> : ( id ) -> ( t ) = @{
1139
    @t = begin_enum_defn ( @id, NULL_type ) ;
1140
    no_type_defns++ ;
1141
@} ;
1142
 
1143
<type_enum_end> : ( p ) -> ( t ) = @{
1144
    @t = end_enum_defn ( @p ) ;
1145
@} ;
1146
 
1147
 
1148
/*
1149
    DECLARATION SPECIFIERS
1150
 
1151
    These actions describe how to construct and combine declaration
1152
    specifiers.  These include the storage class specifiers, the function
1153
    specifiers, friend and typedef.  The action dspec_join combines two
1154
    declaration specifiers by bitwise or'ing them and checking for
1155
    duplications.  The action dspec_complete is analogous to tspec_complete
1156
    but also checks any associated declaration specifiers.  It also does
1157
    not check for inferred types.
1158
*/
1159
 
1160
<dspec_none> : () -> ( ds ) = @{ @ds = dspec_none ; @} ;
1161
<dspec_auto> : () -> ( ds ) = @{ @ds = dspec_auto ; @} ;
1162
<dspec_register> : () -> ( ds ) = @{ @ds = dspec_register ; @} ;
1163
<dspec_static> : () -> ( ds ) = @{ @ds = dspec_static ; @} ;
1164
<dspec_extern> : () -> ( ds ) = @{ @ds = dspec_extern ; @} ;
1165
<dspec_typedef> : () -> ( ds ) = @{ @ds = dspec_typedef ; @} ;
1166
<dspec_inline> : () -> ( ds ) = @{ @ds = dspec_inline ; @} ;
1167
 
1168
<dspec_join> : ( a, b ) -> ( ds ) = @{
1169
    /* Combine two declaration specifiers */
1170
    DECL_SPEC d = ( ( @a & @b ) & dspec_duplicate ) ;
1171
    if ( d ) report ( crt_loc, ERR_dcl_spec_dup ( d ) ) ;
1172
    @ds = ( @a | @b ) ;
1173
@} ;
1174
 
1175
<dspec_check> : ( ds ) -> () = @{
1176
    if ( have_type_specifier ) report ( crt_loc, ERR_dcl_spec_order ( @ds ) ) ;
1177
@} ;
1178
 
1179
<dspec_complete> : ( bt, t, cv, ds ) -> ( c, d ) = @{
1180
    /* Complete a declaration specifier and a type */
1181
    @d = complete_dspec ( @ds, @bt, @t, @cv ) ;
1182
    @c = complete_pre_type ( @bt, @t, @cv, 0 ) ;
1183
    have_type_specifier = 0 ;
1184
@} ;
1185
 
1186
 
1187
/*
1188
    OBJECT DECLARATIONS
1189
 
1190
    These actions describe how to construct an object declaration.
1191
*/
1192
 
1193
<declare_id> : ( ds, bt, t, id ) -> ( d ) = @{
1194
    if ( in_weak_param ) {
1195
	@d = make_param_decl ( @ds, @t, @id, CONTEXT_WEAK_PARAM ) ;
1196
    } else if ( type_tag ( @t ) == type_func_tag ) {
1197
	check_weak_func ( @t, 0 ) ;
1198
	@d = make_func_decl ( @ds, @t, @id, 0 ) ;
1199
    } else {
1200
	int def = predict_obj_defn () ;
1201
	@d = make_object_decl ( @ds, @t, @id, def ) ;
1202
    }
1203
    if ( IS_id_type_alias ( @d ) ) {
1204
	BASE_TYPE bs = DEREF_btype ( id_type_alias_rep ( @d ) ) ;
1205
	bs |= @bt ;
1206
	COPY_btype ( id_type_alias_rep ( @d ), bs ) ;
1207
    }
1208
    have_type_declaration = TYPE_DECL_NONE ;
1209
    have_func_declarator = 0 ;
1210
@} ;
1211
 
1212
<define_func> : ( ds, t, id ) -> ( d ) = @{
1213
    @d = make_func_decl ( @ds, @t, @id, 1 ) ;
1214
    have_type_declaration = TYPE_DECL_NONE ;
1215
    have_func_declarator = 0 ;
1216
@} ;
1217
 
1218
<declare_id_empty> : ( ds, bt, t, cv ) -> () = @{
1219
    IGNORE empty_decl ( @ds, NULL_type, @bt, @t, @cv, last_lex_token, 0 ) ;
1220
    have_type_declaration = TYPE_DECL_NONE ;
1221
    have_func_declarator = 0 ;
1222
    have_type_specifier = 0 ;
1223
@} ;
1224
 
1225
<declare_empty> : () -> () = @{
1226
    report ( crt_loc, ERR_dcl_dcl_semicolon () ) ;
1227
@} ;
1228
 
1229
<declare_param> : ( ds, t, id ) -> ( d ) = @{
1230
    @d = make_param_decl ( @ds, @t, @id, CONTEXT_PARAMETER ) ;
1231
    have_type_declaration = TYPE_DECL_NONE ;
1232
    have_func_declarator = 0 ;
1233
@} ;
1234
 
1235
<declare_weak_param> : ( id ) -> () = @{
1236
    IGNORE weak_param_decl ( @id ) ;
1237
    have_type_declaration = TYPE_DECL_NONE ;
1238
    have_func_declarator = 0 ;
1239
@} ;
1240
 
1241
<declare_member> : ( t, id ) -> () = @{
1242
    IDENTIFIER id = make_member_decl ( dspec_none, @t, @id, 0 ) ;
1243
    if ( do_dump ) dump_declare ( id, &decl_loc, 0 ) ;
1244
    have_type_declaration = TYPE_DECL_NONE ;
1245
    have_func_declarator = 0 ;
1246
@} ;
1247
 
1248
<declare_member_empty> : ( bt, t, cv ) -> () = @{
1249
    IGNORE empty_decl ( dspec_none, NULL_type, @bt, @t, @cv, last_lex_token, 1 ) ;
1250
    have_type_declaration = TYPE_DECL_NONE ;
1251
    have_func_declarator = 0 ;
1252
    have_type_specifier = 0 ;
1253
@} ;
1254
 
1255
<declare_bitfield> : ( t, id ) -> () = @{
1256
    IDENTIFIER id = make_member_decl ( dspec_none, @t, @id, 0 ) ;
1257
    if ( do_dump ) dump_declare ( id, &decl_loc, 0 ) ;
1258
    have_type_declaration = TYPE_DECL_NONE ;
1259
    have_func_declarator = 0 ;
1260
@} ;
1261
 
1262
<declare_enum> : ( t, id, e ) -> () = @{
1263
    IGNORE make_enumerator ( @t, @id, @e ) ;
1264
@} ;
1265
 
1266
<declarator_begin> : ( id ) -> () = @{
1267
    IDENTIFIER pid = underlying_id ( @id ) ;
1268
    DEREF_loc ( id_loc ( pid ), decl_loc ) ;
1269
@} ;
1270
 
1271
<declarator_bad> : ( t ) -> () = @{
1272
    if ( IS_NULL_type ( @t ) ) {
1273
	report ( crt_loc, ERR_dcl_meaning_paren () ) ;
1274
    }
1275
@} ;
1276
 
1277
<declarator_weak> : ( id ) -> () = @{
1278
    report ( crt_loc, ERR_dcl_fct_par_typedef ( @id ) ) ;
1279
@} ;
1280
 
1281
<declare_extern> : ( e ) -> () = @{
1282
    external_declaration ( @e, 1 ) ;
1283
@} ;
1284
 
1285
<decl_none> : () -> ( d ) = @{
1286
    @d = NULL_id ;
1287
@} ;
1288
 
1289
 
1290
/*
1291
    INITIALISERS
1292
 
1293
    These actions describe the object initialisers.  The main action is
1294
    initialise_id which initialises d to e (which can be the null expression).
1295
    The action initialiser_bad is used to weed out badly placed function
1296
    style initialisers caused by their inclusion in the declarators.
1297
*/
1298
 
1299
<initialise_id> : ( d, e ) -> () = @{
1300
    int def = init_object ( @d, @e ) ;
1301
    if ( do_dump ) dump_declare ( @d, &decl_loc, def ) ;
1302
@} ;
1303
 
1304
 
1305
/*
1306
    OFFSETS
1307
 
1308
    These actions describe the constant offset expressions.
1309
*/
1310
 
1311
<offset_nspace> : ( t ) -> ( ns ) = @{
1312
    @ns = offset_nspace ( @t ) ;
1313
@} ;
1314
 
1315
<offset_member> : ( b, s, id, ns ) -> ( a, t ) = @{
1316
    OFFSET off = offset_member ( @s, @id, &@t, @ns, 1 ) ;
1317
    @a = offset_add ( @b, off ) ;
1318
@} ;
1319
 
1320
<offset_index> : ( b, s, e ) -> ( a, t ) = @{
1321
    OFFSET off = offset_index ( @s, @e, &@t ) ;
1322
    @a = offset_add ( @b, off ) ;
1323
@} ;
1324
 
1325
 
1326
/*
1327
    OTHER DECLARATIONS
1328
 
1329
    These actions describe the declarations not covered above.
1330
*/
1331
 
1332
<declare_asm> : ( a, p ) -> ( e ) = @{
1333
    @e = make_asm ( @a, @p ) ;
1334
@} ;
1335
 
1336
<decl_hash_if> : ( a ) -> () = @{
1337
    target_decl ( lex_if, @a ) ;
1338
@} ;
1339
 
1340
<decl_hash_elif> : ( a ) -> () = @{
1341
    target_decl ( lex_elif, @a ) ;
1342
@} ;
1343
 
1344
<decl_hash_else> : () -> () = @{
1345
    target_decl ( lex_else, NULL_exp ) ;
1346
@} ;
1347
 
1348
<decl_hash_endif> : () -> () = @{
1349
    target_decl ( lex_endif, NULL_exp ) ;
1350
@} ;
1351
 
1352
<cond_hash_if> : ( a ) -> ( c ) = @{
1353
    EXP c = crt_hash_cond ;
1354
    crt_hash_cond = make_if_cond ( @a, c ) ;
1355
    @c = c ;
1356
@} ;
1357
 
1358
<cond_hash_elif> : ( a ) -> () = @{
1359
    EXP c = make_else_cond ( crt_hash_cond ) ;
1360
    crt_hash_cond = make_if_cond ( @a, c ) ;
1361
@} ;
1362
 
1363
<cond_hash_else> : () -> () = @{
1364
    crt_hash_cond = make_else_cond ( crt_hash_cond ) ;
1365
@} ;
1366
 
1367
<cond_hash_endif> : ( a ) -> () = @{
1368
    crt_hash_cond = @a ;
1369
@} ;
1370
 
1371
 
1372
/*
1373
    ERROR REPORTING
1374
 
1375
    These actions describe the error reporting functions for syntax errors
1376
    and for weeding out extra constructs which have been allowed in the
1377
    grammar to permit for better error reporting.
1378
*/
1379
 
1380
<error_fatal> : () -> () = @{
1381
    /* Unrecoverable syntax errors */
1382
    ERROR err = ERR_lex_parse ( crt_token ) ;
1383
    err = concat_error ( err, ERR_lex_abort () ) ;
1384
    report ( crt_loc, err ) ;
1385
    have_syntax_error = 1 ;
1386
@} ;
1387
 
1388
<error_syntax> : () -> () = @{
1389
    /* Syntax errors */
1390
    ERROR err = ERR_lex_parse ( crt_token ) ;
1391
    report ( crt_loc, err ) ;
1392
    have_syntax_error = 1 ;
1393
@} ;
1394
 
1395
<error_comma> : () -> () = @{
1396
    /* Extra comma at the end of a list */
1397
    report ( crt_loc, ERR_lex_extra_comma () ) ;
1398
@} ;
1399
 
1400
<expected> : ( t ) -> () = @{
1401
    /* Expected symbol */
1402
    int p = primary_form ( crt_lex_token ) ;
1403
    if ( p != @t ) report ( crt_loc, ERR_lex_expect ( @t ) ) ;
1404
@} ;
1405
 
1406
 
1407
 
1408
/*
1409
    PARSER COUNTERS
1410
 
1411
    These actions correspond to the various parser counters defined in
1412
    predict.c.  For example no_side_effects gives the total number of side
1413
    effects encountered, while diff_side_effects gives the number defined
1414
    since a previous call of no_side_effects.
1415
*/
1416
 
1417
<no_side_effects> : () -> ( n ) = @{
1418
    @n = no_side_effects ;
1419
@} ;
1420
 
1421
<no_type_defns> : () -> ( n ) = @{
1422
    @n = no_type_defns ;
1423
@} ;
1424
 
1425
<diff_side_effects> : ( m ) -> ( n ) = @{
1426
    @n = no_side_effects - @m ;
1427
@} ;
1428
 
1429
<diff_type_defns> : ( m ) -> ( n ) = @{
1430
    @n = no_type_defns - @m ;
1431
@} ;
1432
 
1433
<sizeof_begin> : () -> () = @{
1434
    suppress_usage++ ;
1435
@} ;
1436
 
1437
<sizeof_end> : () -> () = @{
1438
    suppress_usage-- ;
1439
@} ;
1440
 
1441
 
1442
/*
1443
    PREDICATE LITERALS
1444
 
1445
    These actions give the basic values, true and false, for the type
1446
    BOOL.
1447
*/
1448
 
1449
<bool_false> : () -> ( b ) = @{ @b = 0 ; @} ;
1450
<bool_true> : () -> ( b ) = @{ @b = 1 ; @} ;
1451
 
1452
 
1453
/*
1454
    PARSER PREDICATES
1455
 
1456
    In several places the parser needs some help in order to resolve
1457
    ambiguities by means of look-ahead etc.  This help is provided by
1458
    means of the following predicates.  See predict.c for more details.
1459
*/
1460
 
1461
<is_function> : ( t ) -> ( b ) = @{
1462
    @b = function_params ( @t ) ;
1463
@} ;
1464
 
1465
<is_decl_specifier> : () -> ( b ) = @{
1466
    /* Resolve declaration-specifiers from other declarators */
1467
    @b = predict_dspec ( 0 ) ;
1468
@} ;
1469
 
1470
<is_decl_statement> : ( d ) -> ( b ) = @{
1471
    /* Resolve declaration-statements from expression-statements */
1472
    int b = predict_decl () ;
1473
    if ( b ) {
1474
	if ( !@d ) report ( crt_loc, ERR_stmt_dcl_start () ) ;
1475
	in_declaration++ ;
1476
    }
1477
    @b = b ;
1478
@} ;
1479
 
1480
<is_type_id_false> : () -> ( b ) = @{
1481
    /* Resolve type-ids from expressions */
1482
    @b = predict_typeid ( 0 ) ;
1483
@} ;
1484
 
1485
<is_type_id_true> : () -> ( b ) = @{
1486
    /* Resolve type-ids from expressions */
1487
    @b = predict_typeid ( 1 ) ;
1488
@} ;
1489
 
1490
<is_type_specifier> : () -> ( b ) = @{
1491
    /* Resolve type-specifiers from other declarators */
1492
    @b = predict_tspec ( 0 ) ;
1493
@} ;
1494
 
1495
<is_parameter> : () -> ( b ) = @{
1496
    /* Resolve parameter declarators from type names */
1497
    @b = predict_param () ;
1498
@} ;
1499
 
1500
 
1501
/*
1502
    PARSER HACKS AND PATCHES
1503
 
1504
    In a couple of places it is necessary to fool the parser by changing
1505
    the next token (or even inserting an extra token) depending on the
1506
    current state.
1507
*/
1508
 
1509
<rescan_token> : () -> () = @{
1510
    RESCAN_LEXER ;
1511
@} ;
1512
 
1513
<check_decl_specifier> : () -> () = @{
1514
    /* A type-name can be a declarator-id */
1515
    if ( have_type_specifier && crt_lex_token == lex_type_Hname ) {
1516
	crt_lex_token = lex_identifier ;
1517
    }
1518
@} ;
1519
 
1520
 
1521
/*
1522
    FILE TRAILERS
1523
 
1524
    These trailers are appended to the parser definition and declaration
1525
    output files.
1526
*/
1527
 
1528
%trailer% @{
1529
@}, @{
1530
 
1531
 
1532
/*
1533
    DUMMY LEXICAL TOKEN VALUES
1534
 
1535
    These values are used as lexical token values in certain circumstances
1536
    but do not represent actual tokens.  Note that they are all negative.
1537
*/
1538
 
1539
#define lex_ignore_token	-1
1540
#define lex_end_condition	-2
1541
#define lex_included		-3
1542
 
1543
 
1544
#endif
1545
@} ;