Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997, 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
ACCESS ;
49
ACCESSES ;
50
BOOL ;
51
BTYPE ;
52
CONDITION ;
53
COUNT ;
54
CV ;
55
DECL ;
56
DSPEC ;
57
EXP ;
58
IDENTIFIER ;
59
KEY ;
60
LEX ;
61
LINKAGE ;
62
LIST-EXP ;
63
LIST-TYPE ;
64
NAMESPACE ;
65
NUMBER ;
66
OFFSET ;
67
QUALIFIER ;
68
TEMPLATE ;
69
TYPE ;
70
 
71
 
72
/*
73
    LIST OF TERMINALS
74
 
75
    This list of terminals corresponds to that given in symbols.h and
76
    psyntax.h.
77
*/
78
 
79
%terminals%
80
 
81
!unknown ;
82
 
83
/* Identifiers */
84
identifier : () -> ( :IDENTIFIER ) ;
85
type-name : () -> ( :IDENTIFIER ) ;
86
namespace-name : () -> ( :IDENTIFIER ) ;
87
statement-name : () -> ( :IDENTIFIER ) ;
88
destructor-name : () -> ( :IDENTIFIER ) ;
89
template-id : () -> ( :IDENTIFIER ) ;
90
template-type : () -> ( :IDENTIFIER ) ;
91
 
92
/* Nested name specifiers */
93
nested-name : () -> ( :NAMESPACE ) ;
94
full-name : () -> ( :NAMESPACE ) ;
95
nested-name-star : () -> ( :IDENTIFIER ) ;
96
full-name-star : () -> ( :IDENTIFIER ) ;
97
 
98
/* Literals */
99
!char-lit ; !wchar-lit ; !string-lit ; !wstring-lit ; !integer-lit ;
100
 
101
/* Literal expressions */
102
char-exp : () -> ( :EXP ) ;
103
wchar-exp : () -> ( :EXP ) ;
104
string-exp : () -> ( :EXP ) ;
105
wstring-exp : () -> ( :EXP ) ;
106
integer-exp : () -> ( :EXP ) ;
107
floating-exp : () -> ( :EXP ) ;
108
 
109
/* Token applications */
110
complex-exp : () -> ( :EXP ) ;
111
complex-stmt : () -> ( :EXP ) ;
112
complex-type : () -> ( :TYPE ) ;
113
 
114
/* Target-dependent preprocessing directives */
115
hash-if : () -> ( :EXP ) ;
116
hash-elif : () -> ( :EXP ) ;
117
hash-else ;
118
hash-endif ;
119
hash-pragma ;
120
 
121
/* End of file markers */
122
!newline ; eof ;
123
 
124
/* Symbols */
125
and-1 ; and-eq-1 ; arrow ; assign ; !backslash ; close-brace-1 ;
126
close-round ; close-square-1 ; colon ; comma ; compl-1 ; div ; div-eq ;
127
dot ; ellipsis ; eq ; greater ; greater-eq ; !hash-1 ; !hash-hash-1 ;
128
less ; less-eq ; logical-and-1 ; logical-or-1 ; lshift ; lshift-eq ;
129
minus ; minus-eq ; minus-minus ; not-1 ; not-eq-1 ; open-brace-1 ;
130
open-round ; open-square-1 ; or-1 ; or-eq-1 ; plus ; plus-eq ; plus-plus ;
131
question ; rem ; rem-eq ; rshift ; rshift-eq ; semicolon ; star ;
132
star-eq ; xor-1 ; xor-eq-1 ; arrow-star ; colon-colon ; dot-star ; abs ;
133
max ; min ;
134
 
135
/* Digraphs */
136
!close-brace-2 ; !close-square-2 ; !hash-2 ; !hash-hash-2 ;
137
!open-brace-2 ; !open-square-2 ;
138
 
139
/* C keywords */
140
auto ; break ; case ; char ; const ; continue ; default ; do ; double ;
141
else ; enum ; extern ; float ; for ; goto ; if ; int ; long ; register ;
142
return ; short ; signed ; sizeof ; static ; struct ; switch ; typedef ;
143
union ; unsigned ; void ; volatile ; while ;
144
 
145
/* C++ keywords */
146
asm ; bool ; catch ; class ; const-cast ; delete ; dynamic-cast ;
147
explicit ; export ; false ; friend ; inline ; mutable ; namespace ; new ;
148
operator ; private ; protected ; public ; reinterpret-cast ;
149
static-cast ; template ; this ; throw ; true ; try ; typeid ; typename ;
150
using ; virtual ; wchar-t ;
151
 
152
/* ISO keywords */
153
!and-2 ; !and-eq-2 ; !compl-2 ; !logical-and-2 ; !logical-or-2 ;
154
!not-2 ; !not-eq-2 ; !or-2 ; !or-eq-2 ; !xor-2 ; !xor-eq-2 ;
155
 
156
/* TenDRA keywords */
157
!accept ; !after ; alignof ; !all ; !allow ; !ambiguous ; !analysis ;
158
!argument ; !arith-cap ; !array ; !as ; !assert ; !assignment ; !begin ;
159
!bitfield ; !block ; bottom ; !cast ; !character ; !class-cap ; !code ;
160
!comment ; !compatible ; !complete ; !compute ; !conditional ;
161
!conversion ; !decimal ; !decl ; !define ; !define-cap ; !defined ;
162
!definition ; !depth ; !directive ; !directory ; !disallow ; discard ;
163
!dollar ; !either ; !elif ; ellipsis-exp ; !end ; !endif ; !environment ;
164
!equality ; !error ; !escape ; exhaustive ; !exp-cap ; !explain ;
165
!extend ; !external ; !extra ; fall ; !file ; !float-cap ; !forward ;
166
!func-cap ; !function ; !hexadecimal ; !hiding ; !ident ; !identif ;
167
!ifdef ; !ifndef ; !ignore ; !implement ; !implicit ; !import ; !include ;
168
!includes ; !include-next ; !incompatible ; !incomplete ; !indented ;
169
!initialization ; !integer ; !interface ; !internal ; !into ; !int-cap ;
170
!keyword ; !limit ; !line ; !linkage ; !lit ; !longlong ; !lvalue ;
171
!macro ; !main ; !member ; !member-cap ; !name ; !nat-cap ; !nested ;
172
!nline ; !no ; !no-def ; !object ; !octal ; !of ; !off ; !on ; !option ;
173
!overflow ; overload ; !pointer ; !postpone ; !pragma ; !precedence ;
174
!preserve ; !printf ; !proc-cap ; !promote ; !promoted ; !prototype ;
175
ptrdiff-t ; !qualifier ; !quote ; reachable ; !reference ; !reject ;
176
!representation ; !reset ; !resolution ; !rvalue ; !scalar-cap ; !scanf ;
177
set ; size-t ; !size-t-2 ; !sort ; !std ; !stmt-cap ; !string ;
178
!struct-cap ; !suspend ; !tag ; !tag-cap ; !tendra ; !text ; !this-name ;
179
!token ; !type ; !type-cap ; !typeof ; !un-known ; !unassert ; !undef ;
180
!unify ; !union-cap ; !unmatched ; !unpostpone ; unreachable ; unused ;
181
!use ; !value ; !variable ; !variety-cap ; !volatile-t ; vtable ;
182
!warning ; weak ; !writeable ; !zzzz ;
183
 
184
/* Miscellaneous symbols */
185
!array-op ; !builtin-file ; !builtin-line ; !close-template ; !cond-op ;
186
!delete-full ; !delete-array ; !delete-array-full ; !func-op ; !hash-op ;
187
!hash-hash-op ; inset-start ; inset-end ; !macro-arg ; !new-full ;
188
!new-array ; !new-array-full ; !open-init ; !open-template ; !zzzzzz ;
189
 
190
 
191
/*
192
    ALTERNATIVE REPRESENTATIONS
193
 
194
    The ISO keywords and digraphs will have been replaced by their primary
195
    representations by this stage.  These rules are effectively identities
196
    for these alternatives.  Don't try removing them - SID gets very
197
    confused.
198
*/
199
 
200
%productions%
201
 
202
close-brace =	{ close-brace-1 ; } ;
203
close-square =	{ close-square-1 ; } ;
204
open-brace =	{ open-brace-1 ; } ;
205
open-square =	{ open-square-1 ; } ;
206
 
207
and =		{ and-1 ; } ;
208
and-eq =	{ and-eq-1 ; } ;
209
compl =		{ compl-1 ; } ;
210
logical-and =	{ logical-and-1 ; } ;
211
logical-or =	{ logical-or-1 ; } ;
212
not =		{ not-1 ; } ;
213
not-eq =	{ not-eq-1 ; } ;
214
or =		{ or-1 ; } ;
215
or-eq =		{ or-eq-1 ; } ;
216
xor =		{ xor-1 ; } ;
217
xor-eq =	{ xor-eq-1 ; } ;
218
 
219
ellipsis-aux =	{ ellipsis ; || ellipsis-exp ; } ;
220
 
221
 
222
/*
223
    LEXICAL TOKENS
224
 
225
    These actions give the lexical token numbers for various symbols.
226
*/
227
 
228
<lex_crt> : () -> ( :LEX ) ;
229
<lex_close_round> : () -> ( :LEX ) ;
230
<lex_close_square> : () -> ( :LEX ) ;
231
<lex_colon> : () -> ( :LEX ) ;
232
<lex_cond_op> : () -> ( :LEX ) ;
233
<lex_open_round> : () -> ( :LEX ) ;
234
<lex_semicolon> : () -> ( :LEX ) ;
235
<lex_array_op> : () -> ( :LEX ) ;
236
<lex_func_op> : () -> ( :LEX ) ;
237
<lex_new> : () -> ( :LEX ) ;
238
<lex_delete> : () -> ( :LEX ) ;
239
<lex_new_array> : () -> ( :LEX ) ;
240
<lex_delete_array> : () -> ( :LEX ) ;
241
<lex_alignof> : () -> ( :LEX ) ;
242
<lex_sizeof> : () -> ( :LEX ) ;
243
<lex_typeid> : () -> ( :LEX ) ;
244
<lex_vtable> : () -> ( :LEX ) ;
245
 
246
 
247
/*
248
    EXPECTED SYMBOLS
249
 
250
    These rules are used when a certain symbol is expected.  If it is
251
    not present then the action expected is called with the appropriate
252
    lexical token number.
253
*/
254
 
255
<expected> : ( :LEX ) -> () ;
256
<error_fatal> : () -> () ;
257
<error_syntax> : () -> () ;
258
 
259
close-round-x = {
260
	close-round ;
261
    ##	t = <lex_close_round> ; <expected> ( t ) ;
262
} ;
263
 
264
close-square-x = {
265
	close-square ;
266
    ##	t = <lex_close_square> ; <expected> ( t ) ;
267
} ;
268
 
269
colon-x = {
270
	colon ;
271
    ##	t = <lex_colon> ; <expected> ( t ) ;
272
} ;
273
 
274
open-round-x = {
275
	open-round ;
276
    ##	t = <lex_open_round> ; <expected> ( t ) ;
277
} ;
278
 
279
semicolon-x = {
280
	semicolon ;
281
    ##	t = <lex_semicolon> ; <expected> ( t ) ;
282
} ;
283
 
284
 
285
/*
286
    IDENTIFIERS
287
 
288
    The identifier terminal is exclusive - it does not include those
289
    identifiers which are actually type and namespace names.  This rule
290
    gives all identifiers and sets the appropriate identifier type.
291
*/
292
 
293
any-identifier : () -> ( id : IDENTIFIER ) = {
294
	id = identifier ;
295
    ||	id = type-name ;
296
    ||	id = namespace-name ;
297
    ||	id = statement-name ;
298
} ;
299
 
300
 
301
/*
302
    NAMESPACE SPECIFIERS
303
 
304
    The nested-name-specifiers are handled by the terminals nested-name
305
    (corresponding to nested-name-specifier in the specification) and
306
    full-name (corresponding to :: nested-name-specifier).  These rules
307
    give various combinations of these specifiers.
308
*/
309
 
310
<namespace_none> : () -> ( :NAMESPACE ) ;
311
<namespace_global> : () -> ( :NAMESPACE ) ;
312
<namespace_nested> : ( :NAMESPACE ) -> () ;
313
<namespace_full> : ( :NAMESPACE ) -> () ;
314
 
315
nonempty-nested-name : () -> ( ns : NAMESPACE ) = {
316
	ns = nested-name ; <namespace_nested> ( ns ) ;
317
    ||	ns = full-name ; <namespace_full> ( ns ) ;
318
} ;
319
 
320
any-nested-name : () -> ( ns : NAMESPACE ) = {
321
	ns = nonempty-nested-name ;
322
    ||	colon-colon ; ns = <namespace_global> ;
323
} ;
324
 
325
any-nested-name-opt : () -> ( ns : NAMESPACE ) = {
326
	ns = any-nested-name ;
327
    ||	ns = <namespace_none> ;
328
} ;
329
 
330
 
331
/*
332
    LITERAL EXPRESSIONS
333
 
334
    These rules describe the literal expressions.  These are the integer
335
    and floating point literals, the character and string literals, plus
336
    the boolean literals true and false.  Concatenation of adjacent string
337
    literals has already been performed.
338
*/
339
 
340
<exp_true> : () -> ( :EXP ) ;
341
<exp_false> : () -> ( :EXP ) ;
342
 
343
integer-literal : () -> ( e : EXP ) = {
344
	e = integer-exp ;
345
} ;
346
 
347
character-literal : () -> ( e : EXP ) = {
348
	e = char-exp ;
349
    ||	e = wchar-exp ;
350
} ;
351
 
352
floating-literal : () -> ( e : EXP ) = {
353
	e = floating-exp ;
354
} ;
355
 
356
string-literal : () -> ( e : EXP ) = {
357
	e = string-exp ;
358
    ||	e = wstring-exp ;
359
} ;
360
 
361
boolean-literal : () -> ( e : EXP ) = {
362
	false ; e = <exp_false> ;
363
    ||	true ; e = <exp_true> ;
364
} ;
365
 
366
literal : () -> ( e : EXP ) = {
367
	e = integer-literal ;
368
    ||	e = character-literal ;
369
    ||	e = floating-literal ;
370
    ||	e = string-literal ;
371
    ||	e = boolean-literal ;
372
} ;
373
 
374
 
375
/*
376
    OPERATOR AND CONVERSION FUNCTION IDENTIFIERS
377
 
378
    These rules describe the overloaded operator and conversion function
379
    names.  These consist of 'operator' followed by one of a large number
380
    of operator names (including a few illegal ones which are immediately
381
    reported using error_overload) or a type name.  Note the use of the
382
    predicate is_array to distinguish 'operator new []' from 'operator
383
    new [ expression ]'.  The rule operator-id subsumes both the rules
384
    operator-function-id and conversion-function-id from the grammar.
385
*/
386
 
387
<is_array> : () -> ( :BOOL ) ;
388
<type_decl_begin> : () -> ( :BOOL ) ;
389
<type_decl_end> : ( :BOOL ) -> ( :BOOL ) ;
390
<type_decl_quit> : ( :BOOL ) -> () ;
391
<qual_get> : () -> ( :QUALIFIER, :BOOL ) ;
392
<qual_set> : ( :QUALIFIER, :BOOL ) -> () ;
393
<qual_none> : () -> () ;
394
<error_overload> : ( :LEX ) -> () ;
395
<operator_func> : ( :LEX ) -> ( :IDENTIFIER ) ;
396
<conversion_func> : ( :TYPE, :BOOL ) -> ( :IDENTIFIER ) ;
397
<id_anon> : () -> ( :IDENTIFIER ) ;
398
 
399
conversion-type-id : () -> ( :TYPE ) ;
400
 
401
operator-name : () -> ( op : LEX ) = {
402
	op = <lex_crt> ;
403
	{
404
		and  ;
405
	    ||	and-eq  ;
406
	    ||	arrow  ;
407
	    ||	arrow-star  ;
408
	    ||	assign  ;
409
	    ||	comma  ;
410
	    ||	compl  ;
411
	    ||	div  ;
412
	    ||	div-eq  ;
413
	    ||	eq  ;
414
	    ||	greater  ;
415
	    ||	greater-eq  ;
416
	    ||	less  ;
417
	    ||	less-eq  ;
418
	    ||	logical-and  ;
419
	    ||	logical-or  ;
420
	    ||	lshift  ;
421
	    ||	lshift-eq  ;
422
	    ||	minus  ;
423
	    ||	minus-eq  ;
424
	    ||	minus-minus  ;
425
	    ||	not  ;
426
	    ||	not-eq  ;
427
	    ||	or  ;
428
	    ||	or-eq  ;
429
	    ||	plus  ;
430
	    ||	plus-eq  ;
431
	    ||	plus-plus  ;
432
	    ||	rem  ;
433
	    ||	rem-eq  ;
434
	    ||	rshift  ;
435
	    ||	rshift-eq  ;
436
	    ||	star  ;
437
	    ||	star-eq  ;
438
	    ||	xor  ;
439
	    ||	xor-eq  ;
440
	    ||	abs  ;
441
	    ||	max  ;
442
	    ||	min  ;
443
	} ;
444
    ||
445
	open-round ; close-round-x ;
446
	op = <lex_func_op> ;
447
    ||
448
	open-square ; close-square-x ;
449
	op = <lex_array_op> ;
450
    ||
451
	new ;
452
	op = <lex_new> ;
453
    ||
454
	delete ;
455
	op = <lex_delete> ;
456
    ||
457
	new ; ? = <is_array> ; open-square ; close-square-x ;
458
	op = <lex_new_array> ;
459
    ||
460
	delete ; ? = <is_array> ; open-square ; close-square-x ;
461
	op = <lex_delete_array> ;
462
    ||
463
	op = <lex_crt> ;
464
	{
465
		dot ;
466
	    ||	dot-star ;
467
	    ||	colon-colon ;
468
	    ||	colon ;
469
	    ||	alignof ;
470
	    ||	sizeof ;
471
	    ||	typeid ;
472
	    ||	vtable ;
473
	} ;
474
	<error_overload> ( op ) ;
475
    ||
476
	question ; colon-x ;
477
	op = <lex_cond_op> ;
478
	<error_overload> ( op ) ;
479
} ;
480
 
481
operator-id : () -> ( id : IDENTIFIER ) = {
482
	operator ;
483
	( i, b ) = <qual_get> ;
484
	td = <type_decl_begin> ;
485
	{
486
		t = conversion-type-id ;
487
		d = <type_decl_end> ( td ) ;
488
		tid = <conversion_func> ( t, d ) ;
489
	    ||
490
		op = operator-name ;
491
		<type_decl_quit> ( td ) ;
492
		tid = <operator_func> ( op ) ;
493
	} ;
494
	<qual_set> ( i, b ) ;
495
	id = tid ;
496
} ;
497
 
498
 
499
/*
500
    IDENTIFIER EXPRESSIONS
501
 
502
    These rules describe the qualified and unqualified identifier
503
    expressions.  The identifier qualifiers have been reworked slightly
504
    to make it clear exactly what is being qualified when and by what.
505
*/
506
 
507
<bool_true> : () -> ( :BOOL ) ;
508
<bool_false> : () -> ( :BOOL ) ;
509
<namespace_id> : ( :NAMESPACE, :IDENTIFIER ) -> ( :IDENTIFIER ) ;
510
<namespace_simple> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
511
<namespace_complex> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
512
<namespace_templ> : ( :NAMESPACE, :IDENTIFIER, :BOOL ) -> ( :IDENTIFIER ) ;
513
<decl_nspace_begin> : ( :NAMESPACE ) -> () ;
514
<decl_nspace_end> : ( :NAMESPACE ) -> () ;
515
<rescan_template> : ( :NAMESPACE ) -> () ;
516
<id_none> : () -> ( :IDENTIFIER ) ;
517
 
518
unqualified-type : () -> ( :IDENTIFIER ) ;
519
any-qualified-type : () -> ( :IDENTIFIER ) ;
520
qualified-stmt-name : () -> ( :IDENTIFIER ) ;
521
 
522
template-opt : ( ns : NAMESPACE ) -> ( t : BOOL ) = {
523
	<rescan_template> ( ns ) ; template ; t = <bool_true> ;
524
    ||	t = <bool_false> ;
525
} ;
526
 
527
nested-id : ( ns : NAMESPACE ) -> ( id : IDENTIFIER ) = {
528
	id = identifier ;
529
    ||
530
	id = namespace-name ;
531
    ||
532
	id = destructor-name ;
533
    ||
534
	id = template-id ;
535
    ||
536
	<decl_nspace_begin> ( ns ) ;
537
	id = operator-id ;
538
	<decl_nspace_end> ( ns ) ;
539
} ;
540
 
541
unqualified-id : () -> ( id : IDENTIFIER ) = {
542
	uid = identifier ;
543
	id = <namespace_simple> ( uid ) ;
544
    ||
545
	uid = namespace-name ;
546
	id = <namespace_simple> ( uid ) ;
547
    ||
548
	uid = operator-id ;
549
	id = <namespace_complex> ( uid ) ;
550
    ||
551
	uid = destructor-name ;
552
	id = <namespace_complex> ( uid ) ;
553
    ||
554
	uid = template-id ;
555
	id = <namespace_complex> ( uid ) ;
556
} ;
557
 
