Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997, 1998
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
/*
32
    C SYNTAX
33
 
34
    This module contains the syntax for the C language.
35
*/
36
 
37
 
38
/*
39
    TYPE DECLARATIONS
40
 
41
    The types BOOL, COUNT and LEX are natural types arising from the
42
    parser.  The remaining types directly correspond to types within the
43
    main program, or composite types formed from them.
44
*/
45
 
46
%types%
47
 
48
BOOL ;
49
BTYPE ;
50
CONDITION ;
51
COUNT ;
52
CV ;
53
DECL ;
54
DSPEC ;
55
EXP ;
56
IDENTIFIER ;
57
KEY ;
58
LEX ;
59
LIST-EXP ;
60
NAMESPACE ;
61
NUMBER ;
62
OFFSET ;
63
TYPE ;
64
 
65
 
66
/*
67
    LIST OF TERMINALS
68
 
69
    This list of terminals corresponds to that given in symbols.h.  It can
70
    be automatically generated using the routine sid_terminals defined in
71
    debug.c (q.v).
72
*/
73
 
74
%terminals%
75
 
76
!unknown ;
77
 
78
/* Identifiers */
79
identifier : () -> ( :IDENTIFIER ) ;
80
type-name : () -> ( :IDENTIFIER ) ;
81
!namespace-name : () -> ( :IDENTIFIER ) ;
82
statement-name : () -> ( :IDENTIFIER ) ;
83
!destructor-name : () -> ( :IDENTIFIER ) ;
84
!template-id : () -> ( :IDENTIFIER ) ;
85
!template-type : () -> ( :IDENTIFIER ) ;
86
 
87
/* Nested name specifiers */
88
!nested-name : () -> ( :NAMESPACE ) ;
89
!full-name : () -> ( :NAMESPACE ) ;
90
!nested-name-star : () -> ( :IDENTIFIER ) ;
91
!full-name-star : () -> ( :IDENTIFIER ) ;
92
 
93
/* Literals */
94
!char-lit ; !wchar-lit ; !string-lit ; !wstring-lit ; !integer-lit ;
95
 
96
/* Literal expressions */
97
char-exp : () -> ( :EXP ) ;
98
wchar-exp : () -> ( :EXP ) ;
99
string-exp : () -> ( :EXP ) ;
100
wstring-exp : () -> ( :EXP ) ;
101
integer-exp : () -> ( :EXP ) ;
102
floating-exp : () -> ( :EXP ) ;
103
 
104
/* Token applications */
105
complex-exp : () -> ( :EXP ) ;
106
complex-stmt : () -> ( :EXP ) ;
107
complex-type : () -> ( :TYPE ) ;
108
 
109
/* Target-dependent preprocessing directives */
110
hash-if : () -> ( :EXP ) ;
111
hash-elif : () -> ( :EXP ) ;
112
hash-else ;
113
hash-endif ;
114
hash-pragma ;
115
 
116
/* End of file markers */
117
!newline ; eof ;
118
 
119
/* Symbols */
120
and-1 ; and-eq-1 ; arrow ; assign ; !backslash ; close-brace-1 ;
121
close-round ; close-square-1 ; colon ; comma ; compl-1 ; div ; div-eq ;
122
dot ; ellipsis ; eq ; greater ; greater-eq ; !hash-1 ; !hash-hash-1 ;
123
less ; less-eq ; logical-and-1 ; logical-or-1 ; lshift ; lshift-eq ;
124
minus ; minus-eq ; minus-minus ; not-1 ; not-eq-1 ; open-brace-1 ;
125
open-round ; open-square-1 ; or-1 ; or-eq-1 ; plus ; plus-eq ; plus-plus ;
126
question ; rem ; rem-eq ; rshift ; rshift-eq ; semicolon ; star ;
127
star-eq ; xor-1 ; xor-eq-1 ; !arrow-star ; !colon-colon ; !dot-star ;
128
abs ; max ; min ;
129
 
130
/* Digraphs */
131
!close-brace-2 ; !close-square-2 ; !hash-2 ; !hash-hash-2 ;
132
!open-brace-2 ; !open-square-2 ;
133
 
134
/* C keywords */
135
auto ; break ; case ; char ; const ; continue ; default ; do ; double ;
136
else ; enum ; extern ; float ; for ; goto ; if ; int ; long ; register ;
137
return ; short ; signed ; sizeof ; static ; struct ; switch ; typedef ;
138
union ; unsigned ; void ; volatile ; while ;
139
 
140
/* C++ keywords */
141
asm ; !bool ; !catch ; !class ; !const-cast ; !delete ; !dynamic-cast ;
142
!explicit ; !export ; !false ; !friend ; inline ; !mutable ; !namespace ;
143
!new ; !operator ; !private ; !protected ; !public ; !reinterpret-cast ;
144
!static-cast ; !template ; !this ; !throw ; !true ; !try ; !typeid ;
145
!typename ; !using ; !virtual ; wchar-t ;
146
 
147
/* ISO keywords */
148
!and-2 ; !and-eq-2 ; !compl-2 ; !logical-and-2 ; !logical-or-2 ;
149
!not-2 ; !not-eq-2 ; !or-2 ; !or-eq-2 ; !xor-2 ; !xor-eq-2 ;
150
 
151
/* TenDRA keywords */
152
!accept ; !after ; alignof ; !all ; !allow ; !ambiguous ; !analysis ;
153
!argument ; !arith-cap ; !array ; !as ; !assert ; !assignment ; !begin ;
154
!bitfield ; !block ; bottom ; !cast ; !character ; !class-cap ; !code ;
155
!comment ; !compatible ; !complete ; !compute ; !conditional ;
156
!conversion ; !decimal ; !decl ; !define ; !define-cap ; !defined ;
157
!definition ; !depth ; !directive ; !directory ; !disallow ; discard ;
158
!dollar ; !either ; !elif ; ellipsis-exp ; !end ; !endif ; !environment ;
159
!equality ; !error ; !escape ; exhaustive ; !exp-cap ; !explain ;
160
!extend ; !external ; !extra ; fall ; !file ; !float-cap ; !forward ;
161
!func-cap ; !function ; !hexadecimal ; !hiding ; !ident ; !identif ;
162
!ifdef ; !ifndef ; !ignore ; !implement ; !implicit ; !import ; !include ;
163
!includes ; !include-next ; !incompatible ; !incomplete ; !indented ;
164
!initialization ; !integer ; !interface ; !internal ; !into ; !int-cap ;
165
!keyword ; !limit ; !line ; !linkage ; !lit ; !longlong ; !lvalue ;
166
!macro ; !main ; !member ; !member-cap ; !name ; !nat-cap ; !nested ;
167
!nline ; !no ; !no-def ; !object ; !octal ; !of ; !off ; !on ; !option ;
168
!overflow ; !overload ; !pointer ; !postpone ; !pragma ; !precedence ;
169
!preserve ; !printf ; !proc-cap ; !promote ; !promoted ; !prototype ;
170
ptrdiff-t ; !qualifier ; !quote ; reachable ; !reference ; !reject ;
171
!representation ; !reset ; !resolution ; !rvalue ; !scalar-cap ; !scanf ;
172
set ; size-t ; !size-t-2 ; !sort ; !std ; !stmt-cap ; !string ;
173
!struct-cap ; !suspend ; !tag ; !tag-cap ; !tendra ; !text ; !this-name ;
174
!token ; !type ; !type-cap ; !typeof ; !un-known ; !unassert ; !undef ;
175
!unify ; !union-cap ; !unmatched ; !unpostpone ; unreachable ; unused ;
176
!use ; !value ; !variable ; !variety-cap ; !volatile-t ; !vtable ;
177
!warning ; weak ; !writeable ; !zzzz ;
178
 
179
/* Miscellaneous symbols */
180
!array-op ; !builtin-file ; !builtin-line ; !close-template ; !cond-op ;
181
!delete-full ; !delete-array ; !delete-array-full ; !func-op ; !hash-op ;
182
!hash-hash-op ; inset-start ; inset-end ; !macro-arg ; !new-full ;
183
!new-array ; !new-array-full ; !open-init ; !open-template ; !zzzzzz ;
184
 
185
 
186
/*
187
    ALTERNATIVE REPRESENTATIONS
188
 
189
    The ISO keywords and digraphs will have been replaced by their primary
190
    representations by this stage.  These rules are effectively identities
191
    for these alternatives.  Don't try removing them - SID gets very
192
    confused.
193
*/
194
 
195
%productions%
196
 
197
close-brace =	{ close-brace-1 ; } ;
198
close-square =	{ close-square-1 ; } ;
199
open-brace =	{ open-brace-1 ; } ;
200
open-square =	{ open-square-1 ; } ;
201
 
202
and =		{ and-1 ; } ;
203
and-eq =	{ and-eq-1 ; } ;
204
compl =		{ compl-1 ; } ;
205
logical-and =	{ logical-and-1 ; } ;
206
logical-or =	{ logical-or-1 ; } ;
207
not =		{ not-1 ; } ;
208
not-eq =	{ not-eq-1 ; } ;
209
or =		{ or-1 ; } ;
210
or-eq =		{ or-eq-1 ; } ;
211
xor =		{ xor-1 ; } ;
212
xor-eq =	{ xor-eq-1 ; } ;
213
 
214
 
215
/*
216
    LEXICAL TOKENS
217
 
218
    These actions give the lexical token numbers for various symbols.
219
*/
220
 
221
<lex_crt> : () -> ( :LEX ) ;
222
<lex_open_round> : () -> ( :LEX ) ;
223
<lex_semicolon> : () -> ( :LEX ) ;
224
<lex_alignof> : () -> ( :LEX ) ;
225
<lex_sizeof> : () -> ( :LEX ) ;
226
 
227
 
228
/*
229
    EXPECTED SYMBOLS
230
 
231
    These rules are used when a certain symbol is expected.  If it is
232
    not present then the action expected is called with the appropriate
233
    lexical token number.
234
*/
235
 
236
<expected> : ( :LEX ) -> () ;
237
<error_fatal> : () -> () ;
238
<error_syntax> : () -> () ;
239
 
240
open-round-x = {
241
	open-round ;
242
    ##	t = <lex_open_round> ; <expected> ( t ) ;
243
} ;
244
 
245
semicolon-x = {
246
	semicolon ;
247
    ##	t = <lex_semicolon> ; <expected> ( t ) ;
248
} ;
249
 
250
 
251
/*
252
    IDENTIFIERS
253
 
254
    The identifier terminal is exclusive - it does not include those
255
    identifiers which are actually type and namespace names.  This rule
256
    gives all identifiers and sets the appropriate identifier type.
257
*/
258
 
259
<id_anon> : () -> ( :IDENTIFIER ) ;
260
<id_none> : () -> ( :IDENTIFIER ) ;
261
 
262
any-identifier : () -> ( id : IDENTIFIER ) = {
263
	id = identifier ;
264
    ||	id = type-name ;
265
    ||	id = statement-name ;
266
} ;
267
 
268
any-identifier-opt : () -> ( id : IDENTIFIER ) = {
269
	id = any-identifier ;
270
    ||	id = <id_anon> ;
271
} ;
272
 
273
id-entry : () -> ( id : IDENTIFIER ) = {
274
	id = any-identifier ;
275
    ##
276
	<error_syntax> ;
277
	id = <id_none> ;
278
} ;
279
 
280
operator-id : () -> ( id : IDENTIFIER ) = {
281
	<error_syntax> ;
282
	id = <id_none> ;
283
} ;
284
 
285
 
286
/*
287
    LITERAL EXPRESSIONS
288
 
289
    These rules describe the literal expressions.  These are the integer
290
    and floating point literals and the character and string literals.
291
    Concatenation of adjacent string literals has already been performed.
292
*/
293
 
294
integer-literal : () -> ( e : EXP ) = {
295
	e = integer-exp ;
296
} ;
297
 
298
character-literal : () -> ( e : EXP ) = {
299
	e = char-exp ;
300
    ||	e = wchar-exp ;
301
} ;
302
 
303
floating-literal : () -> ( e : EXP ) = {
304
	e = floating-exp ;
305
} ;
306
 
307
string-literal : () -> ( e : EXP ) = {
308
	e = string-exp ;
309
    ||	e = wstring-exp ;
310
} ;
311
 
312
literal : () -> ( e : EXP ) = {
313
	e = integer-literal ;
314
    ||	e = character-literal ;
315
    ||	e = floating-literal ;
316
    ||	e = string-literal ;
317
} ;
318
 
319
 
320
/*
321
    PRIMARY EXPRESSIONS
322
 
323
    This rule describes the primary expressions.  These include the
324
    literals, the identity expressions, the this expression and the
325
    parenthesised expressions.  The assertion expressions are an
326
    extension.
327
*/
328
 
