source: src/Parser/parser.yy @ 72457b6

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

add optional virtual keyword in cast

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