558
qualified-id : () -> ( id : IDENTIFIER ) = {
559
	ns = nested-name ;
560
	q = template-opt ( ns ) ; uid = nested-id ( ns ) ;
561
	<namespace_nested> ( ns ) ;
562
	id = <namespace_templ> ( ns, uid, q ) ;
563
} ;
564
 
565
full-qualified-id : () -> ( id : IDENTIFIER ) = {
566
	ns = full-name ;
567
	q = template-opt ( ns ) ; uid = nested-id ( ns ) ;
568
	<namespace_full> ( ns ) ;
569
	id = <namespace_templ> ( ns, uid, q ) ;
570
} ;
571
 
572
top-qualified-id : () -> ( id : IDENTIFIER ) = {
573
	colon-colon ;
574
	ns = <namespace_global> ;
575
	q = template-opt ( ns ) ; uid = nested-id ( ns ) ;
576
	id = <namespace_templ> ( ns, uid, q ) ;
577
} ;
578
 
579
id-expression : () -> ( id : IDENTIFIER ) = {
580
	id = unqualified-id ;
581
    ||	id = qualified-id ;
582
    ||	id = full-qualified-id ;
583
    ||	id = top-qualified-id ;
584
} ;
585
 
586
any-qualified-id : () -> ( id : IDENTIFIER ) = {
587
	id = id-expression ;
588
    ||	id = unqualified-type ;
589
    ||	id = any-qualified-type ;
590
    ||	id = qualified-stmt-name ;
591
} ;
592
 
593
id-entry : () -> ( id : IDENTIFIER ) = {
594
	id = any-qualified-id ;
595
    ##
596
	<error_syntax> ;
597
	id = <id_none> ;
598
} ;
599
 
600
 
601
/*
602
    PRIMARY EXPRESSIONS
603
 
604
    This rule describes the primary expressions.  These include the
605
    literals, the identity expressions, the this expression and the
606
    parenthesised expressions.  The assertion expressions are an
607
    extension.
608
*/
609
 
610
<exp_this> : () -> ( :EXP ) ;
611
<exp_ellipsis> : () -> ( :EXP ) ;
612
<exp_paren_begin> : () -> () ;
613
<exp_paren_end> : ( :EXP ) -> ( :EXP ) ;
614
<exp_identifier> : ( :IDENTIFIER ) -> ( :EXP ) ;
615
 
616
expression : () -> ( :EXP ) ;
617
 
618
primary-expression : () -> ( e : EXP ) = {
619
	e = literal ;
620
    ||
621
	this ;
622
	e = <exp_this> ;
623
    ||
624
	id = id-expression ;
625
	e = <exp_identifier> ( id ) ;
626
    ||
627
	ellipsis-exp ;
628
	e = <exp_ellipsis> ;
629
    ||
630
	open-round ;
631
	<exp_paren_begin> ;
632
	a = expression ;
633
	e = <exp_paren_end> ( a ) ;
634
	close-round ;
635
    ||
636
	e = complex-exp ;
637
} ;
638
 
639
 
640
/*
641
    EXPRESSION LISTS
642
 
643
    These rules describes the lists of expressions.  Note that the
644
    constituents are assignment-expressions so that any commas are list
645
    separators rather than comma operators.
646
*/
647
 
648
<list_exp_null> : () -> ( :LIST-EXP ) ;
649
<list_exp_cons> : ( :EXP, :LIST-EXP ) -> ( :LIST-EXP ) ;
650
 
651
assignment-expression : () -> ( :EXP ) ;
652
 
653
expression-list : () -> ( p : LIST-EXP ) = {
654
	e = assignment-expression ;
655
	{
656
		comma ; q = expression-list ;
657
	    ||	q = <list_exp_null> ;
658
	} ;
659
	p = <list_exp_cons> ( e, q ) ;
660
} ;
661
 
662
expression-list-opt : () -> ( p : LIST-EXP ) = {
663
	p = expression-list ;
664
    ||	p = <list_exp_null> ;
665
} ;
666
 
667
 
668
/*
669
    QUALIFIED TYPE NAMES
670
 
671
    These rules describe the qualified and unqualified type names.
672
*/
673
 
674
any-type-name : () -> ( id : IDENTIFIER ) = {
675
	id = type-name ;
676
    ||	id = template-type ;
677
} ;
678
 
679
unqualified-type : () -> ( id : IDENTIFIER ) = {
680
	tid = any-type-name ;
681
	id = <namespace_simple> ( tid ) ;
682
} ;
683
 
684
qualified-type : () -> ( id : IDENTIFIER ) = {
685
	ns = nested-name ; tid = any-type-name ;
686
	<namespace_nested> ( ns ) ;
687
	id = <namespace_id> ( ns, tid ) ;
688
} ;
689
 
690
full-qualified-type : () -> ( id : IDENTIFIER ) = {
691
	ns = full-name ; tid = any-type-name ;
692
	<namespace_full> ( ns ) ;
693
	id = <namespace_id> ( ns, tid ) ;
694
} ;
695
 
696
top-qualified-type : () -> ( id : IDENTIFIER ) = {
697
	colon-colon ; tid = any-type-name ;
698
	ns = <namespace_global> ;
699
	id = <namespace_id> ( ns, tid ) ;
700
} ;
701
 
702
any-qualified-type : () -> ( id : IDENTIFIER ) = {
703
	id = qualified-type ;
704
    ||	id = full-qualified-type ;
705
    ||	id = top-qualified-type ;
706
} ;
707
 
708
 
709
/*
710
    FIELD SELECTOR EXPRESSIONS
711
 
712
    These rules are used to perform field selector look-up following a
713
    '.' or '->' operator.  The input namespace gives the class being
714
    selected from (or the null namespace in case of an error).  Note
715
    the provisions for dummy destructor calls.
716
*/
717
 
718
<btype_none> : () -> ( :BTYPE ) ;
719
<namespace_type> : ( :NAMESPACE ) -> ( :IDENTIFIER ) ;
720
<pseudo_destructor> : ( :IDENTIFIER, :BTYPE, :IDENTIFIER, :BTYPE ) -> ( :IDENTIFIER ) ;
721
 
722
any-class-name : () -> ( :IDENTIFIER ) ;
723
base-type-specifier : () -> ( :BTYPE ) ;
724
 
725
field-type-expression : ( ns : NAMESPACE ) -> ( id : IDENTIFIER ) = {
726
	tid = unqualified-type ;
727
	id = <namespace_id> ( ns, tid ) ;
728
    ||
729
	tid = qualified-type ;
730
	id = <namespace_id> ( ns, tid ) ;
731
    ||
732
	id = full-qualified-type ;
733
    ||
734
	id = top-qualified-type ;
735
} ;
736
 
737
pseudo-destr-prefix : ( ns : NAMESPACE ) -> ( id : IDENTIFIER, bt : BTYPE, cns : NAMESPACE ) = {
738
	cns = any-nested-name ;
739
	id = <namespace_type> ( cns ) ;
740
	bt = <btype_none> ;
741
    ||
742
	id = field-type-expression ( ns ) ; colon-colon ;
743
	bt = <btype_none> ;
744
	cns = ns ;
745
    ||
746
	bt = base-type-specifier ; colon-colon ;
747
	id = <id_none> ;
748
	cns = ns ;
749
} ;
750
 
751
pseudo-destr-suffix : () -> ( id : IDENTIFIER, bt : BTYPE ) = {
752
	id = any-class-name ;
753
	bt = <btype_none> ;
754
    ||
755
	bt = base-type-specifier ;
756
	id = <id_none> ;
757
} ;
758
 
759
field-id-expression : ( ns : NAMESPACE ) -> ( id : IDENTIFIER ) = {
760
	uid = nested-id ( ns ) ;
761
	<qual_none> ;
762
	id = <namespace_id> ( ns, uid ) ;
763
    ||
764
	qid = qualified-id ;
765
	id = <namespace_id> ( ns, qid ) ;
766
    ||
767
	id = full-qualified-id ;
768
    ||
769
	id = top-qualified-id ;
770
    ||
771
	id = field-type-expression ( ns ) ;
772
    ||
773
	( id1, bt1, ns1 ) = pseudo-destr-prefix ( ns ) ;
774
	( i, b ) = <qual_get> ;
775
	compl ; ( id2, bt2 ) = pseudo-destr-suffix ;
776
	<qual_set> ( i, b ) ;
777
	uid = <pseudo_destructor> ( id1, bt1, id2, bt2 ) ;
778
	id = <namespace_id> ( ns1, uid ) ;
779
    ||
780
	compl ; ( id2, bt2 ) = pseudo-destr-suffix ;
781
	<qual_none> ;
782
	id = <pseudo_destructor> ( id2, bt2, id2, bt2 ) ;
783
} ;
784
 
785
 
786
/*
787
    POSTFIX EXPRESSIONS
788
 
789
    These rules describes the postfix expressions.  These include array
790
    indexing, function calls and function style casts, field selectors,
791
    postfix increment and decrement operations, new style casts and
792
    type identification operators.
793
*/
794
 
795
<exp_postinc> : ( :EXP ) -> ( :EXP ) ;
796
<exp_postdec> : ( :EXP ) -> ( :EXP ) ;
797
<exp_index> : ( :EXP, :EXP ) -> ( :EXP ) ;
798
<exp_func> : ( :EXP, :LIST-EXP ) -> ( :EXP ) ;
799
 