329
<exp_ellipsis> : () -> ( :EXP ) ;
330
<exp_paren_begin> : () -> () ;
331
<exp_paren_end> : ( :EXP ) -> ( :EXP ) ;
332
<exp_identifier> : ( :IDENTIFIER ) -> ( :EXP ) ;
333
 
334
expression : () -> ( :EXP ) ;
335
 
336
primary-expression : () -> ( e : EXP ) = {
337
	e = literal ;
338
    ||
339
	id = identifier ;
340
	e = <exp_identifier> ( id ) ;
341
    ||
342
	ellipsis-exp ;
343
	e = <exp_ellipsis> ;
344
    ||
345
	open-round ;
346
	<exp_paren_begin> ;
347
	a = expression ;
348
	e = <exp_paren_end> ( a ) ;
349
	close-round ;
350
    ||
351
	e = complex-exp ;
352
} ;
353
 
354
 
355
/*
356
    EXPRESSION LISTS
357
 
358
    These rules describes the lists of expressions.  Note that the
359
    constituents are assignment-expressions so that any commas are list
360
    separators rather than comma operators.
361
*/
362
 
363
<list_exp_null> : () -> ( :LIST-EXP ) ;
364
<list_exp_cons> : ( :EXP, :LIST-EXP ) -> ( :LIST-EXP ) ;
365
 
366
assignment-expression : () -> ( :EXP ) ;
367
 
368
expression-list : () -> ( p : LIST-EXP ) = {
369
	e = assignment-expression ;
370
	{
371
		comma ; q = expression-list ;
372
	    ||	q = <list_exp_null> ;
373
	} ;
374
	p = <list_exp_cons> ( e, q ) ;
375
} ;
376
 
377
expression-list-opt : () -> ( p : LIST-EXP ) = {
378
	p = expression-list ;
379
    ||	p = <list_exp_null> ;
380
} ;
381
 
382
 
383
/*
384
    FIELD SELECTOR EXPRESSIONS
385
 
386
    These rules are used to perform field selector look-up following a
387
    '.' or '->' operator.  The input namespace gives the class being
388
    selected from (or the null namespace in case of an error).  Note
389
    the provisions for dummy destructor calls.
390
*/
391
 
392
<rescan_member> : ( :NAMESPACE, :IDENTIFIER ) -> ( :IDENTIFIER ) ;
393
 
394
field-id-expression : ( ns : NAMESPACE ) -> ( id : IDENTIFIER ) = {
395
	uid = any-identifier ;
396
	id = <rescan_member> ( ns, uid ) ;
397
} ;
398
 
399
 
400
/*
401
    POSTFIX EXPRESSIONS
402
 
403
    These rules describes the postfix expressions.  These include array
404
    indexing, function calls and function style casts, field selectors,
405
    postfix increment and decrement operations, new style casts and
406
    type identification operators.
407
*/
408
 
409
<exp_postinc> : ( :EXP ) -> ( :EXP ) ;
410
<exp_postdec> : ( :EXP ) -> ( :EXP ) ;
411
<exp_index> : ( :EXP, :EXP ) -> ( :EXP ) ;
412
<exp_func> : ( :EXP, :LIST-EXP ) -> ( :EXP ) ;
413
 
414
<exp_dot_begin> : ( :EXP ) -> ( :EXP, :TYPE, :NAMESPACE ) ;
415
<exp_dot_end> : ( :EXP, :TYPE, :NAMESPACE, :IDENTIFIER ) -> ( :EXP ) ;
416
<exp_arrow_begin> : ( :EXP ) -> ( :EXP, :TYPE, :NAMESPACE ) ;
417
<exp_arrow_end> : ( :EXP, :TYPE, :NAMESPACE, :IDENTIFIER ) -> ( :EXP ) ;
418
<rescan_token> : () -> () ;
419
 
420
<no_type_defns> : () -> ( :COUNT ) ;
421
<no_side_effects> : () -> ( :COUNT ) ;
422
<diff_type_defns> : ( :COUNT ) -> ( :COUNT ) ;
423
<diff_side_effects> : ( :COUNT ) -> ( :COUNT ) ;
424
<sizeof_begin> : () -> () ;
425
<sizeof_end> : () -> () ;
426
 
427
type-id : () -> ( :TYPE, :COUNT ) ;
428
type-id-false : () -> ( :TYPE, :COUNT ) ;
429
type-id-true : () -> ( :TYPE, :COUNT ) ;
430
 
431
postfix-expression : () -> ( e : EXP ) = {
432
	e = primary-expression ;
433
    ||
434
	a = postfix-expression ;
435
	open-square ; b = expression ; close-square ;
436
	e = <exp_index> ( a, b ) ;
437
    ||
438
	a = postfix-expression ;
439
	open-round ; p = expression-list-opt ;
440
	e = <exp_func> ( a, p ) ;
441
	close-round ;
442
    ||
443
	a = postfix-expression ;
444
	( b, t, ns ) = <exp_dot_begin> ( a ) ;
445
	dot ; id = field-id-expression ( ns ) ;
446
	e = <exp_dot_end> ( b, t, ns, id ) ;
447
	<rescan_token> ;
448
    ||
449
	a = postfix-expression ;
450
	( b, t, ns ) = <exp_arrow_begin> ( a ) ;
451
	arrow ; id = field-id-expression ( ns ) ;
452
	e = <exp_arrow_end> ( b, t, ns, id ) ;
453
	<rescan_token> ;
454
    ||
455
	a = postfix-expression ; plus-plus ;
456
	e = <exp_postinc> ( a ) ;
457
    ||
458
	a = postfix-expression ; minus-minus ;
459
	e = <exp_postdec> ( a ) ;
460
} ;
461
 
462
 
463
/*
464
    UNARY EXPRESSIONS
465
 
466
    These rules describe the unary expressions.  These include the simple
467
    unary operations (indirection, address, unary plus, unary minus, logical
468
    negation and bitwise complement), the prefix increment and decrement
469
    operations and sizeof expressions, as well as the new and delete
470
    expressions.
471
*/
472
 
473
<exp_not> : ( :EXP ) -> ( :EXP ) ;
474
<exp_ref> : ( :EXP ) -> ( :EXP ) ;
475
<exp_indir> : ( :EXP ) -> ( :EXP ) ;
476
<exp_unary> : ( :LEX, :EXP ) -> ( :EXP ) ;
477
<exp_preinc> : ( :EXP ) -> ( :EXP ) ;
478
<exp_predec> : ( :EXP ) -> ( :EXP ) ;
479
 
