source: src/Parser/parser.yy @ ada0eb06

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ada0eb06 was ea0c5e3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

forgot to handle and test u8 concatenated strings

  • Property mode set to 100644
File size: 114.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// parser.yy --
8//
9// Author           : Peter A. Buhr
10// Created On       : Sat Sep  1 20:22:55 2001
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Sep 11 18:12:00 2017
13// Update Count     : 2787
14//
15
16// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
17// grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While parts have been
18// copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar.
19// In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax
20// that must be subsequently rejected by semantic checks.  Nevertheless, there are still several semantic checks
21// required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions.
22
23// Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with
24// the grammar.
25
26// The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
27//
28// 1. designation with '=' (use ':' instead)
29//
30// Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has
31// two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
32//
33// 1. designation with and without '=' (use ':' instead)
34// 2. attributes not allowed in parenthesis of declarator
35//
36// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
37// (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the
38// syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable
39// parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation"
40// grammar rule.
41
42%{
43#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
44#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
45#define YYERROR_VERBOSE
46
47#undef __GNUC_MINOR__
48
49#include <cstdio>
50#include <stack>
51using namespace std;
52
53#include "ParseNode.h"
54#include "TypedefTable.h"
55#include "TypeData.h"
56#include "LinkageSpec.h"
57#include "Common/SemanticError.h"                                               // error_str
58
59extern DeclarationNode * parseTree;
60extern LinkageSpec::Spec linkage;
61extern TypedefTable typedefTable;
62
63stack< LinkageSpec::Spec > linkageStack;
64
65bool appendStr( string & to, string & from ) {
66        // 1. Multiple strings are concatenated into a single string but not combined internally. The reason is that
67        //    "\x12" "3" is treated as 2 characters versus 1 because "escape sequences are converted into single members of
68        //    the execution character set just prior to adjacent string literal concatenation" (C11, Section 6.4.5-8). It is
69        //    easier to let the C compiler handle this case.
70        //
71        // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
72        //    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
73        //    i.e., u"a" U"b" L"c" is disallowed.
74
75        if ( from[0] != '"' ) {                                                         // encoding ?
76                if ( to[0] != '"' ) {                                                   // encoding ?
77                        if ( to[0] != from[0] || to[1] != from[1] ) { // different encodings ?
78                                yyerror( "non-matching string encodings for string-literal concatenation" );
79                                return false;                                                   // parse error, must call YYERROR in action
80                        } else if ( from[1] == '8' ) {
81                                from.erase( 0, 1 );                                             // remove 2nd encoding
82                        } // if
83                } else {
84                        if ( from[1] == '8' ) {                                         // move encoding to start
85                                to = "u8" + to;
86                                from.erase( 0, 1 );                                             // remove 2nd encoding
87                        } else {
88                                to = from[0] + to;
89                        } // if
90                } // if
91                from.erase( 0, 1 );                                                             // remove 2nd encoding
92        } // if
93        to += " " + from;                                                                       // concatenated into single string
94        return true;
95} // appendStr
96
97DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
98        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
99        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
100        //cur->addType( specifier );
101        for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
102                cl->cloneBaseType( cur );
103        } // for
104        declList->addType( cl );
105//      delete cl;
106        return declList;
107} // distAttr
108
109void distExt( DeclarationNode * declaration ) {
110        // distribute EXTENSION across all declarations
111        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
112                iter->set_extension( true );
113        } // for
114} // distExt
115
116bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
117%}
118
119%define parse.error verbose
120
121// Types declaration
122%union
123{
124        Token tok;
125        ParseNode * pn;
126        ExpressionNode * en;
127        DeclarationNode * decl;
128        DeclarationNode::Aggregate aggKey;
129        DeclarationNode::TypeClass tclass;
130        StatementNode * sn;
131        WaitForStmt * wfs;
132        Expression * constant;
133        IfCtl * ifctl;
134        ForCtl * fctl;
135        LabelNode * label;
136        InitializerNode * in;
137        OperKinds op;
138        std::string * str;
139        bool flag;
140        CatchStmt::Kind catch_kind;
141}
142
143//************************* TERMINAL TOKENS ********************************
144
145// keywords
146%token TYPEDEF
147%token EXTERN STATIC AUTO REGISTER
148%token THREADLOCAL                                                                              // C11
149%token INLINE FORTRAN                                                                   // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
150%token NORETURN                                                                                 // C11
151%token CONST VOLATILE
152%token RESTRICT                                                                                 // C99
153%token ATOMIC                                                                                   // C11
154%token FORALL MUTEX VIRTUAL                                                             // CFA
155%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
156%token BOOL COMPLEX IMAGINARY                                                   // C99
157%token ZERO_T ONE_T                                                                             // CFA
158%token VALIST                                                                                   // GCC
159%token TYPEOF LABEL                                                                             // GCC
160%token ENUM STRUCT UNION
161%token COROUTINE MONITOR THREAD                                                 // CFA
162%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
163%token SIZEOF OFFSETOF
164%token ATTRIBUTE EXTENSION                                                              // GCC
165%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
166%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
167%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
168%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
169
170// names and constants: lexer differentiates between identifier and typedef names
171%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
172%token<tok> TIMEOUT                             WOR
173%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
174%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
175// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
176// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
177// converted into the tuple index (.)(1). e.g., 3.x
178%token<tok>     FLOATING_DECIMALconstant        FLOATING_FRACTIONconstant       FLOATINGconstant
179
180// multi-character operators
181%token ARROW                                                                                    // ->
182%token ICR DECR                                                                                 // ++   --
183%token LS RS                                                                                    // <<   >>
184%token LE GE EQ NE                                                                              // <=   >=      ==      !=
185%token ANDAND OROR                                                                              // &&   ||
186%token ELLIPSIS                                                                                 // ...
187
188%token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
189%token PLUSassign       MINUSassign                                                     // +=   -=
190%token LSassign         RSassign                                                        // <<=  >>=
191%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
192
193%token ATassign                                                                                 // @=
194
195%type<tok> identifier  no_attr_identifier
196%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
197%type<tok> quasi_keyword
198%type<constant> string_literal
199%type<str> string_literal_list
200
201// expressions
202%type<en> constant
203%type<en> tuple                                                 tuple_expression_list
204%type<op> ptrref_operator                               unary_operator                          assignment_operator
205%type<en> primary_expression                    postfix_expression                      unary_expression
206%type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
207%type<en> shift_expression                              relational_expression           equality_expression
208%type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
209%type<en> logical_AND_expression                logical_OR_expression
210%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
211%type<en> comma_expression                              comma_expression_opt
212%type<en> argument_expression_list              argument_expression                     default_initialize_opt
213%type<ifctl> if_control_expression
214%type<fctl> for_control_expression
215%type<en> subrange
216%type<decl> asm_name_opt
217%type<en> asm_operands_opt asm_operands_list asm_operand
218%type<label> label_list
219%type<en> asm_clobbers_list_opt
220%type<flag> asm_volatile_opt
221%type<en> handler_predicate_opt
222
223// statements
224%type<sn> statement                                             labeled_statement                       compound_statement
225%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
226%type<sn> selection_statement
227%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
228%type<en> case_value
229%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
230%type<sn> fall_through                                  fall_through_opt
231%type<sn> iteration_statement                   jump_statement
232%type<sn> expression_statement                  asm_statement
233%type<sn> with_statement                                with_clause_opt
234%type<sn> exception_statement                   handler_clause                          finally_clause
235%type<catch_kind> handler_key
236%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
237%type<sn> waitfor_statement
238%type<wfs> waitfor_clause
239
240// declarations
241%type<decl> abstract_declarator abstract_ptr abstract_array abstract_function array_dimension multi_array_dimension
242%type<decl> abstract_parameter_declarator abstract_parameter_ptr abstract_parameter_array abstract_parameter_function array_parameter_dimension array_parameter_1st_dimension
243%type<decl> abstract_parameter_declaration
244
245%type<aggKey> aggregate_key
246%type<decl> aggregate_type aggregate_type_nobody
247
248%type<decl> assertion assertion_list_opt
249
250%type<en>   bit_subrange_size_opt bit_subrange_size
251
252%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
253
254%type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
255
256%type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list
257%type<decl> declaration_specifier declaration_specifier_nobody declarator declaring_list
258
259%type<decl> elaborated_type elaborated_type_nobody
260
261%type<decl> enumerator_list enum_type enum_type_nobody
262%type<en> enumerator_value_opt
263
264%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
265
266%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
267%type<en> field field_list field_name fraction_constants
268
269%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
270
271%type<decl> identifier_parameter_declarator identifier_parameter_ptr identifier_parameter_array identifier_parameter_function
272%type<decl> identifier_list
273
274%type<decl> cfa_abstract_array cfa_abstract_declarator_no_tuple cfa_abstract_declarator_tuple
275%type<decl> cfa_abstract_function cfa_abstract_parameter_declaration cfa_abstract_parameter_list
276%type<decl> cfa_abstract_ptr cfa_abstract_tuple
277
278%type<decl> cfa_array_parameter_1st_dimension
279
280%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
281%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
282
283%type<decl> cfa_identifier_parameter_array cfa_identifier_parameter_declarator_no_tuple
284%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
285
286%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt
287
288%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
289
290%type<decl> c_declaration
291%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
292%type<decl> KR_declaration_list KR_declaration_list_opt
293
294%type<decl> parameter_declaration parameter_list parameter_type_list
295%type<decl> parameter_type_list_opt
296
297%type<decl> paren_identifier paren_type
298
299%type<decl> storage_class storage_class_list
300
301%type<decl> sue_declaration_specifier sue_declaration_specifier_nobody sue_type_specifier sue_type_specifier_nobody
302
303%type<tclass> type_class
304%type<decl> type_declarator type_declarator_name type_declaring_list
305
306%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
307%type<decl> typedef typedef_declaration typedef_expression
308
309%type<decl> variable_type_redeclarator type_ptr type_array type_function
310
311%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
312
313%type<decl> type type_no_function
314%type<decl> type_parameter type_parameter_list type_initializer_opt
315
316%type<en> type_list
317
318%type<decl> type_qualifier type_qualifier_name type_qualifier_list_opt type_qualifier_list
319%type<decl> type_specifier type_specifier_nobody
320
321%type<decl> variable_declarator variable_ptr variable_array variable_function
322%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
323
324%type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
325
326// initializers
327%type<in>  initializer initializer_list initializer_opt
328
329// designators
330%type<en>  designator designator_list designation
331
332
333// Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string
334// is ambiguous:
335// .---------.                          matches IF '(' comma_expression ')' statement . (reduce)
336// if ( C ) S1 else S2
337// `-----------------'          matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
338// Similar issues exit with the waitfor statement.
339
340// Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
341// associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
342%precedence THEN        // rule precedence for IF/WAITFOR statement
343%precedence WOR         // token precedence for start of WOR in WAITFOR statement
344%precedence TIMEOUT     // token precedence for start of TIMEOUT in WAITFOR statement
345%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
346
347
348%start translation_unit                                                                 // parse-tree root
349
350%%
351//************************* Namespace Management ********************************
352
353// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
354// "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
355// context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
356// Hence, this grammar uses the ANSI style.
357//
358// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
359// introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
360// type name creates a third class of identifiers that must be distinguished by the scanner.
361//
362// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
363// accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
364// actions during the parser update this data structure when the class of identifiers change.
365//
366// Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
367// local scope; it must revert to its original class at the end of the block.  Since type names can be local to a
368// particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are
369// local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
370// "typedef" or "otype" declarations).
371//
372// The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
373// scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
374// within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point
375// of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
376// enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
377// rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around
378// "push" and "pop" nonterminals to resolve conflicts of this sort.
379
380push:
381                { typedefTable.enterScope(); }
382        ;
383
384pop:
385                { typedefTable.leaveScope(); }
386        ;
387
388//************************* CONSTANTS ********************************
389
390constant:
391                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
392        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
393        | FLOATING_DECIMALconstant                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
394        | FLOATING_FRACTIONconstant                                     { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
395        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
396        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
397        ;
398
399quasi_keyword:                                                                                  // CFA
400        TIMEOUT
401        | WOR
402        ;
403
404identifier:
405        IDENTIFIER
406        | ATTR_IDENTIFIER                                                                       // CFA
407        | quasi_keyword
408        ;
409
410no_attr_identifier:
411        IDENTIFIER
412        | quasi_keyword
413        ;
414
415string_literal:
416        string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
417        ;
418
419string_literal_list:                                                                    // juxtaposed strings are concatenated
420        STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
421        | string_literal_list STRINGliteral
422                {
423                        if ( ! appendStr( *$1, *$2 ) ) YYERROR;         // append 2nd juxtaposed string to 1st
424                        delete $2;                                                                      // allocated by lexer
425                        $$ = $1;                                                                        // conversion from tok to str
426                }
427        ;
428
429//************************* EXPRESSIONS ********************************
430
431primary_expression:
432        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
433                { $$ = new ExpressionNode( build_varref( $1 ) ); }
434        | quasi_keyword
435                { $$ = new ExpressionNode( build_varref( $1 ) ); }
436        | tuple
437        | '(' comma_expression ')'
438                { $$ = $2; }
439        | '(' compound_statement ')'                                            // GCC, lambda expression
440                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
441        | primary_expression '{' argument_expression_list '}' // CFA, constructor call
442                {
443                        Token fn;
444                        fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
445                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
446                }
447        | type_name '.' no_attr_identifier                                      // CFA, nested type
448                { $$ = nullptr; }                                                               // FIX ME
449        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
450                { $$ = nullptr; }                                                               // FIX ME
451        ;
452
453postfix_expression:
454        primary_expression
455        | postfix_expression '[' push assignment_expression pop ']'
456                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
457                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
458                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
459                // equivalent to the old x[i,j].
460                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
461        | postfix_expression '(' argument_expression_list ')'
462                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
463        | postfix_expression '.' no_attr_identifier
464                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
465        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
466                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
467        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
468                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
469        | postfix_expression ARROW no_attr_identifier
470                {
471                        $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
472                }
473        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
474                        { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
475        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
476                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
477        | postfix_expression ICR
478                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
479        | postfix_expression DECR
480                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
481        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
482                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
483        | '^' primary_expression '{' argument_expression_list '}' // CFA
484                {
485                        Token fn;
486                        fn.str = new string( "^?{}" );                          // location undefined
487                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );
488                }
489        ;
490
491argument_expression_list:
492        argument_expression
493        | argument_expression_list ',' argument_expression
494                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
495        ;
496
497argument_expression:
498        // empty
499                { $$ = nullptr; }
500        // | '@'                                                                                                // use default argument
501        //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
502        | assignment_expression
503        ;
504
505field_list:                                                                                             // CFA, tuple field selector
506        field
507        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
508        ;
509
510field:                                                                                                  // CFA, tuple field selector
511        field_name
512        | FLOATING_DECIMALconstant field
513                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
514        | FLOATING_DECIMALconstant '[' push field_list pop ']'
515                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
516        | field_name '.' field
517                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
518        | field_name '.' '[' push field_list pop ']'
519                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
520        | field_name ARROW field
521                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
522        | field_name ARROW '[' push field_list pop ']'
523                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
524        ;
525
526field_name:
527        INTEGERconstant fraction_constants
528                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); }
529        | FLOATINGconstant fraction_constants
530                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
531        | no_attr_identifier fraction_constants
532                {
533                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
534                }
535        ;
536
537fraction_constants:
538        // empty
539                { $$ = nullptr; }
540        | fraction_constants FLOATING_FRACTIONconstant
541                {
542                        Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
543                        $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1,  constant ) ) : new ExpressionNode( constant );
544                }
545        ;
546
547unary_expression:
548        postfix_expression
549                // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires
550                // semantics checks, e.g., ++3, 3--, *3, &&3
551        | constant
552                { $$ = $1; }
553        | string_literal
554                { $$ = new ExpressionNode( $1 ); }
555        | EXTENSION cast_expression                                                     // GCC
556                { $$ = $2->set_extension( true ); }
557                // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:
558                //              { * X; }         // dereference X
559                //              { * int X; } // CFA declaration of pointer to int
560        | ptrref_operator cast_expression                                       // CFA
561                {
562                        switch ( $1 ) {
563                          case OperKinds::AddressOf:
564                                $$ = new ExpressionNode( build_addressOf( $2 ) );
565                                break;
566                          case OperKinds::PointTo:
567                                $$ = new ExpressionNode( build_unary_val( $1, $2 ) );
568                                break;
569                          case OperKinds::And:
570                                $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) );
571                                break;
572                          default:
573                                assert( false );
574                        }
575                }
576        | unary_operator cast_expression
577                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
578        | ICR unary_expression
579                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); }
580        | DECR unary_expression
581                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
582        | SIZEOF unary_expression
583                { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
584        | SIZEOF '(' type_no_function ')'
585                { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
586        | ALIGNOF unary_expression                                                      // GCC, variable alignment
587                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
588        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
589                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
590        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
591                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
592        | ATTR_IDENTIFIER
593                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); }
594        | ATTR_IDENTIFIER '(' argument_expression ')'
595                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
596        | ATTR_IDENTIFIER '(' type ')'
597                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
598        ;
599
600ptrref_operator:
601        '*'                                                                                     { $$ = OperKinds::PointTo; }
602        | '&'                                                                           { $$ = OperKinds::AddressOf; }
603                // GCC, address of label must be handled by semantic check for ref,ref,label
604        | ANDAND                                                                        { $$ = OperKinds::And; }
605        ;
606
607unary_operator:
608        '+'                                                                                     { $$ = OperKinds::UnPlus; }
609        | '-'                                                                           { $$ = OperKinds::UnMinus; }
610        | '!'                                                                           { $$ = OperKinds::Neg; }
611        | '~'                                                                           { $$ = OperKinds::BitNeg; }
612        ;
613
614cast_expression:
615        unary_expression
616        | '(' type_no_function ')' cast_expression
617                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
618                // VIRTUAL cannot be opt because of look ahead issues
619        | '(' VIRTUAL ')' cast_expression
620                { $$ = new ExpressionNode( build_virtual_cast( nullptr, $4 ) ); }
621        | '(' VIRTUAL type_no_function ')' cast_expression
622                { $$ = new ExpressionNode( build_virtual_cast( $3, $5 ) ); }
623//      | '(' type_no_function ')' tuple
624//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
625        ;
626
627exponential_expression:
628        cast_expression
629        | exponential_expression '\\' cast_expression
630                { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }
631        ;
632
633multiplicative_expression:
634        exponential_expression
635        | multiplicative_expression '*' exponential_expression
636                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
637        | multiplicative_expression '/' exponential_expression
638                { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
639        | multiplicative_expression '%' exponential_expression
640                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
641        ;
642
643additive_expression:
644        multiplicative_expression
645        | additive_expression '+' multiplicative_expression
646                { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); }
647        | additive_expression '-' multiplicative_expression
648                { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); }
649        ;
650
651shift_expression:
652        additive_expression
653        | shift_expression LS additive_expression
654                { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); }
655        | shift_expression RS additive_expression
656                { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); }
657        ;
658
659relational_expression:
660        shift_expression
661        | relational_expression '<' shift_expression
662                { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); }
663        | relational_expression '>' shift_expression
664                { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); }
665        | relational_expression LE shift_expression
666                { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); }
667        | relational_expression GE shift_expression
668                { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); }
669        ;
670
671equality_expression:
672        relational_expression
673        | equality_expression EQ relational_expression
674                { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); }
675        | equality_expression NE relational_expression
676                { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); }
677        ;
678
679AND_expression:
680        equality_expression
681        | AND_expression '&' equality_expression
682                { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); }
683        ;
684
685exclusive_OR_expression:
686        AND_expression
687        | exclusive_OR_expression '^' AND_expression
688                { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); }
689        ;
690
691inclusive_OR_expression:
692        exclusive_OR_expression
693        | inclusive_OR_expression '|' exclusive_OR_expression
694                { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); }
695        ;
696
697logical_AND_expression:
698        inclusive_OR_expression
699        | logical_AND_expression ANDAND inclusive_OR_expression
700                { $$ = new ExpressionNode( build_and_or( $1, $3, true ) ); }
701        ;
702
703logical_OR_expression:
704        logical_AND_expression
705        | logical_OR_expression OROR logical_AND_expression
706                { $$ = new ExpressionNode( build_and_or( $1, $3, false ) ); }
707        ;
708
709conditional_expression:
710        logical_OR_expression
711        | logical_OR_expression '?' comma_expression ':' conditional_expression
712                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
713                // FIX ME: this hack computes $1 twice
714        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
715                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
716        ;
717
718constant_expression:
719        conditional_expression
720        ;
721
722assignment_expression:
723                // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
724        conditional_expression
725        | unary_expression assignment_operator assignment_expression
726                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
727        ;
728
729assignment_expression_opt:
730        // empty
731                { $$ = nullptr; }
732        | assignment_expression
733        ;
734
735assignment_operator:
736        '='                                                                                     { $$ = OperKinds::Assign; }
737        | ATassign                                                                      { $$ = OperKinds::AtAssn; }
738        | EXPassign                                                                     { $$ = OperKinds::ExpAssn; }
739        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
740        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
741        | MODassign                                                                     { $$ = OperKinds::ModAssn; }
742        | PLUSassign                                                            { $$ = OperKinds::PlusAssn; }
743        | MINUSassign                                                           { $$ = OperKinds::MinusAssn; }
744        | LSassign                                                                      { $$ = OperKinds::LSAssn; }
745        | RSassign                                                                      { $$ = OperKinds::RSAssn; }
746        | ANDassign                                                                     { $$ = OperKinds::AndAssn; }
747        | ERassign                                                                      { $$ = OperKinds::ERAssn; }
748        | ORassign                                                                      { $$ = OperKinds::OrAssn; }
749        ;
750
751tuple:                                                                                                  // CFA, tuple
752                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
753                // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array
754//      '[' ']'
755//              { $$ = new ExpressionNode( build_tuple() ); }
756//      '[' push assignment_expression pop ']'
757//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
758        '[' push ',' tuple_expression_list pop ']'
759                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
760        | '[' push assignment_expression ',' tuple_expression_list pop ']'
761                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
762        ;
763
764tuple_expression_list:
765        assignment_expression_opt
766        | tuple_expression_list ',' assignment_expression_opt
767                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
768        ;
769
770comma_expression:
771        assignment_expression
772        | comma_expression ',' assignment_expression
773                { $$ = new ExpressionNode( build_comma( $1, $3 ) ); }
774        ;
775
776comma_expression_opt:
777        // empty
778                { $$ = nullptr; }
779        | comma_expression
780        ;
781
782//*************************** STATEMENTS *******************************
783
784statement:
785        labeled_statement
786        | compound_statement
787        | expression_statement                                          { $$ = $1; }
788        | selection_statement
789        | iteration_statement
790        | jump_statement
791        | with_statement
792        | waitfor_statement
793        | exception_statement
794        | asm_statement
795
796labeled_statement:
797                // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
798        identifier_or_type_name ':' attribute_list_opt statement
799                {
800                        $$ = $4->add_label( $1, $3 );
801                }
802        ;
803
804compound_statement:
805        '{' '}'
806                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
807        | '{'
808                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
809                // requires its own scope.
810          push push
811          local_label_declaration_opt                                           // GCC, local labels
812          statement_decl_list                                                           // C99, intermix declarations and statements
813          pop '}'
814                { $$ = new StatementNode( build_compound( $5 ) ); }
815        ;
816
817statement_decl_list:                                                                    // C99
818        statement_decl
819        | statement_decl_list push statement_decl
820                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
821        ;
822
823statement_decl:
824        declaration                                                                                     // CFA, new & old style declarations
825                { $$ = new StatementNode( $1 ); }
826        | EXTENSION declaration                                                         // GCC
827                {
828                        distExt( $2 );
829                        $$ = new StatementNode( $2 );
830                }
831        | function_definition
832                { $$ = new StatementNode( $1 ); }
833        | EXTENSION function_definition                                         // GCC
834                {
835                        distExt( $2 );
836                        $$ = new StatementNode( $2 );
837                }
838        | statement pop
839        ;
840
841statement_list_nodecl:
842        statement
843        | statement_list_nodecl statement
844                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
845        ;
846
847expression_statement:
848        comma_expression_opt ';'
849                { $$ = new StatementNode( build_expr( $1 ) ); }
850        ;
851
852selection_statement:
853        IF '(' push if_control_expression ')' statement         %prec THEN
854                // explicitly deal with the shift/reduce conflict on if/else
855                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
856        | IF '(' push if_control_expression ')' statement ELSE statement
857                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
858        | SWITCH '(' comma_expression ')' case_clause
859                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
860        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
861                {
862                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
863                        // The semantics of the declaration list is changed to include associated initialization, which is performed
864                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
865                        // statement around the switch.  Statements after the initial declaration list can never be executed, and
866                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
867                        // statement.
868                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
869                }
870        | CHOOSE '(' comma_expression ')' case_clause           // CFA
871                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
872        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
873                {
874                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
875                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
876                }
877        ;
878
879if_control_expression:
880        comma_expression pop
881                { $$ = new IfCtl( nullptr, $1 ); }
882        | c_declaration pop                                                                     // no semi-colon
883                { $$ = new IfCtl( $1, nullptr ); }
884        | cfa_declaration pop                                                           // no semi-colon
885                { $$ = new IfCtl( $1, nullptr ); }
886        | declaration comma_expression                                          // semi-colon separated
887                { $$ = new IfCtl( $1, $2 ); }
888        ;
889
890// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
891// clause allows a list of values and subranges.
892
893case_value:                                                                                             // CFA
894        constant_expression                                                     { $$ = $1; }
895        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
896                { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
897        | subrange                                                                                      // CFA, subrange
898        ;
899
900case_value_list:                                                                                // CFA
901        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
902                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
903        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
904        ;
905
906case_label:                                                                                             // CFA
907        CASE case_value_list ':'                                        { $$ = $2; }
908        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
909                // A semantic check is required to ensure only one default clause per switch/choose statement.
910        ;
911
912case_label_list:                                                                                // CFA
913        case_label
914        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
915        ;
916
917case_clause:                                                                                    // CFA
918        case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
919        ;
920
921switch_clause_list_opt:                                                                 // CFA
922        // empty
923                { $$ = nullptr; }
924        | switch_clause_list
925        ;
926
927switch_clause_list:                                                                             // CFA
928        case_label_list statement_list_nodecl
929                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
930        | switch_clause_list case_label_list statement_list_nodecl
931                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
932        ;
933
934choose_clause_list_opt:                                                                 // CFA
935        // empty
936                { $$ = nullptr; }
937        | choose_clause_list
938        ;
939
940choose_clause_list:                                                                             // CFA
941        case_label_list fall_through
942                { $$ = $1->append_last_case( $2 ); }
943        | case_label_list statement_list_nodecl fall_through_opt
944                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
945        | choose_clause_list case_label_list fall_through
946                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
947        | choose_clause_list case_label_list statement_list_nodecl fall_through_opt
948                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
949        ;
950
951fall_through_opt:                                                                               // CFA
952        // empty
953                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
954        | fall_through
955        ;
956
957fall_through:                                                                                   // CFA
958        FALLTHRU
959                { $$ = nullptr; }
960        | FALLTHRU ';'
961                { $$ = nullptr; }
962        ;
963
964iteration_statement:
965        WHILE '(' comma_expression ')' statement
966                { $$ = new StatementNode( build_while( $3, $5 ) ); }
967        | DO statement WHILE '(' comma_expression ')' ';'
968                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
969        | FOR '(' push for_control_expression ')' statement
970                { $$ = new StatementNode( build_for( $4, $6 ) ); }
971        ;
972
973for_control_expression:
974        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
975                { $$ = new ForCtl( $1, $4, $6 ); }
976        | declaration comma_expression_opt ';' comma_expression_opt // C99
977                { $$ = new ForCtl( $1, $2, $4 ); }
978        ;
979
980jump_statement:
981        GOTO identifier_or_type_name ';'
982                { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
983        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
984                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
985                // whereas normal operator precedence yields goto (*i)+3;
986                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
987        | CONTINUE ';'
988                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
989                { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
990        | CONTINUE identifier_or_type_name ';'                          // CFA, multi-level continue
991                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
992                // the target of the transfer appears only at the start of an iteration statement.
993                { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
994        | BREAK ';'
995                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
996                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
997        | BREAK identifier_or_type_name ';'                                     // CFA, multi-level exit
998                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
999                // the target of the transfer appears only at the start of an iteration statement.
1000                { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
1001        | RETURN comma_expression_opt ';'
1002                { $$ = new StatementNode( build_return( $2 ) ); }
1003        | THROW assignment_expression_opt ';'                           // handles rethrow
1004                { $$ = new StatementNode( build_throw( $2 ) ); }
1005        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
1006                { $$ = new StatementNode( build_resume( $2 ) ); }
1007        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
1008                { $$ = new StatementNode( build_resume_at( $2, $4 ) ); }
1009        ;
1010
1011with_statement:
1012        WITH '(' tuple_expression_list ')' statement
1013                { $$ = nullptr; }                                                               // FIX ME
1014        ;
1015
1016when_clause:
1017        WHEN '(' comma_expression ')'
1018                { $$ = $3; }
1019        ;
1020
1021when_clause_opt:
1022        // empty
1023                { $$ = nullptr; }
1024        | when_clause
1025        ;
1026
1027waitfor:
1028        WAITFOR '(' identifier ')'
1029                {
1030                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
1031                        delete $3;
1032                }
1033        | WAITFOR '(' identifier ',' argument_expression_list ')'
1034                {
1035                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
1036                        $$->set_last( $5 );
1037                        delete $3;
1038                }
1039        ;
1040
1041timeout:
1042        TIMEOUT '(' comma_expression ')'
1043                { $$ = $3; }
1044        ;
1045
1046waitfor_clause:
1047        when_clause_opt waitfor statement                                       %prec THEN
1048                { $$ = build_waitfor( $2, $3, $1 ); }
1049        | when_clause_opt waitfor statement WOR waitfor_clause
1050                { $$ = build_waitfor( $2, $3, $1, $5 ); }
1051        | when_clause_opt timeout statement                                     %prec THEN
1052                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
1053        | when_clause_opt ELSE statement
1054                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
1055                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
1056        | when_clause_opt timeout statement WOR when_clause ELSE statement
1057                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
1058        ;
1059
1060waitfor_statement:
1061        when_clause_opt waitfor statement                                       %prec THEN
1062                { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
1063        | when_clause_opt waitfor statement WOR waitfor_clause
1064                { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
1065        ;
1066
1067exception_statement:
1068        TRY compound_statement handler_clause
1069                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
1070        | TRY compound_statement finally_clause
1071                { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
1072        | TRY compound_statement handler_clause finally_clause
1073                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
1074        ;
1075
1076handler_clause:
1077        handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
1078                { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
1079        | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
1080                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
1081        ;
1082
1083handler_predicate_opt:
1084        //empty
1085                { $$ = nullptr; }
1086        | ';' conditional_expression
1087                { $$ = $2; }
1088        ;
1089
1090handler_key:
1091        CATCH
1092                { $$ = CatchStmt::Terminate; }
1093        | CATCHRESUME
1094                { $$ = CatchStmt::Resume; }
1095        ;
1096
1097finally_clause:
1098        FINALLY compound_statement
1099                {
1100                        $$ = new StatementNode( build_finally( $2 ) );
1101                }
1102        ;
1103
1104exception_declaration:
1105                // No SUE declaration in parameter list.
1106        type_specifier_nobody
1107        | type_specifier_nobody declarator
1108                {
1109                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1110                        $$ = $2->addType( $1 );
1111                }
1112        | type_specifier_nobody variable_abstract_declarator
1113                { $$ = $2->addType( $1 ); }
1114        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
1115                {
1116                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1117                        $$ = $1->addName( $2 );
1118                }
1119        | cfa_abstract_declarator_tuple                                         // CFA
1120        ;
1121
1122asm_statement:
1123        ASM asm_volatile_opt '(' string_literal ')' ';'
1124                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
1125        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
1126                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
1127        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
1128                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
1129        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
1130                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
1131        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
1132                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
1133        ;
1134
1135asm_volatile_opt:                                                                               // GCC
1136        // empty
1137                { $$ = false; }
1138        | VOLATILE
1139                { $$ = true; }
1140        ;
1141
1142asm_operands_opt:                                                                               // GCC
1143        // empty
1144                { $$ = nullptr; }                                                               // use default argument
1145        | asm_operands_list
1146        ;
1147
1148asm_operands_list:                                                                              // GCC
1149        asm_operand
1150        | asm_operands_list ',' asm_operand
1151                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
1152        ;
1153
1154asm_operand:                                                                                    // GCC
1155        string_literal '(' constant_expression ')'
1156                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
1157        | '[' constant_expression ']' string_literal '(' constant_expression ')'
1158                { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
1159        ;
1160
1161asm_clobbers_list_opt:                                                                  // GCC
1162        // empty
1163                { $$ = nullptr; }                                                               // use default argument
1164        | string_literal
1165                { $$ = new ExpressionNode( $1 ); }
1166        | asm_clobbers_list_opt ',' string_literal
1167                // set_last return ParseNode *
1168                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
1169        ;
1170
1171label_list:
1172        no_attr_identifier
1173                {
1174                        $$ = new LabelNode(); $$->labels.push_back( *$1 );
1175                        delete $1;                                                                      // allocated by lexer
1176                }
1177        | label_list ',' no_attr_identifier
1178                {
1179                        $$ = $1; $1->labels.push_back( *$3 );
1180                        delete $3;                                                                      // allocated by lexer
1181                }
1182        ;
1183
1184//******************************* DECLARATIONS *********************************
1185
1186declaration_list_opt:                                                                   // used at beginning of switch statement
1187        pop
1188                { $$ = nullptr; }
1189        | declaration_list
1190        ;
1191
1192declaration_list:
1193        declaration
1194        | declaration_list push declaration
1195                { $$ = $1->appendList( $3 ); }
1196        ;
1197
1198KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
1199        // empty
1200                { $$ = nullptr; }
1201        | KR_declaration_list
1202        ;
1203
1204KR_declaration_list:
1205        push c_declaration pop ';'
1206                { $$ = $2; }
1207        | KR_declaration_list push c_declaration pop ';'
1208                { $$ = $1->appendList( $3 ); }
1209        ;
1210
1211local_label_declaration_opt:                                                    // GCC, local label
1212        // empty
1213        | local_label_declaration_list
1214        ;
1215
1216local_label_declaration_list:                                                   // GCC, local label
1217        LABEL local_label_list ';'
1218        | local_label_declaration_list LABEL local_label_list ';'
1219        ;
1220
1221local_label_list:                                                                               // GCC, local label
1222        no_attr_identifier_or_type_name                         {}
1223        | local_label_list ',' no_attr_identifier_or_type_name {}
1224        ;
1225
1226declaration:                                                                                    // old & new style declarations
1227        c_declaration pop ';'
1228        | cfa_declaration pop ';'                                                       // CFA
1229        ;
1230
1231// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
1232// declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to
1233// the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration
1234// modifiers are interpreted from left to right and the entire type specification is distributed across all variables in
1235// the declaration list (as in Pascal).  ANSI C and the new CFA declarations may appear together in the same program
1236// block, but cannot be mixed within a specific declaration.
1237//
1238//                      CFA                                     C
1239//              [10] int x;                     int x[10];              // array of 10 integers
1240//              [10] * char y;          char *y[10];    // array of 10 pointers to char
1241
1242cfa_declaration:                                                                                // CFA
1243        cfa_variable_declaration
1244        | cfa_typedef_declaration
1245        | cfa_function_declaration
1246        | type_declaring_list
1247        | trait_specifier
1248        ;
1249
1250cfa_variable_declaration:                                                               // CFA
1251        cfa_variable_specifier initializer_opt
1252                {
1253                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1254                        $$ = $1->addInitializer( $2 );
1255                }
1256        | declaration_qualifier_list cfa_variable_specifier initializer_opt
1257                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
1258                // them as a type_qualifier cannot appear in that context.
1259                {
1260                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1261                        $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
1262                }
1263        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
1264                {
1265                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
1266                        $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
1267                }
1268        ;
1269
1270cfa_variable_specifier:                                                                 // CFA
1271                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1272                // storage-class
1273        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
1274                {
1275                        typedefTable.setNextIdentifier( *$2 );
1276                        $$ = $1->addName( $2 )->addAsmName( $3 );
1277                }
1278        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
1279                {
1280                        typedefTable.setNextIdentifier( *$2 );
1281                        $$ = $1->addName( $2 )->addAsmName( $3 );
1282                }
1283        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
1284                {
1285                        typedefTable.setNextIdentifier( *$3 );
1286                        $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
1287                }
1288        ;
1289
1290cfa_function_declaration:                                                               // CFA
1291        cfa_function_specifier
1292                {
1293                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1294                        $$ = $1;
1295                }
1296        | type_qualifier_list cfa_function_specifier
1297                {
1298                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1299                        $$ = $2->addQualifiers( $1 );
1300                }
1301        | declaration_qualifier_list cfa_function_specifier
1302                {
1303                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1304                        $$ = $2->addQualifiers( $1 );
1305                }
1306        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
1307                {
1308                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1309                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
1310                }
1311        | cfa_function_declaration pop ',' push identifier_or_type_name
1312                {
1313                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
1314                        $$ = $1->appendList( $1->cloneType( $5 ) );
1315                }
1316        ;
1317
1318cfa_function_specifier:                                                                 // CFA
1319//      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
1320//              {
1321//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
1322//              }
1323//      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
1324//              {
1325//                      typedefTable.setNextIdentifier( *$5 );
1326//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1327//              }
1328//      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
1329//              {
1330//                      typedefTable.setNextIdentifier( *$5 );
1331//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1332//              }
1333//      | '[' ']' typegen_name
1334                // identifier_or_type_name must be broken apart because of the sequence:
1335                //
1336                //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
1337                //   '[' ']' type_specifier
1338                //
1339                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
1340                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
1341        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
1342                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
1343                {
1344                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1345                }
1346        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
1347                {
1348                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1349                }
1350        ;
1351
1352cfa_function_return:                                                                    // CFA
1353        '[' push cfa_parameter_list pop ']'
1354                { $$ = DeclarationNode::newTuple( $3 ); }
1355        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
1356                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
1357                // ']'.
1358                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
1359        ;
1360
1361cfa_typedef_declaration:                                                                // CFA
1362        TYPEDEF cfa_variable_specifier
1363                {
1364                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1365                        $$ = $2->addTypedef();
1366                }
1367        | TYPEDEF cfa_function_specifier
1368                {
1369                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1370                        $$ = $2->addTypedef();
1371                }
1372        | cfa_typedef_declaration pop ',' push no_attr_identifier
1373                {
1374                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
1375                        $$ = $1->appendList( $1->cloneType( $5 ) );
1376                }
1377        ;
1378
1379// Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as
1380// a separate form of declaration, which syntactically precludes storage-class specifiers and initialization.
1381
1382typedef_declaration:
1383        TYPEDEF type_specifier declarator
1384                {
1385                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1386                        $$ = $3->addType( $2 )->addTypedef();
1387                }
1388        | typedef_declaration pop ',' push declarator
1389                {
1390                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1391                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
1392                }
1393        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
1394                {
1395                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1396                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
1397                }
1398        | type_specifier TYPEDEF declarator
1399                {
1400                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1401                        $$ = $3->addType( $1 )->addTypedef();
1402                }
1403        | type_specifier TYPEDEF type_qualifier_list declarator
1404                {
1405                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1406                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
1407                }
1408        ;
1409
1410typedef_expression:
1411                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
1412        TYPEDEF no_attr_identifier '=' assignment_expression
1413                {
1414                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
1415                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
1416                }
1417        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
1418                {
1419                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
1420                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
1421                }
1422        ;
1423
1424//c_declaration:
1425//      declaring_list pop ';'
1426//      | typedef_declaration pop ';'
1427//      | typedef_expression pop ';'                                            // GCC, naming expression type
1428//      | sue_declaration_specifier pop ';'
1429//      ;
1430//
1431//declaring_list:
1432//              // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1433//              // storage-class
1434//       declarator asm_name_opt initializer_opt
1435//              {
1436//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
1437//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
1438//              }
1439//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
1440//              {
1441//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
1442//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
1443//              }
1444//      ;
1445
1446c_declaration:
1447        declaration_specifier declaring_list
1448                {
1449                        $$ = distAttr( $1, $2 );
1450                }
1451        | typedef_declaration
1452        | typedef_expression                                                            // GCC, naming expression type
1453        | sue_declaration_specifier
1454        ;
1455
1456declaring_list:
1457                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1458                // storage-class
1459        declarator asm_name_opt initializer_opt
1460                {
1461                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1462                        $$ = $1->addAsmName( $2 )->addInitializer( $3 );
1463                }
1464        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
1465                {
1466                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1467                        $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
1468                }
1469        ;
1470
1471declaration_specifier:                                                                  // type specifier + storage class
1472        basic_declaration_specifier
1473        | sue_declaration_specifier
1474        | type_declaration_specifier
1475        ;
1476
1477declaration_specifier_nobody:                                                   // type specifier + storage class - {...}
1478                // Preclude SUE declarations in restricted scopes:
1479                //
1480                //    int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
1481                //
1482                // because it is impossible to call f due to name equivalence.
1483        basic_declaration_specifier
1484        | sue_declaration_specifier_nobody
1485        | type_declaration_specifier
1486        ;
1487
1488type_specifier:                                                                                 // type specifier
1489        basic_type_specifier
1490        | sue_type_specifier
1491        | type_type_specifier
1492        ;
1493
1494type_specifier_nobody:                                                                  // type specifier - {...}
1495                // Preclude SUE declarations in restricted scopes:
1496                //
1497                //    int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
1498                //
1499                // because it is impossible to call f due to name equivalence.
1500        basic_type_specifier
1501        | sue_type_specifier_nobody
1502        | type_type_specifier
1503        ;
1504
1505type_qualifier_list_opt:                                                                // GCC, used in asm_statement
1506        // empty
1507                { $$ = nullptr; }
1508        | type_qualifier_list
1509        ;
1510
1511type_qualifier_list:
1512                // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration.
1513                //
1514                // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same
1515                // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it
1516                // appeared only once.
1517        type_qualifier
1518        | type_qualifier_list type_qualifier
1519                { $$ = $1->addQualifiers( $2 ); }
1520        ;
1521
1522type_qualifier:
1523        type_qualifier_name
1524        | attribute
1525        ;
1526
1527type_qualifier_name:
1528        CONST
1529                { $$ = DeclarationNode::newTypeQualifier( Type::Const ); }
1530        | RESTRICT
1531                { $$ = DeclarationNode::newTypeQualifier( Type::Restrict ); }
1532        | VOLATILE
1533                { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); }
1534        | MUTEX
1535                { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); }
1536        | ATOMIC
1537                { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
1538        | FORALL '('
1539                {
1540                        typedefTable.enterScope();
1541                }
1542          type_parameter_list ')'                                                       // CFA
1543                {
1544                        typedefTable.leaveScope();
1545                        $$ = DeclarationNode::newForall( $4 );
1546                }
1547        ;
1548
1549declaration_qualifier_list:
1550        storage_class_list
1551        | type_qualifier_list storage_class_list                        // remaining OBSOLESCENT (see 2 )
1552                { $$ = $1->addQualifiers( $2 ); }
1553        | declaration_qualifier_list type_qualifier_list storage_class_list
1554                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1555        ;
1556
1557storage_class_list:
1558                // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that
1559                // only one of each is specified, except for inline, which can appear with the others.
1560                //
1561                // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration
1562                // specifiers in a declaration.
1563        storage_class
1564        | storage_class_list storage_class
1565                { $$ = $1->addQualifiers( $2 ); }
1566        ;
1567
1568storage_class:
1569        EXTERN
1570                { $$ = DeclarationNode::newStorageClass( Type::Extern ); }
1571        | STATIC
1572                { $$ = DeclarationNode::newStorageClass( Type::Static ); }
1573        | AUTO
1574                { $$ = DeclarationNode::newStorageClass( Type::Auto ); }
1575        | REGISTER
1576                { $$ = DeclarationNode::newStorageClass( Type::Register ); }
1577        | THREADLOCAL                                                                           // C11
1578                { $$ = DeclarationNode::newStorageClass( Type::Threadlocal ); }
1579                // Put function specifiers here to simplify parsing rules, but separate them semantically.
1580        | INLINE                                                                                        // C99
1581                { $$ = DeclarationNode::newFuncSpecifier( Type::Inline ); }
1582        | FORTRAN                                                                                       // C99
1583                { $$ = DeclarationNode::newFuncSpecifier( Type::Fortran ); }
1584        | NORETURN                                                                                      // C11
1585                { $$ = DeclarationNode::newFuncSpecifier( Type::Noreturn ); }
1586        ;
1587
1588basic_type_name:
1589        CHAR
1590                { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
1591        | DOUBLE
1592                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
1593        | FLOAT
1594                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
1595        | INT
1596                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
1597        | LONG
1598                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
1599        | SHORT
1600                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
1601        | SIGNED
1602                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
1603        | UNSIGNED
1604                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
1605        | VOID
1606                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
1607        | BOOL                                                                                          // C99
1608                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
1609        | COMPLEX                                                                                       // C99
1610                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
1611        | IMAGINARY                                                                                     // C99
1612                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
1613        | ZERO_T
1614                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
1615        | ONE_T
1616                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
1617        | VALIST                                                                                        // GCC, __builtin_va_list
1618                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
1619        ;
1620
1621basic_declaration_specifier:
1622                // A semantic check is necessary for conflicting storage classes.
1623        basic_type_specifier
1624        | declaration_qualifier_list basic_type_specifier
1625                { $$ = $2->addQualifiers( $1 ); }
1626        | basic_declaration_specifier storage_class                     // remaining OBSOLESCENT (see 2)
1627                { $$ = $1->addQualifiers( $2 ); }
1628        | basic_declaration_specifier storage_class type_qualifier_list
1629                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1630        | basic_declaration_specifier storage_class basic_type_specifier
1631                { $$ = $3->addQualifiers( $2 )->addType( $1 ); }
1632        ;
1633
1634basic_type_specifier:
1635        direct_type
1636        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
1637                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
1638        ;
1639
1640direct_type:
1641                // A semantic check is necessary for conflicting type qualifiers.
1642        basic_type_name
1643        | type_qualifier_list basic_type_name
1644                { $$ = $2->addQualifiers( $1 ); }
1645        | direct_type type_qualifier
1646                { $$ = $1->addQualifiers( $2 ); }
1647        | direct_type basic_type_name
1648                { $$ = $1->addType( $2 ); }
1649        ;
1650
1651indirect_type:
1652        TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
1653                { $$ = $3; }
1654        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
1655                { $$ = DeclarationNode::newTypeof( $3 ); }
1656        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
1657                { $$ = DeclarationNode::newAttr( $1, $3 ); }
1658        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
1659                { $$ = DeclarationNode::newAttr( $1, $3 ); }
1660        ;
1661
1662sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
1663        sue_type_specifier
1664        | declaration_qualifier_list sue_type_specifier
1665                { $$ = $2->addQualifiers( $1 ); }
1666        | sue_declaration_specifier storage_class                       // remaining OBSOLESCENT (see 2)
1667                { $$ = $1->addQualifiers( $2 ); }
1668        | sue_declaration_specifier storage_class type_qualifier_list
1669                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1670        ;
1671
1672sue_type_specifier:                                                                             // struct, union, enum + type specifier
1673        elaborated_type
1674        | type_qualifier_list
1675                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
1676          elaborated_type
1677                { $$ = $3->addQualifiers( $1 ); }
1678        | sue_type_specifier type_qualifier
1679                { $$ = $1->addQualifiers( $2 ); }
1680        ;
1681
1682sue_declaration_specifier_nobody:                                               // struct, union, enum - {...} + storage class + type specifier
1683        sue_type_specifier_nobody
1684        | declaration_qualifier_list sue_type_specifier_nobody
1685                { $$ = $2->addQualifiers( $1 ); }
1686        | sue_declaration_specifier_nobody storage_class        // remaining OBSOLESCENT (see 2)
1687                { $$ = $1->addQualifiers( $2 ); }
1688        | sue_declaration_specifier_nobody storage_class type_qualifier_list
1689                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1690        ;
1691
1692sue_type_specifier_nobody:                                                              // struct, union, enum - {...} + type specifier
1693        elaborated_type_nobody
1694        | type_qualifier_list elaborated_type_nobody
1695                { $$ = $2->addQualifiers( $1 ); }
1696        | sue_type_specifier_nobody type_qualifier
1697                { $$ = $1->addQualifiers( $2 ); }
1698        ;
1699
1700type_declaration_specifier:
1701        type_type_specifier
1702        | declaration_qualifier_list type_type_specifier
1703                { $$ = $2->addQualifiers( $1 ); }
1704        | type_declaration_specifier storage_class                      // remaining OBSOLESCENT (see 2)
1705                { $$ = $1->addQualifiers( $2 ); }
1706        | type_declaration_specifier storage_class type_qualifier_list
1707                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1708        ;
1709
1710type_type_specifier:                                                                    // typedef types
1711        type_name
1712        | type_qualifier_list type_name
1713                { $$ = $2->addQualifiers( $1 ); }
1714        | type_type_specifier type_qualifier
1715                { $$ = $1->addQualifiers( $2 ); }
1716        ;
1717
1718type_name:
1719        TYPEDEFname
1720                { $$ = DeclarationNode::newFromTypedef( $1 ); }
1721        | '.' TYPEDEFname
1722                { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
1723        | type_name '.' TYPEDEFname
1724                { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
1725        | typegen_name
1726        | '.' typegen_name
1727                { $$ = $2; }                                                                    // FIX ME
1728        | type_name '.' typegen_name
1729                { $$ = $3; }                                                                    // FIX ME
1730        ;
1731
1732typegen_name:                                                                                   // CFA
1733        TYPEGENname '(' ')'
1734                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
1735        | TYPEGENname '(' type_list ')'
1736                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
1737        ;
1738
1739elaborated_type:                                                                                // struct, union, enum
1740        aggregate_type
1741        | enum_type
1742        ;
1743
1744elaborated_type_nobody:                                                                 // struct, union, enum - {...}
1745        aggregate_type_nobody
1746        | enum_type_nobody
1747        ;
1748
1749aggregate_type:                                                                                 // struct, union
1750        aggregate_key attribute_list_opt '{' field_declaration_list '}'
1751                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
1752        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
1753                {
1754                        typedefTable.makeTypedef( *$3 );                        // create typedef
1755                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
1756                        forall = false;                                                         // reset
1757                }
1758          '{' field_declaration_list '}'
1759                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
1760        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
1761                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
1762        | aggregate_type_nobody
1763        ;
1764
1765aggregate_type_nobody:                                                                  // struct, union - {...}
1766        aggregate_key attribute_list_opt no_attr_identifier
1767                {
1768                        typedefTable.makeTypedef( *$3 );
1769                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
1770                }
1771        | aggregate_key attribute_list_opt TYPEDEFname
1772                {
1773                        typedefTable.makeTypedef( *$3 );
1774                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
1775                }
1776        | aggregate_key attribute_list_opt typegen_name         // CFA
1777                { $$ = $3->addQualifiers( $2 ); }
1778        ;
1779
1780aggregate_key:
1781        STRUCT
1782                { $$ = DeclarationNode::Struct; }
1783        | UNION
1784                { $$ = DeclarationNode::Union; }
1785        | COROUTINE
1786                { $$ = DeclarationNode::Coroutine; }
1787        | MONITOR
1788                { $$ = DeclarationNode::Monitor; }
1789        | THREAD
1790                { $$ = DeclarationNode::Thread; }
1791        ;
1792
1793field_declaration_list:
1794        // empty
1795                { $$ = nullptr; }
1796        | field_declaration_list field_declaration
1797                { $$ = $1 ? $1->appendList( $2 ) : $2; }
1798        ;
1799
1800field_declaration:
1801        cfa_field_declaring_list ';'                                            // CFA, new style field declaration
1802        | EXTENSION cfa_field_declaring_list ';'                        // GCC
1803                {
1804                        distExt( $2 );                                                          // mark all fields in list
1805                        $$ = $2;
1806                }
1807        | type_specifier field_declaring_list ';'
1808                {
1809                        $$ = distAttr( $1, $2 ); }
1810        | EXTENSION type_specifier field_declaring_list ';'     // GCC
1811                {
1812                        distExt( $3 );                                                          // mark all fields in list
1813                        $$ = distAttr( $2, $3 );
1814                }
1815        ;
1816
1817cfa_field_declaring_list:                                                               // CFA, new style field declaration
1818        cfa_abstract_declarator_tuple                                           // CFA, no field name
1819        | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
1820                { $$ = $1->addName( $2 ); }
1821        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
1822                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
1823        | cfa_field_declaring_list ','                                          // CFA, no field name
1824                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
1825        ;
1826
1827field_declaring_list:
1828        field_declarator
1829        | field_declaring_list ',' attribute_list_opt field_declarator
1830                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
1831        ;
1832
1833field_declarator:
1834        // empty
1835                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
1836        // '@'
1837        //      { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
1838        | bit_subrange_size                                                                     // no field name
1839                { $$ = DeclarationNode::newBitfield( $1 ); }
1840        | variable_declarator bit_subrange_size_opt
1841                // A semantic check is required to ensure bit_subrange only appears on base type int.
1842                { $$ = $1->addBitfield( $2 ); }
1843        | variable_type_redeclarator bit_subrange_size_opt
1844                // A semantic check is required to ensure bit_subrange only appears on base type int.
1845                { $$ = $1->addBitfield( $2 ); }
1846        | variable_abstract_declarator                                          // CFA, no field name
1847        ;
1848
1849bit_subrange_size_opt:
1850        // empty
1851                { $$ = nullptr; }
1852        | bit_subrange_size
1853                { $$ = $1; }
1854        ;
1855
1856bit_subrange_size:
1857        ':' constant_expression
1858                { $$ = $2; }
1859        ;
1860
1861enum_type:                                                                                              // enum
1862        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
1863                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
1864        | ENUM attribute_list_opt no_attr_identifier_or_type_name
1865                { typedefTable.makeTypedef( *$3 ); }
1866          '{' enumerator_list comma_opt '}'
1867                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
1868        | enum_type_nobody
1869        ;
1870
1871enum_type_nobody:                                                                               // enum - {...}
1872        ENUM attribute_list_opt no_attr_identifier_or_type_name
1873                {
1874                        typedefTable.makeTypedef( *$3 );
1875                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
1876                }
1877        ;
1878
1879enumerator_list:
1880        no_attr_identifier_or_type_name enumerator_value_opt
1881                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
1882        | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
1883                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
1884        ;
1885
1886enumerator_value_opt:
1887        // empty
1888                { $$ = nullptr; }
1889        | '=' constant_expression
1890                { $$ = $2; }
1891        ;
1892
1893// Minimum of one parameter after which ellipsis is allowed only at the end.
1894
1895cfa_parameter_type_list_opt:                                                    // CFA
1896        // empty
1897                { $$ = nullptr; }
1898        | cfa_parameter_type_list
1899        ;
1900
1901cfa_parameter_type_list:                                                                // CFA, abstract + real
1902        cfa_abstract_parameter_list
1903        | cfa_parameter_list
1904        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
1905                { $$ = $1->appendList( $5 ); }
1906        | cfa_abstract_parameter_list pop ',' push ELLIPSIS
1907                { $$ = $1->addVarArgs(); }
1908        | cfa_parameter_list pop ',' push ELLIPSIS
1909                { $$ = $1->addVarArgs(); }
1910        ;
1911
1912cfa_parameter_list:                                                                             // CFA
1913                // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
1914                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
1915        cfa_parameter_declaration
1916        | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
1917                { $$ = $1->appendList( $5 ); }
1918        | cfa_parameter_list pop ',' push cfa_parameter_declaration
1919                { $$ = $1->appendList( $5 ); }
1920        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
1921                { $$ = $1->appendList( $5 )->appendList( $9 ); }
1922        ;
1923
1924cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
1925        cfa_abstract_parameter_declaration
1926        | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
1927                { $$ = $1->appendList( $5 ); }
1928        ;
1929
1930parameter_type_list_opt:
1931        // empty
1932                { $$ = nullptr; }
1933        | parameter_type_list
1934        ;
1935
1936parameter_type_list:
1937        parameter_list
1938        | parameter_list pop ',' push ELLIPSIS
1939                { $$ = $1->addVarArgs(); }
1940        ;
1941
1942parameter_list:                                                                                 // abstract + real
1943        abstract_parameter_declaration
1944        | parameter_declaration
1945        | parameter_list pop ',' push abstract_parameter_declaration
1946                { $$ = $1->appendList( $5 ); }
1947        | parameter_list pop ',' push parameter_declaration
1948                { $$ = $1->appendList( $5 ); }
1949        ;
1950
1951// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
1952// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
1953
1954cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
1955        parameter_declaration
1956        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
1957                { $$ = $1->addName( $2 ); }
1958        | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
1959                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
1960                { $$ = $1->addName( $2 ); }
1961        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
1962                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
1963        | cfa_function_specifier
1964        ;
1965
1966cfa_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
1967        abstract_parameter_declaration
1968        | cfa_identifier_parameter_declarator_no_tuple
1969        | cfa_abstract_tuple
1970                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
1971        | type_qualifier_list cfa_abstract_tuple
1972                { $$ = $2->addQualifiers( $1 ); }
1973        | cfa_abstract_function
1974        ;
1975
1976parameter_declaration:
1977                // No SUE declaration in parameter list.
1978        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
1979                {
1980                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1981                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
1982                }
1983        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
1984                {
1985                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1986                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
1987                }
1988        ;
1989
1990abstract_parameter_declaration:
1991        declaration_specifier_nobody default_initialize_opt
1992                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
1993        | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
1994                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
1995        ;
1996
1997// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
1998// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
1999// identifiers.  The ANSI-style parameter-list can redefine a typedef name.
2000
2001identifier_list:                                                                                // K&R-style parameter list => no types
2002        no_attr_identifier
2003                { $$ = DeclarationNode::newName( $1 ); }
2004        | identifier_list ',' no_attr_identifier
2005                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
2006        ;
2007
2008identifier_or_type_name:
2009        identifier
2010        | TYPEDEFname
2011        | TYPEGENname
2012        ;
2013
2014no_attr_identifier_or_type_name:
2015        no_attr_identifier
2016        | TYPEDEFname
2017        | TYPEGENname
2018        ;
2019
2020type_no_function:                                                                               // sizeof, alignof, cast (constructor)
2021        cfa_abstract_declarator_tuple                                           // CFA
2022        | type_specifier
2023        | type_specifier abstract_declarator
2024                { $$ = $2->addType( $1 ); }
2025        ;
2026
2027type:                                                                                                   // typeof, assertion
2028        type_no_function
2029        | cfa_abstract_function                                                         // CFA
2030        ;
2031
2032initializer_opt:
2033        // empty
2034                { $$ = nullptr; }
2035        | '=' initializer
2036                { $$ = $2; }
2037        | '=' VOID
2038                { $$ = nullptr; }
2039        | ATassign initializer
2040                { $$ = $2->set_maybeConstructed( false ); }
2041        ;
2042
2043initializer:
2044        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
2045        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
2046        ;
2047
2048initializer_list:
2049        // empty
2050                { $$ = nullptr; }
2051        | initializer
2052        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
2053        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
2054        | initializer_list ',' designation initializer
2055                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
2056        ;
2057
2058// There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of
2059// '=' to separator the designator from the initializer value, as in:
2060//
2061//              int x[10] = { [1] = 3 };
2062//
2063// The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment.  To disambiguate this case, CFA
2064// changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for
2065// field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to
2066// shift/reduce conflicts
2067
2068designation:
2069        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
2070        | no_attr_identifier ':'                                                        // GCC, field name
2071                { $$ = new ExpressionNode( build_varref( $1 ) ); }
2072        ;
2073
2074designator_list:                                                                                // C99
2075        designator
2076        | designator_list designator
2077                { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
2078        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
2079        ;
2080
2081designator:
2082        '.' no_attr_identifier                                                          // C99, field name
2083                { $$ = new ExpressionNode( build_varref( $2 ) ); }
2084        | '[' push assignment_expression pop ']'                        // C99, single array element
2085                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
2086                { $$ = $3; }
2087        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
2088                { $$ = $3; }
2089        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
2090                { $$ = new ExpressionNode( build_range( $3, $5 ) ); }
2091        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
2092                { $$ = $4; }
2093        ;
2094
2095// The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters,
2096// rather than an object-oriented type system. This required four groups of extensions:
2097//
2098// Overloading: function, data, and operator identifiers may be overloaded.
2099//
2100// Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
2101//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
2102//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
2103//
2104// Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call
2105//     site. A polymorphic function is not a template; it is a function, with an address and a type.
2106//
2107// Specifications and Assertions: Specifications are collections of declarations parameterized by one or more
2108//     types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass
2109//     hierarchies. Unlike classes, they can define relationships between types.  Assertions declare that a type or
2110//     types provide the operations declared by a specification.  Assertions are normally used to declare requirements
2111//     on type arguments of polymorphic functions.
2112
2113type_parameter_list:                                                                    // CFA
2114        type_parameter
2115                { $$ = $1; }
2116        | type_parameter_list ',' type_parameter
2117                { $$ = $1->appendList( $3 ); }
2118        ;
2119
2120type_initializer_opt:                                                                   // CFA
2121        // empty
2122                { $$ = nullptr; }
2123        | '=' type
2124                { $$ = $2; }
2125        ;
2126
2127type_parameter:                                                                                 // CFA
2128        type_class no_attr_identifier_or_type_name
2129                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
2130          type_initializer_opt assertion_list_opt
2131                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
2132        | type_specifier identifier_parameter_declarator
2133        ;
2134
2135type_class:                                                                                             // CFA
2136        OTYPE
2137                { $$ = DeclarationNode::Otype; }
2138        | DTYPE
2139                { $$ = DeclarationNode::Dtype; }
2140        | FTYPE
2141                { $$ = DeclarationNode::Ftype; }
2142        | TTYPE
2143                { $$ = DeclarationNode::Ttype; }
2144        ;
2145
2146assertion_list_opt:                                                                             // CFA
2147        // empty
2148                { $$ = nullptr; }
2149        | assertion_list_opt assertion
2150                { $$ = $1 ? $1->appendList( $2 ) : $2; }
2151        ;
2152
2153assertion:                                                                                              // CFA
2154        '|' no_attr_identifier_or_type_name '(' type_list ')'
2155                {
2156                        typedefTable.openTrait( *$2 );
2157                        $$ = DeclarationNode::newTraitUse( $2, $4 );
2158                }
2159        | '|' '{' push trait_declaration_list '}'
2160                { $$ = $4; }
2161        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
2162                { $$ = nullptr; }
2163        ;
2164
2165type_list:                                                                                              // CFA
2166        type
2167                { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
2168        | assignment_expression
2169        | type_list ',' type
2170                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
2171        | type_list ',' assignment_expression
2172                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
2173        ;
2174
2175type_declaring_list:                                                                    // CFA
2176        OTYPE type_declarator
2177                { $$ = $2; }
2178        | storage_class_list OTYPE type_declarator
2179                { $$ = $3->addQualifiers( $1 ); }
2180        | type_declaring_list ',' type_declarator
2181                { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
2182        ;
2183
2184type_declarator:                                                                                // CFA
2185        type_declarator_name assertion_list_opt
2186                { $$ = $1->addAssertions( $2 ); }
2187        | type_declarator_name assertion_list_opt '=' type
2188                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
2189        ;
2190
2191type_declarator_name:                                                                   // CFA
2192        no_attr_identifier_or_type_name
2193                {
2194                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
2195                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
2196                }
2197        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
2198                {
2199                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
2200                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
2201                }
2202        ;
2203
2204trait_specifier:                                                                                // CFA
2205        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
2206                {
2207                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
2208                        $$ = DeclarationNode::newTrait( $2, $5, 0 );
2209                }
2210        | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
2211                {
2212                        typedefTable.enterTrait( *$2 );
2213                        typedefTable.enterScope();
2214                }
2215          trait_declaration_list '}'
2216                {
2217                        typedefTable.leaveTrait();
2218                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
2219                        $$ = DeclarationNode::newTrait( $2, $5, $10 );
2220                }
2221        ;
2222
2223trait_declaration_list:                                                                 // CFA
2224        trait_declaration
2225        | trait_declaration_list push trait_declaration
2226                { $$ = $1->appendList( $3 ); }
2227        ;
2228
2229trait_declaration:                                                                              // CFA
2230        cfa_trait_declaring_list pop ';'
2231        | trait_declaring_list pop ';'
2232        ;
2233
2234cfa_trait_declaring_list:                                                               // CFA
2235        cfa_variable_specifier
2236                {
2237                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
2238                        $$ = $1;
2239                }
2240        | cfa_function_specifier
2241                {
2242                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
2243                        $$ = $1;
2244                }
2245        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
2246                {
2247                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
2248                        $$ = $1->appendList( $1->cloneType( $5 ) );
2249                }
2250        ;
2251
2252trait_declaring_list:                                                                   // CFA
2253        type_specifier declarator
2254                {
2255                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
2256                        $$ = $2->addType( $1 );
2257                }
2258        | trait_declaring_list pop ',' push declarator
2259                {
2260                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
2261                        $$ = $1->appendList( $1->cloneBaseType( $5 ) );
2262                }
2263        ;
2264
2265//***************************** EXTERNAL DEFINITIONS *****************************
2266
2267translation_unit:
2268        // empty
2269                {}                                                                                              // empty input file
2270        | external_definition_list
2271                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
2272        ;
2273
2274external_definition_list:
2275        external_definition
2276        | external_definition_list push external_definition
2277                { $$ = $1 ? $1->appendList( $3 ) : $3; }
2278        ;
2279
2280external_definition_list_opt:
2281        // empty
2282                { $$ = nullptr; }
2283        | external_definition_list
2284        ;
2285
2286external_definition:
2287        declaration
2288        | external_function_definition
2289        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
2290                {
2291                        $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) );
2292                }
2293        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
2294                {
2295                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
2296                        linkage = LinkageSpec::linkageUpdate( linkage, $2 );
2297                }
2298          '{' external_definition_list_opt '}'
2299                {
2300                        linkage = linkageStack.top();
2301                        linkageStack.pop();
2302                        $$ = $5;
2303                }
2304        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
2305                {
2306                        distExt( $2 );                                                          // mark all fields in list
2307                        $$ = $2;
2308                }
2309        ;
2310
2311external_function_definition:
2312        function_definition
2313                // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
2314                // legacy code with global functions missing the type-specifier for the return type, and assuming "int".
2315                // Parsing is possible because function_definition does not appear in the context of an expression (nested
2316                // functions preclude this concession, i.e., all nested function must have a return type). A function prototype
2317                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
2318        | function_declarator compound_statement
2319                {
2320                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2321                        typedefTable.leaveScope();
2322                        $$ = $1->addFunctionBody( $2 );
2323                }
2324        | KR_function_declarator KR_declaration_list_opt compound_statement
2325                {
2326                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2327                        typedefTable.leaveScope();
2328                        $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
2329                }
2330        ;
2331
2332with_clause_opt:
2333        // empty
2334                { $$ = nullptr; }                                                               // FIX ME
2335        | WITH '(' tuple_expression_list ')'
2336                { $$ = nullptr; }                                                               // FIX ME
2337        ;
2338
2339function_definition:
2340        cfa_function_declaration with_clause_opt compound_statement     // CFA
2341                {
2342                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2343                        typedefTable.leaveScope();
2344                        $$ = $1->addFunctionBody( $3 );
2345                }
2346        | declaration_specifier function_declarator with_clause_opt compound_statement
2347                {
2348                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2349                        typedefTable.leaveScope();
2350                        $$ = $2->addFunctionBody( $4 )->addType( $1 );
2351                }
2352        | type_qualifier_list function_declarator with_clause_opt compound_statement
2353                {
2354                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2355                        typedefTable.leaveScope();
2356                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
2357                }
2358        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
2359                {
2360                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2361                        typedefTable.leaveScope();
2362                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
2363                }
2364        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
2365                {
2366                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2367                        typedefTable.leaveScope();
2368                        $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
2369                }
2370
2371                // Old-style K&R function definition, OBSOLESCENT (see 4)
2372        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
2373                {
2374                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2375                        typedefTable.leaveScope();
2376                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
2377                }
2378        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
2379                {
2380                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2381                        typedefTable.leaveScope();
2382                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
2383                }
2384
2385                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
2386        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
2387                {
2388                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2389                        typedefTable.leaveScope();
2390                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
2391                }
2392        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
2393                {
2394                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2395                        typedefTable.leaveScope();
2396                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
2397                }
2398        ;
2399
2400declarator:
2401        variable_declarator
2402        | variable_type_redeclarator
2403        | function_declarator
2404        ;
2405
2406subrange:
2407        constant_expression '~' constant_expression                     // CFA, integer subrange
2408                { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
2409        ;
2410
2411asm_name_opt:                                                                                   // GCC
2412        // empty
2413                { $$ = nullptr; }
2414        | ASM '(' string_literal ')' attribute_list_opt
2415                {
2416                        DeclarationNode * name = new DeclarationNode();
2417                        name->asmName = $3;
2418                        $$ = name->addQualifiers( $5 );
2419                }
2420        ;
2421
2422attribute_list_opt:                                                                             // GCC
2423        // empty
2424                { $$ = nullptr; }
2425        | attribute_list
2426        ;
2427
2428attribute_list:                                                                                 // GCC
2429        attribute
2430        | attribute_list attribute
2431                { $$ = $2->addQualifiers( $1 ); }
2432        ;
2433
2434attribute:                                                                                              // GCC
2435        ATTRIBUTE '(' '(' attribute_name_list ')' ')'
2436                { $$ = $4; }
2437        ;
2438
2439attribute_name_list:                                                                    // GCC
2440        attribute_name
2441        | attribute_name_list ',' attribute_name
2442                { $$ = $3->addQualifiers( $1 ); }
2443        ;
2444
2445attribute_name:                                                                                 // GCC
2446        // empty
2447                { $$ = nullptr; }
2448        | attr_name
2449                { $$ = DeclarationNode::newAttribute( $1 ); }
2450        | attr_name '(' argument_expression_list ')'
2451                { $$ = DeclarationNode::newAttribute( $1, $3 ); }
2452        ;
2453
2454attr_name:                                                                                              // GCC
2455        IDENTIFIER
2456        | quasi_keyword
2457        | TYPEDEFname
2458        | TYPEGENname
2459        | CONST
2460                { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
2461        ;
2462
2463// ============================================================================
2464// The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary
2465// because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as
2466// in:
2467//
2468//              int (*f())[10] { ... };
2469//              ... (*f())[3] += 1;             // definition mimics usage
2470//
2471// Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of
2472// the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context.
2473// ============================================================================
2474
2475// ----------------------------------------------------------------------------
2476// The set of valid declarators before a compound statement for defining a function is less than the set of declarators
2477// to define a variable or function prototype, e.g.:
2478//
2479//              valid declaration               invalid definition
2480//              -----------------               ------------------
2481//              int f;                                  int f {}
2482//              int *f;                                 int *f {}
2483//              int f[10];                              int f[10] {}
2484//              int (*f)(int);                  int (*f)(int) {}
2485//
2486// To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence
2487// variable_declarator and function_declarator.
2488// ----------------------------------------------------------------------------
2489
2490// This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes
2491// declaring an array of functions versus a pointer to an array of functions.
2492
2493variable_declarator:
2494        paren_identifier attribute_list_opt
2495                { $$ = $1->addQualifiers( $2 ); }
2496        | variable_ptr
2497        | variable_array attribute_list_opt
2498                { $$ = $1->addQualifiers( $2 ); }
2499        | variable_function attribute_list_opt
2500                { $$ = $1->addQualifiers( $2 ); }
2501        ;
2502
2503paren_identifier:
2504        identifier
2505                {
2506                        typedefTable.setNextIdentifier( *$1 );
2507                        $$ = DeclarationNode::newName( $1 );
2508                }
2509        | '(' paren_identifier ')'                                                      // redundant parenthesis
2510                { $$ = $2; }
2511        ;
2512
2513variable_ptr:
2514        ptrref_operator variable_declarator
2515                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2516        | ptrref_operator type_qualifier_list variable_declarator
2517                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2518        | '(' variable_ptr ')' attribute_list_opt
2519                { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
2520        ;
2521
2522variable_array:
2523        paren_identifier array_dimension
2524                { $$ = $1->addArray( $2 ); }
2525        | '(' variable_ptr ')' array_dimension
2526                { $$ = $2->addArray( $4 ); }
2527        | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
2528                { $$ = $2->addArray( $4 ); }
2529        | '(' variable_array ')'                                                        // redundant parenthesis
2530                { $$ = $2; }
2531        ;
2532
2533variable_function:
2534        '(' variable_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2535                { $$ = $2->addParamList( $6 ); }
2536        | '(' variable_function ')'                                                     // redundant parenthesis
2537                { $$ = $2; }
2538        ;
2539
2540// This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is
2541// no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist
2542// is the same scope.  The pattern precludes returning arrays and functions versus pointers to arrays and functions.
2543
2544function_declarator:
2545        function_no_ptr attribute_list_opt
2546                { $$ = $1->addQualifiers( $2 ); }
2547        | function_ptr
2548        | function_array attribute_list_opt
2549                { $$ = $1->addQualifiers( $2 ); }
2550        ;
2551
2552function_no_ptr:
2553        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2554                { $$ = $1->addParamList( $4 ); }
2555        | '(' function_ptr ')' '(' push parameter_type_list_opt pop ')'
2556                { $$ = $2->addParamList( $6 ); }
2557        | '(' function_no_ptr ')'                                                       // redundant parenthesis
2558                { $$ = $2; }
2559        ;
2560
2561function_ptr:
2562        ptrref_operator function_declarator
2563                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2564        | ptrref_operator type_qualifier_list function_declarator
2565                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2566        | '(' function_ptr ')'
2567                { $$ = $2; }
2568        ;
2569
2570function_array:
2571        '(' function_ptr ')' array_dimension
2572                { $$ = $2->addArray( $4 ); }
2573        | '(' function_array ')' multi_array_dimension          // redundant parenthesis
2574                { $$ = $2->addArray( $4 ); }
2575        | '(' function_array ')'                                                        // redundant parenthesis
2576                { $$ = $2; }
2577        ;
2578
2579// This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4)
2580//
2581//   f( a, b, c ) int a, *b, c[]; {}
2582//
2583// that is not redefining a typedef name (see function_declarator for additional comments). The pattern precludes
2584// returning arrays and functions versus pointers to arrays and functions.
2585
2586KR_function_declarator:
2587        KR_function_no_ptr
2588        | KR_function_ptr
2589        | KR_function_array
2590        ;
2591
2592KR_function_no_ptr:
2593        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
2594                { $$ = $1->addIdList( $3 ); }
2595        | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')'
2596                { $$ = $2->addParamList( $6 ); }
2597        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
2598                { $$ = $2; }
2599        ;
2600
2601KR_function_ptr:
2602        ptrref_operator KR_function_declarator
2603                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2604        | ptrref_operator type_qualifier_list KR_function_declarator
2605                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2606        | '(' KR_function_ptr ')'
2607                { $$ = $2; }
2608        ;
2609
2610KR_function_array:
2611        '(' KR_function_ptr ')' array_dimension
2612                { $$ = $2->addArray( $4 ); }
2613        | '(' KR_function_array ')' multi_array_dimension       // redundant parenthesis
2614                { $$ = $2->addArray( $4 ); }
2615        | '(' KR_function_array ')'                                                     // redundant parenthesis
2616                { $$ = $2; }
2617        ;
2618
2619// This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
2620//
2621//              typedef int foo;
2622//              {
2623//                 int foo; // redefine typedef name in new scope
2624//              }
2625//
2626// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2627// and functions versus pointers to arrays and functions.
2628
2629variable_type_redeclarator:
2630        paren_type attribute_list_opt
2631                { $$ = $1->addQualifiers( $2 ); }
2632        | type_ptr
2633        | type_array attribute_list_opt
2634                { $$ = $1->addQualifiers( $2 ); }
2635        | type_function attribute_list_opt
2636                { $$ = $1->addQualifiers( $2 ); }
2637        ;
2638
2639paren_type:
2640        typedef
2641        | '(' paren_type ')'
2642                { $$ = $2; }
2643        ;
2644
2645type_ptr:
2646        ptrref_operator variable_type_redeclarator
2647                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2648        | ptrref_operator type_qualifier_list variable_type_redeclarator
2649                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2650        | '(' type_ptr ')' attribute_list_opt
2651                { $$ = $2->addQualifiers( $4 ); }
2652        ;
2653
2654type_array:
2655        paren_type array_dimension
2656                { $$ = $1->addArray( $2 ); }
2657        | '(' type_ptr ')' array_dimension
2658                { $$ = $2->addArray( $4 ); }
2659        | '(' type_array ')' multi_array_dimension                      // redundant parenthesis
2660                { $$ = $2->addArray( $4 ); }
2661        | '(' type_array ')'                                                            // redundant parenthesis
2662                { $$ = $2; }
2663        ;
2664
2665type_function:
2666        paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2667                { $$ = $1->addParamList( $4 ); }
2668        | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2669                { $$ = $2->addParamList( $6 ); }
2670        | '(' type_function ')'                                                         // redundant parenthesis
2671                { $$ = $2; }
2672        ;
2673
2674// This pattern parses a declaration for a parameter variable of a function prototype or actual that is not redefining a
2675// typedef name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes
2676// declaring an array of functions versus a pointer to an array of functions, and returning arrays and functions versus
2677// pointers to arrays and functions.
2678
2679identifier_parameter_declarator:
2680        paren_identifier attribute_list_opt
2681                { $$ = $1->addQualifiers( $2 ); }
2682        | identifier_parameter_ptr
2683        | identifier_parameter_array attribute_list_opt
2684                { $$ = $1->addQualifiers( $2 ); }
2685        | identifier_parameter_function attribute_list_opt
2686                { $$ = $1->addQualifiers( $2 ); }
2687        ;
2688
2689identifier_parameter_ptr:
2690        ptrref_operator identifier_parameter_declarator
2691                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2692        | ptrref_operator type_qualifier_list identifier_parameter_declarator
2693                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2694        | '(' identifier_parameter_ptr ')' attribute_list_opt
2695                { $$ = $2->addQualifiers( $4 ); }
2696        ;
2697
2698identifier_parameter_array:
2699        paren_identifier array_parameter_dimension
2700                { $$ = $1->addArray( $2 ); }
2701        | '(' identifier_parameter_ptr ')' array_dimension
2702                { $$ = $2->addArray( $4 ); }
2703        | '(' identifier_parameter_array ')' multi_array_dimension // redundant parenthesis
2704                { $$ = $2->addArray( $4 ); }
2705        | '(' identifier_parameter_array ')'                            // redundant parenthesis
2706                { $$ = $2; }
2707        ;
2708
2709identifier_parameter_function:
2710        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2711                { $$ = $1->addParamList( $4 ); }
2712        | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2713                { $$ = $2->addParamList( $6 ); }
2714        | '(' identifier_parameter_function ')'                         // redundant parenthesis
2715                { $$ = $2; }
2716        ;
2717
2718// This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name,
2719// e.g.:
2720//
2721//              typedef int foo;
2722//              int f( int foo ); // redefine typedef name in new scope
2723//
2724// and allows the C99 array options, which can only appear in a parameter list.
2725
2726type_parameter_redeclarator:
2727        typedef attribute_list_opt
2728                { $$ = $1->addQualifiers( $2 ); }
2729        | type_parameter_ptr
2730        | type_parameter_array attribute_list_opt
2731                { $$ = $1->addQualifiers( $2 ); }
2732        | type_parameter_function attribute_list_opt
2733                { $$ = $1->addQualifiers( $2 ); }
2734        ;
2735
2736typedef:
2737        TYPEDEFname
2738                {
2739                        typedefTable.setNextIdentifier( *$1 );
2740                        $$ = DeclarationNode::newName( $1 );
2741                }
2742        | TYPEGENname
2743                {
2744                        typedefTable.setNextIdentifier( *$1 );
2745                        $$ = DeclarationNode::newName( $1 );
2746                }
2747        ;
2748
2749type_parameter_ptr:
2750        ptrref_operator type_parameter_redeclarator
2751                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2752        | ptrref_operator type_qualifier_list type_parameter_redeclarator
2753                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2754        | '(' type_parameter_ptr ')' attribute_list_opt
2755                { $$ = $2->addQualifiers( $4 ); }
2756        ;
2757
2758type_parameter_array:
2759        typedef array_parameter_dimension
2760                { $$ = $1->addArray( $2 ); }
2761        | '(' type_parameter_ptr ')' array_parameter_dimension
2762                { $$ = $2->addArray( $4 ); }
2763        ;
2764
2765type_parameter_function:
2766        typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
2767                { $$ = $1->addParamList( $4 ); }
2768        | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2769                { $$ = $2->addParamList( $6 ); }
2770        ;
2771
2772// This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to
2773// which the type applies, e.g.:
2774//
2775//              sizeof( int );
2776//              sizeof( int * );
2777//              sizeof( int [10] );
2778//              sizeof( int (*)() );
2779//              sizeof( int () );
2780//
2781// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2782// and functions versus pointers to arrays and functions.
2783
2784abstract_declarator:
2785        abstract_ptr
2786        | abstract_array attribute_list_opt
2787                { $$ = $1->addQualifiers( $2 ); }
2788        | abstract_function attribute_list_opt
2789                { $$ = $1->addQualifiers( $2 ); }
2790        ;
2791
2792abstract_ptr:
2793        ptrref_operator
2794                { $$ = DeclarationNode::newPointer( 0, $1 ); }
2795        | ptrref_operator type_qualifier_list
2796                { $$ = DeclarationNode::newPointer( $2, $1 ); }
2797        | ptrref_operator abstract_declarator
2798                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2799        | ptrref_operator type_qualifier_list abstract_declarator
2800                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2801        | '(' abstract_ptr ')' attribute_list_opt
2802                { $$ = $2->addQualifiers( $4 ); }
2803        ;
2804
2805abstract_array:
2806        array_dimension
2807        | '(' abstract_ptr ')' array_dimension
2808                { $$ = $2->addArray( $4 ); }
2809        | '(' abstract_array ')' multi_array_dimension          // redundant parenthesis
2810                { $$ = $2->addArray( $4 ); }
2811        | '(' abstract_array ')'                                                        // redundant parenthesis
2812                { $$ = $2; }
2813        ;
2814
2815abstract_function:
2816        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
2817                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
2818        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2819                { $$ = $2->addParamList( $6 ); }
2820        | '(' abstract_function ')'                                                     // redundant parenthesis
2821                { $$ = $2; }
2822        ;
2823
2824array_dimension:
2825                // Only the first dimension can be empty.
2826        '[' ']'
2827                { $$ = DeclarationNode::newArray( 0, 0, false ); }
2828        | '[' ']' multi_array_dimension
2829                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
2830        | multi_array_dimension
2831        ;
2832
2833multi_array_dimension:
2834        '[' push assignment_expression pop ']'
2835                { $$ = DeclarationNode::newArray( $3, 0, false ); }
2836        | '[' push '*' pop ']'                                                          // C99
2837                { $$ = DeclarationNode::newVarArray( 0 ); }
2838        | multi_array_dimension '[' push assignment_expression pop ']'
2839                { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
2840        | multi_array_dimension '[' push '*' pop ']'            // C99
2841                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
2842        ;
2843
2844// This pattern parses a declaration of a parameter abstract variable or function prototype, i.e., there is no
2845// identifier to which the type applies, e.g.:
2846//
2847//              int f( int );                   // not handled here
2848//              int f( int * );                 // abstract function-prototype parameter; no parameter name specified
2849//              int f( int (*)() );             // abstract function-prototype parameter; no parameter name specified
2850//              int f( int (int) );             // abstract function-prototype parameter; no parameter name specified
2851//
2852// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2853// and functions versus pointers to arrays and functions. In addition, the pattern handles the
2854// special meaning of parenthesis around a typedef name:
2855//
2856//              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
2857//              parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
2858//              not as redundant parentheses around the identifier."
2859//
2860// For example:
2861//
2862//              typedef float T;
2863//              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator
2864//              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator
2865//              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator
2866//              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator
2867//
2868// In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
2869// not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
2870// functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
2871// functions.
2872
2873abstract_parameter_declarator:
2874        abstract_parameter_ptr
2875        | abstract_parameter_array attribute_list_opt
2876                { $$ = $1->addQualifiers( $2 ); }
2877        | abstract_parameter_function attribute_list_opt
2878                { $$ = $1->addQualifiers( $2 ); }
2879        ;
2880
2881abstract_parameter_ptr:
2882        ptrref_operator
2883                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
2884        | ptrref_operator type_qualifier_list
2885                { $$ = DeclarationNode::newPointer( $2, $1 ); }
2886        | ptrref_operator abstract_parameter_declarator
2887                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
2888        | ptrref_operator type_qualifier_list abstract_parameter_declarator
2889                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2890        | '(' abstract_parameter_ptr ')' attribute_list_opt
2891                { $$ = $2->addQualifiers( $4 ); }
2892        ;
2893
2894abstract_parameter_array:
2895        array_parameter_dimension
2896        | '(' abstract_parameter_ptr ')' array_parameter_dimension
2897                { $$ = $2->addArray( $4 ); }
2898        | '(' abstract_parameter_array ')' multi_array_dimension // redundant parenthesis
2899                { $$ = $2->addArray( $4 ); }
2900        | '(' abstract_parameter_array ')'                                      // redundant parenthesis
2901                { $$ = $2; }
2902        ;
2903
2904abstract_parameter_function:
2905        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
2906                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
2907        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2908                { $$ = $2->addParamList( $6 ); }
2909        | '(' abstract_parameter_function ')'                           // redundant parenthesis
2910                { $$ = $2; }
2911        ;
2912
2913array_parameter_dimension:
2914                // Only the first dimension can be empty or have qualifiers.
2915        array_parameter_1st_dimension
2916        | array_parameter_1st_dimension multi_array_dimension
2917                { $$ = $1->addArray( $2 ); }
2918        | multi_array_dimension
2919        ;
2920
2921// The declaration of an array parameter has additional syntax over arrays in normal variable declarations:
2922//
2923//              ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in
2924//              a declaration of a function parameter with an array type, and then only in the outermost array type derivation."
2925
2926array_parameter_1st_dimension:
2927        '[' ']'
2928                { $$ = DeclarationNode::newArray( 0, 0, false ); }
2929        // multi_array_dimension handles the '[' '*' ']' case
2930        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
2931                { $$ = DeclarationNode::newVarArray( $3 ); }
2932        | '[' push type_qualifier_list pop ']'
2933                { $$ = DeclarationNode::newArray( 0, $3, false ); }
2934        // multi_array_dimension handles the '[' assignment_expression ']' case
2935        | '[' push type_qualifier_list assignment_expression pop ']'
2936                { $$ = DeclarationNode::newArray( $4, $3, false ); }
2937        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
2938                { $$ = DeclarationNode::newArray( $5, $4, true ); }
2939        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
2940                { $$ = DeclarationNode::newArray( $5, $3, true ); }
2941        ;
2942
2943// This pattern parses a declaration of an abstract variable, but does not allow "int ()" for a function pointer.
2944//
2945//              struct S {
2946//          int;
2947//          int *;
2948//          int [10];
2949//          int (*)();
2950//      };
2951
2952variable_abstract_declarator:
2953        variable_abstract_ptr
2954        | variable_abstract_array attribute_list_opt
2955                { $$ = $1->addQualifiers( $2 ); }
2956        | variable_abstract_function attribute_list_opt
2957                { $$ = $1->addQualifiers( $2 ); }
2958        ;
2959
2960variable_abstract_ptr:
2961        ptrref_operator
2962                { $$ = DeclarationNode::newPointer( 0, $1 ); }
2963        | ptrref_operator type_qualifier_list
2964                { $$ = DeclarationNode::newPointer( $2, $1 ); }
2965        | ptrref_operator variable_abstract_declarator
2966                { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
2967        | ptrref_operator type_qualifier_list variable_abstract_declarator
2968                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
2969        | '(' variable_abstract_ptr ')' attribute_list_opt
2970                { $$ = $2->addQualifiers( $4 ); }
2971        ;
2972
2973variable_abstract_array:
2974        array_dimension
2975        | '(' variable_abstract_ptr ')' array_dimension
2976                { $$ = $2->addArray( $4 ); }
2977        | '(' variable_abstract_array ')' multi_array_dimension // redundant parenthesis
2978                { $$ = $2->addArray( $4 ); }
2979        | '(' variable_abstract_array ')'                                       // redundant parenthesis
2980                { $$ = $2; }
2981        ;
2982
2983variable_abstract_function:
2984        '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2985                { $$ = $2->addParamList( $6 ); }
2986        | '(' variable_abstract_function ')'                            // redundant parenthesis
2987                { $$ = $2; }
2988        ;
2989
2990// This pattern parses a new-style declaration for a parameter variable or function prototype that is either an
2991// identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.
2992
2993cfa_identifier_parameter_declarator_tuple:                              // CFA
2994        cfa_identifier_parameter_declarator_no_tuple
2995        | cfa_abstract_tuple
2996        | type_qualifier_list cfa_abstract_tuple
2997                { $$ = $2->addQualifiers( $1 ); }
2998        ;
2999
3000cfa_identifier_parameter_declarator_no_tuple:                   // CFA
3001        cfa_identifier_parameter_ptr
3002        | cfa_identifier_parameter_array
3003        ;
3004
3005cfa_identifier_parameter_ptr:                                                   // CFA
3006                // No SUE declaration in parameter list.
3007        ptrref_operator type_specifier_nobody
3008                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3009        | type_qualifier_list ptrref_operator type_specifier_nobody
3010                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3011        | ptrref_operator cfa_abstract_function
3012                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3013        | type_qualifier_list ptrref_operator cfa_abstract_function
3014                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3015        | ptrref_operator cfa_identifier_parameter_declarator_tuple
3016                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3017        | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple
3018                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3019        ;
3020
3021cfa_identifier_parameter_array:                                                 // CFA
3022                // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
3023                // shift/reduce conflict with new-style empty (void) function return type.
3024        '[' ']' type_specifier_nobody
3025                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
3026        | cfa_array_parameter_1st_dimension type_specifier_nobody
3027                { $$ = $2->addNewArray( $1 ); }
3028        | '[' ']' multi_array_dimension type_specifier_nobody
3029                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
3030        | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier_nobody
3031                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
3032        | multi_array_dimension type_specifier_nobody
3033                { $$ = $2->addNewArray( $1 ); }
3034
3035        | '[' ']' cfa_identifier_parameter_ptr
3036                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
3037        | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr
3038                { $$ = $2->addNewArray( $1 ); }
3039        | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr
3040                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
3041        | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr
3042                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
3043        | multi_array_dimension cfa_identifier_parameter_ptr
3044                { $$ = $2->addNewArray( $1 ); }
3045        ;
3046
3047cfa_array_parameter_1st_dimension:
3048        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
3049                { $$ = DeclarationNode::newVarArray( $3 ); }
3050        | '[' push type_qualifier_list assignment_expression pop ']'
3051                { $$ = DeclarationNode::newArray( $4, $3, false ); }
3052        | '[' push declaration_qualifier_list assignment_expression pop ']'
3053                // declaration_qualifier_list must be used because of shift/reduce conflict with
3054                // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
3055                // appear in this context.
3056                { $$ = DeclarationNode::newArray( $4, $3, true ); }
3057        | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
3058                { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
3059        ;
3060
3061// This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no
3062// identifier to which the type applies, e.g.:
3063//
3064//              [int] f( int );                         // abstract variable parameter; no parameter name specified
3065//              [int] f( [int] (int) );         // abstract function-prototype parameter; no parameter name specified
3066//
3067// These rules need LR(3):
3068//
3069//              cfa_abstract_tuple identifier_or_type_name
3070//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
3071//
3072// since a function return type can be syntactically identical to a tuple type:
3073//
3074//              [int, int] t;
3075//              [int, int] f( int );
3076//
3077// Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
3078// cfa_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
3079// lookahead. To accomplish this, cfa_abstract_declarator has an entry point without tuple, and tuple declarations are
3080// duplicated when appearing with cfa_function_specifier.
3081
3082cfa_abstract_declarator_tuple:                                                  // CFA
3083        cfa_abstract_tuple
3084        | type_qualifier_list cfa_abstract_tuple
3085                { $$ = $2->addQualifiers( $1 ); }
3086        | cfa_abstract_declarator_no_tuple
3087        ;
3088
3089cfa_abstract_declarator_no_tuple:                                               // CFA
3090        cfa_abstract_ptr
3091        | cfa_abstract_array
3092        ;
3093
3094cfa_abstract_ptr:                                                                               // CFA
3095        ptrref_operator type_specifier
3096                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3097        | type_qualifier_list ptrref_operator type_specifier
3098                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3099        | ptrref_operator cfa_abstract_function
3100                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3101        | type_qualifier_list ptrref_operator cfa_abstract_function
3102                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3103        | ptrref_operator cfa_abstract_declarator_tuple
3104                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
3105        | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple
3106                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
3107        ;
3108
3109cfa_abstract_array:                                                                             // CFA
3110                // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
3111                // empty (void) function return type.
3112        '[' ']' type_specifier
3113                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
3114        | '[' ']' multi_array_dimension type_specifier
3115                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
3116        | multi_array_dimension type_specifier
3117                { $$ = $2->addNewArray( $1 ); }
3118        | '[' ']' cfa_abstract_ptr
3119                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
3120        | '[' ']' multi_array_dimension cfa_abstract_ptr
3121                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
3122        | multi_array_dimension cfa_abstract_ptr
3123                { $$ = $2->addNewArray( $1 ); }
3124        ;
3125
3126cfa_abstract_tuple:                                                                             // CFA
3127        '[' push cfa_abstract_parameter_list pop ']'
3128                { $$ = DeclarationNode::newTuple( $3 ); }
3129        ;
3130
3131cfa_abstract_function:                                                                  // CFA
3132//      '[' ']' '(' cfa_parameter_type_list_opt ')'
3133//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
3134        cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
3135                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
3136        | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
3137                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
3138        ;
3139
3140// 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in
3141//    each declaration, and in the specifier-qualifier list in each structure declaration and type name."
3142//
3143// 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of
3144//    the declaration specifiers in a declaration is an obsolescent feature."
3145//
3146// 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not
3147//    prototype-format parameter type declarators) is an obsolescent feature."
3148//
3149// 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and
3150//    declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
3151
3152//************************* MISCELLANEOUS ********************************
3153
3154comma_opt:                                                                                              // redundant comma
3155        // empty
3156        | ','
3157        ;
3158
3159default_initialize_opt:
3160        // empty
3161                { $$ = nullptr; }
3162        | '=' assignment_expression
3163                { $$ = $2; }
3164        ;
3165
3166%%
3167// ----end of grammar----
3168
3169// Local Variables: //
3170// mode: c++ //
3171// tab-width: 4 //
3172// compile-command: "make install" //
3173// End: //
Note: See TracBrowser for help on using the repository browser.