800
<exp_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
801
<exp_func_cast> : ( :TYPE, :LIST-EXP ) -> ( :EXP ) ;
802
<exp_dynamic_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
803
<exp_static_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
804
<exp_reinterpret_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
805
<exp_const_cast> : ( :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
806
 
807
<exp_typeid_exp> : ( :EXP, :LEX, :COUNT ) -> ( :EXP ) ;
808
<exp_typeid_type> : ( :TYPE, :LEX, :COUNT ) -> ( :EXP ) ;
809
 
810
<exp_dot_begin> : ( :EXP ) -> ( :EXP, :TYPE, :NAMESPACE ) ;
811
<exp_dot_end> : ( :EXP, :TYPE, :NAMESPACE, :IDENTIFIER, :BOOL ) -> ( :EXP ) ;
812
<exp_arrow_begin> : ( :EXP ) -> ( :EXP, :TYPE, :NAMESPACE ) ;
813
<exp_arrow_end> : ( :EXP, :TYPE, :NAMESPACE, :IDENTIFIER, :BOOL ) -> ( :EXP ) ;
814
<rescan_token> : () -> () ;
815
 
816
<no_type_defns> : () -> ( :COUNT ) ;
817
<no_side_effects> : () -> ( :COUNT ) ;
818
<diff_type_defns> : ( :COUNT ) -> ( :COUNT ) ;
819
<diff_side_effects> : ( :COUNT ) -> ( :COUNT ) ;
820
<sizeof_begin> : () -> () ;
821
<sizeof_end> : () -> () ;
822
 
823
simple-type-id : () -> ( :TYPE ) ;
824
type-id : () -> ( :TYPE, :COUNT ) ;
825
type-id-false : () -> ( :TYPE, :COUNT ) ;
826
type-id-true : () -> ( :TYPE, :COUNT ) ;
827
 
828
cast-operand : () -> ( t : TYPE, e : EXP, n : COUNT ) = {
829
	less ; ( t, n ) = type-id ; greater ;
830
	open-round ; e = expression ; close-round ;
831
} ;
832
 
833
typeid-expression : ( op : LEX ) -> ( e : EXP ) = {
834
	<sizeof_begin> ;
835
	n1 = <no_side_effects> ;
836
	m1 = <no_type_defns> ;
837
	open-round ;
838
	{
839
		a = expression ; close-round ;
840
		n2 = <diff_side_effects> ( n1 ) ;
841
		c = <exp_typeid_exp> ( a, op, n2 ) ;
842
	    ||
843
		( t, m2 ) = type-id-true ; close-round ;
844
		c = <exp_typeid_type> ( t, op, m2 ) ;
845
	} ;
846
	<sizeof_end> ;
847
	e = c ;
848
} ;
849
 
850
postfix-expression : () -> ( e : EXP ) = {
851
	e = primary-expression ;
852
    ||
853
	a = postfix-expression ;
854
	open-square ; b = expression ; close-square ;
855
	e = <exp_index> ( a, b ) ;
856
    ||
857
	a = postfix-expression ;
858
	open-round ; p = expression-list-opt ; close-round ;
859
	e = <exp_func> ( a, p ) ;
860
    ||
861
	t = simple-type-id ;
862
	open-round ; p = expression-list-opt ; close-round ;
863
	e = <exp_func_cast> ( t, p ) ;
864
    ||
865
	a = postfix-expression ;
866
	( b, t, ns ) = <exp_dot_begin> ( a ) ;
867
	dot ; q = template-opt ( ns ) ; id = field-id-expression ( ns ) ;
868
	e = <exp_dot_end> ( b, t, ns, id, q ) ;
869
	<rescan_token> ;
870
    ||
871
	a = postfix-expression ;
872
	( b, t, ns ) = <exp_arrow_begin> ( a ) ;
873
	arrow ; q = template-opt ( ns ) ; id = field-id-expression ( ns ) ;
874
	e = <exp_arrow_end> ( b, t, ns, id, q ) ;
875
	<rescan_token> ;
876
    ||
877
	a = postfix-expression ; plus-plus ;
878
	e = <exp_postinc> ( a ) ;
879
    ||
880
	a = postfix-expression ; minus-minus ;
881
	e = <exp_postdec> ( a ) ;
882
    ||
883
	dynamic-cast ; ( t, a, n ) = cast-operand ;
884
	e = <exp_dynamic_cast> ( t, a, n ) ;
885
    ||
886
	static-cast ; ( t, a, n ) = cast-operand ;
887
	e = <exp_static_cast> ( t, a, n ) ;
888
    ||
889
	reinterpret-cast ; ( t, a, n ) = cast-operand ;
890
	e = <exp_reinterpret_cast> ( t, a, n ) ;
891
    ||
892
	const-cast ; ( t, a, n ) = cast-operand ;
893
	e = <exp_const_cast> ( t, a, n ) ;
894
    ||
895
	typeid ; op = <lex_typeid> ; e = typeid-expression ( op ) ;
896
    ||
897
	vtable ; op = <lex_vtable> ; e = typeid-expression ( op ) ;
898
} ;
899
 
900
 
901
/*
902
    NEW EXPRESSIONS
903
 
904
    These rules describe the new expressions.  These consist of a new
905
    operator followed by an optional placement, a type identifier (either
906
    a simplified form or a bracketed full form), and an optional initialiser
907
    list.  Note that the second and third components have been combined
908
    as the single rule new-place-and-type.
909
*/
910
 
911
<exp_none> : () -> ( :EXP ) ;
912
<exp_new> : ( :BOOL, :LIST-EXP, :TYPE, :COUNT, :BOOL, :EXP ) -> ( :EXP ) ;
913
<exp_new_start> : () -> ( :EXP ) ;
914
<exp_new_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
915
<exp_new_init> : ( :TYPE, :LIST-EXP ) -> ( :EXP ) ;
916
<exp_new_none> : ( :TYPE ) -> ( :EXP ) ;
917
 
918
new-type-id : () -> ( :TYPE, :COUNT ) ;
919
 
920
new-initialiser-opt : ( t : TYPE ) -> ( e : EXP ) = {
921
	open-round ; p = expression-list-opt ; close-round ;
922
	e = <exp_new_init> ( t, p ) ;
923
    ||
924
	e = <exp_new_none> ( t ) ;
925
} ;
926
 
927
colon-colon-opt : () -> ( b : BOOL ) = {
928
	colon-colon ; b = <bool_true> ;
929
    ||	b = <bool_false> ;
930
} ;
931
 
932
new-place-and-type : () -> ( p : LIST-EXP, t : TYPE, n : COUNT ) = {
933
	open-round ;
934
	{
935
		p = expression-list ; close-round ;
936
		td = <type_decl_begin> ;
937
		{
938
			open-round ; ( s, m ) = type-id ; close-round ;
939
		    ||
940
			( s, m ) = new-type-id ;
941
		} ;
942
		<type_decl_quit> ( td ) ;
943
		t = s ;
944
		n = m ;
945
	    ||
946
		( t, n ) = type-id-false ; close-round ;
947
		p = <list_exp_null> ;
948
	} ;
949
    ||
950
	( t, n ) = new-type-id ;
951
	p = <list_exp_null> ;
952
} ;
953
 
954
new-expression : () -> ( e : EXP ) = {
955
	b = colon-colon-opt ; new ;
956
	td = <type_decl_begin> ;
957
	( p, t, n ) = new-place-and-type ;
958
	d = <type_decl_end> ( td ) ;
959
	s = <exp_new_start> ;
960
	i = new-initialiser-opt ( t ) ;
961
	a = <exp_new_end> ( s, i ) ;
962
	e = <exp_new> ( b, p, t, n, d, a ) ;
963
} ;
964
 
965
 
966
/*
967
    DELETE EXPRESSIONS
968
 
969
    This rule describes the delete expressions.  These consist of a
970
    delete operator followed by the expression to be deleted.  The
971
    anachronistic form of the 'delete []' operator, in which the array
972
    size had to be given, has been included in the grammar, to be weeded
973
    out by the action anachronism_delete.
974
*/
975
 
976
<exp_delete> : ( :BOOL, :LEX, :EXP ) -> ( :EXP ) ;
977
<anachronism_delete> : ( :EXP ) -> () ;
978
 
979
cast-expression : () -> ( :EXP ) ;
980
unary-expression : () -> ( :EXP ) ;
981
 
982
delete-operator : () -> ( op : LEX ) = {
983
	delete ;
984
	op = <lex_delete> ;
985
    ||
986
	delete ; open-square ; close-square ;
987
	op = <lex_delete_array> ;
988
    ||
989
	delete ; open-square ; e = expression ;
990
	<anachronism_delete> ( e ) ;
991
	close-square ;
992
	op = <lex_delete_array> ;
993
} ;
994
 
995
delete-expression : () -> ( e : EXP ) = {
996
	b = colon-colon-opt ;
997
	op = delete-operator ;
998
	a = cast-expression ;
999
	e = <exp_delete> ( b, op, a ) ;
1000
} ;
1001
 
1002
 
1003
/*
1004
    UNARY EXPRESSIONS
1005
 
1006
    These rules describe the unary expressions.  These include the simple
1007
    unary operations (indirection, address, unary plus, unary minus, logical
1008
    negation and bitwise complement), the prefix increment and decrement
1009
    operations and sizeof expressions, as well as the new and delete
1010
    expressions.
1011
*/
1012
 
1013
<exp_not> : ( :EXP ) -> ( :EXP ) ;
1014
<exp_ref> : ( :EXP ) -> ( :EXP ) ;
1015
<exp_indir> : ( :EXP ) -> ( :EXP ) ;
1016
<exp_unary> : ( :LEX, :EXP ) -> ( :EXP ) ;
1017
<exp_preinc> : ( :EXP ) -> ( :EXP ) ;
1018
<exp_predec> : ( :EXP ) -> ( :EXP ) ;
1019
 
1020
<exp_sizeof> : ( :LEX, :TYPE, :EXP, :COUNT ) -> ( :EXP ) ;
1021
<type_of> : ( :LEX, :EXP, :COUNT ) -> ( :TYPE ) ;
1022
 
1023
sizeof-expression : ( op : LEX ) -> ( e : EXP ) = {
1024
	<sizeof_begin> ;
1025
	n1 = <no_side_effects> ;
1026
	m1 = <no_type_defns> ;
1027
	{
1028
		a = unary-expression ;
1029
		n2 = <diff_side_effects> ( n1 ) ;
1030
		m2 = <diff_type_defns> ( m1 ) ;
1031
		t = <type_of> ( op, a, n2 ) ;
1032
		c = <exp_sizeof> ( op, t, a, m2 ) ;
1033
	    ||
1034
		open-round ; ( t, m2 ) = type-id-true ;
1035
		a = <exp_none> ;
1036
		c = <exp_sizeof> ( op, t, a, m2 ) ;
1037
		close-round ;
1038
	} ;
1039
	<sizeof_end> ;
1040
	e = c ;
1041
} ;
1042
 
1043
unary-operator : () -> () = {
1044
	plus ;
1045
    ||	minus ;
1046
    ||	compl ;
1047
    ||	abs ;
1048
} ;
1049
 
1050
unary-expression : () -> ( e : EXP ) = {
1051
	e = postfix-expression ;
1052
    ||
1053
	plus-plus ; a = cast-expression ;
1054
	e = <exp_preinc> ( a ) ;
1055
    ||
1056
	minus-minus ; a = cast-expression ;
1057
	e = <exp_predec> ( a ) ;
1058
    ||
1059
	star ; a = cast-expression ;
1060
	e = <exp_indir> ( a )  ;
1061
    ||
1062
	and ; a = cast-expression ;
1063
	e = <exp_ref> ( a )  ;
1064
    ||
1065
	not ; a = cast-expression ;
1066
	e = <exp_not> ( a ) ;
1067
    ||
1068
	op = <lex_crt> ; unary-operator ;
1069
	a = cast-expression ;
1070
	e = <exp_unary> ( op, a ) ;
1071
    ||
1072
	sizeof ; op = <lex_sizeof> ; e = sizeof-expression ( op ) ;
1073
    ||
1074
	alignof ; op = <lex_alignof> ; e = sizeof-expression ( op ) ;
1075
    ||
1076
	e = new-expression ;
1077
    ||
1078
	e = delete-expression ;
1079
} ;
1080
 
1081
 
1082
/*
1083
    CAST EXPRESSIONS
1084
 
1085
    This rule describes the traditional style cast expressions, consisting
1086
    of a bracketed type identifier followed by an expression.  The ignore
1087
    keyword is an extension which is semantically equivalent to casting
1088
    to void.
1089
*/
1090
 
1091
<exp_ignore> : ( :EXP ) -> ( :EXP ) ;
1092
 
1093
cast-expression : () -> ( e : EXP ) = {
1094
	e = unary-expression ;
1095
    ||
1096
	open-round ; ( t, n ) = type-id-false ; close-round ;
1097
	a = cast-expression ;
1098
	e = <exp_cast> ( t, a, n ) ;
1099
    ||
1100
	discard ; a = cast-expression ;
1101
	e = <exp_ignore> ( a ) ;
1102
} ;
1103
 
1104
 
1105
/*
1106
    POINTER MEMBER EXPRESSIONS
1107
 
1108
    This rule describes the pointer to member expressions, consisting of
1109
    the '.*' and '->*' operators.
1110
*/
1111
 
1112
<exp_ptr_mem> : () -> () ;
1113
<exp_dot_star> : ( :EXP, :EXP ) -> ( :EXP ) ;
1114
<exp_arrow_star> : ( :EXP, :EXP ) -> ( :EXP ) ;
1115
 
1116
pm-expression : () -> ( e : EXP ) = {
1117
	e = cast-expression ;
1118
    ||
1119
	a = pm-expression ; dot-star ;
1120
	<exp_ptr_mem> ;
1121
	b = cast-expression ;
1122
	e = <exp_dot_star> ( a, b ) ;
1123
    ||
1124
	a = pm-expression ; arrow-star ;
1125
	<exp_ptr_mem> ;
1126
	b = cast-expression ;
1127
	e = <exp_arrow_star> ( a, b ) ;
1128
} ;
1129
 
1130
 
1131
/*
1132
    MULTIPLICATIVE EXPRESSIONS
1133
 
1134
    This rule describes the multiplicative expressions.  These include
1135
    the division and remainder operations, as well as multiplication.
1136
*/
1137
 
1138
<exp_div> : ( :EXP, :EXP ) -> ( :EXP ) ;
1139
<exp_rem> : ( :EXP, :EXP ) -> ( :EXP ) ;
1140
<exp_mult> : ( :EXP, :EXP ) -> ( :EXP ) ;
1141
 
1142
multiplicative-expression : () -> ( e : EXP ) = {
1143
	e = pm-expression ;
1144
    ||
1145
	a = multiplicative-expression ; star ; b = pm-expression ;
1146
	e = <exp_mult> ( a, b ) ;
1147
    ||
1148
	a = multiplicative-expression ; div ; b = pm-expression ;
1149
	e = <exp_div> ( a, b ) ;
1150
    ||
1151
	a = multiplicative-expression ; rem ; b = pm-expression ;
1152
	e = <exp_rem> ( a, b ) ;
1153
} ;
1154
 
1155
 
1156
/*
1157
    ADDITIVE EXPRESSIONS
1158
 
1159
    This rule describes the additive expressions.  These include both the
1160
    addition and the subtraction operations.
1161
*/
1162
 
1163
<exp_plus> : ( :EXP, :EXP ) -> ( :EXP ) ;
1164
<exp_minus> : ( :EXP, :EXP ) -> ( :EXP ) ;
1165
 
1166
additive-expression : () -> ( e : EXP ) = {
1167
	e = multiplicative-expression ;
1168
    ||
1169
	a = additive-expression ; plus ; b = multiplicative-expression ;
1170
	e = <exp_plus> ( a, b ) ;
1171
    ||
1172
	a = additive-expression ; minus ; b = multiplicative-expression ;
1173
	e = <exp_minus> ( a, b ) ;
1174
} ;
1175
 
1176
 
1177
/*
1178
    SHIFT EXPRESSIONS
1179
 
1180
    This rule describes the shift expressions.  Both left and right shifts
1181
    are included.
1182
*/
1183
 
1184
<exp_lshift> : ( :EXP, :EXP ) -> ( :EXP ) ;
1185
<exp_rshift> : ( :EXP, :EXP ) -> ( :EXP ) ;
1186
 
1187
shift-expression : () -> ( e : EXP ) = {
1188
	e = additive-expression ;
1189
    ||
1190
	a = shift-expression ; lshift ; b = additive-expression ;
1191
	e = <exp_lshift> ( a, b ) ;
1192
    ||
1193
	a = shift-expression ; rshift ; b = additive-expression ;
1194
	e = <exp_rshift> ( a, b ) ;
1195
} ;
1196
 
1197
 
1198
/*
1199
    RELATIONAL EXPRESSIONS
1200
 
1201
    These rules describe the relational expressions, less than, greater
1202
    than, less than or equal and greater than or equal.
1203
*/
1204
 
1205
<exp_relation> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
1206
 
1207
relational-operator : () -> () = {
1208
	less ;
1209
    ||	greater ;
1210
    ||	less-eq ;
1211
    ||	greater-eq ;
1212
} ;
1213
 
1214
relational-expression : () -> ( e : EXP ) = {
1215
	e = shift-expression ;
1216
    ||
1217
	a = relational-expression ;
1218
	op = <lex_crt> ; relational-operator ;
1219
	b = shift-expression ;
1220
	e = <exp_relation> ( op, a, b ) ;
1221
} ;
1222
 
1223
 
1224
/*
1225
    EQUALITY EXPRESSIONS
1226
 
1227
    These rules describe the equality expressions, equal and not equal.
1228
*/
1229
 
1230
<exp_equality> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
1231
 
1232
equality-operator : () -> () = {
1233
	eq ;
1234
    ||	not-eq ;
1235
} ;
1236
 
1237
equality-expression : () -> ( e : EXP ) = {
1238
	e = relational-expression ;
1239
    ||
1240
	a = equality-expression ;
1241
	op = <lex_crt> ; equality-operator ;
1242
	b = relational-expression ;
1243
	e = <exp_equality> ( op, a, b ) ;
1244
} ;
1245
 
1246
 
1247
/*
1248
    MAXIMUM AND MINIMUM EXPRESSIONS (EXTENSION)
1249
 
1250
    These rules describes the maximum and minimum expressions.
1251
*/
1252
 
1253
<exp_maxmin> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
1254
 
1255
maxmin-operator : () -> () = {
1256
	max ;
1257
    ||	min ;
1258
} ;
1259
 
1260
maxmin-expression : () -> ( e : EXP ) = {
1261
	e = equality-expression ;
1262
    ||
1263
	a = maxmin-expression ;
1264
	op = <lex_crt> ; maxmin-operator ;
1265
	b = equality-expression ;
1266
	e = <exp_maxmin> ( op, a, b ) ;
1267
} ;
1268
 
1269
 
1270
/*
1271
    AND EXPRESSIONS
1272
 
1273
    This rule describes the bitwise and expressions.
1274
*/
1275
 
1276
<exp_and> : ( :EXP, :EXP ) -> ( :EXP ) ;
1277
 
1278
and-expression : () -> ( e : EXP ) = {
1279
	e = maxmin-expression ;
1280
    ||
1281
	a = and-expression ; and ; b = maxmin-expression ;
1282
	e = <exp_and> ( a, b ) ;
1283
} ;
1284
 
1285
 
1286
/*
1287
    EXCLUSIVE OR EXPRESSIONS
1288
 
1289
    This rule describes the bitwise exclusive or expressions.
1290
*/
1291
 
1292
<exp_xor> : ( :EXP, :EXP ) -> ( :EXP ) ;
1293
 
1294
exclusive-or-expression : () -> ( e : EXP ) = {
1295
	e = and-expression ;
1296
    ||
1297
	a = exclusive-or-expression ; xor ; b = and-expression ;
1298
	e = <exp_xor> ( a, b ) ;
1299
} ;
1300
 
1301
 
1302
/*
1303
    INCLUSIVE OR EXPRESSIONS
1304
 
1305
    This rule describes the bitwise inclusive or expressions.
1306
*/
1307
 
1308
<exp_or> : ( :EXP, :EXP ) -> ( :EXP ) ;
1309
 
1310
inclusive-or-expression : () -> ( e : EXP ) = {
1311
	e = exclusive-or-expression ;
1312
    ||
1313
	a = inclusive-or-expression ; or ; b = exclusive-or-expression ;
1314
	e = <exp_or> ( a, b ) ;
1315
} ;
1316
 
1317
 
1318
/*
1319
    LOGICAL AND EXPRESSIONS
1320
 
1321
    This rule describes the logical and expressions.
1322
*/
1323
 
1324
<exp_log_and> : ( :EXP, :EXP ) -> ( :EXP ) ;
1325
 
1326
logical-and-expression : () -> ( e : EXP ) = {
1327
	e = inclusive-or-expression ;
1328
    ||
1329
	a = logical-and-expression ;
1330
	logical-and ; b = inclusive-or-expression ;
1331
	e = <exp_log_and> ( a, b ) ;
1332
} ;
1333
 
1334
 
1335
/*
1336
    LOGICAL OR EXPRESSIONS
1337
 
1338
    This rule describes the logical or expressions.
1339
*/
1340
 
1341
<exp_log_or> : ( :EXP, :EXP ) -> ( :EXP ) ;
1342
 
1343
logical-or-expression : () -> ( e : EXP ) = {
1344
	e = logical-and-expression ;
1345
    ||
1346
	a = logical-or-expression ;
1347
	logical-or ; b = logical-and-expression ;
1348
	e = <exp_log_or> ( a, b ) ;
1349
} ;
1350
 
1351
 
1352
/*
1353
    CONDITIONAL EXPRESSIONS
1354
 
1355
    This rule describes the conditional expressions, consisting of the
1356
    '?:' operator.
1357
*/
1358
 
1359
<exp_cond> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1360
 
1361
conditional-expression : () -> ( e : EXP ) = {
1362
	e = logical-or-expression ;
1363
    ||
1364
	c = logical-or-expression ;
1365
	question ; a = expression ;
1366
	colon ; b = assignment-expression ;
1367
	e = <exp_cond> ( c, a, b ) ;
1368
} ;
1369
 
1370
 
1371
/*
1372
    THROW EXPRESSIONS
1373
 
1374
    This rule describes the throw expressions.  These consist of 'throw'
1375
    followed by an optional expression.  The extension 'throw type-id'
1376
    has also been added.
1377
*/
1378
 
1379
<exp_throw> : ( :EXP ) -> ( :EXP ) ;
1380
<exp_throw_type> : ( :TYPE, :COUNT ) -> ( :EXP ) ;
1381
 
1382
throw-expression : () -> ( e : EXP ) = {
1383
	throw ;
1384
	{
1385
		a = assignment-expression ;
1386
	    ||
1387
		( t, n ) = type-id-false ;
1388
		a = <exp_throw_type> ( t, n ) ;
1389
	    ||
1390
		a = <exp_none> ;
1391
	} ;
1392
	e = <exp_throw> ( a ) ;
1393
} ;
1394
 
1395
 
1396
/*
1397
    ASSIGNMENT EXPRESSIONS
1398
 
1399
    These rules describe the assignment expressions.  These include both
1400
    simple assignment and the 'operate and becomes' operators like '+='.
1401
*/
1402
 
1403
<exp_assign> : ( :EXP, :EXP ) -> ( :EXP ) ;
1404
<exp_assign_op> : ( :LEX, :EXP, :EXP ) -> ( :EXP ) ;
1405
 
1406
assignment-operator : () -> () = {
1407
	and-eq ;
1408
    ||	div-eq ;
1409
    ||	lshift-eq ;
1410
    ||	minus-eq ;
1411
    ||	or-eq ;
1412
    ||	plus-eq ;
1413
    ||	rem-eq ;
1414
    ||	rshift-eq ;
1415
    ||	star-eq ;
1416
    ||	xor-eq ;
1417
} ;
1418
 
1419
assignment-expression : () -> ( e : EXP ) = {
1420
	e = conditional-expression ;
1421
    ||
1422
	a = logical-or-expression ;
1423
	assign ; b = assignment-expression ;
1424
	e = <exp_assign> ( a, b ) ;
1425
    ||
1426
	a = logical-or-expression ;
1427
	op = <lex_crt> ; assignment-operator ;
1428
	b = assignment-expression ;
1429
	e = <exp_assign_op> ( op, a, b ) ;
1430
    ||
1431
	e = throw-expression ;
1432
} ;
1433
 
1434
expression-entry : () -> ( e : EXP ) = {
1435
	e = assignment-expression ;
1436
    ##
1437
	<error_syntax> ;
1438
	e = <exp_none> ;
1439
} ;
1440
 
1441
 
1442
/*
1443
    FLOW ANALYSIS EXPRESSIONS (EXTENSION)
1444
 
1445
    This rule describes the flow analysis expressions, which are an
1446
    extension to the standard syntax.  These consist of the assignment
1447
    expressions, plus operations for setting and discarding values.
1448
*/
1449
 
1450
<exp_set> : ( :EXP ) -> ( :EXP ) ;
1451
<exp_unused> : ( :EXP ) -> ( :EXP ) ;
1452
 
1453
flow-expression : () -> ( e : EXP ) = {
1454
	set ; open-round ; a = expression ;
1455
	e = <exp_set> ( a ) ;
1456
	close-round ;
1457
    ||
1458
	unused ; open-round ; a = expression ;
1459
	e = <exp_unused> ( a ) ;
1460
	close-round ;
1461
} ;
1462
 
1463
inset-flow-expression : () -> ( e : EXP ) = {
1464
	inset-start ; set ; a = expression ;
1465
	e = <exp_set> ( a ) ;
1466
	inset-end ;
1467
    ||
1468
	inset-start ; unused ; a = expression ;
1469
	e = <exp_unused> ( a ) ;
1470
	inset-end ;
1471
} ;
1472
 
1473
inset-flow-statement : () -> ( e : EXP ) = {
1474
	inset-start ; set ; a = expression ;
1475
	e = <exp_set> ( a ) ;
1476
	semicolon ; inset-end ;
1477
    ||
1478
	inset-start ; unused ; a = expression ;
1479
	e = <exp_unused> ( a ) ;
1480
	semicolon ; inset-end ;
1481
} ;
1482
 
1483
 
1484
/*
1485
    EXPRESSIONS
1486
 
1487
    This rule describes the top level expressions.  These are derived
1488
    from the flow-expressions by the addition of the comma operator.
1489
*/
1490
 
1491
<exp_comma> : ( :LIST-EXP ) -> ( :EXP ) ;
1492
 
1493
comma-expression-head : () -> ( e : EXP ) = {
1494
	e = assignment-expression ; comma ;
1495
    ||
1496
	e = flow-expression ;
1497
    ||
1498
	e = inset-flow-expression ;
1499
} ;
1500
 
1501
comma-expression-tail : () -> ( p : LIST-EXP ) = {
1502
	a = assignment-expression ;
1503
	q = <list_exp_null> ;
1504
	p = <list_exp_cons> ( a, q ) ;
1505
    ||
1506
	a = comma-expression-head ; q = comma-expression-tail ;
1507
	p = <list_exp_cons> ( a, q ) ;
1508
} ;
1509
 
1510
expression : () -> ( e : EXP ) = {
1511
	e = assignment-expression ;
1512
    ||
1513
	a = comma-expression-head ; q = comma-expression-tail ;
1514
	p = <list_exp_cons> ( a, q ) ;
1515
	e = <exp_comma> ( p ) ;
1516
} ;
1517
 
1518
 
1519
/*
1520
    INITIALISER EXPRESSIONS
1521
 
1522
    An initialiser expression consists of an assignment expression
1523
    with all its temporary variables bound to it.
1524
*/
1525
 
1526
initialiser-expression : () -> ( e : EXP ) = {
1527
	e = assignment-expression ;
1528
} ;
1529
 
1530
 
1531
/*
1532
    CONSTANT EXPRESSIONS
1533
 
1534
    This rule describes the constant expressions.  Lexically these are
1535
    identical to the conditional-expressions, but with restrictions on
1536
    the permitted operands.  Constant expressions are identified by
1537
    evaluation - whenever a valid constant expression is encountered it
1538
    is evaluated to give an integer literal expression.
1539
*/
1540
 
1541
<exp_eval> : ( :EXP ) -> ( :EXP ) ;
1542
 
1543
constant-expression : () -> ( e : EXP ) = {
1544
	a = conditional-expression ;
1545
	e = <exp_eval> ( a ) ;
1546
} ;
1547
 
1548
 
1549
/*
1550
    LABELLED STATEMENTS
1551
 
1552
    This rule describes the labelled statements.  These include the case
1553
    and default statements as well as the simple labels.  Note that the
1554
    statements following the labels are only the first component of the
1555
    label body.  Actually imposing some structure on the labelled statements
1556
    is the most difficult part of the statement processing.
1557
*/
1558
 
1559
<stmt_case_begin> : ( :EXP ) -> ( :EXP ) ;
1560
<stmt_case_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1561
<stmt_default_begin> : () -> ( :EXP ) ;
1562
<stmt_default_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1563
<stmt_label_begin> : ( :IDENTIFIER ) -> ( :EXP ) ;
1564
<stmt_label_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1565
<stmt_label_set> : () -> () ;
1566
<stmt_label_mod> : () -> () ;
1567
<stmt_label_clear> : () -> () ;
1568
 
1569
statement : () -> ( :EXP ) ;
1570
 
1571
fall-check : () -> () = {
1572
	fall ; <stmt_label_set> ;
1573
    ||	fall ; semicolon ; <stmt_label_set> ;
1574
    ||	$ ;
1575
} ;
1576
 
1577
labelled-statement : () -> ( e : EXP ) = {
1578
	fall-check ;
1579
	case ; c = constant-expression ;
1580
	a = <stmt_case_begin> ( c ) ;
1581
	<stmt_label_set> ;
1582
	colon ; b = statement ;
1583
	e = <stmt_case_end> ( a, b ) ;
1584
    ||
1585
	fall-check ;
1586
	default ;
1587
	a = <stmt_default_begin> ;
1588
	<stmt_label_set> ;
1589
	colon ; b = statement ;
1590
	e = <stmt_default_end> ( a, b ) ;
1591
    ||
1592
	id = any-identifier ;
1593
	<qual_none> ;
1594
	<stmt_label_mod> ;
1595
	a = <stmt_label_begin> ( id ) ;
1596
	colon ; b = statement ;
1597
	e = <stmt_label_end> ( a, b ) ;
1598
} ;
1599
 
1600
 
1601
/*
1602
    EXPRESSION STATEMENTS
1603
 
1604
    This rule describes the expression statements, consisting of an optional
1605
    expression followed by a semicolon.  There is an ambiguity between empty
1606
    expression statements (i.e. just a semicolon) and empty declaration
1607
    statements.  We have resolved this by explicitly making declaration
1608
    statements non-empty.
1609
*/
1610
 
1611
<stmt_exp> : ( :EXP ) -> ( :EXP ) ;
1612
<stmt_none> : () -> ( :EXP ) ;
1613
<reach_check> : () -> ( :BOOL ) ;
1614
<reach_prev> : ( :BOOL ) -> () ;
1615
 
1616
block-expression : () -> ( e : EXP ) = {
1617
	e = expression ;
1618
    ||	e = flow-expression ;
1619
} ;
1620
 
1621
expression-statement : () -> ( e : EXP ) = {
1622
	a = block-expression ;
1623
	r = <reach_check> ;
1624
	e = <stmt_exp> ( a ) ;
1625
	<stmt_label_clear> ;
1626
	semicolon ;
1627
    ||
1628
	a = inset-flow-statement ;
1629
	r = <reach_check> ;
1630
	e = <stmt_exp> ( a ) ;
1631
	<stmt_label_clear> ;
1632
    ||
1633
	semicolon ;
1634
	e = <stmt_none> ;
1635
} ;
1636
 
1637
 
1638
/*
1639
    COMPOUND STATEMENTS
1640
 
1641
    These rules describe the compound statements, consisting of a list of
1642
    statements enclosed within braces.  Note that compound statements
1643
    automatically define a local scope.
1644
*/
1645
 
1646
<stmt_compound_begin> : () -> ( :EXP ) ;
1647
<stmt_compound_end> : ( :EXP ) -> ( :EXP ) ;
1648
<stmt_compound_add> : ( :EXP, :EXP ) -> ( :EXP ) ;
1649
<stmt_compound_block> : ( :EXP ) -> () ;
1650
<stmt_compound_mark> : ( :EXP ) -> () ;
1651
 
1652
statement-seq-opt : ( c : EXP ) -> ( e : EXP ) = {
1653
	a = statement ;
1654
	b = <stmt_compound_add> ( c, a ) ;
1655
	e = statement-seq-opt ( b ) ;
1656
    ||
1657
	e = c ;
1658
} ;
1659
 
1660
compound-statement : () -> ( e : EXP ) = {
1661
	c = <stmt_compound_begin> ;
1662
	open-brace ;
1663
	<stmt_compound_block> ( c ) ;
1664
	a = statement-seq-opt ( c ) ;
1665
	close-brace ;
1666
	e = <stmt_compound_end> ( a ) ;
1667
	<rescan_token> ;
1668
} ;
1669
 
1670
 
1671
/*
1672
    LOCAL STATEMENT SCOPES
1673
 
1674
    Several statements, in addition to the compound statements, form local
1675
    scopes (for example, the body of an iteration statement).  This rule
1676
    describes such scopes, the initial scope expression begin passed in as
1677
    c to avoid predicate problems.  Note that local scopes which are also
1678
    compound statements are treated differently from other (simple)
1679
    statements.
1680
*/
1681
 
1682
simple-statement : () -> ( :EXP ) ;
1683
 
1684
scoped-stmt-body : ( c : EXP ) -> ( e : EXP ) = {
1685
	open-brace ;
1686
	<stmt_compound_block> ( c ) ;
1687
	e = statement-seq-opt ( c ) ;
1688
	close-brace ;
1689
    ||
1690
	a = simple-statement ;
1691
	e = <stmt_compound_add> ( c, a ) ;
1692
} ;
1693
 
1694
scoped-statement : ( c : EXP ) -> ( e : EXP ) = {
1695
	a = scoped-stmt-body ( c ) ;
1696
	e = <stmt_compound_end> ( a ) ;
1697
	<rescan_token> ;
1698
    ##
1699
	<error_syntax> ;
1700
	e = <stmt_compound_end> ( c ) ;
1701
	<rescan_token> ;
1702
} ;
1703
 
1704
 
1705
/*
1706
    DECLARATION STATEMENTS
1707
 
1708
    This rule describes the (non-empty) declaration statements, consisting
1709
    of just a declaration.  See expression-statement for a discussion of
1710
    empty statements.  The look-ahead required to distinguish declaration-
1711
    statements from expression-statements is implemented using the predicate
1712
    is_decl_statement.
1713
*/
1714
 
1715
<is_decl_statement> : () -> ( :BOOL ) ;
1716
<dspec_none> : () -> ( :DSPEC ) ;
1717
<type_none> : () -> ( :TYPE ) ;
1718
<stmt_decl> : ( :EXP ) -> ( :EXP ) ;
1719
 
1720
declaration-basic : ( :TYPE, :DSPEC ) -> () ;
1721
declaration-nonempty : ( :TYPE, :DSPEC ) -> ( :EXP ) ;
1722
 
1723
declaration-statement : () -> ( e : EXP ) = {
1724
	? = <is_decl_statement> ;
1725
	ds = <dspec_none> ;
1726
	t = <type_none> ;
1727
	a = declaration-nonempty ( t, ds ) ;
1728
	e = <stmt_decl> ( a ) ;
1729
	<stmt_label_clear> ;
1730
} ;
1731
 
1732
simple-declaration : () -> ( e : EXP ) = {
1733
	? = <is_decl_statement> ;
1734
	ds = <dspec_none> ;
1735
	t = <type_none> ;
1736
	declaration-basic ( t, ds ) ;
1737
	a = <exp_none> ;
1738
	e = <stmt_decl> ( a ) ;
1739
} ;
1740
 
1741
 
1742
/*
1743
    TARGET DEPENDENT CONDITIONAL COMPILATIONS
1744
 
1745
    These rules describe the unresolved target dependent conditional
1746
    compilations.  Note that these must be structured, as opposed to the
1747
    normal unstructured preprocessing directives.  Any braces required
1748
    to make the lists of statements in target dependent conditional
1749
    bodies into compound statements are automatically inserted by the
1750
    preprocessor.
1751
*/
1752
 
1753
<stmt_hash_if> : ( :EXP, :EXP ) -> ( :EXP ) ;
1754
<stmt_hash_elif> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1755
<stmt_hash_endif> : ( :EXP, :EXP ) -> ( :EXP ) ;
1756
<cond_hash_if> : ( :EXP ) -> ( :EXP ) ;
1757
<cond_hash_elif> : ( :EXP ) -> () ;
1758
<cond_hash_else> : () -> () ;
1759
<cond_hash_endif> : ( :EXP ) -> () ;
1760
 
1761
target-condition-head : () -> ( e : EXP, p : EXP, r : BOOL ) = {
1762
	c = hash-if ;
1763
	p = <cond_hash_if> ( c ) ;
1764
	r = <reach_check> ;
1765
	a = compound-statement ;
1766
	<reach_prev> ( r ) ;
1767
	e = <stmt_hash_if> ( c, a ) ;
1768
    ||
1769
	( a, p, r ) = target-condition-head ;
1770
	c = hash-elif ;
1771
	<cond_hash_elif> ( c ) ;
1772
	s = <reach_check> ;
1773
	b = compound-statement ;
1774
	<reach_prev> ( r ) ;
1775
	e = <stmt_hash_elif> ( a, c, b ) ;
1776
} ;
1777
 
1778
target-condition : () -> ( e : EXP ) = {
1779
	( a, p, r ) = target-condition-head ;
1780
	{
1781
		hash-else ;
1782
		<cond_hash_else> ;
1783
		s = <reach_check> ;
1784
		b = compound-statement ;
1785
	    ||
1786
		b = <stmt_none> ;
1787
	} ;
1788
	<cond_hash_endif> ( p ) ;
1789
	hash-endif ;
1790
	<reach_prev> ( r ) ;
1791
	e = <stmt_hash_endif> ( a, b ) ;
1792
} ;
1793
 
1794
 
1795
/*
1796
    SELECTION STATEMENTS
1797
 
1798
    These rules describe the selection statements, consisting of the if
1799
    and switch statements, plus the target dependent conditionals above.
1800
    The way that the dangling else problem is dealt with is interesting.
1801
    A simple optional else-block leads to an ambiguity, however an
1802
    exception handler gives precisely what is required.  To paraphrase,
1803
    an if statement always has an associated else, except when it doesn't.
1804
*/
1805
 
1806
<stmt_if_begin> : ( :EXP ) -> ( :EXP ) ;
1807
<stmt_if_cont> : ( :EXP, :EXP ) -> ( :EXP ) ;
1808
<stmt_if_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1809
<stmt_else> : () -> () ;
1810
<stmt_no_else> : () -> ( :EXP ) ;
1811
<stmt_switch_begin> : ( :EXP ) -> ( :EXP ) ;
1812
<stmt_switch_end> : ( :EXP, :EXP, :BOOL ) -> ( :EXP ) ;
1813
<cond_inject> : ( :EXP, :EXP ) -> ( :EXP ) ;
1814
 
1815
<condition_get> : () -> ( :CONDITION ) ;
1816
<condition_set> : ( :CONDITION ) -> () ;
1817
 
1818
condition-declaration : () -> ( :EXP ) ;
1819
 
1820
condition : () -> ( e : EXP ) = {
1821
	e = expression ;
1822
    ||	e = condition-declaration ;
1823
} ;
1824
 
1825
selection-statement : () -> ( e : EXP ) = {
1826
	if ;
1827
	x = <condition_get> ;
1828
	r = <reach_check> ;
1829
	open-round-x ; c = condition ;
1830
	a = <stmt_if_begin> ( c ) ;
1831
	close-round ;
1832
	bs = <stmt_compound_begin> ;
1833
	bc = <cond_inject> ( bs, c ) ;
1834
	b = scoped-statement ( bc ) ;
1835
	<reach_prev> ( r ) ;
1836
	d = <stmt_if_cont> ( a, b ) ;
1837
	{
1838
		else ;
1839
		<stmt_else> ;
1840
		fs = <stmt_compound_begin> ;
1841
		fc = <cond_inject> ( fs, c ) ;
1842
		f = scoped-statement ( fc ) ;
1843
	    ##
1844
		f = <stmt_no_else> ;
1845
	} ;
1846
	<reach_prev> ( r ) ;
1847
	e = <stmt_if_end> ( d, f ) ;
1848
	<condition_set> ( x ) ;
1849
	<stmt_label_clear> ;
1850
    ||
1851
	switch ;
1852
	r = <reach_check> ;
1853
	open-round ; c = condition ;
1854
	a = <stmt_switch_begin> ( c ) ;
1855
	close-round ;
1856
	{
1857
		exhaustive ; ex = <bool_true> ;
1858
	    ||	ex = <bool_false> ;
1859
	} ;
1860
	bs = <stmt_compound_begin> ;
1861
	bc = <cond_inject> ( bs, c ) ;
1862
	b = scoped-statement ( bc ) ;
1863
	<reach_prev> ( r ) ;
1864
	e = <stmt_switch_end> ( a, b, ex ) ;
1865
	<stmt_label_clear> ;
1866
    ||
1867
	e = target-condition ;
1868
	<stmt_label_clear> ;
1869
} ;
1870
 
1871
 
1872
/*
1873
    ITERATION STATEMENTS
1874
 
1875
    These rules describe the iteration statements, consisting of the
1876
    while, do and for statements.
1877
*/
1878
 
1879
<stmt_while_begin> : ( :EXP ) -> ( :EXP ) ;
1880
<stmt_while_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1881
<stmt_do_begin> : () -> ( :EXP ) ;
1882
<stmt_do_end> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1883
<stmt_for_begin> : () -> ( :EXP ) ;
1884
<stmt_for_init> : ( :EXP, :EXP ) -> ( :EXP ) ;
1885
<stmt_for_cond> : ( :EXP, :EXP, :EXP ) -> ( :EXP ) ;
1886
<stmt_for_end> : ( :EXP, :EXP ) -> ( :EXP ) ;
1887
<bind_temporary> : ( :EXP ) -> ( :EXP ) ;
1888
<exp_location> : ( :EXP ) -> ( :EXP ) ;
1889
<init_inject> : ( :EXP, :EXP ) -> ( :EXP ) ;
1890
<loop_inject> : ( :EXP, :EXP ) -> ( :EXP ) ;
1891
 
1892
for-init-statement : () -> ( e : EXP ) = {
1893
	e = expression-statement ;
1894
    ||	e = simple-declaration ;
1895
} ;
1896
 
1897
for-cond-statement : () -> ( a : EXP, e : EXP ) = {
1898
	c = condition ;
1899
	a = <bind_temporary> ( c ) ;
1900
	e = <exp_location> ( a ) ;
1901
	semicolon ;
1902
    ||
1903
	semicolon ;
1904
	a = <exp_none> ;
1905
	e = <exp_location> ( a ) ;
1906
} ;
1907
 
1908
for-end-statement : () -> ( e : EXP ) = {
1909
	a = expression ;
1910
	b = <stmt_exp> ( a ) ;
1911
	e = <bind_temporary> ( b ) ;
1912
    ||
1913
	e = <exp_none> ;
1914
} ;
1915
 
1916
iteration-statement : () -> ( e : EXP ) = {
1917
	while ;
1918
	x = <condition_get> ;
1919
	r = <reach_check> ;
1920
	open-round ; c0 = condition ;
1921
	c = <bind_temporary> ( c0 ) ;
1922
	a = <stmt_while_begin> ( c ) ;
1923
	close-round ;
1924
	bs = <stmt_compound_begin> ;
1925
	bc = <loop_inject> ( bs, c ) ;
1926
	b = scoped-statement ( bc ) ;
1927
	<reach_prev> ( r ) ;
1928
	e = <stmt_while_end> ( a, b ) ;
1929
	<condition_set> ( x ) ;
1930
	<stmt_label_clear> ;
1931
    ||
1932
	do ;
1933
	x = <condition_get> ;
1934
	r = <reach_check> ;
1935
	a = <stmt_do_begin> ;
1936
	bs = <stmt_compound_begin> ;
1937
	b = scoped-statement ( bs ) ;
1938
	while ; open-round ; c0 = expression ;
1939
	c = <bind_temporary> ( c0 ) ;
1940
	<reach_prev> ( r ) ;
1941
	e = <stmt_do_end> ( a, b, c ) ;
1942
	close-round ;
1943
	<condition_set> ( x ) ;
1944
	<stmt_label_clear> ;
1945
	semicolon-x ;
1946
    ||
1947
	for ;
1948
	x = <condition_get> ;
1949
	r = <reach_check> ;
1950
	open-round ;
1951
	f = <stmt_for_begin> ;
1952
	a = for-init-statement ;
1953
	g = <stmt_for_init> ( f, a ) ;
1954
	( c, cp ) = for-cond-statement ;
1955
	ds = <stmt_compound_begin> ;
1956
	b = for-end-statement ;
1957
	h = <stmt_for_cond> ( g, cp, b ) ;
1958
	close-round ;
1959
	da = <init_inject> ( ds, a ) ;
1960
	dc = <loop_inject> ( da, c ) ;
1961
	<stmt_compound_mark> ( dc ) ;
1962
	d = scoped-statement ( dc ) ;
1963
	<reach_prev> ( r ) ;
1964
	e = <stmt_for_end> ( h, d ) ;
1965
	<condition_set> ( x ) ;
1966
	<stmt_label_clear> ;
1967
	<rescan_token> ;
1968
} ;
1969
 
1970
 
1971
/*
1972
    JUMP STATEMENTS
1973
 
1974
    This rule describes the jump statements, consisting of the break,
1975
    continue, return and goto statements.
1976
*/
1977
 
1978
<stmt_break> : () -> ( :EXP ) ;
1979
<stmt_continue> : () -> ( :EXP ) ;
1980
<stmt_return> : ( :EXP ) -> ( :EXP ) ;
1981
<stmt_goto> : ( :IDENTIFIER ) -> ( :EXP ) ;
1982
<stmt_goto_case> : ( :EXP ) -> ( :EXP ) ;
1983
<stmt_goto_default> : () -> ( :EXP ) ;
1984
 
1985
jump-label : () -> ( e : EXP ) = {
1986
	id = any-identifier ;
1987
	<qual_none> ;
1988
	e = <stmt_goto> ( id ) ;
1989
    ||
1990
	case ; c = constant-expression ;
1991
	e = <stmt_goto_case> ( c ) ;
1992
    ||
1993
	default ;
1994
	e = <stmt_goto_default> () ;
1995
} ;
1996
 
1997
jump-statement : () -> ( e : EXP ) = {
1998
	break ;
1999
	r = <reach_check> ;
2000
	e = <stmt_break> ;
2001
	<stmt_label_clear> ;
2002
	semicolon-x ;
2003
    ||
2004
	continue ;
2005
	r = <reach_check> ;
2006
	e = <stmt_continue> ;
2007
	<stmt_label_clear> ;
2008
	semicolon-x ;
2009
    ||
2010
	return ;
2011
	r = <reach_check> ;
2012
	{
2013
		a = expression ;
2014
	    ||	a = <exp_none> ;
2015
	} ;
2016
	e = <stmt_return> ( a ) ;
2017
	<stmt_label_clear> ;
2018
	semicolon-x ;
2019
    ||
2020
	goto ;
2021
	r = <reach_check> ;
2022
	e = jump-label ;
2023
	<stmt_label_clear> ;
2024
	semicolon-x ;
2025
} ;
2026
 
2027
 
2028
/*
2029
    TRY BLOCKS
2030
 
2031
    These rules describe the try blocks and exception handlers.  A try
2032
    block consists of 'try' followed by a compound statement, giving the
2033
    exception body, and a list of exception handlers (the syntax has been
2034
    extended to allow empty lists).  Each exception handler consists of
2035
    'catch' followed by an exception declaration and a compound statement,
2036
    giving the handler body.
2037
*/
2038
 
2039
<stmt_catch_begin> : ( :EXP, :DECL ) -> ( :EXP ) ;
2040
<stmt_catch_end> : ( :EXP, :EXP ) -> () ;
2041
<stmt_caught> : () -> ( :EXP ) ;
2042
<stmt_try_begin> : () -> ( :EXP ) ;
2043
<stmt_try_inject> : ( :EXP ) -> () ;
2044
<stmt_try_cont> : ( :EXP, :EXP ) -> ( :EXP ) ;
2045
<stmt_try_end> : ( :EXP ) -> ( :EXP ) ;
2046
 
2047
exception-declaration : ( :COUNT ) -> ( :DECL ) ;
2048
 
2049
handler : ( a : EXP ) -> () = {
2050
	catch ;
2051
	c = <stmt_compound_begin> ;
2052
	<stmt_try_inject> ( a ) ;
2053
	n = <no_type_defns> ;
2054
	open-round ; d = exception-declaration ( n ) ;
2055
	b = <stmt_catch_begin> ( a, d ) ;
2056
	close-round ;
2057
	open-brace ;
2058
	<stmt_compound_block> ( c ) ;
2059
	e0 = <exp_none> ;
2060
	e1 = <stmt_decl> ( e0 ) ;
2061
	c1 = <stmt_compound_add> ( c, e1 ) ;
2062
	e2 = <stmt_caught> ;
2063
	c2 = <stmt_compound_add> ( c1, e2 ) ;
2064
	c3 = statement-seq-opt ( c2 ) ;
2065
	close-brace ;
2066
	c4 = <stmt_compound_end> ( c3 ) ;
2067
	<stmt_catch_end> ( b, c4 ) ;
2068
	<rescan_token> ;
2069
} ;
2070
 
2071
handler-seq-opt : ( a : EXP ) -> () = {
2072
	handler ( a ) ;
2073
	handler-seq-opt ( a ) ;
2074
    ||
2075
	$ ;
2076
} ;
2077
 
2078
try-block : () -> ( e : EXP ) = {
2079
	try ;
2080
	r = <reach_check> ;
2081
	a = <stmt_try_begin> ;
2082
	b = compound-statement ;
2083
	c = <stmt_try_cont> ( a, b ) ;
2084
	handler-seq-opt ( c ) ;
2085
	<reach_prev> ( r ) ;
2086
	e = <stmt_try_end> ( c ) ;
2087
	<stmt_label_clear> ;
2088
} ;
2089
 
2090
 
2091
/*
2092
    FLOW CONTROL STATEMENTS (EXTENSION)
2093
 
2094
    This rule describes the extensions added to the statements to handle
2095
    flow control and variable analysis commands.
2096
*/
2097
 
2098
<reach_set> : () -> () ;
2099
<reach_unset> : () -> () ;
2100
<stmt_reach> : ( :EXP ) -> ( :EXP ) ;
2101
<stmt_unreach> : ( :EXP ) -> ( :EXP ) ;
2102
 
2103
control-statement : () -> ( e : EXP ) = {
2104
	reachable ; <reach_set> ;
2105
	a = statement ;
2106
	e = <stmt_reach> ( a ) ;
2107
    ||
2108
	unreachable ; <reach_unset> ;
2109
	a = statement ;
2110
	e = <stmt_unreach> ( a ) ;
2111
} ;
2112
 
2113
 
2114
/*
2115
    TOKENISED STATEMENTS
2116
 
2117
    This rule describes the tokenised statements.  This comprises the
2118
    statement names and the complex statements.
2119
*/
2120
 
2121
qualified-stmt-name : () -> ( id : IDENTIFIER ) = {
2122
	uid = statement-name ;
2123
	id = <namespace_simple> ( uid ) ;
2124
    ||
2125
	ns = nested-name ; uid = statement-name ;
2126
	<namespace_nested> ( ns ) ;
2127
	id = <namespace_id> ( ns, uid ) ;
2128
    ||
2129
	ns = full-name ; uid = statement-name ;
2130
	<namespace_full> ( ns ) ;
2131
	id = <namespace_id> ( ns, uid ) ;
2132
    ||
2133
	colon-colon ; uid = statement-name ;
2134
	ns = <namespace_global> ;
2135
	id = <namespace_id> ( ns, uid ) ;
2136
} ;
2137
 
2138
token-statement : () -> ( e : EXP ) = {
2139
	id = qualified-stmt-name ;
2140
	a = <exp_identifier> ( id ) ;
2141
	e = <stmt_exp> ( a ) ;
2142
    ||
2143
	a = complex-stmt ;
2144
	e = <stmt_exp> ( a ) ;
2145
} ;
2146
 
2147
 
2148
/*
2149
    STATEMENTS
2150
 
2151
    This rule describes the statements.  These consist of the all the
2152
    types of statements listing above, including the try blocks.
2153
*/
2154
 
2155
simple-statement : () -> ( e : EXP ) = {
2156
	e = labelled-statement ;
2157
    ||	e = expression-statement ;
2158
    ||	e = selection-statement ;
2159
    ||	e = iteration-statement ;
2160
    ||	e = jump-statement ;
2161
    ||	e = declaration-statement ;
2162
    ||	e = try-block ;
2163
    ||	e = control-statement ;
2164
    ||	e = token-statement ;
2165
} ;
2166
 
2167
statement : () -> ( e : EXP ) = {
2168
	e = simple-statement ;
2169
    ||	e = compound-statement ;
2170
} ;
2171
 
2172
statement-entry : () -> ( e : EXP ) = {
2173
	e = statement ;
2174
    ##
2175
	<error_syntax> ;
2176
	e = <exp_none> ;
2177
} ;
2178
 
2179
 
2180
/*
2181
    CONST-VOLATILE QUALIFIERS
2182
 
2183
    These rules describe the lists of const and volatile type qualifiers.
2184
*/
2185
 
2186
<cv_none> : () -> ( :CV ) ;
2187
<cv_const> : () -> ( :CV ) ;
2188
<cv_volatile> : () -> ( :CV ) ;
2189
<cv_join> : ( :CV, : CV ) -> ( :CV ) ;
2190
 
2191
cv-qualifier : () -> ( cv : CV ) = {
2192
	const ; cv = <cv_const> ;
2193
    ||	volatile ; cv = <cv_volatile> ;
2194
} ;
2195
 
2196
cv-qualifier-seq : () -> ( cv : CV ) = {
2197
	a = cv-qualifier ;
2198
	{
2199
		cv = a ;
2200
	    ||	b = cv-qualifier-seq ; cv = <cv_join> ( a, b ) ;
2201
	} ;
2202
} ;
2203
 
2204
cv-qualifier-seq-opt : () -> ( cv : CV ) = {
2205
	cv = <cv_none> ;
2206
    ||	cv = cv-qualifier-seq ;
2207
} ;
2208
 
2209
 
2210
/*
2211
    SIMPLE TYPE SPECIFIERS
2212
 
2213
    These rules describe the simple type specifiers.  These comprise the
2214
    type names (class names, enumeration names and typedef names) plus the
2215
    basic type keywords.  size_t and ptrdiff_t have been included for
2216
    future convenience only.  Each simple type specifier gives a partial
2217
    type, which is only completed using type_complete when the entire type
2218
    specifier has been given.
2219
*/
2220
 
2221
<btype_char> : () -> ( :BTYPE ) ;
2222
<btype_short> : () -> ( :BTYPE ) ;
2223
<btype_int> : () -> ( :BTYPE ) ;
2224
<btype_long> : () -> ( :BTYPE ) ;
2225
<btype_signed> : () -> ( :BTYPE ) ;
2226
<btype_unsigned> : () -> ( :BTYPE ) ;
2227
<btype_float> : () -> ( :BTYPE ) ;
2228
<btype_double> : () -> ( :BTYPE ) ;
2229
<btype_bool> : () -> ( :BTYPE ) ;
2230
<btype_wchar_t> : () -> ( :BTYPE ) ;
2231
<btype_size_t> : () -> ( :BTYPE ) ;
2232
<btype_ptrdiff_t> : () -> ( :BTYPE ) ;
2233
<btype_void> : () -> ( :BTYPE ) ;
2234
<btype_bottom> : () -> ( :BTYPE ) ;
2235
<btype_join> : ( :BTYPE, :BTYPE ) -> ( :BTYPE ) ;
2236
 
2237
<type_pre> : () -> ( :TYPE ) ;
2238
<type_name> : ( :IDENTIFIER ) -> ( :TYPE ) ;
2239
<type_join> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
2240
<type_complete> : ( :BTYPE, :TYPE, :CV ) -> ( :TYPE ) ;
2241
 
2242
base-type-specifier : () -> ( bt : BTYPE ) = {
2243
	char ; bt = <btype_char> ;
2244
    ||	short ; bt = <btype_short> ;
2245
    ||	int ; bt = <btype_int> ;
2246
    ||	long ; bt = <btype_long> ;
2247
    ||	signed ; bt = <btype_signed> ;
2248
    ||	unsigned ; bt = <btype_unsigned> ;
2249
    ||	float ; bt = <btype_float> ;
2250
    ||	double ; bt = <btype_double> ;
2251
    ||	bool ; bt = <btype_bool> ;
2252
    ||	wchar-t ; bt = <btype_wchar_t> ;
2253
    ||	size-t ; bt = <btype_size_t> ;
2254
    ||	ptrdiff-t ; bt = <btype_ptrdiff_t> ;
2255
    ||	void ; bt = <btype_void> ;
2256
    ||	bottom ; bt = <btype_bottom> ;
2257
} ;
2258
 
2259
simple-type-specifier : () -> ( bt : BTYPE, t : TYPE ) = {
2260
	bt = base-type-specifier ;
2261
	t = <type_pre> ;
2262
    ||
2263
	id = unqualified-type ;
2264
	t = <type_name> ( id ) ;
2265
	bt = <btype_none> ;
2266
    ||
2267
	id = any-qualified-type ;
2268
	t = <type_name> ( id ) ;
2269
	bt = <btype_none> ;
2270
    ||
2271
	t = complex-type ;
2272
	bt = <btype_none> ;
2273
} ;
2274
 
2275
simple-type-id : () -> ( t : TYPE ) = {
2276
	( bt, p ) = simple-type-specifier ;
2277
	cv = <cv_none> ;
2278
	t = <type_complete> ( bt, p, cv ) ;
2279
} ;
2280
 
2281
 
2282
/*
2283
    ELABORATED TYPE SPECIFIERS
2284
 
2285
    This rule describes the elaborated type specifiers, such as 'struct tag'.
2286
    Again, type_elaborate only gives a partial type.
2287
*/
2288
 
2289
<key_class> : () -> ( :KEY ) ;
2290
<key_struct> : () -> ( :KEY ) ;
2291
<key_union> : () -> ( :KEY ) ;
2292
<key_enum> : () -> ( :KEY ) ;
2293
 
2294
<declarator_start> : () -> () ;
2295
<type_elaborate> : ( :IDENTIFIER, :KEY ) -> ( :TYPE ) ;
2296
<type_typename> : ( :NAMESPACE, :IDENTIFIER ) -> ( :TYPE ) ;
2297
 
2298
class-key : () -> ( key : KEY ) = {
2299
	class ; key = <key_class> ;
2300
    ||	struct ; key = <key_struct> ;
2301
    ||	union ; key = <key_union> ;
2302
} ;
2303
 
2304
class-or-enum-key : () -> ( key : KEY ) = {
2305
	key = class-key ;
2306
    ||	enum ; key = <key_enum> ;
2307
} ;
2308
 
2309
any-class-name : () -> ( id : IDENTIFIER ) = {
2310
	id = any-identifier ;
2311
    ||	id = template-type ;
2312
} ;
2313
 
2314
elaborated-type-specifier : () -> ( t : TYPE ) = {
2315
	key = class-or-enum-key ;
2316
	<declarator_start> ;
2317
	ns = any-nested-name-opt ; aid = any-class-name ;
2318
	id = <namespace_id> ( ns, aid ) ;
2319
	t = <type_elaborate> ( id, key ) ;
2320
    ||
2321
	typename ;
2322
	<declarator_start> ;
2323
	ns = any-nested-name-opt ; id = any-class-name ;
2324
	t = <type_typename> ( ns, id ) ;
2325
} ;
2326
 
2327
 
2328
/*
2329
    ACCESS SPECIFIERS
2330
 
2331
    This rule describes the class access specifiers, private, protected
2332
    and public.  When defining a class the current access specifier is
2333
    held in a simple state variable which can be accessed via the actions
2334
    access_set and access_get.
2335
*/
2336
 
2337
<access_private> : () -> ( :ACCESS ) ;
2338
<access_protected> : () -> ( :ACCESS ) ;
2339
<access_public> : () -> ( :ACCESS ) ;
2340
<access_none> : () -> ( :ACCESS ) ;
2341
<access_set> : ( :ACCESS ) -> () ;
2342
<access_get> : () -> ( :ACCESS ) ;
2343
 
2344
access-specifier : () -> ( a : ACCESS ) = {
2345
	private ; a = <access_private> ;
2346
    ||	protected ; a = <access_protected> ;
2347
    ||	public ; a = <access_public> ;
2348
} ;
2349
 
2350
 
2351
/*
2352
    TARGET DEPENDENT MEMBER DECLARATION SEQUENCES
2353
 
2354
    These rules describe the unresolved target dependent conditional
2355
    member declarations.  See target-condition for details.
2356
*/
2357
 
2358
<decl_hash_if> : ( :EXP ) -> () ;
2359
<decl_hash_elif> : ( :EXP ) -> () ;
2360
<decl_hash_else> : () -> () ;
2361
<decl_hash_endif> : () -> () ;
2362
 
2363
member-specification-opt : ( :TYPE, :DSPEC ) -> () ;
2364
 
2365
member-cond-body : () -> () = {
2366
	open-brace ;
2367
	ds = <dspec_none> ;
2368
	t = <type_none> ;
2369
	member-specification-opt ( t, ds ) ;
2370
	close-brace ;
2371
} ;
2372
 
2373
member-cond-head : () -> ( p : EXP ) = {
2374
	c = hash-if ;
2375
	p = <cond_hash_if> ( c ) ;
2376
	<decl_hash_if> ( c ) ;
2377
	member-cond-body ;
2378
    ||
2379
	p = member-cond-head ;
2380
	c = hash-elif ;
2381
	<cond_hash_elif> ( c ) ;
2382
	<decl_hash_elif> ( c ) ;
2383
	member-cond-body ;
2384
} ;
2385
 
2386
member-cond : () -> () = {
2387
	p = member-cond-head ;
2388
	{
2389
		hash-else ;
2390
		<cond_hash_else> ;
2391
		<decl_hash_else> ;
2392
		member-cond-body ;
2393
	    ||
2394
		$ ;
2395
	} ;
2396
	<cond_hash_endif> ( p ) ;
2397
	hash-endif ;
2398
	<decl_hash_endif> ;
2399
} ;
2400
 
2401
 
2402
/*
2403
    CLASS MEMBER SPECIFIERS
2404
 
2405
    These rules describe the class member specifiers.  These consist
2406
    of a list of member declarations, which may also contain a number
2407
    of access specifiers.
2408
*/
2409
 
2410
<template_check> : ( :TYPE, :DSPEC ) -> () ;
2411
 
2412
member-declaration : ( :TYPE, :DSPEC ) -> () ;
2413
 
2414
member-elem : ( t : TYPE, ds : DSPEC ) -> () = {
2415
	member-declaration ( t, ds ) ;
2416
    ||
2417
	b = access-specifier ; colon ;
2418
	<access_set> ( b ) ;
2419
    ||
2420
	<template_check> ( t, ds ) ;
2421
	member-cond ;
2422
} ;
2423
 
2424
member-specification-opt : ( t : TYPE, ds : DSPEC ) -> () = {
2425
	member-elem ( t, ds ) ;
2426
	member-specification-opt ( t, ds ) ;
2427
    ||
2428
	$ ;
2429
} ;
2430
 
2431
 
2432
/*
2433
    BASE CLASS SPECIFIERS
2434
 
2435
    These rules describe the base class specifiers.  These are either
2436
    empty or a colon followed by a list of class names, each of which
2437
    may be qualified by an access specification and by 'virtual'.
2438
*/
2439
 
2440
<class_base> : ( :IDENTIFIER, :ACCESS, :BOOL ) -> () ;
2441
<class_base_end> : ( :BOOL ) -> () ;
2442
 
2443
base-specifier : () -> () = {
2444
	{
2445
		a = access-specifier ;
2446
		v = <bool_false> ;
2447
	    ||
2448
		a = access-specifier ;
2449
		virtual ; v = <bool_true> ;
2450
	    ||
2451
		virtual ; v = <bool_true> ;
2452
		a = <access_none> ;
2453
	    ||
2454
		virtual ; v = <bool_true> ;
2455
		a = access-specifier ;
2456
	    ||
2457
		a = <access_none> ;
2458
		v = <bool_false> ;
2459
	} ;
2460
	ns = any-nested-name-opt ; aid = any-class-name ;
2461
	id = <namespace_id> ( ns, aid ) ;
2462
	<class_base> ( id, a, v ) ;
2463
} ;
2464
 
2465
base-specifier-list : () -> () = {
2466
	base-specifier ;
2467
	{
2468
		comma ; base-specifier-list ;
2469
	    ||	$ ;
2470
	} ;
2471
} ;
2472
 
2473
base-clause-opt : () -> ( t : BOOL ) = {
2474
	colon ; base-specifier-list ; t = <bool_true> ;
2475
    ||	colon ; t = <bool_false> ;
2476
    ||	t = <bool_true>;
2477
} ;
2478
 
2479
 
2480
/*
2481
    CLASS SPECIFIERS
2482
 
2483
    These rules describe the class (which includes structure and union)
2484
    type specifiers.  These consist of a class key followed by an optional
2485
    class name, a list of base classes, and the class definition body.
2486
    This body consists of a list of member declarations enclosed within
2487
    braces.  Note that the default access specifier for the class is
2488
    completely determined by the class key, it is 'private' for 'class'
2489
    and 'public' for 'struct' and 'union'.
2490
*/
2491
 
2492
<is_class_spec> : () -> ( :BOOL ) ;
2493
<access_check_class> : () -> () ;
2494
<access_check> : () -> () ;
2495
<template_decl> : ( :TYPE ) -> () ;
2496
 
2497
<type_class_begin> : ( :IDENTIFIER, :KEY, :TYPE ) -> ( :IDENTIFIER, :BOOL ) ;
2498
<type_class_end> : ( :IDENTIFIER, :BOOL ) -> ( :IDENTIFIER ) ;
2499
 
2500
class-specifier : ( q : TYPE ) -> ( c : IDENTIFIER ) = {
2501
	key = class-key ;
2502
	? = <is_class_spec> ;
2503
	<declarator_start> ;
2504
	{
2505
		ns = any-nested-name-opt ; aid = any-class-name ;
2506
		id = <namespace_id> ( ns, aid ) ;
2507
	    ||
2508
		id = <id_anon> ;
2509
	} ;
2510
	( qu, i ) = <qual_get> ;
2511
	<template_decl> ( q ) ;
2512
	b = <access_get> ;
2513
	( p, f ) = <type_class_begin> ( id, key, q ) ;
2514
	s = base-clause-opt ;
2515
	<class_base_end> ( s ) ;
2516
	ds = <dspec_none> ;
2517
	t = <type_none> ;
2518
	open-brace ; member-specification-opt ( t, ds ) ; close-brace ;
2519
	<access_check_class> ;
2520
	c = <type_class_end> ( p, f ) ;
2521
	<access_set> ( b ) ;
2522
	<qual_set> ( qu, i ) ;
2523
	<rescan_token> ;
2524
} ;
2525
 
2526
 
2527
/*
2528
    ENUMERATION TYPE SPECIFIERS
2529
 
2530
    These rules describe the enumeration type specifiers.  These consist
2531
    of 'enum' followed by an optional identifier and an enumeration
2532
    definition body.  This body consists of a list of enumerator definitions
2533
    enclosed within braces.
2534
*/
2535
 
2536
<error_comma> : () -> () ;
2537
<is_enum_spec> : () -> ( :BOOL ) ;
2538
<type_enum_begin> : ( :IDENTIFIER, :TYPE ) -> ( :IDENTIFIER ) ;
2539
<type_enum_end> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
2540
<declare_enum> : ( :IDENTIFIER, :IDENTIFIER, :EXP ) -> () ;
2541
<declarator_posn> : ( :IDENTIFIER ) -> () ;
2542
 
2543
enumerator-definition : ( e : IDENTIFIER ) -> () = {
2544
	eid = any-identifier ;
2545
	id = <namespace_simple> ( eid ) ;
2546
	<declarator_posn> ( id ) ;
2547
	{
2548
		assign ; c = constant-expression ;
2549
	    ||	c = <exp_none> ;
2550
	} ;
2551
	<declare_enum> ( e, id, c ) ;
2552
} ;
2553
 
2554
enumerator-list : ( e : IDENTIFIER ) -> () = {
2555
	enumerator-definition ( e ) ;
2556
	{
2557
		comma ; enumerator-list ( e ) ;
2558
	    ||	comma ; comma ; <error_comma> ; enumerator-list ( e ) ;
2559
	    ||	comma ; <error_comma> ;
2560
	    ||	$ ;
2561
	} ;
2562
} ;
2563
 
2564
enum-specifier : ( q : TYPE ) -> ( e : IDENTIFIER ) = {
2565
	enum ;
2566
	? = <is_enum_spec> ;
2567
	<declarator_start> ;
2568
	{
2569
		ns = any-nested-name-opt ; aid = any-class-name ;
2570
		id = <namespace_id> ( ns, aid ) ;
2571
	    ||
2572
		id = <id_anon> ;
2573
	} ;
2574
	( qu, i ) = <qual_get> ;
2575
	p = <type_enum_begin> ( id, q ) ;
2576
	open-brace ;
2577
	{
2578
		enumerator-list ( p ) ;
2579
	    ||	$ ;
2580
	} ;
2581
	close-brace ;
2582
	<access_check> ;
2583
	e = <type_enum_end> ( p ) ;
2584
	<qual_set> ( qu, i ) ;
2585
} ;
2586
 
2587
 
2588
/*
2589
    TYPE SPECIFIERS
2590
 
2591
    These rules describes the type specifiers.  These consist of the simple
2592
    type specifiers, the class definitions, the enumeration definitions,
2593
    the elaborated type specifiers and the const and volatile qualifiers.
2594
    Sequences of these specifiers may be combined into a single partial
2595
    type using type_join.  The partial type is not turned into a real
2596
    type until type_complete is applied to it.  Note that the rule
2597
    check-type-specifier-seq is identical to type-specifier-seq except
2598
    that it always calls the predicate is_type_specifier to check what
2599
    is coming next.
2600
*/
2601
 
2602
<is_type_specifier> : () -> ( :BOOL ) ;
2603
 
2604
type-specifier : ( s : TYPE ) -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
2605
	( bt, t ) = simple-type-specifier ;
2606
	cv = <cv_none> ;
2607
    ||
2608
	c = class-specifier ( s ) ;
2609
	t = <type_name> ( c ) ;
2610
	bt = <btype_none> ;
2611
	cv = <cv_none> ;
2612
    ||
2613
	e = enum-specifier ( s ) ;
2614
	t = <type_name> ( e ) ;
2615
	bt = <btype_none> ;
2616
	cv = <cv_none> ;
2617
    ||
2618
	t = elaborated-type-specifier ;
2619
	bt = <btype_none> ;
2620
	cv = <cv_none> ;
2621
    ||
2622
	cv = cv-qualifier ;
2623
	bt = <btype_none> ;
2624
	t = <type_none> ;
2625
} ;
2626
 