480
<exp_none> : () -> ( :EXP ) ;
481
<exp_sizeof> : ( :LEX, :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
482
<type_of> : ( :LEX, :EXP, :COUNT ) -> ( :TYPE ) ;
483
 
484
unary-expression : () -> ( :EXP ) ;
485
cast-expression : () -> ( :EXP ) ;
486
 
487
sizeof-expression : ( op : LEX ) -> ( e : EXP ) = {
488
	<sizeof_begin> ;
489
	n1 = <no_side_effects> ;
490
	m1 = <no_type_defns> ;
491
	{
492
		a = unary-expression ;
493
		n2 = <diff_side_effects> ( n1 ) ;
494
		m2 = <diff_type_defns> ( m1 ) ;
495
		t = <type_of> ( op, a, n2 ) ;
496
		c = <exp_sizeof> ( op, t, a, m2 ) ;
497
	    ||
498
		open-round ; ( t, m2 ) = type-id-true ;
499
		a = <exp_none> ;
500
		c = <exp_sizeof> ( op, t, a, m2 ) ;
501
		close-round ;
502
	} ;
503
	<sizeof_end> ;
504
	e = c ;
505
} ;
506
 
507
unary-operator : () -> () = {
508
	plus ;
509
    ||	minus ;
510
    ||	compl ;
511
    ||	abs ;
512
} ;
513
 
514
unary-expression : () -> ( e : EXP ) = {
515
	e = postfix-expression ;
516
    ||
517
	plus-plus ; a = unary-expression ;
518
	e = <exp_preinc> ( a ) ;
519
    ||
520
	minus-minus ; a = unary-expression ;
521
	e = <exp_predec> ( a ) ;
522
    ||
523
	star ; a = cast-expression ;
524
	e = <exp_indir> ( a )  ;
525
    ||
526
	and ; a = cast-expression ;
527
	e = <exp_ref> ( a )  ;
528
    ||
529
	not ; a = cast-expression ;
530
	e = <exp_not> ( a ) ;
531
    ||
532
	op = <lex_crt> ; unary-operator ;
533
	a = cast-expression ;
534
	e = <exp_unary> ( op, a ) ;
535
    ||
536
	sizeof ; op = <lex_sizeof> ; e = sizeof-expression ( op ) ;
537
    ||
538
	alignof ; op = <lex_alignof> ; e = sizeof-expression ( op ) ;
539
} ;
540
 
541
 
542
/*
543
    CAST EXPRESSIONS
544
 
545
    This rule describes the traditional style cast expressions, consisting
546
    of a bracketed type identifier followed by an expression.  The ignore
547
    keyword is an extension which is semantically equivalent to casting
548
    to void.
549
*/
550
 
551
<exp_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
552
<exp_ignore> : ( :EXP ) -> ( :EXP ) ;
553
 
554
cast-expression : () -> ( e : EXP ) = {
555
	e = unary-expression ;
556
    ||
557
	open-round ; ( t, n ) = type-id-false ; close-round ;
558
	a = cast-expression ;
559
	e = <exp_cast> ( t, a, n ) ;
560
    ||
561
	discard ; a = cast-expression ;
562
	e = <exp_ignore> ( a ) ;
563
} ;
564
 
565
 
566
/*
567
    MULTIPLICATIVE EXPRESSIONS
568
 
569
    This rule describes the multiplicative expressions.  These include
570
    the division and remainder operations, as well as multiplication.
571
*/
572
 
573
<exp_div> : ( :EXP, :EXP ) -> ( :EXP ) ;
574
<exp_rem> : ( :EXP, :EXP ) -> ( :EXP ) ;
575
<exp_mult> : ( :EXP, :EXP ) -> ( :EXP ) ;
576
 
577
multiplicative-expression : () -> ( e : EXP ) = {
578
	e = cast-expression ;
579
    ||
580
	a = multiplicative-expression ; star ; b = cast-expression ;
581
	e = <exp_mult> ( a, b ) ;
582
    ||
583
	a = multiplicative-expression ; div ; b = cast-expression ;
584
	e = <exp_div> ( a, b ) ;
585
    ||
586
	a = multiplicative-expression ; rem ; b = cast-expression ;
587
	e = <exp_rem> ( a, b ) ;
588
} ;
589
 
590
 
591
/*
592
    ADDITIVE EXPRESSIONS
593
 
594
    This rule describes the additive expressions.  These include both the
595
    addition and the subtraction operations.
596
*/
597
 
598
<exp_plus> : ( :EXP, :EXP ) -> ( :EXP ) ;
599
<exp_minus> : ( :EXP, :EXP ) -> ( :EXP ) ;
600
 
601
additive-expression : () -> ( e : EXP ) = {
602
	e = multiplicative-expression ;
603
    ||
604
	a = additive-expression ; plus ; b = multiplicative-expression ;
605
	e = <exp_plus> ( a, b ) ;
606
    ||
607
	a = additive-expression ; minus ; b = multiplicative-expression ;
608
	e = <exp_minus> ( a, b ) ;
609
} ;
610
 
611
 
612
/*
613
    SHIFT EXPRESSIONS
614
 
615
    This rule describes the shift expressions.  Both left and right shifts
616
    are included.
617
*/
618
 
619
<exp_lshift> : ( :EXP, :EXP ) -> ( :EXP ) ;
620
<exp_rshift> : ( :EXP, :EXP ) -> ( :EXP ) ;
621
 
622
shift-expression : () -> ( e : EXP ) = {
623
	e = additive-expression ;
624
    ||
625
	a = shift-expression ; lshift ; b = additive-expression ;
626
	e = <exp_lshift> ( a, b ) ;
627
    ||
628
	a = shift-expression ; rshift ; b = additive-expression ;
629
	e = <exp_rshift> ( a, b ) ;
630
} ;
631
 
632
 
633
/*
634
    RELATIONAL EXPRESSIONS
635
 
636
    These rules describe the relational expressions, less than, greater
637
    than, less than or equal and greater than or equal.
638
*/
639
 
640
<exp_relation> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
641
 
642
relational-operator : () -> () = {
643
	less ;
644
    ||	greater ;
645
    ||	less-eq ;
646
    ||	greater-eq ;
647
} ;
648
 
649
relational-expression : () -> ( e : EXP ) = {
650
	e = shift-expression ;
651
    ||
652
	a = relational-expression ;
653
	op = <lex_crt> ; relational-operator ;
654
	b = shift-expression ;
655
	e = <exp_relation> ( op, a, b ) ;
656
} ;
657
 
658
 
659
/*
660
    EQUALITY EXPRESSIONS
661
 
662
    These rules describe the equality expressions, equal and not equal.
663
*/
664
 
665
<exp_equality> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
666
 
667
equality-operator : () -> () = {
668
	eq ;
669
    ||	not-eq ;
670
} ;
671
 
672
equality-expression : () -> ( e : EXP ) = {
673
	e = relational-expression ;
674
    ||
675
	a = equality-expression ;
676
	op = <lex_crt> ; equality-operator ;
677
	b = relational-expression ;
678
	e = <exp_equality> ( op, a, b ) ;
679
} ;
680
 
681
 
682
/*
683
    MAXIMUM AND MINIMUM EXPRESSIONS (EXTENSION)
684
 
685
    These rules describes the maximum and minimum expressions.
686
*/
687
 
688
<exp_maxmin> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
689
 
690
maxmin-operator : () -> () = {
691
	max ;
692
    ||	min ;
693
} ;
694
 
695
maxmin-expression : () -> ( e : EXP ) = {
696
	e = equality-expression ;
697
    ||
698
	a = maxmin-expression ;
699
	op = <lex_crt> ; maxmin-operator ;
700
	b = equality-expression ;
701
	e = <exp_maxmin> ( op, a, b ) ;
702
} ;
703
 
704
 
705
/*
706
    AND EXPRESSIONS
707
 
708
    This rule describes the bitwise and expressions.
709
*/
710
 
711
<exp_and> : ( :EXP, :EXP ) -> ( :EXP ) ;
712
 
713
and-expression : () -> ( e : EXP ) = {
714
	e = maxmin-expression ;
715
    ||
716
	a = and-expression ; and ; b = maxmin-expression ;
717
	e = <exp_and> ( a, b ) ;
718
} ;
719
 
720
 
721
/*
722
    EXCLUSIVE OR EXPRESSIONS
723
 
724
    This rule describes the bitwise exclusive or expressions.
725
*/
726
 
727
<exp_xor> : ( :EXP, :EXP ) -> ( :EXP ) ;
728
 
729
exclusive-or-expression : () -> ( e : EXP ) = {
730
	e = and-expression ;
731
    ||
732
	a = exclusive-or-expression ; xor ; b = and-expression ;
733
	e = <exp_xor> ( a, b ) ;
734
} ;
735
 
736
 
737
/*
738
    INCLUSIVE OR EXPRESSIONS
739
 
740
    This rule describes the bitwise inclusive or expressions.
741
*/
742
 
743
<exp_or> : ( :EXP, :EXP ) -> ( :EXP ) ;
744
 
745
inclusive-or-expression : () -> ( e : EXP ) = {
746
	e = exclusive-or-expression ;
747
    ||
748
	a = inclusive-or-expression ; or ; b = exclusive-or-expression ;
749
	e = <exp_or> ( a, b ) ;
750
} ;
751
 
752
 
753
/*
754
    LOGICAL AND EXPRESSIONS
755
 
756
    This rule describes the logical and expressions.
757
*/
758
 
759
<exp_log_and> : ( :EXP, :EXP ) -> ( :EXP ) ;
760
 
761
logical-and-expression : () -> ( e : EXP ) = {
762
	e = inclusive-or-expression ;
763
    ||
764
	a = logical-and-expression ;
765
	logical-and ; b = inclusive-or-expression ;
766
	e = <exp_log_and> ( a, b ) ;
767
} ;
768
 
769
 
770
/*
771
    LOGICAL OR EXPRESSIONS
772
 
773
    This rule describes the logical or expressions.
774
*/
775
 
776
<exp_log_or> : ( :EXP, :EXP ) -> ( :EXP ) ;
777
 
778
logical-or-expression : () -> ( e : EXP ) = {
779
	e = logical-and-expression ;
780
    ||
781
	a = logical-or-expression ;
782
	logical-or ; b = logical-and-expression ;
783
	e = <exp_log_or> ( a, b ) ;
784
} ;
785
 
786
 
787
/*
788
    CONDITIONAL EXPRESSIONS
789
 
790
    This rule describes the conditional expressions, consisting of the
791
    '?:' operator.
792
*/
793
 
794
<exp_cond> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
795
 
796
conditional-expression : () -> ( e : EXP ) = {
797
	e = logical-or-expression ;
798
    ||
799
	c = logical-or-expression ;
800
	question ; a = expression ;
801
	colon ; b = conditional-expression ;
802
	e = <exp_cond> ( c, a, b ) ;
803
} ;
804
 
805
 
806
/*
807
    ASSIGNMENT EXPRESSIONS
808
 
809
    These rules describe the assignment expressions.  These include both
810
    simple assignment and the 'operate and becomes' operators like '+='.
811
*/
812
 
813
<exp_assign> : ( :EXP, :EXP ) -> ( :EXP ) ;
814
<exp_assign_op> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
815
 
816
assignment-operator : () -> () = {
817
	and-eq ;
818
    ||	div-eq ;
819
    ||	lshift-eq ;
820
    ||	minus-eq ;
821
    ||	or-eq ;
822
    ||	plus-eq ;
823
    ||	rem-eq ;
824
    ||	rshift-eq ;
825
    ||	star-eq ;
826
    ||	xor-eq ;
827
} ;
828
 
829
assignment-expression : () -> ( e : EXP ) = {
830
	e = conditional-expression ;
831
    ||
832
	a = unary-expression ;
833
	assign ; b = assignment-expression ;
834
	e = <exp_assign> ( a, b ) ;
835
    ||
836
	a = unary-expression ;
837
	op = <lex_crt> ; assignment-operator ;
838
	b = assignment-expression ;
839
	e = <exp_assign_op> ( op, a, b ) ;
840
} ;
841
 
842
expression-entry : () -> ( e : EXP ) = {
843
	e = assignment-expression ;
844
    ##
845
	<error_syntax> ;
846
	e = <exp_none> ;
847
} ;
848
 
849
 
850
/*
851
    FLOW ANALYSIS EXPRESSIONS (EXTENSION)
852
 
853
    This rule describes the flow analysis expressions, which are an
854
    extension to the standard syntax.  These consist of the assignment
855
    expressions, plus operations for setting and discarding values.
856
*/
857
 
858
<exp_set> : ( :EXP ) -> ( :EXP ) ;
859
<exp_unused> : ( :EXP ) -> ( :EXP ) ;
860
 
861
flow-expression : () -> ( e : EXP ) = {
862
	set ; open-round ; a = expression ;
863
	e = <exp_set> ( a ) ;
864
	close-round ;
865
    ||
866
	unused ; open-round ; a = expression ;
867
	e = <exp_unused> ( a ) ;
868
	close-round ;
869
} ;
870
 
871
inset-flow-expression : () -> ( e : EXP ) = {
872
	inset-start ; set ; a = expression ;
873
	e = <exp_set> ( a ) ;
874
	inset-end ;
875
    ||
876
	inset-start ; unused ; a = expression ;
877
	e = <exp_unused> ( a ) ;
878
	inset-end ;
879
} ;
880
 
881
inset-flow-statement : () -> ( e : EXP ) = {
882
	inset-start ; set ; a = expression ;
883
	e = <exp_set> ( a ) ;
884
	semicolon ; inset-end ;
885
    ||
886
	inset-start ; unused ; a = expression ;
887
	e = <exp_unused> ( a ) ;
888
	semicolon ; inset-end ;
889
} ;
890
 
891
 
892
/*
893
    EXPRESSIONS
894
 
895
    This rule describes the top level expressions.  These are derived
896
    from the flow-expressions by the addition of the comma operator.
897
*/
898
 
899
<exp_comma> : ( :LIST-EXP ) -> ( :EXP ) ;
900
 
901
comma-expression-head : () -> ( e : EXP ) = {
902
	e = assignment-expression ; comma ;
903
    ||
904
	e = flow-expression ;
905
    ||
906
	e = inset-flow-expression ;
907
} ;
908
 
909
comma-expression-tail : () -> ( p : LIST-EXP ) = {
910
	a = assignment-expression ;
911
	q = <list_exp_null> ;
912
	p = <list_exp_cons> ( a, q ) ;
913
    ||
914
	a = comma-expression-head ; q = comma-expression-tail ;
915
	p = <list_exp_cons> ( a, q ) ;
916
} ;
917
 
918
expression : () -> ( e : EXP ) = {
919
	e = assignment-expression ;
920
    ||
921
	a = comma-expression-head ; q = comma-expression-tail ;
922
	p = <list_exp_cons> ( a, q ) ;
923
	e = <exp_comma> ( p ) ;
924
} ;
925
 
926
 
927
/*
928
    INITIALISER EXPRESSIONS
929
 
930
    An initialiser expression consists of an assignment expression
931
    with all its temporary variables bound to it.
932
*/
933
 
934
initialiser-expression : () -> ( e : EXP ) = {
935
	e = assignment-expression ;
936
} ;
937
 
938
 
939
/*
940
    CONSTANT EXPRESSIONS
941
 
942
    This rule describes the constant expressions.  Lexically these are
943
    identical to the conditional-expressions, but with restrictions on
944
    the permitted operands.  Constant expressions are identified by
945
    evaluation - whenever a valid constant expression is encountered it
946
    is evaluated to give an integer literal expression.
947
*/
948
 
949
<exp_eval> : ( :EXP ) -> ( :EXP ) ;
950
 
951
constant-expression : () -> ( e : EXP ) = {
952
	a = conditional-expression ;
953
	e = <exp_eval> ( a ) ;
954
} ;
955
 
956
 
957
/*
958
    LABELLED STATEMENTS
959
 
960
    This rule describes the labelled statements.  These include the case
961
    and default statements as well as the simple labels.  Note that the
962
    statements following the labels are only the first component of the
963
    label body.  Actually imposing some structure on the labelled statements
964
    is the most difficult part of the statement processing.
965
*/
966
 
967
<stmt_case_begin> : ( :EXP ) -> ( :EXP ) ;
968
<stmt_case_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
969
<stmt_default_begin> : () -> ( :EXP ) ;
970
<stmt_default_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
971
<stmt_label_begin> : ( :IDENTIFIER ) -> ( :EXP ) ;
972
<stmt_label_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
973
<stmt_label_set> : () -> () ;
974
<stmt_label_mod> : () -> () ;
975
<stmt_label_clear> : () -> () ;
976
 
977
statement : () -> ( :EXP ) ;
978
 
979
fall-check : () -> () = {
980
	fall ; <stmt_label_set> ;
981
    ||	fall ; semicolon ; <stmt_label_set> ;
982
    ||	$ ;
983
} ;
984
 
985
labelled-statement : () -> ( e : EXP ) = {
986
	fall-check ;
987
	case ; c = constant-expression ;
988
	a = <stmt_case_begin> ( c ) ;
989
	<stmt_label_set> ;
990
	colon ; b = statement ;
991
	e = <stmt_case_end> ( a, b ) ;
992
    ||
993
	fall-check ;
994
	default ;
995
	a = <stmt_default_begin> ;
996
	<stmt_label_set> ;
997
	colon ; b = statement ;
998
	e = <stmt_default_end> ( a, b ) ;
999
    ||
1000
	id = any-identifier ;
1001
	<stmt_label_mod> ;
1002
	a = <stmt_label_begin> ( id ) ;
1003
	colon ; b = statement ;
1004
	e = <stmt_label_end> ( a, b ) ;
1005
} ;
1006
 
1007
 
1008
/*
1009
    EXPRESSION STATEMENTS
1010
 
1011
    This rule describes the expression statements, consisting of an optional
1012
    expression followed by a semicolon.
1013
*/
1014
 
1015
<stmt_exp> : ( :EXP ) -> ( :EXP ) ;
1016
<stmt_none> : () -> ( :EXP ) ;
1017
<reach_check> : () -> ( :BOOL ) ;
1018
<reach_prev> : ( :BOOL ) -> () ;
1019
 
1020
block-expression : () -> ( e : EXP ) = {
1021
	e = expression ;
1022
    ||	e = flow-expression ;
1023
} ;
1024
 
1025
expression-statement : () -> ( e : EXP ) = {
1026
	a = block-expression ;
1027
	r = <reach_check> ;
1028
	e = <stmt_exp> ( a ) ;
1029
	<stmt_label_clear> ;
1030
	semicolon ;
1031
    ||
1032
	a = inset-flow-statement ;
1033
	r = <reach_check> ;
1034
	e = <stmt_exp> ( a ) ;
1035
	<stmt_label_clear> ;
1036
    ||
1037
	semicolon ;
1038
	e = <stmt_none> ;
1039
} ;
1040
 
1041
 
1042
/*
1043
    COMPOUND STATEMENTS
1044
 
1045
    These rules describe the compound statements, consisting of a list of
1046
    statements enclosed within braces.  Note that compound statements
1047
    automatically define a local scope.
1048
*/
1049
 
1050
<stmt_compound_begin> : () -> ( :EXP ) ;
1051
<stmt_compound_end> : ( :EXP ) -> ( :EXP ) ;
1052
<stmt_compound_add> : ( :EXP, :EXP ) -> ( :EXP ) ;
1053
<stmt_compound_block> : ( :EXP ) -> ( :BOOL ) ;
1054
<stmt_compound_mark> : ( :EXP ) -> () ;
1055
<stmt_return_fall> : () -> ( :EXP ) ;
1056
 
1057
<bool_true> : () -> ( :BOOL ) ;
1058
<bool_false> : () -> ( :BOOL ) ;
1059
 
1060
declaration-statement : ( :BOOL ) -> ( :EXP ) ;
1061
 
1062
statement-seq-opt : ( c : EXP, d : BOOL ) -> ( e : EXP ) = {
1063
	a = statement ;
1064
	b = <stmt_compound_add> ( c, a ) ;
1065
	db = <bool_false> ;
1066
	e = statement-seq-opt ( b, db ) ;
1067
    ||
1068
	a = declaration-statement ( d ) ;
1069
	b = <stmt_compound_add> ( c, a ) ;
1070
	e = statement-seq-opt ( b, d ) ;
1071
    ||
1072
	e = c ;
1073
} ;
1074
 
1075
compound-statement : () -> ( e : EXP ) = {
1076
	c = <stmt_compound_begin> ;
1077
	open-brace ;
1078
	d = <stmt_compound_block> ( c ) ;
1079
	a = statement-seq-opt ( c, d ) ;
1080
	close-brace ;
1081
	e = <stmt_compound_end> ( a ) ;
1082
	<rescan_token> ;
1083
} ;
1084
 
1085
function-body : () -> ( e : EXP ) = {
1086
	c = <stmt_compound_begin> ;
1087
	open-brace ;
1088
	d = <stmt_compound_block> ( c ) ;
1089
	b = statement-seq-opt ( c, d ) ;
1090
	r = <stmt_return_fall> ;
1091
	a = <stmt_compound_add> ( b, r ) ;
1092
	close-brace ;
1093
	e = <stmt_compound_end> ( a ) ;
1094
	<rescan_token> ;
1095
} ;
1096
 
1097
function-definition-entry : () -> ( e : EXP ) = {
1098
	e = function-body ;
1099
    ##
1100
	<error_syntax> ;
1101
	e = <exp_none> ;
1102
} ;
1103
 
1104
 
1105
/*
1106
    LOCAL STATEMENT SCOPES
1107
 
1108
    Several statements, in addition to the compound statements, form local
1109
    scopes (for example, the body of an iteration statement).  This rule
1110
    describes such scopes, the initial scope expression begin passed in as
1111
    c to avoid predicate problems.  Note that local scopes which are also
1112
    compound statements are treated differently from other (simple)
1113
    statements.
1114
*/
1115
 
1116
simple-statement : () -> ( :EXP ) ;
1117
 
1118
scoped-stmt-body : ( c : EXP ) -> ( e : EXP ) = {
1119
	open-brace ;
1120
	d = <stmt_compound_block> ( c ) ;
1121
	e = statement-seq-opt ( c, d ) ;
1122
	close-brace ;
1123
    ||
1124
	a = simple-statement ;
1125
	e = <stmt_compound_add> ( c, a ) ;
1126
} ;
1127
 
1128
scoped-statement : ( c : EXP ) -> ( e : EXP ) = {
1129
	a = scoped-stmt-body ( c ) ;
1130
	e = <stmt_compound_end> ( a ) ;
1131
	<rescan_token> ;
1132
    ##
1133
	<error_syntax> ;
1134
	e = <stmt_compound_end> ( c ) ;
1135
	<rescan_token> ;
1136
} ;
1137
 
1138
 
1139
/*
1140
    DECLARATION STATEMENTS
1141
 
1142
    This rule describes the (non-empty) declaration statements, consisting
1143
    of just a declaration.  See expression-statement for a discussion of
1144
    empty statements.  The look-ahead required to distinguish declaration-
1145
    statements from expression-statements is implemented using the predicate
1146
    is_decl_statement.
1147
*/
1148
 
1149
<is_decl_statement> : ( :BOOL ) -> ( :BOOL ) ;
1150
<stmt_decl> : () -> ( :EXP ) ;
1151
 
1152
declaration : () -> () ;
1153
 
1154
declaration-statement : ( d : BOOL ) -> ( e : EXP ) = {
1155
	? = <is_decl_statement> ( d ) ;
1156
	declaration ;
1157
	e = <stmt_decl> ;
1158
	<stmt_label_clear> ;
1159
} ;
1160
 
1161
 
1162
/*
1163
    TARGET DEPENDENT CONDITIONAL COMPILATIONS
1164
 
1165
    These rules describe the unresolved target dependent conditional
1166
    compilations.  Note that these must be structured, as opposed to the
1167
    normal unstructured preprocessing directives.  Any braces required
1168
    to make the lists of statements in target dependent conditional
1169
    bodies into compound statements are automatically inserted by the
1170
    preprocessor.
1171
*/
1172
 
1173
<stmt_hash_if> : ( :EXP, :EXP ) -> ( :EXP ) ;
1174
<stmt_hash_elif> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1175
<stmt_hash_endif> : ( :EXP, :EXP ) -> ( :EXP ) ;
1176
<cond_hash_if> : ( :EXP ) -> ( :EXP ) ;
1177
<cond_hash_elif> : ( :EXP ) -> () ;
1178
<cond_hash_else> : () -> () ;
1179
<cond_hash_endif> : ( :EXP ) -> () ;
1180
 
1181
target-condition-head : () -> ( e : EXP, p : EXP, r : BOOL ) = {
1182
	c = hash-if ;
1183
	p = <cond_hash_if> ( c ) ;
1184
	r = <reach_check> ;
1185
	a = compound-statement ;
1186
	<reach_prev> ( r ) ;
1187
	e = <stmt_hash_if> ( c, a ) ;
1188
    ||
1189
	( a, p, r ) = target-condition-head ;
1190
	c = hash-elif ;
1191
	<cond_hash_elif> ( c ) ;
1192
	s = <reach_check> ;
1193
	b = compound-statement ;
1194
	<reach_prev> ( r ) ;
1195
	e = <stmt_hash_elif> ( a, c, b ) ;
1196
} ;
1197
 
1198
target-condition : () -> ( e : EXP ) = {
1199
	( a, p, r ) = target-condition-head ;
1200
	{
1201
		hash-else ;
1202
		<cond_hash_else> ;
1203
		s = <reach_check> ;
1204
		b = compound-statement ;
1205
	    ||
1206
		b = <stmt_none> ;
1207
	} ;
1208
	<cond_hash_endif> ( p ) ;
1209
	hash-endif ;
1210
	<reach_prev> ( r ) ;
1211
	e = <stmt_hash_endif> ( a, b ) ;
1212
} ;
1213
 
1214
 
1215
/*
1216
    SELECTION STATEMENTS
1217
 
1218
    These rules describe the selection statements, consisting of the if
1219
    and switch statements, plus the target dependent conditionals above.
1220
    The way that the dangling else problem is dealt with is interesting.
1221
    A simple optional else-block leads to an ambiguity, however an
1222
    exception handler gives precisely what is required.  To paraphrase,
1223
    an if statement always has an associated else, except when it doesn't.
1224
*/
1225
 
1226
<stmt_if_begin> : ( :EXP ) -> ( :EXP ) ;
1227
<stmt_if_cont> : ( :EXP, :EXP ) -> ( :EXP ) ;
1228
<stmt_if_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1229
<stmt_else> : () -> () ;
1230
<stmt_no_else> : () -> ( :EXP ) ;
1231
<stmt_switch_begin> : ( :EXP ) -> ( :EXP ) ;
1232
<stmt_switch_end> : ( :EXP, :EXP, :BOOL ) -> ( :EXP ) ;
1233
 
1234
<condition_get> : () -> ( :CONDITION ) ;
1235
<condition_set> : ( :CONDITION ) -> () ;
1236
 
1237
selection-statement : () -> ( e : EXP ) = {
1238
	if ;
1239
	x = <condition_get> ;
1240
	r = <reach_check> ;
1241
	open-round-x ; c = expression ;
1242
	a = <stmt_if_begin> ( c ) ;
1243
	close-round ;
1244
	bs = <stmt_compound_begin> ;
1245
	b = scoped-statement ( bs ) ;
1246
	<reach_prev> ( r ) ;
1247
	d = <stmt_if_cont> ( a, b ) ;
1248
	{
1249
		else ;
1250
		<stmt_else> ;
1251
		fs = <stmt_compound_begin> ;
1252
		f = scoped-statement ( fs ) ;
1253
	    ##
1254
		f = <stmt_no_else> ;
1255
	} ;
1256
	<reach_prev> ( r ) ;
1257
	e = <stmt_if_end> ( d, f ) ;
1258
	<condition_set> ( x ) ;
1259
	<stmt_label_clear> ;
1260
    ||
1261
	switch ;
1262
	r = <reach_check> ;
1263
	open-round ; c = expression ;
1264
	a = <stmt_switch_begin> ( c ) ;
1265
	close-round ;
1266
	{
1267
		exhaustive ; ex = <bool_true> ;
1268
	    ||	ex = <bool_false> ;
1269
	} ;
1270
	bs = <stmt_compound_begin> ;
1271
	b = scoped-statement ( bs ) ;
1272
	<reach_prev> ( r ) ;
1273
	e = <stmt_switch_end> ( a, b, ex ) ;
1274
	<stmt_label_clear> ;
1275
    ||
1276
	e = target-condition ;
1277
	<stmt_label_clear> ;
1278
} ;
1279
 
1280
 
1281
/*
1282
    ITERATION STATEMENTS
1283
 
1284
    These rules describe the iteration statements, consisting of the
1285
    while, do and for statements.
1286
*/
1287
 
1288
<stmt_while_begin> : ( :EXP ) -> ( :EXP ) ;
1289
<stmt_while_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1290
<stmt_do_begin> : () -> ( :EXP ) ;
1291
<stmt_do_end> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1292
<stmt_for_begin> : () -> ( :EXP ) ;
1293
<stmt_for_init> : ( :EXP, :EXP ) -> ( :EXP ) ;
1294
<stmt_for_cond> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1295
<stmt_for_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1296
<bind_temporary> : ( :EXP ) -> ( :EXP ) ;
1297
<exp_location> : ( :EXP ) -> ( :EXP ) ;
1298
 
1299
for-init-statement : () -> ( e : EXP ) = {
1300
	e = expression-statement ;
1301
} ;
1302
 
1303
for-cond-statement : () -> ( e : EXP ) = {
1304
	{
1305
		a = expression ;
1306
	    ||	a = <exp_none> ;
1307
	} ;
1308
	b = <bind_temporary> ( a ) ;
1309
	e = <exp_location> ( b ) ;
1310
	semicolon ;
1311
} ;
1312
 
1313
for-end-statement : () -> ( e : EXP ) = {
1314
	a = expression ;
1315
	b = <stmt_exp> ( a ) ;
1316
	e = <bind_temporary> ( b ) ;
1317
    ||
1318
	e = <exp_none> ;
1319
} ;
1320
 
1321
iteration-statement : () -> ( e : EXP ) = {
1322
	while ;
1323
	x = <condition_get> ;
1324
	r = <reach_check> ;
1325
	open-round ; c0 = expression ;
1326
	c = <bind_temporary> ( c0 ) ;
1327
	a = <stmt_while_begin> ( c ) ;
1328
	close-round ;
1329
	bs = <stmt_compound_begin> ;
1330
	b = scoped-statement ( bs ) ;
1331
	<reach_prev> ( r ) ;
1332
	e = <stmt_while_end> ( a, b ) ;
1333
	<condition_set> ( x ) ;
1334
	<stmt_label_clear> ;
1335
    ||
1336
	do ;
1337
	x = <condition_get> ;
1338
	r = <reach_check> ;
1339
	a = <stmt_do_begin> ;
1340
	bs = <stmt_compound_begin> ;
1341
	b = scoped-statement ( bs ) ;
1342
	while ; open-round ; c0 = expression ;
1343
	c = <bind_temporary> ( c0 ) ;
1344
	<reach_prev> ( r ) ;
1345
	e = <stmt_do_end> ( a, b, c ) ;
1346
	close-round ;
1347
	<condition_set> ( x ) ;
1348
	<stmt_label_clear> ;
1349
	semicolon-x ;
1350
    ||
1351
	for ;
1352
	x = <condition_get> ;
1353
	r = <reach_check> ;
1354
	open-round ;
1355
	f = <stmt_for_begin> ;
1356
	a = for-init-statement ;
1357
	g = <stmt_for_init> ( f, a ) ;
1358
	c = for-cond-statement ;
1359
	ds = <stmt_compound_begin> ;
1360
	b = for-end-statement ;
1361
	h = <stmt_for_cond> ( g, c, b ) ;
1362
	close-round ;
1363
	<stmt_compound_mark> ( ds ) ;
1364
	d = scoped-statement ( ds ) ;
1365
	<reach_prev> ( r ) ;
1366
	e = <stmt_for_end> ( h, d ) ;
1367
	<condition_set> ( x ) ;
1368
	<stmt_label_clear> ;
1369
	<rescan_token> ;
1370
} ;
1371
 
1372
 
1373
/*
1374
    JUMP STATEMENTS
1375
 
1376
    This rule describes the jump statements, consisting of the break,
1377
    continue, return and goto statements.
1378
*/
1379
 
1380
<stmt_break> : () -> ( :EXP ) ;
1381
<stmt_continue> : () -> ( :EXP ) ;
1382
<stmt_return> : ( :EXP ) -> ( :EXP ) ;
1383
<stmt_goto> : ( :IDENTIFIER ) -> ( :EXP ) ;
1384
<stmt_goto_case> : ( :EXP ) -> ( :EXP ) ;
1385
<stmt_goto_default> : () -> ( :EXP ) ;
1386
 
1387
jump-label : () -> ( e : EXP ) = {
1388
	id = any-identifier ;
1389
	e = <stmt_goto> ( id ) ;
1390
    ||
1391
	case ; c = constant-expression ;
1392
	e = <stmt_goto_case> ( c ) ;
1393
    ||
1394
	default ;
1395
	e = <stmt_goto_default> () ;
1396
} ;
1397
 
1398
jump-statement : () -> ( e : EXP ) = {
1399
	break ;
1400
	r = <reach_check> ;
1401
	e = <stmt_break> ;
1402
	<stmt_label_clear> ;
1403
	semicolon-x ;
1404
    ||
1405
	continue ;
1406
	r = <reach_check> ;
1407
	e = <stmt_continue> ;
1408
	<stmt_label_clear> ;
1409
	semicolon-x ;
1410
    ||
1411
	return ;
1412
	r = <reach_check> ;
1413
	{
1414
		a = expression ;
1415
	    ||	a = <exp_none> ;
1416
	} ;
1417
	e = <stmt_return> ( a ) ;
1418
	<stmt_label_clear> ;
1419
	semicolon-x ;
1420
    ||
1421
	goto ;
1422
	r = <reach_check> ;
1423
	e = jump-label ;
1424
	<stmt_label_clear> ;
1425
	semicolon-x ;
1426
} ;
1427
 
1428
 
1429
/*
1430
    FLOW CONTROL STATEMENTS (EXTENSION)
1431
 
1432
    This rule describes the extensions added to the statements to handle
1433
    flow control and variable analysis commands.
1434
*/
1435
 
1436
<reach_set> : () -> () ;
1437
<reach_unset> : () -> () ;
1438
<stmt_reach> : ( :EXP ) -> ( :EXP ) ;
1439
<stmt_unreach> : ( :EXP ) -> ( :EXP ) ;
1440
 
1441
control-statement : () -> ( e : EXP ) = {
1442
	reachable ; <reach_set> ;
1443
	a = statement ;
1444
	e = <stmt_reach> ( a ) ;
1445
    ||
1446
	unreachable ; <reach_unset> ;
1447
	a = statement ;
1448
	e = <stmt_unreach> ( a ) ;
1449
} ;
1450
 
1451
 
1452
/*
1453
    TOKENISED STATEMENTS
1454
 
1455
    This rule describes the tokenised statements.  This comprises the
1456
    statement names and the complex statements.
1457
*/
1458
 
1459
token-statement : () -> ( e : EXP ) = {
1460
	id = statement-name ;
1461
	a = <exp_identifier> ( id ) ;
1462
	e = <stmt_exp> ( a ) ;
1463
    ||
1464
	a = complex-stmt ;
1465
	e = <stmt_exp> ( a ) ;
1466
} ;
1467
 
1468
 
1469
/*
1470
    ASM DEFINITIONS
1471
 
1472
    This rule describes the asm definitions.  These consist of 'asm' followed
1473
    by a bracketed string literal and a semicolon.
1474
*/
1475
 
1476
<declare_asm> : ( :EXP, :LIST-EXP ) -> ( :EXP ) ;
1477
 
1478
asm-definition : () -> ( e : EXP ) = {
1479
	asm ; open-round ;
1480
	a = string-literal ;
1481
	{
1482
		comma ; p = expression-list ;
1483
	    ||	p = <list_exp_null> ;
1484
	} ;
1485
	e = <declare_asm> ( a, p ) ;
1486
	close-round ;
1487
	semicolon-x ;
1488
} ;
1489
 
1490
 
1491
/*
1492
    STATEMENTS
1493
 
1494
    This rule describes the statements.  These consist of the all the
1495
    types of statements listing above, including the try blocks.
1496
*/
1497
 
1498
simple-statement : () -> ( e : EXP ) = {
1499
	e = labelled-statement ;
1500
    ||	e = expression-statement ;
1501
    ||	e = selection-statement ;
1502
    ||	e = iteration-statement ;
1503
    ||	e = jump-statement ;
1504
    ||	e = control-statement ;
1505
    ||	e = token-statement ;
1506
    ||	e = asm-definition ;
1507
} ;
1508
 
1509
statement : () -> ( e : EXP ) = {
1510
	e = simple-statement ;
1511
    ||	e = compound-statement ;
1512
} ;
1513
 
1514
statement-entry : () -> ( e : EXP ) = {
1515
	e = statement ;
1516
    ##
1517
	<error_syntax> ;
1518
	e = <exp_none> ;
1519
} ;
1520
 
1521
 
1522
/*
1523
    CONST-VOLATILE QUALIFIERS
1524
 
1525
    These rules describe the lists of const and volatile type qualifiers.
1526
*/
1527
 
1528
<cv_none> : () -> ( :CV ) ;
1529
<cv_const> : () -> ( :CV ) ;
1530
<cv_volatile> : () -> ( :CV ) ;
1531
<cv_join> : ( :CV, : CV ) -> ( :CV ) ;
1532
 
1533
cv-qualifier : () -> ( cv : CV ) = {
1534
	const ; cv = <cv_const> ;
1535
    ||	volatile ; cv = <cv_volatile> ;
1536
} ;
1537
 
1538
cv-qualifier-seq : () -> ( cv : CV ) = {
1539
	a = cv-qualifier ;
1540
	{
1541
		cv = a ;
1542
	    ||	b = cv-qualifier-seq ; cv = <cv_join> ( a, b ) ;
1543
	} ;
1544
} ;
1545
 
1546
cv-qualifier-seq-opt : () -> ( cv : CV ) = {
1547
	cv = <cv_none> ;
1548
    ||	cv = cv-qualifier-seq ;
1549
} ;
1550
 
1551
 
1552
/*
1553
    SIMPLE TYPE SPECIFIERS
1554
 
1555
    These rules describe the simple type specifiers.  These comprise the
1556
    type names (class names, enumeration names and typedef names) plus the
1557
    basic type keywords.  size_t and ptrdiff_t have been included for
1558
    future convenience only.  Each simple type specifier gives a partial
1559
    type, which is only completed using type_complete when the entire type
1560
    specifier has been given.
1561
*/
1562
 
1563
<btype_none> : () -> ( :BTYPE ) ;
1564
<btype_char> : () -> ( :BTYPE ) ;
1565
<btype_short> : () -> ( :BTYPE ) ;
1566
<btype_int> : () -> ( :BTYPE ) ;
1567
<btype_long> : () -> ( :BTYPE ) ;
1568
<btype_signed> : () -> ( :BTYPE ) ;
1569
<btype_unsigned> : () -> ( :BTYPE ) ;
1570
<btype_float> : () -> ( :BTYPE ) ;
1571
<btype_double> : () -> ( :BTYPE ) ;
1572
<btype_wchar_t> : () -> ( :BTYPE ) ;
1573
<btype_size_t> : () -> ( :BTYPE ) ;
1574
<btype_ptrdiff_t> : () -> ( :BTYPE ) ;
1575
<btype_void> : () -> ( :BTYPE ) ;
1576
<btype_bottom> : () -> ( :BTYPE ) ;
1577
<btype_join> : ( :BTYPE, :BTYPE ) -> ( :BTYPE ) ;
1578
 
1579
<type_none> : () -> ( :TYPE ) ;
1580
<type_pre> : () -> ( :TYPE ) ;
1581
<type_name> : ( :IDENTIFIER ) -> ( :TYPE ) ;
1582
<type_join> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
1583
<type_complete> : ( :BTYPE, :TYPE, :CV ) -> ( :TYPE ) ;
1584
 
1585
class-specifier : () -> ( :TYPE ) ;
1586
enum-specifier : () -> ( :TYPE ) ;
1587
 
1588
base-type-specifier : () -> ( bt : BTYPE ) = {
1589
	char ; bt = <btype_char> ;
1590
    ||	short ; bt = <btype_short> ;
1591
    ||	int ; bt = <btype_int> ;
1592
    ||	long ; bt = <btype_long> ;
1593
    ||	signed ; bt = <btype_signed> ;
1594
    ||	unsigned ; bt = <btype_unsigned> ;
1595
    ||	float ; bt = <btype_float> ;
1596
    ||	double ; bt = <btype_double> ;
1597
    ||	wchar-t ; bt = <btype_wchar_t> ;
1598
    ||	size-t ; bt = <btype_size_t> ;
1599
    ||	ptrdiff-t ; bt = <btype_ptrdiff_t> ;
1600
    ||	void ; bt = <btype_void> ;
1601
    ||	bottom ; bt = <btype_bottom> ;
1602
} ;
1603
 
1604
type-specifier : () -> ( bt : BTYPE, t : TYPE ) = {
1605
	bt = base-type-specifier ;
1606
	t = <type_pre> ;
1607
    ||
1608
	id = type-name ;
1609
	t = <type_name> ( id ) ;
1610
	bt = <btype_none> ;
1611
    ||
1612
	t = complex-type ;
1613
	bt = <btype_none> ;
1614
    ||
1615
	t = class-specifier ;
1616
	bt = <btype_none> ;
1617
    ||
1618
	t = enum-specifier ;
1619
	bt = <btype_none> ;
1620
} ;
1621
 
1622
 
1623
/*
1624
    CLASS MEMBER SPECIFIERS
1625
 
1626
    These rules describe the class member specifiers.
1627
*/
1628
 
1629
member-declaration : () -> () ;
1630
 
1631
member-specification-opt : () -> () = {
1632
	member-declaration ;
1633
	member-specification-opt ;
1634
    ||
1635
	$ ;
1636
} ;
1637
 
1638
 
1639
/*
1640
    CLASS SPECIFIERS
1641
 
1642
    These rules describe the class (which includes structure and union)
1643
    type specifiers.  These consist of a class key followed by an optional
1644
    class name, a list of base classes, and the class definition body.
1645
    This body consists of a list of member declarations enclosed within
1646
    braces.
1647
*/
1648
 
1649
<type_class_begin> : ( :IDENTIFIER, :KEY ) -> ( :IDENTIFIER, :BOOL ) ;
1650
<type_class_end> : ( :IDENTIFIER, :BOOL ) -> ( :IDENTIFIER ) ;
1651
<type_elaborate> : ( :IDENTIFIER, :KEY ) -> ( :TYPE ) ;
1652
<key_struct> : () -> ( :KEY ) ;
1653
<key_union> : () -> ( :KEY ) ;
1654
<key_enum> : () -> ( :KEY ) ;
1655
 
1656
class-key : () -> ( key : KEY ) = {
1657
    	struct ; key = <key_struct> ;
1658
    ||	union ; key = <key_union> ;
1659
} ;
1660
 
1661
class-specifier : () -> ( t : TYPE ) = {
1662
	key = class-key ;
1663
	{
1664
		id = any-identifier-opt ;
1665
		( p, f ) = <type_class_begin> ( id, key ) ;
1666
		open-brace ; member-specification-opt ; close-brace ;
1667
		tid = <type_class_end> ( p, f ) ;
1668
		t = <type_name> ( tid ) ;
1669
		<rescan_token> ;
1670
	    ||
1671
		id = any-identifier ;
1672
		t = <type_elaborate> ( id, key ) ;
1673
	} ;
1674
} ;
1675
 
1676
 
1677
/*
1678
    ENUMERATION TYPE SPECIFIERS
1679
 
1680
    These rules describe the enumeration type specifiers.  These consist
1681
    of 'enum' followed by an optional identifier and an enumeration
1682
    definition body.  This body consists of a list of enumerator definitions
1683
    enclosed within braces.
1684
*/
1685
 
1686
<error_comma> : () -> () ;
1687
<type_enum_begin> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
1688
<type_enum_end> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
1689
<declarator_begin> : ( :IDENTIFIER ) -> () ;
1690
<declare_enum> : ( :IDENTIFIER, :IDENTIFIER, :EXP ) -> () ;
1691
 
1692
enumerator-definition : ( e : IDENTIFIER ) -> () = {
1693
	id = any-identifier ;
1694
	<declarator_begin> ( id ) ;
1695
	{
1696
		assign ; c = constant-expression ;
1697
	    ||	c = <exp_none> ;
1698
	} ;
1699
	<declare_enum> ( e, id, c ) ;
1700
} ;
1701
 
1702
enumerator-list : ( e : IDENTIFIER ) -> () = {
1703
	enumerator-definition ( e ) ;
1704
	{
1705
		comma ; enumerator-list ( e ) ;
1706
	    ||	comma ; comma ; <error_comma> ; enumerator-list ( e ) ;
1707
	    ||	comma ; <error_comma> ;
1708
	    ||	$ ;
1709
	} ;
1710
} ;
1711
 
1712
enum-specifier : () -> ( t : TYPE ) = {
1713
	enum ;
1714
	{
1715
		id = any-identifier-opt ;
1716
		p = <type_enum_begin> ( id ) ;
1717
		open-brace ;
1718
		{
1719
			enumerator-list ( p ) ;
1720
		    ||	$ ;
1721
		} ;
1722
		close-brace ;
1723
		tid = <type_enum_end> ( p ) ;
1724
		t = <type_name> ( tid ) ;
1725
	    ||
1726
		id = any-identifier ;
1727
		key = <key_enum> ;
1728
		t = <type_elaborate> ( id, key ) ;
1729
	} ;
1730
} ;
1731
 
1732
 
1733
/*
1734
    TYPE SPECIFIERS
1735
 
1736
    These rules describes the type specifiers.  These consist of the simple
1737
    type specifiers, the class definitions, the enumeration definitions,
1738
    the elaborated type specifiers and the const and volatile qualifiers.
1739
    Sequences of these specifiers may be combined into a single partial
1740
    type using type_join.  The partial type is not turned into a real
1741
    type until type_complete is applied to it.
1742
*/
1743
 
1744
<is_type_specifier> : () -> ( :BOOL ) ;
1745
<check_decl_specifier> : () -> () ;
1746
 
1747
type-qualifier : () -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
1748
	( bt, t ) = type-specifier ;
1749
	cv = <cv_none> ;
1750
    ||
1751
	cv = cv-qualifier ;
1752
	bt = <btype_none> ;
1753
	t = <type_none> ;
1754
} ;
1755
 
