source: src/Parser/parser.yy @ 5bd0aad

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 5bd0aad was dc2b4d6, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Discused updates to handler predicate parsing.

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