2627
type-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
2628
	s = <type_none> ;
2629
	( b1, t1, cv1 ) = type-specifier ( s ) ;
2630
	{
2631
		( b2, t2, cv2 ) = type-specifier-seq ;
2632
		bt = <btype_join> ( b1, b2 ) ;
2633
		t = <type_join> ( t1, t2 ) ;
2634
		cv = <cv_join> ( cv1, cv2 ) ;
2635
	    ||
2636
		bt = b1 ;
2637
		t = t1 ;
2638
		cv = cv1 ;
2639
	} ;
2640
} ;
2641
 
2642
check-type-specifier-seq : () -> ( bt : BTYPE, t : TYPE, cv : CV ) = {
2643
	? = <is_type_specifier> ;
2644
	s = <type_none> ;
2645
	( b1, t1, cv1 ) = type-specifier ( s ) ;
2646
	{
2647
		( b2, t2, cv2 ) = check-type-specifier-seq ;
2648
		bt = <btype_join> ( b1, b2 ) ;
2649
		t = <type_join> ( t1, t2 ) ;
2650
		cv = <cv_join> ( cv1, cv2 ) ;
2651
	    ||
2652
		bt = b1 ;
2653
		t = t1 ;
2654
		cv = cv1 ;
2655
	} ;
2656
} ;
2657
 