1756
type-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
1757
	( b1, t1, cv1 ) = type-qualifier ;
1758
	{
1759
		( b2, t2, cv2 ) = type-specifier-seq ;
1760
		bt = <btype_join> ( b1, b2 ) ;
1761
		t = <type_join> ( t1, t2 ) ;
1762
		cv = <cv_join> ( cv1, cv2 ) ;
1763
	    ||
1764
		bt = b1 ;
1765
		t = t1 ;
1766
		cv = cv1 ;
1767
	} ;
1768
} ;
1769
 
1770
check-type-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
1771
	? = <is_type_specifier> ;
1772
	( b1, t1, cv1 ) = type-qualifier ;
1773
	<check_decl_specifier> ;
1774
	{
1775
		( b2, t2, cv2 ) = check-type-specifier-seq ;
1776
		bt = <btype_join> ( b1, b2 ) ;
1777
		t = <type_join> ( t1, t2 ) ;
1778
		cv = <cv_join> ( cv1, cv2 ) ;
1779
	    ||
1780
		bt = b1 ;
1781
		t = t1 ;
1782
		cv = cv1 ;
1783
	} ;
1784
} ;
1785
 
1786
 
1787
/*
1788
    STORAGE CLASS SPECIFIERS
1789
 
1790
    This rule describes the storage class specifiers, including 'typedef'
1791
    as well as the more obvious 'static', 'extern' and so on.  'inline'
1792
    has been added as an extension.
1793
*/
1794
 
