source: src/Parser/parser.yy @ e195093

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 e195093 was 641c3d0, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add "= void" syntax to delete overloaded routine

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