2658
 
2659
/*
2660
    STORAGE CLASS SPECIFIERS
2661
 
2662
    This rule describes the storage class specifiers, including 'mutable'
2663
    as well as the more obvious 'static', 'extern' and so on.
2664
*/
2665
 
2666
<dspec_auto> : () -> ( :DSPEC ) ;
2667
<dspec_extern> : () -> ( :DSPEC ) ;
2668
<dspec_static> : () -> ( :DSPEC ) ;
2669
<dspec_mutable> : () -> ( :DSPEC ) ;
2670
<dspec_register> : () -> ( :DSPEC ) ;
2671
 
2672
storage-class-specifier : () -> ( ds : DSPEC ) = {
2673
	auto ; ds = <dspec_auto> ;
2674
    ||	extern ; ds = <dspec_extern> ;
2675
    ||	static ; ds = <dspec_static> ;
2676
    ||	mutable ; ds = <dspec_mutable> ;
2677
    ||	register ; ds = <dspec_register> ;
2678
} ;
2679
 
2680
 
2681
/*
2682
    FUNCTION SPECIFIERS
2683
 
2684
    This rule describes the function specifiers, 'inline, 'virtual' and
2685
    'explicit'.
2686
*/
2687
 
2688
<dspec_inline> : () -> ( :DSPEC ) ;
2689
<dspec_virtual> : () -> ( :DSPEC ) ;
2690
<dspec_explicit> : () -> ( :DSPEC ) ;
2691
<dspec_overload> : () -> ( :DSPEC ) ;
2692
 
2693
function-specifier : () -> ( ds : DSPEC ) = {
2694
	inline ; ds = <dspec_inline> ;
2695
    ||	virtual ; ds = <dspec_virtual> ;
2696
    ||	explicit ; ds = <dspec_explicit> ;
2697
    ||	overload ; ds = <dspec_overload> ;
2698
} ;
2699
 
2700
 