1795
<dspec_auto> : () -> ( :DSPEC ) ;
1796
<dspec_extern> : () -> ( :DSPEC ) ;
1797
<dspec_static> : () -> ( :DSPEC ) ;
1798
<dspec_register> : () -> ( :DSPEC ) ;
1799
<dspec_typedef> : () -> ( :DSPEC ) ;
1800
<dspec_inline> : () -> ( :DSPEC ) ;
1801
 
1802
storage-class-specifier : () -> ( ds : DSPEC ) = {
1803
	auto ; ds = <dspec_auto> ;
1804
    ||	extern ; ds = <dspec_extern> ;
1805
    ||	static ; ds = <dspec_static> ;
1806
    ||	register ; ds = <dspec_register> ;
1807
    ||	typedef ; ds = <dspec_typedef> ;
1808
    ||	inline ; ds = <dspec_inline> ;
1809
} ;
1810
 
1811
 
1812
/*
1813
    DECLARATION SPECIFIERS
1814
 
1815
    These rules describes the declaration specifiers.  These consist of
1816
    the type specifiers, the cv-qualifiers, and the storage class
1817
    specifiers.  Like type specifiers, declaration specifiers can be
1818
    formed into lists which are only turned into complete types and
1819
    declaration specifiers later.
1820
*/
1821
 
1822
<dspec_none> : () -> ( :DSPEC ) ;
1823
<dspec_join> : ( :DSPEC, :DSPEC ) -> ( :DSPEC ) ;
1824
<dspec_check> : ( :DSPEC ) -> () ;
1825
 
1826
<is_decl_specifier> : () -> ( :BOOL ) ;
1827
 
1828
decl-specifier : () -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
1829
	ds = storage-class-specifier ;
1830
	<dspec_check> ( ds ) ;
1831
	bt = <btype_none> ;
1832
	t = <type_none> ;
1833
	cv = <cv_none> ;
1834
    ||
1835
	cv = cv-qualifier ;
1836
	bt = <btype_none> ;
1837
	t = <type_none> ;
1838
	ds = <dspec_none> ;
1839
    ||
1840
	( bt, t ) = type-specifier ;
1841
	cv = <cv_none> ;
1842
	ds = <dspec_none> ;
1843
} ;
1844
 
1845
decl-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
1846
	( b1, t1, cv1, ds1 ) = decl-specifier ;
1847
	<check_decl_specifier> ;
1848
	{
1849
		( b2, t2, cv2, ds2 ) = decl-specifier-seq ;
1850
		bt = <btype_join> ( b1, b2 ) ;
1851
		t = <type_join> ( t1, t2 ) ;
1852
		cv = <cv_join> ( cv1, cv2 ) ;
1853
		ds = <dspec_join> ( ds1, ds2 ) ;
1854
	    ||
1855
		bt = b1 ;
1856
		t = t1 ;
1857
		cv = cv1 ;
1858
		ds = ds1 ;
1859
	} ;
1860
} ;
1861
 
1862
check-decl-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
1863
	? = <is_decl_specifier> ;
1864
	( b1, t1, cv1, ds1 ) = decl-specifier ;
1865
	<check_decl_specifier> ;
1866
	{
1867
		( b2, t2, cv2, ds2 ) = check-decl-specifier-seq ;
1868
		bt = <btype_join> ( b1, b2 ) ;
1869
		t = <type_join> ( t1, t2 ) ;
1870
		cv = <cv_join> ( cv1, cv2 ) ;
1871
		ds = <dspec_join> ( ds1, ds2 ) ;
1872
	    ||
1873
		bt = b1 ;
1874
		t = t1 ;
1875
		cv = cv1 ;
1876
		ds = ds1 ;
1877
	} ;
1878
} ;
1879
 
1880
check-decl-specifier-seq-opt : () -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
1881
	( bt, t, cv, ds ) = check-decl-specifier-seq ;
1882
    ||
1883
	bt = <btype_none> ;
1884
	t = <type_none> ;
1885
	cv = <cv_none> ;
1886
	ds = <dspec_none> ;
1887
} ;
1888
 
1889
/*
1890
    POINTER OPERATORS
1891
 
1892
    These rules describe the pointer, reference and pointer to member
1893
    operators.  They build up a partial type, containing the pointer
1894
    information, but not what is pointed to.  This is only filled in later
1895
    by type_inject.  The const and volatile qualified references have been
1896
    included in the grammar, but are weeded out by type_ref.
1897
*/
1898
 
1899
<type_ptr> : ( :CV ) -> ( :TYPE ) ;
1900
 
1901
ptr-operator : () -> ( p : TYPE ) = {
1902
	star ; cv = cv-qualifier-seq-opt ;
1903
	p = <type_ptr> ( cv ) ;
1904
} ;
1905
 
1906
 
1907
/*
1908
    DECLARATORS
1909
 
1910
    These rules describe the declarators.  The rule declarator-aux
1911
    builds up a partial type, containing pointer, array, and other
1912
    type information, but not the base type of what is pointed to etc.
1913
    This base type is provided by the rule declarator and filled in
1914
    using type_inject.
1915
*/
1916
 
1917
<type_array> : ( :EXP ) -> ( :TYPE ) ;
1918
<type_inject> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
1919
<type_build> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
1920
<type_func> : ( :BOOL ) -> ( :TYPE ) ;
1921
<type_func_weak> : ( :BOOL ) -> ( :TYPE ) ;
1922
<type_func_none> : () -> ( :TYPE ) ;
1923
<type_func_old> : () -> ( :TYPE ) ;
1924
 
1925
<declarator_bad> : ( :TYPE ) -> () ;
1926
 
1927
<param_begin> : ( :IDENTIFIER ) -> () ;
1928
<param_end> : () -> () ;
1929
 
1930
declarator-aux : () -> ( :TYPE, :IDENTIFIER ) ;
1931
parameter-declaration-list : () -> ( :BOOL ) ;
1932
parameter-id-list : () -> () ;
1933
 
1934
declarator-tail : ( id : IDENTIFIER ) -> ( t : TYPE ) = {
1935
	open-round ;
1936
	<param_begin> ( id ) ;
1937
	{
1938
		ell = parameter-declaration-list ;
1939
		s = <type_func> ( ell ) ;
1940
		close-round ;
1941
	    ||
1942
		parameter-id-list ;
1943
		s = <type_func_old> ;
1944
		close-round ;
1945
	    ||
1946
		s = <type_func_none> ;
1947
		close-round ;
1948
	} ;
1949
	t = s ;
1950
	<param_end> ;
1951
    ||
1952
	open-square ;
1953
	{
1954
		e = constant-expression ;
1955
	    ||	e = <exp_none> ;
1956
	} ;
1957
	t = <type_array> ( e ) ;
1958
	close-square ;
1959
    ||
1960
	weak ; open-round ;
1961
	<param_begin> ( id ) ;
1962
	{
1963
		ell = parameter-declaration-list ;
1964
	    ||	ell = <bool_false> ;
1965
	} ;
1966
	t = <type_func_weak> ( ell ) ;
1967
	close-round ;
1968
	<param_end> ;
1969
} ;
1970
 
1971
direct-declarator : () -> ( t : TYPE, id : IDENTIFIER ) = {
1972
	id = any-identifier ;
1973
	t = <type_none> ;
1974
	<declarator_begin> ( id ) ;
1975
    ||
1976
	( p, id ) = direct-declarator ;
1977
	q = declarator-tail ( id ) ;
1978
	t = <type_build> ( p, q ) ;
1979
    ||
1980
	open-round ; ( t, id ) = declarator-aux ;
1981
	<declarator_bad> ( t ) ;
1982
	close-round ;
1983
} ;
1984
 
1985
declarator-aux : () -> ( t : TYPE, id : IDENTIFIER ) = {
1986
	( t, id ) = direct-declarator ;
1987
    ||
1988
	p = ptr-operator ; ( q, id ) = declarator-aux ;
1989
	t = <type_build> ( q, p ) ;
1990
} ;
1991
 