2701
/*
2702
    DECLARATION SPECIFIERS
2703
 
2704
    These rules describes the declaration specifiers.  These consist of
2705
    the type specifiers, the storage class and function specifiers, plus
2706
    'friend' and 'typedef'.  Like type specifiers, declaration specifiers
2707
    can be formed into lists which are only turned into complete types
2708
    and declaration specifiers later.  Again check-decl-specifier-seq is
2709
    identical to decl-specifier-seq except that it always calls the
2710
    predicate is_decl_specifier to check what is coming next.
2711
*/
2712
 
2713
<dspec_friend> : () -> ( :DSPEC ) ;
2714
<dspec_typedef> : () -> ( :DSPEC ) ;
2715
<dspec_join> : ( :DSPEC, :DSPEC ) -> ( :DSPEC ) ;
2716
<dspec_check> : ( :DSPEC ) -> () ;
2717
 
2718
<is_decl_specifier> : () -> ( :BOOL ) ;
2719
<check_decl_specifier> : () -> () ;
2720
 
2721
decl-specifier : ( s : TYPE ) -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
2722
	{
2723
		ds = storage-class-specifier ;
2724
	    ||	ds = function-specifier ;
2725
	    ||	friend ; ds = <dspec_friend> ;
2726
	    ||	typedef ; ds = <dspec_typedef> ;
2727
	} ;
2728
	<dspec_check> ( ds ) ;
2729
	bt = <btype_none> ;
2730
	t = <type_none> ;
2731
	cv = <cv_none> ;
2732
    ||
2733
	( bt, t, cv ) = type-specifier ( s ) ;
2734
	ds = <dspec_none> ;
2735
} ;
2736
 
2737
decl-specifier-seq : ( s : TYPE ) -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
2738
	( b1, t1, cv1, ds1 ) = decl-specifier ( s ) ;
2739
	<check_decl_specifier> ;
2740
	{
2741
		( b2, t2, cv2, ds2 ) = decl-specifier-seq ( s ) ;
2742
		bt = <btype_join> ( b1, b2 ) ;
2743
		t = <type_join> ( t1, t2 ) ;
2744
		cv = <cv_join> ( cv1, cv2 ) ;
2745
		ds = <dspec_join> ( ds1, ds2 ) ;
2746
	    ||
2747
		bt = b1 ;
2748
		t = t1 ;
2749
		cv = cv1 ;
2750
		ds = ds1 ;
2751
	} ;
2752
} ;
2753
 
2754
check-decl-specifier-seq : ( s : TYPE ) -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
2755
	? = <is_decl_specifier> ;
2756
	( b1, t1, cv1, ds1 ) = decl-specifier ( s ) ;
2757
	{
2758
		( b2, t2, cv2, ds2 ) = check-decl-specifier-seq ( s ) ;
2759
		bt = <btype_join> ( b1, b2 ) ;
2760
		t = <type_join> ( t1, t2 ) ;
2761
		cv = <cv_join> ( cv1, cv2 ) ;
2762
		ds = <dspec_join> ( ds1, ds2 ) ;
2763
	    ||
2764
		bt = b1 ;
2765
		t = t1 ;
2766
		cv = cv1 ;
2767
		ds = ds1 ;
2768
	} ;
2769
} ;
2770
 
2771
check-decl-specifier-seq-opt : ( s : TYPE ) -> ( bt : BTYPE, t : TYPE, cv : CV, ds : DSPEC ) = {
2772
	( bt, t, cv, ds ) = check-decl-specifier-seq ( s ) ;
2773
    ||
2774
	bt = <btype_none> ;
2775
	t = <type_none> ;
2776
	cv = <cv_none> ;
2777
	ds = <dspec_none> ;
2778
} ;
2779
 
2780
 
2781
/*
2782
    POINTER OPERATORS
2783
 
2784
    These rules describe the pointer, reference and pointer to member
2785
    operators.  They build up a partial type, containing the pointer
2786
    information, but not what is pointed to.  This is only filled in later
2787
    by type_inject.  The const and volatile qualified references have been
2788
    included in the grammar, but are weeded out by type_ref.
2789
*/
2790
 
2791
<type_ptr> : ( :CV ) -> ( :TYPE ) ;
2792
<type_ref> : ( :CV ) -> ( :TYPE ) ;
2793
<type_ptr_mem> : ( :IDENTIFIER, :CV ) -> ( :TYPE ) ;
2794
 
2795
ptr-operator : () -> ( p : TYPE ) = {
2796
	star ; cv = cv-qualifier-seq-opt ;
2797
	p = <type_ptr> ( cv ) ;
2798
    ||
2799
	and ; cv = cv-qualifier-seq-opt ;
2800
	p = <type_ref> ( cv ) ;
2801
    ||
2802
	id = nested-name-star ; cv = cv-qualifier-seq-opt ;
2803
	p = <type_ptr_mem> ( id, cv ) ;
2804
    ||
2805
	id = full-name-star ; cv = cv-qualifier-seq-opt ;
2806
	p = <type_ptr_mem> ( id, cv ) ;
2807
} ;
2808
 
2809
 
2810
/*
2811
    DECLARATORS
2812
 
2813
    These rules describe the declarators.  The rule declarator-aux
2814
    builds up a partial type, containing pointer, array, and other
2815
    type information, but not the base type of what is pointed to etc.
2816
    This base type is provided by the rule declarator and filled in
2817
    using type_inject.  Note also that the function style initialisers
2818
    have been included in this rule.  They are distinguished from the
2819
    parameter declaration clauses by the predicate is_initialiser.  This
2820
    can lead to initialisers appearing in the wrong places, but they are
2821
    easily weeded out using initialiser_bad.
2822
*/
2823
 
2824
<type_array> : ( :EXP ) -> ( :TYPE ) ;
2825
<type_build> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
2826
<type_inject> : ( :TYPE, :TYPE ) -> ( :TYPE ) ;
2827
<type_func> : ( :BOOL, :BOOL, :CV, :LIST-TYPE ) -> ( :TYPE ) ;
2828
 
2829
<declarator_begin> : ( :IDENTIFIER ) -> () ;
2830
<declarator_end> : ( :DECL ) -> () ;
2831
<declarator_type> : ( :IDENTIFIER ) -> ( :IDENTIFIER ) ;
2832
 
2833
<param_begin> : ( :IDENTIFIER ) -> () ;
2834
<param_end> : () -> () ;
2835
 
2836
<is_initialiser> : () -> ( :BOOL ) ;
2837
<initialiser_bad> : ( :BOOL ) -> () ;
2838
<declarator_bad> : ( :TYPE ) -> () ;
2839
 
2840
exception-specification-opt : () -> ( :LIST-TYPE ) ;
2841
declarator-aux : () -> ( :TYPE, :IDENTIFIER, :BOOL ) ;
2842
parameter-declaration-clause : () -> ( :BOOL ) ;
2843
 
2844
declarator-id : () -> ( id : IDENTIFIER ) = {
2845
	id = id-expression ;
2846
    ||
2847
	tid = unqualified-type ;
2848
	id = <declarator_type> ( tid ) ;
2849
    ||
2850
	tid = any-qualified-type ;
2851
	id = <declarator_type> ( tid ) ;
2852
    ||
2853
	id = qualified-stmt-name ;
2854
} ;
2855
 
2856
parameter-tail : ( w : BOOL ) -> ( t : TYPE ) = {
2857
	ell = parameter-declaration-clause ;
2858
	close-round ;
2859
	cv = cv-qualifier-seq-opt ;
2860
	ex = exception-specification-opt ;
2861
	t = <type_func> ( ell, w, cv, ex ) ;
2862
} ;
2863
 
2864
declarator-tail : ( id : IDENTIFIER ) -> ( t : TYPE, c : BOOL ) = {
2865
	open-round ;
2866
	{
2867
		w = <bool_false> ;
2868
		<param_begin> ( id ) ;
2869
		t = parameter-tail ( w ) ;
2870
		<param_end> ;
2871
		c = <bool_false> ;
2872
	    ||
2873
		? = <is_initialiser> ;
2874
		c = <bool_true> ;
2875
		t = <type_none> ;
2876
	} ;
2877
    ||
2878
	open-square ;
2879
	{
2880
		e = constant-expression ;
2881
	    ||	e = <exp_none> ;
2882
	} ;
2883
	t = <type_array> ( e ) ;
2884
	close-square ;
2885
	c = <bool_false> ;
2886
    ||
2887
	weak ; open-round ;
2888
	w = <bool_true> ;
2889
	<param_begin> ( id ) ;
2890
	t = parameter-tail ( w ) ;
2891
	<param_end> ;
2892
	c = <bool_false> ;
2893
} ;
2894
 
2895
direct-declarator : () -> ( t : TYPE, id : IDENTIFIER, c : BOOL ) = {
2896
	id = declarator-id ;
2897
	t = <type_none> ;
2898
	c = <bool_false> ;
2899
	<declarator_begin> ( id ) ;
2900
    ||
2901
	( p, id, b ) = direct-declarator ;
2902
	( i, a ) = <qual_get> ;
2903
	( q, c ) = declarator-tail ( id ) ;
2904
	<initialiser_bad> ( b ) ;
2905
	t = <type_build> ( p, q ) ;
2906
	<qual_set> ( i, a ) ;
2907
    ||
2908
	open-round ; ( t, id, c ) = declarator-aux ;
2909
	<initialiser_bad> ( c ) ;
2910
	<declarator_bad> ( t ) ;
2911
	close-round ;
2912
} ;
2913
 
2914
declarator-aux : () -> ( t : TYPE, id : IDENTIFIER, c : BOOL ) = {
2915
	( t, id, c ) = direct-declarator ;
2916
    ||
2917
	p = ptr-operator ; ( q, id, c ) = declarator-aux ;
2918
	t = <type_build> ( q, p ) ;
2919
} ;
2920
 
2921
declarator : ( p : TYPE ) -> ( t : TYPE, id : IDENTIFIER, c : BOOL ) = {
2922
	( q, id, c ) = declarator-aux ;
2923
	<template_decl> ( p ) ;
2924
	t = <type_inject> ( q, p ) ;
2925
} ;
2926
 
2927
 
2928
/*
2929
    ABSTRACT DECLARATORS
2930
 
2931
    These rules describe the abstract declarators.  These are identical
2932
    to the declarators except that they do not have a declarator-id.
2933
    Also initialisers cannot appear in abstract declarators.
2934
*/
2935
 
2936
abstract-declarator-aux : () -> ( :TYPE ) ;
2937
 
2938
abstract-declarator-tail : () -> ( t : TYPE ) = {
2939
	open-round ;
2940
	id = <id_none> ;
2941
	w = <bool_false> ;
2942
	<param_begin> ( id ) ;
2943
	t = parameter-tail ( w ) ;
2944
	<param_end> ;
2945
    ||
2946
	open-square ;
2947
	{
2948
		e = constant-expression ;
2949
	    ||	e = <exp_none> ;
2950
	} ;
2951
	t = <type_array> ( e ) ;
2952
	close-square ;
2953
    ||
2954
	weak ; open-round ;
2955
	id = <id_none> ;
2956
	w = <bool_true> ;
2957
	<param_begin> ( id ) ;
2958
	t = parameter-tail ( w ) ;
2959
	<param_end> ;
2960
} ;
2961
 
2962
direct-abstract-declarator : () -> ( t : TYPE ) = {
2963
	t = abstract-declarator-tail ;
2964
    ||
2965
	p = direct-abstract-declarator ;
2966
	q = abstract-declarator-tail ;
2967
	t = <type_build> ( p, q ) ;
2968
    ||
2969
	open-round ; t = abstract-declarator-aux ;
2970
	<declarator_bad> ( t ) ;
2971
	close-round ;
2972
} ;
2973
 
2974
abstract-declarator-aux : () -> ( t : TYPE ) = {
2975
	t = direct-abstract-declarator ;
2976
    ||
2977
	t = ptr-operator ;
2978
    ||
2979
	p = ptr-operator ; q = abstract-declarator-aux ;
2980
	t = <type_build> ( q, p ) ;
2981
} ;
2982
 
2983
abstract-declarator-opt : ( p : TYPE ) -> ( t : TYPE ) = {
2984
	q = abstract-declarator-aux ;
2985
	t = <type_inject> ( q, p ) ;
2986
    ||
2987
	t = p ;
2988
} ;
2989
 
2990
 
2991
/*
2992
    PARAMETER DECLARATOR
2993
 
2994
    A parameter declarator can be a declarator, an abstract-declarator or
2995
    be empty.  The easiest way to do this is as a separate set of rules.
2996
    A predicate is necessary to distinguish declarator-ids from type names.
2997
    Again it is not necessary to include initialisers.
2998
*/
2999
 
3000
<is_parameter> : () -> ( :BOOL ) ;
3001
 
3002
parameter-declarator-aux : () -> ( :TYPE, :IDENTIFIER ) ;
3003
parameter-declarator-aux-opt : () -> ( :TYPE, :IDENTIFIER ) ;
3004
 
3005
direct-parameter-declarator : () -> ( t : TYPE, id : IDENTIFIER ) = {
3006
	? = <is_parameter> ;
3007
	id = declarator-id ;
3008
	t = <type_none> ;
3009
	<declarator_posn> ( id ) ;
3010
    ||
3011
	( p, id ) = direct-parameter-declarator ;
3012
	( i, b ) = <qual_get> ;
3013
	q = abstract-declarator-tail ;
3014
	<qual_set> ( i, b ) ;
3015
	t = <type_build> ( p, q ) ;
3016
    ||
3017
	t = abstract-declarator-tail ;
3018
	id = <id_anon> ;
3019
	<declarator_posn> ( id ) ;
3020
    ||
3021
	open-round ;
3022
	( t, id ) = parameter-declarator-aux ;
3023
	<declarator_bad> ( t ) ;
3024
	close-round ;
3025
} ;
3026
 
3027
parameter-declarator-aux : () -> ( t : TYPE, id : IDENTIFIER ) = {
3028
	( t, id ) = direct-parameter-declarator ;
3029
    ||
3030
	p = ptr-operator ;
3031
	( q, id ) = parameter-declarator-aux-opt ;
3032
	t = <type_build> ( q, p ) ;
3033
} ;
3034
 
3035
parameter-declarator-aux-opt : () -> ( t : TYPE, id : IDENTIFIER ) = {
3036
	( t, id ) = parameter-declarator-aux ;
3037
    ||
3038
	t = <type_none> ;
3039
	id = <id_anon> ;
3040
	<declarator_posn> ( id ) ;
3041
} ;
3042
 
3043
parameter-declarator-opt : ( p : TYPE ) -> ( t : TYPE, id : IDENTIFIER ) = {
3044
	( q, id ) = parameter-declarator-aux-opt ;
3045
	t = <type_inject> ( q, p ) ;
3046
} ;
3047
 
3048
 
3049
/*
3050
    FUNCTION PARAMETER DECLARATIONS
3051
 
3052
    These rules describe the function parameter declarations.  The rules
3053
    differ slightly from those given in the standard, which was clearly
3054
    not written with LL(1) parsers in mind, but are equivalent.
3055
*/
3056
 
3057
<dspec_complete> : ( :BTYPE, :TYPE, :CV, :DSPEC ) -> ( :TYPE, :DSPEC ) ;
3058
<declare_param> : ( :DSPEC, :TYPE, :IDENTIFIER, :NUMBER ) -> ( :DECL ) ;
3059
<initialise_param> : ( :DECL, :EXP ) -> () ;
3060
<param_func> : () -> ( :NUMBER ) ;
3061
<decl_none> : () -> ( :DECL ) ;
3062
<default_arg_skip> : ( :DECL ) -> ( :EXP ) ;
3063
<default_arg_begin> : () -> () ;
3064
<default_arg_end> : () -> () ;
3065
<is_skipped> : ( :NUMBER ) -> ( :BOOL ) ;
3066
 
3067
parameter-declaration : ( s : TYPE, p : NUMBER ) -> ( d : DECL ) = {
3068
	( bt, t1, cv1, ds1 ) = decl-specifier-seq ( s ) ;
3069
	( t2, ds2 ) = <dspec_complete> ( bt, t1, cv1, ds1 ) ;
3070
	<declarator_start> ;
3071
	( t, id ) = parameter-declarator-opt ( t2 ) ;
3072
	d = <declare_param> ( ds2, t, id, p ) ;
3073
	{
3074
		assign ;
3075
		<default_arg_begin> ;
3076
		{
3077
			? = <is_skipped> ( p ) ;
3078
			a = <default_arg_skip> ( d ) ;
3079
		    ||
3080
			a = initialiser-expression ;
3081
		} ;
3082
		<default_arg_end> ;
3083
		e = a ;
3084
	    ||
3085
		e = <exp_none> ;
3086
	} ;
3087
	<initialise_param> ( d, e ) ;
3088
} ;
3089
 
3090
parameter-declaration-list : () -> ( ell : BOOL ) = {
3091
	ellipsis ;
3092
	ell = <bool_true> ;
3093
    ||
3094
	s = <type_none> ;
3095
	p = <param_func> ;
3096
	d = parameter-declaration ( s, p ) ;
3097
	{
3098
		comma ;
3099
		ell = parameter-declaration-list ;
3100
	    ||
3101
		ellipsis ;
3102
		ell = <bool_true> ;
3103
	    ||
3104
		ell = <bool_false> ;
3105
	} ;
3106
} ;
3107
 
3108
parameter-declaration-clause : () -> ( ell : BOOL ) = {
3109
	ell = parameter-declaration-list ;
3110
    ||
3111
	ell = <bool_false> ;
3112
} ;
3113
 
3114
parameter-entry : ( s : TYPE, p : NUMBER ) -> ( d : DECL ) = {
3115
	d = parameter-declaration ( s, p ) ;
3116
    ##
3117
	<error_syntax> ;
3118
	d = <decl_none> ;
3119
} ;
3120
 
3121
 
3122
/*
3123
    TYPE IDENTIFIERS
3124
 
3125
    This rule describes the type identifiers.  There is a predicate to
3126
    distinguish type identifiers from expressions in, for example, sizeof
3127
    expressions.  A count of the number of types defined in the type
3128
    identifier is maintained.
3129
*/
3130
 
3131
<is_type_id_false> : () -> ( :BOOL ) ;
3132
<is_type_id_true> : () -> ( :BOOL ) ;
3133
<type_bitfield> : ( :TYPE, :BTYPE, :EXP ) -> ( :TYPE ) ;
3134
<type_check> : ( :TYPE ) -> () ;
3135
 
3136
type-id : () -> ( t : TYPE, n : COUNT ) = {
3137
	n1 = <no_type_defns> ;
3138
	( bt, p, cv ) = type-specifier-seq ;
3139
	q = <type_complete> ( bt, p, cv ) ;
3140
	t = abstract-declarator-opt ( q ) ;
3141
	n = <diff_type_defns> ( n1 ) ;
3142
	<type_check> ( t ) ;
3143
} ;
3144
 
3145
type-id-false : () -> ( t : TYPE, n : COUNT ) = {
3146
	? = <is_type_id_false> ;
3147
	( t, n ) = type-id ;
3148
} ;
3149
 
3150
type-id-true : () -> ( t : TYPE, n : COUNT ) = {
3151
	? = <is_type_id_true> ;
3152
	( t, n ) = type-id ;
3153
} ;
3154
 
3155
token-type-id : () -> ( t : TYPE ) = {
3156
	( bt, p, cv ) = type-specifier-seq ;
3157
	q = <type_complete> ( bt, p, cv ) ;
3158
	t = abstract-declarator-opt ( q ) ;
3159
} ;
3160
 
3161
member-type-id : () -> ( t : TYPE ) = {
3162
	( bt, p, cv ) = type-specifier-seq ;
3163
	q = <type_complete> ( bt, p, cv ) ;
3164
	{
3165
		t = abstract-declarator-opt ( q ) ;
3166
	    ||
3167
		rem ;
3168
		( i, b ) = <qual_get> ;
3169
		c = constant-expression ;
3170
		t = <type_bitfield> ( q, bt, c ) ;
3171
		<qual_set> ( i, b ) ;
3172
	} ;
3173
} ;
3174
 
3175
type-id-entry : () -> ( t : TYPE ) = {
3176
	t = token-type-id ;
3177
	<type_check> ( t ) ;
3178
    ##
3179
	<error_syntax> ;
3180
	t = <type_none> ;
3181
} ;
3182
 
3183
 
3184
/*
3185
    CONVERSION TYPE IDENTIFIERS
3186
 
3187
    These rules describe those type identifiers which can be used in
3188
    conversion function identifiers.  The predicate is_ptr_operator is
3189
    required to resolve 'operator int * ( 3 )' as a function call rather
3190
    than a multiplication expression.
3191
*/
3192
 
3193
<is_ptr_operator> : () -> ( :BOOL ) ;
3194
 
3195
conversion-declarator-opt : () -> ( t : TYPE ) = {
3196
	? = <is_ptr_operator> ;
3197
	p = ptr-operator ; q = conversion-declarator-opt ;
3198
	t = <type_build> ( q, p ) ;
3199
    ||
3200
	t = <type_none> ;
3201
} ;
3202
 
3203
conversion-type-id : () -> ( t : TYPE ) = {
3204
	( bt, p, cv ) = check-type-specifier-seq ;
3205
	s = <type_complete> ( bt, p, cv ) ;
3206
	q = conversion-declarator-opt () ;
3207
	t = <type_inject> ( q, s ) ;
3208
} ;
3209
 