1992
declarator : ( p : TYPE ) -> ( t : TYPE, id : IDENTIFIER ) = {
1993
	( q, id ) = declarator-aux ;
1994
	t = <type_inject> ( q, p ) ;
1995
} ;
1996
 
1997
 
1998
/*
1999
    ABSTRACT DECLARATORS
2000
 
2001
    These rules describe the abstract declarators.  These are identical
2002
    to the declarators except that they do not have a declarator-id.
2003
    Also initialisers cannot appear in abstract declarators.
2004
*/
2005
 
2006
abstract-declarator-aux : () -> ( :TYPE ) ;
2007
 
2008
abstract-declarator-tail : () -> ( t : TYPE ) = {
2009
	open-round ;
2010
	id = <id_none> ;
2011
	<param_begin> ( id ) ;
2012
	{
2013
		ell = parameter-declaration-list ;
2014
		s = <type_func> ( ell ) ;
2015
	    ||
2016
		s = <type_func_none> ;
2017
	} ;
2018
	close-round ;
2019
	t = s ;
2020
	<param_end> ;
2021
    ||
2022
	open-square ;
2023
	{
2024
		e = constant-expression ;
2025
	    ||	e = <exp_none> ;
2026
	} ;
2027
	t = <type_array> ( e ) ;
2028
	close-square ;
2029
    ||
2030
	weak ; open-round ;
2031
	id = <id_none> ;
2032
	<param_begin> ( id ) ;
2033
	{
2034
		ell = parameter-declaration-list ;
2035
	    ||	ell = <bool_false> ;
2036
	} ;
2037
	t = <type_func_weak> ( ell ) ;
2038
	close-round ;
2039
	<param_end> ;
2040
} ;
2041
 
2042
direct-abstract-declarator : () -> ( t : TYPE ) = {
2043
	t = abstract-declarator-tail ;
2044
    ||
2045
	p = direct-abstract-declarator ;
2046
	q = abstract-declarator-tail ;
2047
	t = <type_build> ( p, q ) ;
2048
    ||
2049
	open-round ; t = abstract-declarator-aux ;
2050
	<declarator_bad> ( t ) ;
2051
	close-round ;
2052
} ;
2053
 
2054
abstract-declarator-aux : () -> ( t : TYPE ) = {
2055
	t = direct-abstract-declarator ;
2056
    ||
2057
	t = ptr-operator ;
2058
    ||
2059
	p = ptr-operator ; q = abstract-declarator-aux ;
2060
	t = <type_build> ( q, p ) ;
2061
} ;
2062
 
2063
abstract-declarator-opt : ( p : TYPE ) -> ( t : TYPE ) = {
2064
	q = abstract-declarator-aux ;
2065
	t = <type_inject> ( q, p ) ;
2066
    ||
2067
	t = p ;
2068
} ;
2069
 
2070
 
2071
/*
2072
    PARAMETER DECLARATOR
2073
 
2074
    A parameter declarator can be a declarator, an abstract-declarator or
2075
    be empty.  The easiest way to do this is as a separate set of rules.
2076
    A predicate is necessary to distinguish declarator-ids from type names.
2077
*/
2078
 
2079
<is_parameter> : () -> ( :BOOL ) ;
2080
 
2081
parameter-declarator-aux : () -> ( :TYPE, :IDENTIFIER ) ;
2082
parameter-declarator-aux-opt : () -> ( :TYPE, :IDENTIFIER ) ;
2083
 
2084
direct-parameter-declarator : () -> ( t : TYPE, id : IDENTIFIER ) = {
2085
	? = <is_parameter> ;
2086
	id = any-identifier ;
2087
	t = <type_none> ;
2088
	<declarator_begin> ( id ) ;
2089
    ||
2090
	( p, id ) = direct-parameter-declarator ;
2091
	q = abstract-declarator-tail ;
2092
	t = <type_build> ( p, q ) ;
2093
    ||
2094
	t = abstract-declarator-tail ;
2095
	id = <id_anon> ;
2096
	<declarator_begin> ( id ) ;
2097
    ||
2098
	open-round ;
2099
	( t, id ) = parameter-declarator-aux ;
2100
	<declarator_bad> ( t ) ;
2101
	close-round ;
2102
} ;
2103
 
2104
parameter-declarator-aux : () -> ( t : TYPE, id : IDENTIFIER ) = {
2105
	( t, id ) = direct-parameter-declarator ;
2106
    ||
2107
	p = ptr-operator ;
2108
	( q, id ) = parameter-declarator-aux-opt ;
2109
	t = <type_build> ( q, p ) ;
2110
} ;
2111
 
2112
parameter-declarator-aux-opt : () -> ( t : TYPE, id : IDENTIFIER ) = {
2113
	( t, id ) = parameter-declarator-aux ;
2114
    ||
2115
	t = <type_none> ;
2116
	id = <id_anon> ;
2117
	<declarator_begin> ( id ) ;
2118
} ;
2119
 
2120
parameter-declarator-opt : ( p : TYPE ) -> ( t : TYPE, id : IDENTIFIER ) = {
2121
	( q, id ) = parameter-declarator-aux-opt ;
2122
	t = <type_inject> ( q, p ) ;
2123
} ;
2124
 
2125
 
2126
/*
2127
    FUNCTION PARAMETER DECLARATIONS
2128
 
2129
    These rules describe the function parameter declarations.  The rules
2130
    differ slightly from those given in the standard, which was clearly
2131
    not written with LL(1) parsers in mind, but are equivalent.
2132
*/
2133
 
2134
<dspec_complete> : ( :BTYPE, :TYPE, :CV, :DSPEC ) -> ( :TYPE, :DSPEC ) ;
2135
<declare_param> : ( :DSPEC, :TYPE, :IDENTIFIER ) -> ( :DECL ) ;
2136
<decl_none> : () -> ( :DECL ) ;
2137
 
2138
parameter-declaration : () -> ( d : DECL ) = {
2139
	( bt, t1, cv, ds1 ) = decl-specifier-seq ;
2140
	( t2, ds ) = <dspec_complete> ( bt, t1, cv, ds1 ) ;
2141
	( t, id ) = parameter-declarator-opt ( t2 ) ;
2142
	d = <declare_param> ( ds, t, id ) ;
2143
} ;
2144
 
2145
parameter-declaration-list : () -> ( ell : BOOL ) = {
2146
	ellipsis ;
2147
	ell = <bool_true> ;
2148
    ||
2149
	d = parameter-declaration ;
2150
	{
2151
		comma ;
2152
		ell = parameter-declaration-list ;
2153
	    ||
2154
		ell = <bool_false> ;
2155
	} ;
2156
} ;
2157
 
2158
parameter-entry : ( s : TYPE, p : NUMBER ) -> ( d : DECL ) = {
2159
	d = parameter-declaration ;
2160
    ##
2161
	<error_syntax> ;
2162
	d = <decl_none> ;
2163
} ;
2164
 
2165
template-type-param : () -> ( d : DECL ) = {
2166
	<error_syntax> ;
2167
	d = <decl_none> ;
2168
} ;
2169
 
2170
 
2171
/*
2172
    NON-PROTOTYPE PARAMETER LISTS
2173
 
2174
    This rules describes the list of function parameter names which
2175
    occur in a non-prototype function definition.
2176
*/
2177
 
2178
<declare_weak_param> : ( :IDENTIFIER ) -> () ;
2179
<declarator_weak> : ( :IDENTIFIER ) -> () ;
2180
 
2181
first-parameter-id : () -> ( id : IDENTIFIER ) = {
2182
	id = identifier ;
2183
    ||	id = statement-name ;
2184
} ;
2185
 
2186
second-parameter-id : () -> ( id : IDENTIFIER ) = {
2187
	id = first-parameter-id ;
2188
    ||	id = type-name ; <declarator_weak> ( id ) ;
2189
} ;
2190
 
2191
parameter-id-tail : () -> () = {
2192
	comma ; id = second-parameter-id ;
2193
	<declarator_begin> ( id ) ;
2194
	<declare_weak_param> ( id ) ;
2195
	parameter-id-tail ;
2196
    ||
2197
	$ ;
2198
} ;
2199
 
2200
parameter-id-list : () -> () = {
2201
	id = first-parameter-id ;
2202
	<declarator_begin> ( id ) ;
2203
	<declare_weak_param> ( id ) ;
2204
	parameter-id-tail ;
2205
} ;
2206
 
2207
 
2208
/*
2209
    TYPE IDENTIFIERS
2210
 
2211
    This rule describes the type identifiers.  There is a predicate to
2212
    distinguish type identifiers from expressions in, for example, sizeof
2213
    expressions.  A count of the number of types defined in the type
2214
    identifier is maintained.
2215
*/
2216
 
2217
<is_type_id_false> : () -> ( :BOOL ) ;
2218
<is_type_id_true> : () -> ( :BOOL ) ;
2219
<type_bitfield> : ( :TYPE, :BTYPE, :EXP ) -> ( :TYPE ) ;
2220
<type_check> : ( :TYPE ) -> () ;
2221
 
2222
type-id : () -> ( t : TYPE, n : COUNT ) = {
2223
	n1 = <no_type_defns> ;
2224
	( bt, p, cv ) = type-specifier-seq ;
2225
	q = <type_complete> ( bt, p, cv ) ;
2226
	t = abstract-declarator-opt ( q ) ;
2227
	n = <diff_type_defns> ( n1 ) ;
2228
	<type_check> ( t ) ;
2229
} ;
2230
 
2231
type-id-false : () -> ( t : TYPE, n : COUNT ) = {
2232
	? = <is_type_id_false> ;
2233
	( t, n ) = type-id ;
2234
} ;
2235
 
2236
type-id-true : () -> ( t : TYPE, n : COUNT ) = {
2237
	? = <is_type_id_true> ;
2238
	( t, n ) = type-id ;
2239
} ;
2240
 
2241
token-type-id : () -> ( t : TYPE ) = {
2242
	( bt, p, cv ) = type-specifier-seq ;
2243
	q = <type_complete> ( bt, p, cv ) ;
2244
	t = abstract-declarator-opt ( q ) ;
2245
} ;
2246
 
2247
member-type-id : () -> ( t : TYPE ) = {
2248
	( bt, p, cv ) = type-specifier-seq ;
2249
	q = <type_complete> ( bt, p, cv ) ;
2250
	{
2251
		t = abstract-declarator-opt ( q ) ;
2252
	    ||
2253
		rem ;
2254
		c = constant-expression ;
2255
		t = <type_bitfield> ( q, bt, c ) ;
2256
	} ;
2257
} ;
2258
 
2259
type-id-entry : () -> ( t : TYPE ) = {
2260
	t = token-type-id ;
2261
	<type_check> ( t ) ;
2262
    ##
2263
	<error_syntax> ;
2264
	t = <type_none> ;
2265
} ;
2266
 
2267
 
2268
/*
2269
    INITIALISERS
2270
 
2271
    These rules describe the initialisers.  This includes the assignment
2272
    style and aggregate initialisers.
2273
*/
2274
 
2275
<exp_aggregate> : ( :LIST-EXP ) -> ( :EXP ) ;
2276
 
2277
initialiser-clause : ( :DECL ) -> ( :EXP ) ;
2278
 
2279
initialiser-list : ( d : DECL ) -> ( p : LIST-EXP ) = {
2280
	b = initialiser-clause ( d ) ;
2281
	a = <exp_location> ( b ) ;
2282
	{
2283
		comma ; q = initialiser-list ( d ) ;
2284
	    ||	comma ; q = <list_exp_null> ;
2285
	    ||	q = <list_exp_null> ;
2286
	} ;
2287
	p = <list_exp_cons> ( a, q ) ;
2288
} ;
2289
 
2290
initialiser-clause : ( d : DECL ) -> ( e : EXP ) = {
2291
	e = initialiser-expression ;
2292
    ||
2293
	open-brace ;
2294
	{
2295
		p = initialiser-list ( d ) ;
2296
	    ||	p = <list_exp_null> ;
2297
	} ;
2298
	close-brace ;
2299
	e = <exp_aggregate> ( p ) ;
2300
} ;
2301
 
2302
initialiser-opt : ( d : DECL ) -> ( e : EXP ) = {
2303
	assign ; e = initialiser-clause ( d ) ;
2304
    ||
2305
	e = <exp_none> ;
2306
} ;
2307
 
2308
initialiser-entry : ( d : DECL ) -> ( e : EXP ) = {
2309
	e = initialiser-clause ( d ) ;
2310
    ##
2311
	<error_syntax> ;
2312
	e = <exp_none> ;
2313
} ;
2314
 
2315
 