3210
 
3211
/*
3212
    NEW TYPE IDENTIFIERS
3213
 
3214
    These rules describe those type identifiers which can be used in
3215
    new expressions.  Again it necessary to resolve 'new int * ( 3 )'
3216
    correctly by means of a predicate.  Note that in array new-declarators
3217
    the first array bound is not necessarily a constant-expression, so
3218
    that, for example, it is possible to form 'new int [n]' for any integral
3219
    expression, n.
3220
*/
3221
 
3222
<type_new_array> : ( :EXP ) -> ( :TYPE ) ;
3223
<is_new_ptr_operator> : () -> ( :BOOL ) ;
3224
 
3225
direct-new-declarator : () -> ( t : TYPE ) = {
3226
	open-square ; a = expression ;
3227
	e = <exp_eval> ( a ) ;
3228
	t = <type_new_array> ( e ) ;
3229
	close-square ;
3230
    ||
3231
	p = direct-new-declarator ;
3232
	open-square ; e = constant-expression ;
3233
	q = <type_array> ( e ) ;
3234
	t = <type_build> ( p, q ) ;
3235
	close-square ;
3236
} ;
3237
 
3238
new-declarator-opt : () -> ( t : TYPE ) = {
3239
	? = <is_new_ptr_operator> ;
3240
	p = ptr-operator ; q = new-declarator-opt ;
3241
	t = <type_build> ( q, p ) ;
3242
    ||
3243
	t = direct-new-declarator ;
3244
    ||
3245
	t = <type_none> ;
3246
} ;
3247
 
3248
new-type-id : () -> ( t : TYPE, n : COUNT ) = {
3249
	n1 = <no_type_defns> ;
3250
	( bt, p, cv ) = type-specifier-seq ;
3251
	s = <type_complete> ( bt, p, cv ) ;
3252
	q = new-declarator-opt () ;
3253
	t = <type_inject> ( q, s ) ;
3254
	n = <diff_type_defns> ( n1 ) ;
3255
} ;
3256
 
3257
 
3258
/*
3259
    INITIALISERS
3260
 
3261
    These rules describe the initialisers.  This includes the assignment
3262
    style and aggregate initialisers, but excludes the function style
3263
    initialisers.  The latter are included as part of the associated
3264
    declarator and passed in to initialiser-opt as c (which is the null
3265
    expression if no such initialiser was given).
3266
*/
3267
 
3268
<exp_aggregate> : ( :LIST-EXP ) -> ( :EXP ) ;
3269
<exp_initialiser> : ( :LIST-EXP ) -> ( :EXP ) ;
3270
<access_check_decl> : ( :DECL ) -> () ;
3271
<access_check_ret> : ( :DECL, :ACCESSES ) -> () ;
3272
<is_true> : ( :BOOL ) -> ( :BOOL ) ;
3273
<rescan_init> : () -> () ;
3274
 
3275
initialiser-clause : ( :DECL ) -> ( :EXP ) ;
3276
 
3277
initialiser-list : ( d : DECL ) -> ( p : LIST-EXP ) = {
3278
	b = initialiser-clause ( d ) ;
3279
	a = <exp_location> ( b ) ;
3280
	{
3281
		comma ; q = initialiser-list ( d ) ;
3282
	    ||	comma ; q = <list_exp_null> ;
3283
	    ||	q = <list_exp_null> ;
3284
	} ;
3285
	p = <list_exp_cons> ( a, q ) ;
3286
} ;
3287
 
3288
initialiser-clause : ( d : DECL ) -> ( e : EXP ) = {
3289
	e = initialiser-expression ;
3290
	<access_check_decl> ( d ) ;
3291
    ||
3292
	open-brace ;
3293
	{
3294
		p = initialiser-list ( d ) ;
3295
	    ||	p = <list_exp_null> ;
3296
	} ;
3297
	close-brace ;
3298
	e = <exp_aggregate> ( p ) ;
3299
} ;
3300
 
3301
initialiser-exp-list : ( d : DECL ) -> ( p : LIST-EXP ) = {
3302
	e = initialiser-expression ;
3303
	<access_check_decl> ( d ) ;
3304
	{
3305
		comma ; q = initialiser-exp-list ( d ) ;
3306
	    ||	q = <list_exp_null> ;
3307
	} ;
3308
	p = <list_exp_cons> ( e, q ) ;
3309
} ;
3310
 
3311
initialiser-opt : ( c : BOOL, d : DECL ) -> ( e : EXP ) = {
3312
	? = <is_true> ( c ) ;
3313
	<rescan_init> ;
3314
	p = initialiser-exp-list ( d ) ;
3315
	e = <exp_initialiser> ( p ) ;
3316
	close-round ;
3317
    ||
3318
	assign ; e = initialiser-clause ( d ) ;
3319
    ||
3320
	e = <exp_none> ;
3321
} ;
3322
 
3323
initialiser-entry : ( d : DECL ) -> ( e : EXP ) = {
3324
	e = initialiser-clause ( d ) ;
3325
    ##
3326
	<error_syntax> ;
3327
	e = <exp_none> ;
3328
} ;
3329
 
3330
 
3331
/*
3332
    INITIALISATION DECLARATORS
3333
 
3334
    These rules describe the declarators with initialisers.  In fact the
3335
    first element in any init-declarator-list is handled separately in the
3336
    rule declaration.  See above for the handling of function style
3337
    initialisers.
3338
*/
3339
 
3340
<declare_id> : ( :DSPEC, :BTYPE, :TYPE, :IDENTIFIER ) -> ( :DECL ) ;
3341
<initialise_id> : ( :DECL, :EXP ) -> () ;
3342
 
3343
init-declarator : ( ds : DSPEC, bt : BTYPE, p : TYPE, r : ACCESSES ) -> () = {
3344
	( t, id, c ) = declarator ( p ) ;
3345
	d = <declare_id> ( ds, bt, t, id ) ;
3346
	<access_check_ret> ( d, r ) ;
3347
	<access_check_decl> ( d ) ;
3348
	e = initialiser-opt ( c, d ) ;
3349
	<initialise_id> ( d, e ) ;
3350
	<access_check_decl> ( d ) ;
3351
	<declarator_end> ( d ) ;
3352
} ;
3353
 
3354
init-declarator-list : ( ds : DSPEC, bt : BTYPE, t : TYPE, r : ACCESSES ) -> () = {
3355
	init-declarator ( ds, bt, t, r ) ;
3356
	{
3357
		comma ;
3358
		<declarator_start> ;
3359
		init-declarator-list ( ds, bt, t, r ) ;
3360
	    ||
3361
		$ ;
3362
	} ;
3363
} ;
3364
 
3365
 
3366
/*
3367
    CONSTRUCTOR CLASS INITIALISERS
3368
 
3369
    These rules describe the class initialisers which may be associated
3370
    with a constructor definition.  These consist of a colon followed by a
3371
    list of class names and expressions associated with these classes.
3372
*/
3373
 
3374
<ctor_begin> : () -> ( :NAMESPACE ) ;
3375
<ctor_end> : ( :NAMESPACE, :EXP, :BOOL ) -> ( :EXP ) ;
3376
<ctor_none> : ( :EXP ) -> ( :EXP, :EXP ) ;
3377
<ctor_initialise> : ( :NAMESPACE, :IDENTIFIER, :EXP ) -> () ;
3378
<ctor_postlude> : ( :EXP, :EXP ) -> ( :EXP ) ;
3379
 
3380
mem-initialiser : ( cns : NAMESPACE ) -> () = {
3381
	ns = any-nested-name-opt ; aid = any-class-name ;
3382
	id = <namespace_id> ( ns, aid ) ;
3383
	( i, b ) = <qual_get> ;
3384
	open-round ; p = expression-list-opt ; close-round ;
3385
	<qual_set> ( i, b ) ;
3386
	e = <exp_initialiser> ( p ) ;
3387
	<ctor_initialise> ( cns, id, e ) ;
3388
    ||
3389
	open-round ; p = expression-list-opt ; close-round ;
3390
	e = <exp_initialiser> ( p ) ;
3391
	id = <id_none> ;
3392
	<ctor_initialise> ( cns, id, e ) ;
3393
} ;
3394
 
3395
mem-initialiser-list : ( cns : NAMESPACE ) -> () = {
3396
	mem-initialiser ( cns ) ;
3397
	{
3398
		comma ; mem-initialiser-list ( cns ) ;
3399
	    ||	$ ;
3400
	} ;
3401
} ;
3402
 
3403
ctor-initialiser-opt : ( c : EXP ) -> ( e : EXP, d : EXP ) = {
3404
	colon ;
3405
	cns = <ctor_begin> ;
3406
	{
3407
		mem-initialiser-list ( cns ) ; b = <bool_true> ;
3408
	    ||	b = <bool_false> ;
3409
	} ;
3410
	e = <ctor_end> ( cns, c, b ) ;
3411
	d = <exp_none> ;
3412
    ||
3413
	( e, d ) = <ctor_none> ( c ) ;
3414
} ;
3415
 
3416
 
3417
/*
3418
    FUNCTION DEFINITIONS
3419
 
3420
    These rules describe the function definitions.  The actual declarator
3421
    for function-definition has been built into declaration.  The rest of
3422
    the definition consists of an optional list of constructor class
3423
    initialisers, which are only actually valid if the function is a
3424
    constructor, plus a compound statement, giving the definition body.
3425
*/
3426
 
3427
<stmt_try_func> : () -> ( :EXP ) ;
3428
 
3429
function-body : ( c : EXP ) -> ( e : EXP ) = {
3430
	( b, d ) = ctor-initialiser-opt ( c ) ;
3431
	open-brace ;
3432
	<stmt_compound_block> ( b ) ;
3433
	a = statement-seq-opt ( b ) ;
3434
	e = <ctor_postlude> ( a, d ) ;
3435
	close-brace ;
3436
} ;
3437
 
3438
function-try-block : () -> ( e : EXP ) = {
3439
	try ;
3440
	r = <reach_check> ;
3441
	a = <stmt_try_func> ;
3442
	b = <stmt_compound_begin> ;
3443
	<stmt_try_inject> ( a ) ;
3444
	f = function-body ( b ) ;
3445
	c = <stmt_compound_end> ( f ) ;
3446
	d = <stmt_try_cont> ( a, c ) ;
3447
	handler-seq-opt ( d ) ;
3448
	<reach_prev> ( r ) ;
3449
	e = <stmt_try_end> ( d ) ;
3450
} ;
3451
 
3452
function-definition-body : () -> ( e : EXP ) = {
3453
	c = <stmt_compound_begin> ;
3454
	{
3455
		a = function-body ( c ) ;
3456
	    ||
3457
		b = function-try-block ;
3458
		a = <stmt_compound_add> ( c, b ) ;
3459
	} ;
3460
	e = <stmt_compound_end> ( a ) ;
3461
	<access_check> ;
3462
} ;
3463
 
3464
function-definition-entry : () -> ( e : EXP ) = {
3465
	e = function-definition-body ;
3466
    ##
3467
	<error_syntax> ;
3468
	e = <exp_none> ;
3469
} ;
3470
 
3471
 
3472
/*
3473
    TARGET DEPENDENT DECLARATION SEQUENCES
3474
 
3475
    These rules describe the unresolved target dependent conditional
3476
    declarations.  See target-condition for details.  The '#pragma'
3477
    directives are included in this rule for convenience.
3478
*/
3479
 
3480
declaration-seq-opt : ( :TYPE, :DSPEC ) -> () ;
3481
 
3482
declaration-cond-body : () -> () = {
3483
	open-brace ;
3484
	ds = <dspec_none> ;
3485
	t = <type_none> ;
3486
	declaration-seq-opt ( t, ds ) ;
3487
	close-brace ;
3488
} ;
3489
 
3490
declaration-cond-head : () -> ( p : EXP ) = {
3491
	c = hash-if ;
3492
	p = <cond_hash_if> ( c ) ;
3493
	<decl_hash_if> ( c ) ;
3494
	declaration-cond-body ;
3495
    ||
3496
	p = declaration-cond-head ;
3497
	c = hash-elif ;
3498
	<cond_hash_elif> ( c ) ;
3499
	<decl_hash_elif> ( c ) ;
3500
	declaration-cond-body ;
3501
} ;
3502
 
3503
declaration-cond : () -> () = {
3504
	p = declaration-cond-head ;
3505
	{
3506
		hash-else ;
3507
		<cond_hash_else> ;
3508
		<decl_hash_else> ;
3509
		declaration-cond-body ;
3510
	    ||
3511
		$ ;
3512
	} ;
3513
	<cond_hash_endif> ( p ) ;
3514
	hash-endif ;
3515
	<decl_hash_endif> ;
3516
    ||
3517
	hash-pragma ;
3518
} ;
3519
 
3520
 
3521
/*
3522
    SEQUENCES OF DECLARATIONS
3523
 
3524
    These rules describe the declaration sequences, consisting of a simple
3525
    list of declarations.
3526
*/
3527
 
3528
<declare_extern> : ( :EXP ) -> () ;
3529
 
3530
declaration : ( :TYPE, :DSPEC ) -> ( :EXP ) ;
3531
 
3532
declaration-elem : ( t : TYPE, ds : DSPEC ) -> () = {
3533
	e = declaration ( t, ds ) ;
3534
	<declare_extern> ( e ) ;
3535
    ||
3536
	<template_check> ( t, ds ) ;
3537
	declaration-cond ;
3538
	<access_check> ;
3539
} ;
3540
 
3541
declaration-seq-opt : ( t : TYPE, ds : DSPEC ) -> () = {
3542
	declaration-elem ( t, ds ) ;
3543
	declaration-seq-opt ( t, ds ) ;
3544
    ||
3545
	$ ;
3546
} ;
3547
 
3548
 
3549
/*
3550
    NAMESPACE DEFINITIONS
3551
 
3552
    These rules describe the namespace definitions, consisting of 'namespace'
3553
    followed by an optional identifier and a list of declarations enclosed
3554
    within braces.
3555
*/
3556
 
3557
<namespace_begin> : ( :IDENTIFIER ) -> () ;
3558
<namespace_end> : () -> () ;
3559
<namespace_begin_anon> : () -> () ;
3560
<namespace_end_anon> : () -> () ;
3561
 
3562
named-namespace-definition : () -> () = {
3563
	namespace ; nid = any-identifier ;
3564
	id = <namespace_simple> ( nid ) ;
3565
	<declarator_posn> ( id ) ;
3566
	<namespace_begin> ( id ) ;
3567
	ds = <dspec_none> ;
3568
	t = <type_none> ;
3569
	open-brace ;
3570
	declaration-seq-opt ( t, ds ) ;
3571
	<namespace_end> ;
3572
	close-brace ;
3573
} ;
3574
 
3575
unnamed-namespace-definition : () -> () = {
3576
	namespace ;
3577
	<namespace_begin_anon> ;
3578
	ds = <dspec_none> ;
3579
	t = <type_none> ;
3580
	open-brace ;
3581
	declaration-seq-opt ( t, ds ) ;
3582
	<namespace_end_anon> ;
3583
	close-brace ;
3584
} ;
3585
 
3586
namespace-definition : () -> () = {
3587
	{
3588
		named-namespace-definition ;
3589
	    ||	unnamed-namespace-definition ;
3590
	} ;
3591
	<rescan_token> ;
3592
} ;
3593
 
3594
 
3595
/*
3596
    NAMESPACE ALIAS DEFINITIONS
3597
 
3598
    These rules describe the namespace alias definitions, consisting of
3599
    an identification of a new name with an existing namespace.
3600
*/
3601
 
3602
<namespace_name> : ( :IDENTIFIER ) -> ( :NAMESPACE ) ;
3603
<namespace_alias> : ( :IDENTIFIER, :NAMESPACE ) -> () ;
3604
 
3605
namespace-alias-definition : () -> () = {
3606
	namespace ; nid = any-identifier ;
3607
	id = <namespace_simple> ( nid ) ;
3608
	<declarator_posn> ( id ) ;
3609
	assign ; pns = any-nested-name-opt ; pid = any-class-name ;
3610
	mid = <namespace_id> ( pns, pid ) ;
3611
	ns = <namespace_name> ( mid ) ;
3612
	<qual_none> ;
3613
	<namespace_alias> ( id, ns ) ;
3614
	semicolon-x ;
3615
} ;
3616
 
3617
 
3618
/*
3619
    USING DECLARATIONS
3620
 
3621
    This rule describes the using declarations, which may be used to bring
3622
    an identifier declared in a namespace into scope.
3623
*/
3624
 
3625
<using_identifier> : ( :IDENTIFIER ) -> () ;
3626
<using_typename> : ( :TYPE ) -> () ;
3627
 
3628
using-declaration : () -> () = {
3629
	using ; id = declarator-id ;
3630
	<using_identifier> ( id ) ;
3631
	semicolon-x ;
3632
    ||
3633
	using ; typename ;
3634
	<declarator_start> ;
3635
	ns = any-nested-name-opt ; id = any-class-name ;
3636
	t = <type_typename> ( ns, id ) ;
3637
	<using_typename> ( t ) ;
3638
	semicolon-x ;
3639
} ;
3640
 
3641
 
3642
/*
3643
    USING DIRECTIVES
3644
 
3645
    This rule describes the using directives, which may be used to bring all
3646
    the identifiers declared in a namespace into scope.
3647
*/
3648
 
3649
<using_namespace> : ( :NAMESPACE ) -> () ;
3650
 
3651
using-directive : () -> () = {
3652
	using ; namespace ;
3653
	pns = any-nested-name-opt ; pid = any-class-name ;
3654
	id = <namespace_id> ( pns, pid ) ;
3655
	ns = <namespace_name> ( id ) ;
3656
	<using_namespace> ( ns ) ;
3657
	semicolon-x ;
3658
} ;
3659
 
3660
 
3661
/*
3662
    ASM DEFINITIONS
3663
 
3664
    This rule describes the asm definitions.  These consist of 'asm' followed
3665
    by a bracketed string literal and a semicolon.
3666
*/
3667
 
3668
<declare_asm> : ( :EXP, :LIST-EXP ) -> ( :EXP ) ;
3669
 
3670
asm-definition : () -> ( e : EXP ) = {
3671
	asm ; open-round ;
3672
	a = string-literal ;
3673
	{
3674
		comma ; p = expression-list ;
3675
	    ||	p = <list_exp_null> ;
3676
	} ;
3677
	e = <declare_asm> ( a, p ) ;
3678
	close-round ;
3679
	semicolon-x ;
3680
} ;
3681
 
3682
 
3683
/*
3684
    LINKAGE SPECIFICATIONS
3685
 
3686
    This rule describes the linkage specifications.  This is implemented
3687
    by a single linkage state variable.  The main action is linkage_string,
3688
    which translates a string literal into a linkage specifier.  The
3689
    'extern' in a linkage specification is distinguished from that in a
3690
    declaration specifier by the predicate is_decl_specifier.
3691
*/
3692
 
3693
<linkage_begin> : ( :LINKAGE ) -> ( :LINKAGE ) ;
3694
<linkage_end> : ( :LINKAGE ) -> () ;
3695
<linkage_string> : ( :EXP ) -> ( :LINKAGE ) ;
3696
<dspec_linkage> : () -> ( :DSPEC ) ;
3697
 
3698
linkage-specification : ( t : TYPE, ds : DSPEC ) -> ( e : EXP ) = {
3699
	extern ; c = string-literal ;
3700
	a = <linkage_string> ( c ) ;
3701
	b = <linkage_begin> ( a ) ;
3702
	ds0 = <dspec_linkage> ;
3703
	ds1 = <dspec_join> ( ds, ds0 ) ;
3704
	{
3705
		e1 = declaration ( t, ds1 ) ;
3706
		<linkage_end> ( b ) ;
3707
	    ||
3708
		open-brace ;
3709
		<template_check> ( t, ds1 ) ;
3710
		t2 = <type_none> ;
3711
		ds2 = <dspec_none> ;
3712
		declaration-seq-opt ( t2, ds2 ) ;
3713
		<linkage_end> ( b ) ;
3714
		close-brace ;
3715
		e1 = <exp_none> ;
3716
	} ;
3717
	e = e1 ;
3718
} ;
3719
 
3720
 
3721
/*
3722
    DECLARATIONS
3723
 
3724
    This rule describes the declarations.  Note that the empty declaration,
3725
    consisting of just a semicolon has been made a separate case (see
3726
    expression-statement).  The first declarator in a simple declaration
3727
    has been factored out of the init-declarator-list and combined with
3728
    the function-definition rule.  Linkage specifications, namespace and
3729
    using declarations and asm-definitions are also classified as
3730
    declarations.
3731
*/
3732
 
3733
<is_function> : () -> ( :BOOL ) ;
3734
<function_begin> : ( :DECL ) -> ( :BOOL ) ;
3735
<function_end> : ( :DECL, :EXP, :BOOL ) -> () ;
3736
<declare_id_empty> : ( :DSPEC, :TYPE, :BTYPE, :TYPE, :CV ) -> () ;
3737
<access_return> : () -> ( :ACCESSES ) ;
3738
<access_free> : ( :ACCESSES ) -> () ;
3739
 