2316
/*
2317
    INITIALISATION DECLARATORS
2318
 
2319
    These rules describe the declarators with initialisers.  In fact the
2320
    first element in any init-declarator-list is handled separately in the
2321
    rule declaration.  See above for the handling of function style
2322
    initialisers.
2323
*/
2324
 
2325
<declare_id> : ( :DSPEC, :BTYPE, :TYPE, :IDENTIFIER ) -> ( :DECL ) ;
2326
<initialise_id> : ( :DECL, :EXP ) -> () ;
2327
 
2328
init-declarator : ( ds : DSPEC, bt : BTYPE, p : TYPE ) -> () = {
2329
	( t, id ) = declarator ( p ) ;
2330
	d = <declare_id> ( ds, bt, t, id ) ;
2331
	e = initialiser-opt ( d ) ;
2332
	<initialise_id> ( d, e ) ;
2333
} ;
2334
 
2335
init-declarator-list : ( ds : DSPEC, bt : BTYPE, t : TYPE ) -> () = {
2336
	init-declarator ( ds, bt, t ) ;
2337
	{
2338
		comma ;
2339
		init-declarator-list ( ds, bt, t ) ;
2340
	    ||
2341
		$ ;
2342
	} ;
2343
} ;
2344
 
2345
 
2346
/*
2347
    TARGET DEPENDENT DECLARATION SEQUENCES
2348
 
2349
    These rules describe the unresolved target dependent conditional
2350
    declarations.  See target-condition for details.  The '#pragma'
2351
    directives are included in this rule for convenience.
2352
*/
2353
 
2354
<decl_hash_if> : ( :EXP ) -> () ;
2355
<decl_hash_elif> : ( :EXP ) -> () ;
2356
<decl_hash_else> : () -> () ;
2357
<decl_hash_endif> : () -> () ;
2358
 
2359
declaration-seq-opt : () -> () ;
2360
 
2361
declaration-cond-body : () -> () = {
2362
	open-brace ;
2363
	ds = <dspec_none> ;
2364
	t = <type_none> ;
2365
	declaration-seq-opt () ;
2366
	close-brace ;
2367
} ;
2368
 
2369
declaration-cond-head : () -> ( p : EXP ) = {
2370
	c = hash-if ;
2371
	p = <cond_hash_if> ( c ) ;
2372
	<decl_hash_if> ( c ) ;
2373
	declaration-cond-body ;
2374
    ||
2375
	p = declaration-cond-head ;
2376
	c = hash-elif ;
2377
	<cond_hash_elif> ( c ) ;
2378
	<decl_hash_elif> ( c ) ;
2379
	declaration-cond-body ;
2380
} ;
2381
 
2382
declaration-cond : () -> () = {
2383
	p = declaration-cond-head ;
2384
	{
2385
		hash-else ;
2386
		<cond_hash_else> ;
2387
		<decl_hash_else> ;
2388
		declaration-cond-body ;
2389
	    ||
2390
		$ ;
2391
	} ;
2392
	<cond_hash_endif> ( p ) ;
2393
	hash-endif ;
2394
	<decl_hash_endif> ;
2395
    ||
2396
	hash-pragma ;
2397
} ;
2398
 
2399
 
2400
/*
2401
    SEQUENCES OF DECLARATIONS
2402
 
2403
    These rules describe the declaration sequences, consisting of a simple
2404
    list of declarations.
2405
*/
2406
 
2407
<declare_extern> : ( :EXP ) -> () ;
2408
<declare_empty> : () -> () ;
2409
 
2410
external-declaration : () -> ( :EXP ) ;
2411
 
2412
declaration-elem : () -> () = {
2413
	e = external-declaration ;
2414
	<declare_extern> ( e ) ;
2415
    ||
2416
	declaration-cond ;
2417
    ||
2418
	semicolon ;
2419
	<declare_empty> ;
2420
} ;
2421
 
2422
declaration-seq-opt : () -> () = {
2423
	declaration-elem ;
2424
	declaration-seq-opt ;
2425
    ||
2426
	$ ;
2427
} ;
2428
 
2429
 
2430
/*
2431
    DECLARATIONS
2432
 
2433
    This rule describes the declarations.
2434
*/
2435
 
2436
<declare_id_empty> : ( :DSPEC, :BTYPE, :TYPE, :CV ) -> () ;
2437
 
2438
declaration : () -> () = {
2439
	( bt, t1, cv, ds1 ) = check-decl-specifier-seq ;
2440
	{
2441
		( t, ds ) = <dspec_complete> ( bt, t1, cv, ds1 ) ;
2442
		init-declarator-list ( ds, bt, t ) ;
2443
	    ||
2444
		<declare_id_empty> ( ds1, bt, t1, cv ) ;
2445
	} ;
2446
	semicolon ;
2447
} ;
2448
 
2449
declaration-entry : ( t : TYPE, ds : DSPEC ) -> () = {
2450
	declaration ;
2451
    ##
2452
	<error_syntax> ;
2453
} ;
2454
 
2455
 
2456
/*
2457
    EXTERNAL DECLARATIONS
2458
 
2459
    This rule describes the external declarations.  Note that the normal
2460
    declaration rule has been unrolled once to allow it to be combined
2461
    with the function-definition rule.
2462
*/
2463
 
2464
<is_function> : ( :TYPE ) -> ( :BOOL ) ;
2465
<define_func> : ( :DSPEC, :TYPE, :IDENTIFIER ) -> ( :DECL ) ;
2466
<function_begin> : ( :DECL ) -> ( :BOOL ) ;
2467
<function_end> : ( :DECL, :EXP, :BOOL ) -> () ;
2468
 
2469
external-declaration : () -> ( e : EXP ) = {
2470
	( bt, t1, cv, ds1 ) = check-decl-specifier-seq-opt ;
2471
	( t, ds ) = <dspec_complete> ( bt, t1, cv, ds1 ) ;
2472
	( s, id ) = declarator ( t ) ;
2473
	{
2474
		d = <declare_id> ( ds, bt, s, id ) ;
2475
		a = initialiser-opt ( d ) ;
2476
		<initialise_id> ( d, a ) ;
2477
		{
2478
			comma ;
2479
			init-declarator-list ( ds, bt, t ) ;
2480
		    ||
2481
			$ ;
2482
		} ;
2483
		semicolon ;
2484
	    ||
2485
		? = <is_function> ( s ) ;
2486
		d = <define_func> ( ds, s, id ) ;
2487
		b = <function_begin> ( d ) ;
2488
		a = function-body ;
2489
		<function_end> ( d, a, b ) ;
2490
		<rescan_token> ;
2491
	} ;
2492
	e = <exp_none> ;
2493
    ||
2494
	( bt, t, cv, ds ) = check-decl-specifier-seq ;
2495
	<declare_id_empty> ( ds, bt, t, cv ) ;
2496
	semicolon ;
2497
	e = <exp_none> ;
2498
    ||
2499
	e = asm-definition ;
2500
} ;
2501
 
2502
 
2503
/*
2504
    CLASS MEMBER DECLARATORS
2505
 
2506
    These rules describe the class member declarators.  Note that the
2507
    rule member-specifier-opt is intended to handle both pure-specifier
2508
    and constant-initialiser.  Also two types are passed into these
2509
    rules, one reflecting the declaration type and the other the sequence
2510
    of type-specifiers used to describe this type.  This is because
2511
    in bitfields 'signed int' is not synonomous with 'int'.
2512
*/
2513
 
2514
<declare_member> : ( :TYPE, :IDENTIFIER ) -> () ;
2515
<declare_bitfield> : ( :TYPE, :IDENTIFIER ) -> () ;
2516
<type_bitfield_mem> : ( :TYPE, :BTYPE, :EXP, :IDENTIFIER ) -> ( :TYPE ) ;
2517
 
2518
member-declarator : ( p : TYPE, q : BTYPE ) -> () = {
2519
	( t, id ) = declarator ( p ) ;
2520
	<declare_member> ( t, id ) ;
2521
    ||
2522
	id = any-identifier-opt ;
2523
	<declarator_begin> ( id ) ;
2524
	colon ; c = constant-expression ;
2525
	t = <type_bitfield_mem> ( p, q, c, id ) ;
2526
	<declare_bitfield> ( t, id ) ;
2527
} ;
2528
 
2529
member-declarator-list : ( p : TYPE, q : BTYPE ) -> () = {
2530
	member-declarator ( p, q ) ;
2531
	{
2532
		comma ;
2533
		member-declarator-list ( p, q ) ;
2534
	    ||
2535
		$ ;
2536
	} ;
2537
} ;
2538
 
2539
 
2540
/*
2541
    CLASS MEMBER DECLARATION
2542
 
2543
    This rule describes the class memeber declarations.
2544
*/
2545
 
2546
<declare_member_empty> : ( :BTYPE, :TYPE, :CV ) -> () ;
2547
 
2548
member-declaration : () -> () = {
2549
	( bt, p, cv ) = check-type-specifier-seq ;
2550
	t = <type_complete> ( bt, p, cv ) ;
2551
	member-declarator ( t, bt ) ;
2552
	{
2553
		semicolon ;
2554
	    ||
2555
		comma ;
2556
		member-declarator-list ( t, bt ) ;
2557
		semicolon ;
2558
	} ;
2559
    ||
2560
	( bt, p, cv ) = check-type-specifier-seq ;
2561
	<declare_member_empty> ( bt, p, cv ) ;
2562
	semicolon ;
2563
} ;
2564
 
2565
 
2566
/*
2567
    TRANSLATION UNITS
2568
 
2569
    This is the main entry point for the grammar.  A translation unit
2570
    consists of a (possibly empty) sequence of declarations, followed
2571
    by the end of the file.
2572
*/
2573
 
2574
translation-unit : ( t : TYPE, ds : DSPEC ) -> () = {
2575
	declaration-seq-opt ; eof ;
2576
    ##
2577
	<error_fatal> ;
2578
} ;
2579
 
2580
 
2581
/*
2582
    CONDITIONAL COMPILATION CONSTANTS
2583
 
2584
    This rule is the alternative entry point for the conditions following
2585
    #if and #elif preprocessing directives.  It consists of a constant
2586
    expression.  The end of line marker which follows this expression is
2587
    handled by the calling routine.
2588
*/
2589
 
2590
hash-if-expression : () -> ( e : EXP ) = {
2591
	e = constant-expression ;
2592
    ##
2593
	<error_syntax> ;
2594
	e = <exp_none> ;
2595
} ;
2596
 
2597
 
2598
/*
2599
    CONSTANT MEMBER DESIGNATORS
2600
 
2601
    These rules describe the constant member offsets.  The entry point
2602
    constant-offset is used for reading member token definitions.
2603
*/
2604
 
2605
<offset_nspace> : ( :TYPE ) -> ( :NAMESPACE ) ;
2606
<offset_index> : ( :OFFSET, :TYPE, :EXP ) -> ( :OFFSET, :TYPE ) ;
2607
<offset_member> : ( :OFFSET, :TYPE, :IDENTIFIER, :NAMESPACE ) -> ( :OFFSET, :TYPE ) ;
2608
 
2609
member-designator : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
2610
	ns = <offset_nspace> ( s ) ;
2611
	<rescan_token> ;
2612
	id = field-id-expression ( ns ) ;
2613
	( a, t ) = <offset_member> ( b, s, id, ns ) ;
2614
	<rescan_token> ;
2615
} ;
2616
 
2617
designator : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
2618
	dot ; ( a, t ) = member-designator ( b, s ) ;
2619
    ||
2620
	open-square ; e = constant-expression ;
2621
	( a, t ) = <offset_index> ( b, s, e ) ;
2622
	close-square ;
2623
} ;
2624
 
2625
designator-list : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
2626
	( a, t ) = designator ( b, s ) ;
2627
    ||
2628
	( c, u ) = designator-list ( b, s ) ;
2629
	( a, t ) = designator ( c, u ) ;
2630
} ;
2631
 
2632
constant-offset : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
2633
	( c, u ) = member-designator ( b, s ) ;
2634
	{
2635
		a = c ;
2636
		t = u ;
2637
	    ||
2638
		( a, t ) = designator-list ( c, u ) ;
2639
	} ;
2640
    ##
2641
	<error_syntax> ;
2642
	a = b ;
2643
	t = s ;
2644
} ;
2645
 
2646
 
2647
/*
2648
    ENTRY POINTS
2649
 
2650
    There are a large number of entry points for the grammar, the main
2651
    one being translation-unit, with others for expressions, types etc.
2652
*/
2653
 
2654
%entry% translation-unit, expression-entry, function-definition-entry,
2655
	declaration-entry, id-entry, operator-id, type-id-entry,
2656
	token-type-id, member-type-id, parameter-entry, statement-entry,
2657
	initialiser-entry, hash-if-expression, template-type-param,
2658
	constant-offset ;