3740
template-declaration : ( :TYPE, :DSPEC ) -> ( :EXP ) ;
3741
 
3742
declaration-basic : ( t : TYPE, ds : DSPEC ) -> () = {
3743
	( bt, t1, cv1, ds1 ) = check-decl-specifier-seq-opt ( t ) ;
3744
	ds2 = <dspec_join> ( ds, ds1 ) ;
3745
	( t2, ds3 ) = <dspec_complete> ( bt, t1, cv1, ds2 ) ;
3746
	t3 = <type_inject> ( t, t2 ) ;
3747
	r = <access_return> ;
3748
	<declarator_start> ;
3749
	( s, id, c ) = declarator ( t3 ) ;
3750
	d = <declare_id> ( ds3, bt, s, id ) ;
3751
	<access_check_ret> ( d, r ) ;
3752
	<access_check_decl> ( d ) ;
3753
	{
3754
		e = initialiser-opt ( c, d ) ;
3755
		<initialise_id> ( d, e ) ;
3756
		<access_check_decl> ( d ) ;
3757
		<declarator_end> ( d ) ;
3758
		{
3759
			comma ;
3760
			<declarator_start> ;
3761
			init-declarator-list ( ds3, bt, t3, r ) ;
3762
		    ||
3763
			$ ;
3764
		} ;
3765
		<access_free> ( r ) ;
3766
		semicolon ;
3767
	    ||
3768
		? = <is_function> ;
3769
		<initialiser_bad> ( c ) ;
3770
		<access_free> ( r ) ;
3771
		b = <function_begin> ( d ) ;
3772
		e = function-definition-body ;
3773
		<function_end> ( d, e, b ) ;
3774
		<declarator_end> ( d ) ;
3775
		<rescan_token> ;
3776
	} ;
3777
    ||
3778
	( bt, t1, cv1, ds1 ) = check-decl-specifier-seq ( t ) ;
3779
	ds2 = <dspec_join> ( ds, ds1 ) ;
3780
	<declare_id_empty> ( ds2, t, bt, t1, cv1 ) ;
3781
	<access_check> ;
3782
	semicolon ;
3783
} ;
3784
 
3785
declaration-other : () -> ( e : EXP ) = {
3786
	e = asm-definition ;
3787
    ||	namespace-definition ; e = <exp_none> ;
3788
    ||	namespace-alias-definition ; e = <exp_none> ;
3789
    ||	using-declaration ; e = <exp_none> ;
3790
    ||	using-directive ; e = <exp_none> ;
3791
} ;
3792
 
3793
declaration-nonempty : ( t : TYPE, ds : DSPEC ) -> ( e : EXP ) = {
3794
	declaration-basic ( t, ds ) ;
3795
	e = <exp_none> ;
3796
    ||
3797
	e = template-declaration ( t, ds ) ;
3798
    ||
3799
	e = linkage-specification ( t, ds ) ;
3800
    ||
3801
	<template_check> ( t, ds ) ;
3802
	e = declaration-other ;
3803
} ;
3804
 
3805
declaration : ( t : TYPE, ds : DSPEC ) -> ( e : EXP ) = {
3806
	e = declaration-nonempty ( t, ds ) ;
3807
    ||
3808
	bt = <btype_none> ;
3809
	t1 = <type_none> ;
3810
	cv = <cv_none> ;
3811
	<declare_id_empty> ( ds, t, bt, t1, cv ) ;
3812
	semicolon ;
3813
	e = <exp_none> ;
3814
} ;
3815
 
3816
declaration-entry : ( t : TYPE, ds : DSPEC ) -> () = {
3817
	declaration-basic ( t, ds ) ;
3818
    ##
3819
	<error_syntax> ;
3820
} ;
3821
 
3822
 
3823
/*
3824
    CLASS MEMBER DECLARATORS
3825
 
3826
    These rules describe the class member declarators.  Note that the
3827
    rule member-specifier-opt is intended to handle both pure-specifier
3828
    and constant-initialiser.  Also two types are passed into these
3829
    rules, one reflecting the declaration type and the other the sequence
3830
    of type-specifiers used to describe this type.  This is because
3831
    in bitfields 'signed int' is not synonomous with 'int'.
3832
*/
3833
 
3834
<declare_member> : ( :DSPEC, :BTYPE, :TYPE, :IDENTIFIER, :BOOL ) -> ( :DECL, :BOOL ) ;
3835
<declare_bitfield> : ( :DSPEC, :TYPE, :IDENTIFIER ) -> ( :DECL ) ;
3836
<type_bitfield_mem> : ( :TYPE, :BTYPE, :EXP, :IDENTIFIER ) -> ( :TYPE ) ;
3837
<initialise_member> : ( :DECL, :EXP, :BOOL ) -> () ;
3838
 
3839
member-specifier-opt : () -> ( e : EXP ) = {
3840
	assign ; e = constant-expression ;
3841
    ||	e = <exp_none> ;
3842
} ;
3843
 
3844
member-declarator : ( ds : DSPEC, p : TYPE, q : BTYPE, r : ACCESSES, f : BOOL ) -> ( d : DECL ) = {
3845
	( t, id, c ) = declarator ( p ) ;
3846
	<initialiser_bad> ( c ) ;
3847
	( d, fr ) = <declare_member> ( ds, q, t, id, f ) ;
3848
	<access_check_ret> ( d, r ) ;
3849
	<access_check_decl> ( d ) ;
3850
	e = member-specifier-opt () ;
3851
	<initialise_member> ( d, e, fr ) ;
3852
	<access_check_decl> ( d ) ;
3853
    ||
3854
	{
3855
		mid = any-identifier ;
3856
		id = <namespace_simple> ( mid ) ;
3857
	    ||
3858
		id = <id_anon> ;
3859
	} ;
3860
	<template_decl> ( p ) ;
3861
	<declarator_begin> ( id ) ;
3862
	( i, b ) = <qual_get> ;
3863
	colon ; c = constant-expression ;
3864
	<qual_set> ( i, b ) ;
3865
	t = <type_bitfield_mem> ( p, q, c, id ) ;
3866
	d = <declare_bitfield> ( ds, t, id ) ;
3867
	<access_check_ret> ( d, r ) ;
3868
	<access_check_decl> ( d ) ;
3869
} ;
3870
 
3871
member-declarator-list : ( ds : DSPEC, p : TYPE, q : BTYPE, r : ACCESSES, f : BOOL ) -> () = {
3872
	d = member-declarator ( ds, p, q, r, f ) ;
3873
	<declarator_end> ( d ) ;
3874
	{
3875
		comma ;
3876
		n = <bool_false> ;
3877
		<declarator_start> ;
3878
		member-declarator-list ( ds, p, q, r, n ) ;
3879
	    ||
3880
		$ ;
3881
	} ;
3882
} ;
3883
 
3884
 
3885
/*
3886
    CLASS MEMBER DECLARATION
3887
 
3888
    This rule describes the class member declarations.  As with the normal
3889
    declaration rule, the first member-declarator has been factored out and
3890
    combined with the function-definition rule.  There is a slight problem
3891
    in that member-declarators allow an initialiser, whereas they are not
3892
    allowed in a function-definition.  However the look-ahead for is_function
3893
    actually occurs in declare_member, so a function definition with an
3894
    initialiser will be resolved as an initialised function declaration
3895
    (which may actually be a legal pure function declaration).  Note also
3896
    that the qualified-ids used to change the access of a member are a
3897
    special case of the first option.
3898
*/
3899
 
3900
template-member-decl : ( :TYPE, :DSPEC ) -> () ;
3901
 
3902
<function_skip> : ( :DECL ) -> () ;
3903
<declare_member_empty> : ( :DSPEC, :TYPE, :BTYPE, :TYPE, :CV ) -> () ;
3904
 
3905
member-declaration : ( t : TYPE, ds : DSPEC ) -> () = {
3906
	( bt, t1, cv1, ds1 ) = check-decl-specifier-seq-opt ( t ) ;
3907
	ds2 = <dspec_join> ( ds, ds1 ) ;
3908
	( t2, ds3 ) = <dspec_complete> ( bt, t1, cv1, ds2 ) ;
3909
	t3 = <type_inject> ( t, t2 ) ;
3910
	r = <access_return> ;
3911
	f = <bool_true> ;
3912
	<declarator_start> ;
3913
	d = member-declarator ( ds3, t3, bt, r, f ) ;
3914
	{
3915
		semicolon ;
3916
		<access_free> ( r ) ;
3917
		<declarator_end> ( d ) ;
3918
	    ||
3919
		comma ;
3920
		<declarator_end> ( d ) ;
3921
		n = <bool_false> ;
3922
		<declarator_start> ;
3923
		member-declarator-list ( ds3, t3, bt, r, n ) ;
3924
		<access_free> ( r ) ;
3925
		semicolon ;
3926
	    ||
3927
		? = <is_function> ;
3928
		<access_free> ( r ) ;
3929
		<function_skip> ( d ) ;
3930
		<declarator_end> ( d ) ;
3931
		<rescan_token> ;
3932
	} ;
3933
    ||
3934
	( bt, t1, cv1, ds1 ) = check-decl-specifier-seq ( t ) ;
3935
	ds2 = <dspec_join> ( ds, ds1 ) ;
3936
	<declare_member_empty> ( ds2, t, bt, t1, cv1 ) ;
3937
	<access_check_class> ;
3938
	semicolon ;
3939
    ||
3940
	t1 = <type_none> ;
3941
	bt = <btype_none> ;
3942
	cv1 = <cv_none> ;
3943
	<declare_member_empty> ( ds, t, bt, t1, cv1 ) ;
3944
	semicolon ;
3945
    ||
3946
	template-member-decl ( t, ds ) ;
3947
    ||
3948
	<template_check> ( t, ds ) ;
3949
	using-declaration ;
3950
} ;
3951
 
3952
 
3953
/*
3954
    CONDITION DECLARATIONS
3955
 
3956
    A condition can be a simple declaration.  These rules describes those
3957
    declarations which are allowed in this situation.
3958
*/
3959
 
3960
<cond_start> : () -> () ;
3961
<cond_end> : () -> ( :EXP ) ;
3962
<cond_type> : ( :TYPE ) -> ( :TYPE ) ;
3963
 
3964
condition-declarator : () -> ( d : DECL ) = {
3965
	( bt, t1, cv1 ) = check-type-specifier-seq ;
3966
	ds1 = <dspec_none> ;
3967
	( t2, ds ) = <dspec_complete> ( bt, t1, cv1, ds1 ) ;
3968
	<declarator_start> ;
3969
	( t3, id, c ) = declarator ( t2 ) ;
3970
	<initialiser_bad> ( c ) ;
3971
	t = <cond_type> ( t3 ) ;
3972
	d = <declare_id> ( ds, bt, t, id ) ;
3973
	<access_check_decl> ( d ) ;
3974
} ;
3975
 
3976
condition-declaration : () -> ( e : EXP ) = {
3977
	? = <is_decl_statement> ;
3978
	<cond_start> ;
3979
	d = condition-declarator ; assign ; a = initialiser-expression ;
3980
	<access_check_decl> ( d ) ;
3981
	<initialise_id> ( d, a ) ;
3982
	<access_check_decl> ( d ) ;
3983
	<declarator_end> ( d ) ;
3984
	e = <cond_end> ;
3985
} ;
3986
 
3987
 
3988
/*
3989
    EXCEPTION DECLARATIONS
3990
 
3991
    This rule describes the exception declarations.  Both declarators and
3992
    abstract declarators are allowed in these declarations, as with function
3993
    parameters.  Therefore the same rule is used.
3994
*/
3995
 
3996
<declare_except> : ( :DSPEC, :TYPE, :IDENTIFIER, :COUNT ) -> ( :DECL ) ;
3997
<declare_none> : () -> ( :DECL ) ;
3998
 
3999
exception-declaration : ( n1 : COUNT ) -> ( d : DECL ) = {
4000
	( bt, t1, cv1 ) = check-type-specifier-seq ;
4001
	ds1 = <dspec_none> ;
4002
	( t2, ds2 ) = <dspec_complete> ( bt, t1, cv1, ds1 ) ;
4003
	<declarator_start> ;
4004
	( t, id ) = parameter-declarator-opt ( t2 ) ;
4005
	n2 = <diff_type_defns> ( n1 ) ;
4006
	d = <declare_except> ( ds2, t, id, n2 ) ;
4007
    ||
4008
	ellipsis-aux ;
4009
	d = <declare_none> ;
4010
} ;
4011
 
4012
 
4013
/*
4014
    EXCEPTION SPECIFICATIONS
4015
 
4016
    These rules describe the exception specifications.  These consist of
4017
    'throw' followed by a bracketed list of type identifiers.
4018
*/
4019
 
4020
<exception_check> : ( :TYPE, :COUNT ) -> ( :TYPE ) ;
4021
<list_type_null> : () -> ( :LIST-TYPE ) ;
4022
<list_type_cons> : ( :TYPE, :LIST-TYPE ) -> ( :LIST-TYPE ) ;
4023
<list_type_all> : () -> ( :LIST-TYPE ) ;
4024
<list_type_ellipsis> : () -> ( :LIST-TYPE ) ;
4025
 
4026
type-id-list : () -> ( p : LIST-TYPE ) = {
4027
	( s, n ) = type-id ;
4028
	t = <exception_check> ( s, n ) ;
4029
	{
4030
		comma ; q = type-id-list ;
4031
	    ||	comma ; <error_comma> ; q = <list_type_null> ;
4032
	    ||	q = <list_type_null> ;
4033
	} ;
4034
	p = <list_type_cons> ( t, q ) ;
4035
} ;
4036
 
4037
exception-specification-opt : () -> ( p : LIST-TYPE ) = {
4038
	throw ; open-round ;
4039
	{
4040
		p = type-id-list ;
4041
	    ||	ellipsis ; p = <list_type_ellipsis> ;
4042
	    ||	p = <list_type_null> ;
4043
	} ;
4044
	close-round ;
4045
    ||
4046
	p = <list_type_all> ;
4047
} ;
4048
 
4049
 
4050
/*
4051
    TEMPLATE DECLARATIONS
4052
 
4053
    These rules describe the template declarations, including template
4054
    specialisations and explicit instantiations.  The rule template-
4055
    parameter-list is sufficiently awkward to require hand crafting via
4056
    the action template_params.
4057
*/
4058
 
4059
<template_params> : ( :BOOL ) -> ( :TEMPLATE ) ;
4060
<template_type> : ( :TEMPLATE, :TYPE ) -> ( :TYPE ) ;
4061
<template_end> : ( :TEMPLATE ) -> () ;
4062
 
4063
export-opt : () -> ( x : BOOL ) = {
4064
	export ; x = <bool_true> ;
4065
    ||	x = <bool_false> ;
4066
} ;
4067
 
4068
template-declaration : ( t : TYPE, ds : DSPEC ) -> ( e : EXP ) = {
4069
	x = export-opt ;
4070
	template ; p = <template_params> ( x ) ;
4071
	t1 = <template_type> ( p, t ) ;
4072
	e = declaration ( t1, ds ) ;
4073
	<template_end> ( p ) ;
4074
	<rescan_token> ;
4075
} ;
4076
 
4077
template-member-decl : ( t : TYPE, ds : DSPEC ) -> () = {
4078
	x = export-opt ;
4079
	template ; p = <template_params> ( x ) ;
4080
	t1 = <template_type> ( p, t ) ;
4081
	member-declaration ( t1, ds ) ;
4082
	<template_end> ( p ) ;
4083
	<rescan_token> ;
4084
} ;
4085
 
4086
 
4087
/*
4088
    TEMPLATE TYPE PARAMETERS
4089
 
4090
    These rules describes the template type parameters.
4091
*/
4092
 
4093
<template_param_type> : ( :IDENTIFIER ) -> ( :DECL ) ;
4094
<template_init_type> : ( :DECL, :TYPE ) -> () ;
4095
<template_param_name> : ( :TYPE, :IDENTIFIER, :DSPEC ) -> ( :DECL ) ;
4096
<template_init_name> : ( :DECL, :IDENTIFIER ) -> () ;
4097
 
4098
template-param-name : () -> ( id : IDENTIFIER ) = {
4099
	tid = any-identifier ;
4100
	id = <namespace_simple> ( tid ) ;
4101
    ||
4102
	id = <id_anon> ;
4103
} ;
4104
 
4105
template-type-param : () -> ( d : DECL ) = {
4106
	{
4107
		class ;
4108
	    ||	typename ;
4109
	} ;
4110
	id = template-param-name ;
4111
	d = <template_param_type> ( id ) ;
4112
	{
4113
		assign ;
4114
		<default_arg_begin> ;
4115
		t = token-type-id ;
4116
		<default_arg_end> ;
4117
		<type_check> ( t ) ;
4118
	    ||
4119
		t = <type_none> ;
4120
	} ;
4121
	<template_init_type> ( d, t ) ;
4122
    ||
4123
	template ;
4124
	e = <bool_false> ;
4125
	p = <template_params> ( e ) ;
4126
	t = <type_none> ;
4127
	ds = <dspec_none> ;
4128
	t1 = <template_type> ( p, t ) ;
4129
	class ; id = template-param-name ;
4130
	d = <template_param_name> ( t1, id, ds ) ;
4131
	{
4132
		assign ;
4133
		<default_arg_begin> ;
4134
		aid = any-qualified-id ;
4135
		tid = <namespace_simple> ( aid ) ;
4136
		<default_arg_end> ;
4137
	    ||
4138
		tid = <id_none> ;
4139
	} ;
4140
	<template_init_name> ( d, tid ) ;
4141
	<template_end> ( p ) ;
4142
	<rescan_token> ;
4143
    ##
4144
	<error_syntax> ;
4145
	d = <decl_none> ;
4146
} ;
4147
 
4148
 
4149
/*
4150
    TRANSLATION UNITS
4151
 
4152
    This is the main entry point for the grammar.  A translation unit
4153
    consists of a (possibly empty) sequence of declarations, followed
4154
    by the end of the file.
4155
*/
4156
 
4157
translation-unit : ( t : TYPE, ds : DSPEC ) -> () = {
4158
	declaration-seq-opt ( t, ds ) ; eof ;
4159
    ##
4160
	<error_fatal> ;
4161
} ;
4162
 
4163
 
4164
/*
4165
    CONDITIONAL COMPILATION CONSTANTS
4166
 
4167
    This rule is the alternative entry point for the conditions following
4168
    #if and #elif preprocessing directives.  It consists of a constant
4169
    expression.  The end of line marker which follows this expression is
4170
    handled by the calling routine.
4171
*/
4172
 
4173
hash-if-expression : () -> ( e : EXP ) = {
4174
	e = constant-expression ;
4175
    ##
4176
	<error_syntax> ;
4177
	e = <exp_none> ;
4178
} ;
4179
 
4180
 
4181
/*
4182
    CONSTANT MEMBER DESIGNATORS
4183
 
4184
    These rules describe the constant member offsets.  The entry point
4185
    constant-offset is used for reading member token definitions.
4186
*/
4187
 
4188
<offset_nspace> : ( :TYPE ) -> ( :NAMESPACE ) ;
4189
<offset_index> : ( :OFFSET, :TYPE, :EXP ) -> ( :OFFSET, :TYPE ) ;
4190
<offset_member> : ( :OFFSET, :TYPE, :IDENTIFIER, :NAMESPACE ) -> ( :OFFSET, :TYPE ) ;
4191
 
4192
member-designator : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
4193
	ns = <offset_nspace> ( s ) ;
4194
	<rescan_token> ;
4195
	id = field-id-expression ( ns ) ;
4196
	( a, t ) = <offset_member> ( b, s, id, ns ) ;
4197
	<rescan_token> ;
4198
} ;
4199
 
4200
designator : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
4201
	dot ; ( a, t ) = member-designator ( b, s ) ;
4202
    ||
4203
	open-square ; e = constant-expression ;
4204
	( a, t ) = <offset_index> ( b, s, e ) ;
4205
	close-square ;
4206
} ;
4207
 
4208
designator-list : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
4209
	( a, t ) = designator ( b, s ) ;
4210
    ||
4211
	( c, u ) = designator-list ( b, s ) ;
4212
	( a, t ) = designator ( c, u ) ;
4213
} ;
4214
 
4215
constant-offset : ( b : OFFSET, s : TYPE ) -> ( a : OFFSET, t : TYPE ) = {
4216
	( c, u ) = member-designator ( b, s ) ;
4217
	{
4218
		a = c ;
4219
		t = u ;
4220
	    ||
4221
		( a, t ) = designator-list ( c, u ) ;
4222
	} ;
4223
    ##
4224
	<error_syntax> ;
4225
	a = b ;
4226
	t = s ;
4227
} ;
4228
 
4229
 
4230
/*
4231
    ENTRY POINTS
4232
 
4233
    There are a large number of entry points for the grammar, the main
4234
    one being translation-unit, with others for expressions, types etc.
4235
*/
4236
 
4237
%entry% translation-unit, expression-entry, function-definition-entry,
4238
	declaration-entry, id-entry, operator-id, type-id-entry,
4239
	token-type-id, member-type-id, parameter-entry, statement-entry,
4240
	initialiser-entry, hash-if-expression, template-type-param,
4241
	constant-offset ;