Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rf9feab8 r90152a4  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 27 17:23:35 2017
    13 // Update Count     : 2992
     12// Last Modified On : Wed Aug  8 17:50:07 2018
     13// Update Count     : 3998
    1414//
    1515
     
    115115} // distExt
    116116
     117void distInl( DeclarationNode * declaration ) {
     118        // distribute EXTENSION across all declarations
     119        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     120                iter->set_inLine( true );
     121        } // for
     122} // distInl
     123
     124void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
     125        // distribute qualifiers across all non-variable declarations in a distribution statemement
     126        for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     127                // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since
     128                // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To
     129                // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to
     130                // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers.
     131                DeclarationNode * clone = qualifiers->clone();
     132                if ( qualifiers->type ) {                                               // forall clause ? (handles SC)
     133                        if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?
     134                                swap( clone->type->forall, iter->type->aggregate.params );
     135                                iter->addQualifiers( clone );
     136                        } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?
     137                                // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together.
     138                                DeclarationNode newnode;
     139                                swap( newnode.type, iter->type->aggInst.aggregate );
     140                                swap( clone->type->forall, newnode.type->aggregate.params );
     141                                newnode.addQualifiers( clone );
     142                                swap( newnode.type, iter->type->aggInst.aggregate );
     143                        } else if ( iter->type->kind == TypeData::Function ) { // routines ?
     144                                swap( clone->type->forall, iter->type->forall );
     145                                iter->addQualifiers( clone );
     146                        } // if
     147                } else {                                                                                // just SC qualifiers
     148                        iter->addQualifiers( clone );
     149                } // if
     150        } // for
     151        delete qualifiers;
     152} // distQual
     153
    117154// There is an ambiguity for inline generic-routine return-types and generic routines.
    118155//   forall( otype T ) struct S { int i; } bar( T ) {}
    119156// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
    120157//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
     158// Currently, the forall is associated with the routine, and the generic type has to be separately defined:
     159//   forall( otype T ) struct S { int T; };
     160//   forall( otype W ) bar( W ) {}
    121161
    122162void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
    123         if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
     163        if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
    124164                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
    125165                declSpec->type->aggregate.params = nullptr;
     
    127167} // rebindForall
    128168
    129 bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     169NameExpr * build_postfix_name( const string * name ) {
     170        NameExpr * new_name = build_varref( new string( "?`" + *name ) );
     171        delete name;
     172        return new_name;
     173} // build_postfix_name
     174
     175DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
     176        if ( ! fieldList ) {                                                            // field declarator ?
     177                if ( ! ( typeSpec->type && typeSpec->type->kind == TypeData::Aggregate ) ) {
     178                        stringstream ss;
     179                        typeSpec->type->print( ss );
     180                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
     181                        return nullptr;
     182                } // if
     183                fieldList = DeclarationNode::newName( nullptr );
     184        } // if
     185        return distAttr( typeSpec, fieldList );                         // mark all fields in list
     186} // fieldDecl
     187
     188ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     189        return new ForCtrl(
     190                distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     191                new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ),
     192                new ExpressionNode( build_binary_val( OperKinds::PlusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) );
     193} // forCtrl
     194
     195
     196bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
    130197
    131198// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    158225        WaitForStmt * wfs;
    159226        Expression * constant;
    160         IfCtl * ifctl;
    161         ForCtl * fctl;
     227        IfCtrl * ifctl;
     228        ForCtrl * fctl;
     229        enum OperKinds compop;
    162230        LabelNode * label;
    163231        InitializerNode * in;
     
    166234        bool flag;
    167235        CatchStmt::Kind catch_kind;
     236        GenericExpr * genexpr;
    168237}
    169238
     
    187256%token TYPEOF LABEL                                                                             // GCC
    188257%token ENUM STRUCT UNION
     258%token EXCEPTION                                                                                // CFA
    189259%token COROUTINE MONITOR THREAD                                                 // CFA
    190260%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
     
    201271%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    202272%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
     273%token<tok> DIRECTIVE
    203274// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
    204275// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
     
    219290%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    220291
     292%token Erange                                                                                   // ~=
    221293%token ATassign                                                                                 // @=
    222294
     
    241313%type<ifctl> if_control_expression
    242314%type<fctl> for_control_expression
     315%type<compop> inclexcl
    243316%type<en> subrange
    244317%type<decl> asm_name_opt
     
    248321%type<flag> asm_volatile_opt
    249322%type<en> handler_predicate_opt
     323%type<genexpr> generic_association generic_assoc_list
    250324
    251325// statements
    252326%type<sn> statement                                             labeled_statement                       compound_statement
    253327%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    254 %type<sn> selection_statement
    255 %type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
     328%type<sn> selection_statement                   if_statement
     329%type<sn> switch_clause_list_opt                switch_clause_list
    256330%type<en> case_value
    257331%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    258 %type<sn> fall_through                                  fall_through_opt
    259332%type<sn> iteration_statement                   jump_statement
    260333%type<sn> expression_statement                  asm_statement
    261 %type<sn> with_statement                                with_clause_opt
     334%type<sn> with_statement
     335%type<en> with_clause_opt
    262336%type<sn> exception_statement                   handler_clause                          finally_clause
    263337%type<catch_kind> handler_key
     
    275349%type<decl> aggregate_type aggregate_type_nobody
    276350
    277 %type<decl> assertion assertion_list_opt
     351%type<decl> assertion assertion_list assertion_list_opt
    278352
    279353%type<en>   bit_subrange_size_opt bit_subrange_size
     
    291365%type<en> enumerator_value_opt
    292366
    293 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
    294 
    295 %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    296 %type<en> field field_list field_name fraction_constants
     367%type<decl> external_definition external_definition_list external_definition_list_opt
     368
     369%type<decl> exception_declaration
     370
     371%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
     372%type<en> field field_name_list field_name fraction_constants_opt
    297373
    298374%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    307383%type<decl> cfa_array_parameter_1st_dimension
    308384
    309 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
     385%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
    310386%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    311387
     
    313389%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    314390
    315 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt
     391%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
    316392
    317393%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
    318394
    319 %type<decl> c_declaration
     395%type<decl> c_declaration static_assert
    320396%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    321 %type<decl> KR_declaration_list KR_declaration_list_opt
    322 
    323 %type<decl> parameter_declaration parameter_list parameter_type_list
    324 %type<decl> parameter_type_list_opt
     397%type<decl> KR_parameter_list KR_parameter_list_opt
     398
     399%type<decl> parameter_declaration parameter_list parameter_type_list_opt
    325400
    326401%type<decl> paren_identifier paren_type
     
    343418%type<decl> type_parameter type_parameter_list type_initializer_opt
    344419
    345 %type<en> type_list
     420%type<en> type_parameters_opt type_list
    346421
    347422%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    354429
    355430// initializers
    356 %type<in>  initializer initializer_list initializer_opt
     431%type<in>  initializer initializer_list_opt initializer_opt
    357432
    358433// designators
     
    378453//   Foo ( *fp )( int );
    379454//   `---'                                              matches start of TYPEGENname '('
    380 // Must be:
     455// must be:
    381456//   Foo( int ) ( *fp )( int );
     457// The same problem occurs here:
     458//   forall( otype T ) struct Foo { T v; } ( *fp )( int );
     459// must be:
     460//   forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int );
    382461
    383462// Order of these lines matters (low-to-high precedence).
    384463%precedence TYPEGENname
     464%precedence '}'
    385465%precedence '('
    386466
    387 %locations                      // support location tracking for error messages
     467%locations                                                                                              // support location tracking for error messages
    388468
    389469%start translation_unit                                                                 // parse-tree root
     
    392472//************************* Namespace Management ********************************
    393473
    394 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
    395 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
    396 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
    397 // Hence, this grammar uses the ANSI style.
    398 //
    399 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
    400 // introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
    401 // type name creates a third class of identifiers that must be distinguished by the scanner.
    402 //
    403 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
    404 // accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
    405 // actions during the parser update this data structure when the class of identifiers change.
    406 //
    407 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
    408 // local scope; it must revert to its original class at the end of the block.  Since type names can be local to a
    409 // particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are
    410 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
    411 // "typedef" or "otype" declarations).
    412 //
    413 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
    414 // scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
    415 // within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point
    416 // of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
    417 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
    418 // rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around
    419 // "push" and "pop" nonterminals to resolve conflicts of this sort.
     474// The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
     475// which are lexically identical.
     476//
     477//   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
     478//   foo f;           // to allow it to appear in this context
     479//
     480// While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
     481// between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
     482// scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
     483// generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
     484// must be distinguished by the lexical scanner.
     485//
     486// Since the scanner cannot distinguish among the different classes of identifiers without some context information,
     487// there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
     488// scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
     489// each context that introduces a name scope, a new level is created in the type table and that level is popped on
     490// exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
     491// This requires distinguishing between type names that are local to the current declaration scope and those that
     492// persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
     493//
     494// The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
     495// the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
     496// around the list separator.
     497//
     498//  int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );
     499//      push               pop   push                   pop
    420500
    421501push:
     
    443523        ;
    444524
    445 identifier:
    446         IDENTIFIER
    447         | ATTR_IDENTIFIER                                                                       // CFA
    448         | quasi_keyword
    449         ;
    450 
    451525no_attr_identifier:
    452526        IDENTIFIER
    453527        | quasi_keyword
     528        | '@'                                                                                           // CFA
     529                { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
     530        ;
     531
     532identifier:
     533        no_attr_identifier
     534        | ATTR_IDENTIFIER                                                                       // CFA
    454535        ;
    455536
     
    480561        | '(' compound_statement ')'                                            // GCC, lambda expression
    481562                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
     563        | constant '`' IDENTIFIER                                                       // CFA, postfix call
     564                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     565        | string_literal '`' IDENTIFIER                                         // CFA, postfix call
     566                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }
     567        | IDENTIFIER '`' IDENTIFIER                                                     // CFA, postfix call
     568                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }
     569        | tuple '`' IDENTIFIER                                                          // CFA, postfix call
     570                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     571        | '(' comma_expression ')' '`' IDENTIFIER                       // CFA, postfix call
     572                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    482573        | type_name '.' no_attr_identifier                                      // CFA, nested type
    483                 { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
    484         | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    485                 { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
     574                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     575        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
     576                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     577        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
     578                {
     579                        // add the missing control expression to the GenericExpr and return it
     580                        $5->control = maybeMoveBuild<Expression>( $3 );
     581                        $$ = new ExpressionNode( $5 );
     582                }
     583        ;
     584
     585generic_assoc_list:                                                                             // C11
     586        generic_association
     587        | generic_assoc_list ',' generic_association
     588                {
     589                        // steal the association node from the singleton and delete the wrapper
     590                        $1->associations.splice($1->associations.end(), $3->associations);
     591                        delete $3;
     592                        $$ = $1;
     593                }
     594        ;
     595
     596generic_association:                                                                    // C11
     597        type_no_function ':' assignment_expression
     598                {
     599                        // create a GenericExpr wrapper with one association pair
     600                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
     601                }
     602        | DEFAULT ':' assignment_expression
     603                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    486604        ;
    487605
    488606postfix_expression:
    489607        primary_expression
    490         | postfix_expression '[' push assignment_expression pop ']'
     608        | postfix_expression '[' assignment_expression ']'
    491609                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    492610                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    493611                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    494612                // equivalent to the old x[i,j].
    495                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
     613                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    496614        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    497615                {
     
    504622        | postfix_expression '.' no_attr_identifier
    505623                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    506         | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    507                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
     624        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
     625                { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger( *$3 ) ) ); }
    508626        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    509627                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
     628        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
     629                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    510630        | postfix_expression ARROW no_attr_identifier
    511631                {
    512632                        $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    513633                }
    514         | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
    515                         { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    516634        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    517635                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     636        | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
     637                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    518638        | postfix_expression ICR
    519639                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    520640        | postfix_expression DECR
    521641                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    522         | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
     642        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    523643                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
     644        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
     645                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    524646        | '^' primary_expression '{' argument_expression_list '}' // CFA
    525647                {
     
    539661        // empty
    540662                { $$ = nullptr; }
    541         // | '@'                                                                                                // use default argument
    542         //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     663        | '?'                                                                                           // CFA, default parameter
     664                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
     665                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    543666        | assignment_expression
    544667        ;
    545668
    546 field_list:                                                                                             // CFA, tuple field selector
     669field_name_list:                                                                                // CFA, tuple field selector
    547670        field
    548         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     671        | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    549672        ;
    550673
     
    553676        | FLOATING_DECIMALconstant field
    554677                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    555         | FLOATING_DECIMALconstant '[' push field_list pop ']'
    556                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
     678        | FLOATING_DECIMALconstant '[' field_name_list ']'
     679                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    557680        | field_name '.' field
    558681                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    559         | field_name '.' '[' push field_list pop ']'
    560                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
     682        | field_name '.' '[' field_name_list ']'
     683                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    561684        | field_name ARROW field
    562685                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    563         | field_name ARROW '[' push field_list pop ']'
    564                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
     686        | field_name ARROW '[' field_name_list ']'
     687                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    565688        ;
    566689
    567690field_name:
    568         INTEGERconstant fraction_constants
     691        INTEGERconstant fraction_constants_opt
    569692                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); }
    570         | FLOATINGconstant fraction_constants
     693        | FLOATINGconstant fraction_constants_opt
    571694                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    572         | no_attr_identifier fraction_constants
     695        | no_attr_identifier fraction_constants_opt
    573696                {
    574697                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    576699        ;
    577700
    578 fraction_constants:
     701fraction_constants_opt:
    579702        // empty
    580703                { $$ = nullptr; }
    581         | fraction_constants FLOATING_FRACTIONconstant
     704        | fraction_constants_opt FLOATING_FRACTIONconstant
    582705                {
    583706                        Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
     
    591714                // semantics checks, e.g., ++3, 3--, *3, &&3
    592715        | constant
    593                 { $$ = $1; }
    594716        | string_literal
    595717                { $$ = new ExpressionNode( $1 ); }
     
    657779        | '(' type_no_function ')' cast_expression
    658780                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     781        | '(' COROUTINE '&' ')' cast_expression                         // CFA
     782                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     783        | '(' THREAD '&' ')' cast_expression                            // CFA
     784                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); }
     785        | '(' MONITOR '&' ')' cast_expression                           // CFA
     786                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); }
    659787                // VIRTUAL cannot be opt because of look ahead issues
    660         | '(' VIRTUAL ')' cast_expression
     788        | '(' VIRTUAL ')' cast_expression                                       // CFA
    661789                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    662         | '(' VIRTUAL type_no_function ')' cast_expression
     790        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    663791                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
    664792//      | '(' type_no_function ')' tuple
     
    752880        | logical_OR_expression '?' comma_expression ':' conditional_expression
    753881                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    754                 // FIX ME: this hack computes $1 twice
     882                // FIX ME: computes $1 twice
    755883        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    756884                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
     
    766894        | unary_expression assignment_operator assignment_expression
    767895                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
     896        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
     897                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
    768898        ;
    769899
     
    795925//      '[' ']'
    796926//              { $$ = new ExpressionNode( build_tuple() ); }
    797 //      '[' push assignment_expression pop ']'
     927//      | '[' push assignment_expression pop ']'
    798928//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    799         '[' push ',' tuple_expression_list pop ']'
    800                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    801         | '[' push assignment_expression ',' tuple_expression_list pop ']'
    802                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
     929        '[' ',' tuple_expression_list ']'
     930                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
     931        | '[' push assignment_expression pop ',' tuple_expression_list ']'
     932                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    803933        ;
    804934
     
    826956        labeled_statement
    827957        | compound_statement
    828         | expression_statement                                          { $$ = $1; }
     958        | expression_statement
    829959        | selection_statement
    830960        | iteration_statement
     
    834964        | waitfor_statement
    835965        | exception_statement
     966        | enable_disable_statement
     967                { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; }
    836968        | asm_statement
     969        | DIRECTIVE
     970                { $$ = new StatementNode( build_directive( $1 ) ); }
     971        ;
    837972
    838973labeled_statement:
     
    847982        '{' '}'
    848983                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    849         | '{'
    850                 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
    851                 // requires its own scope.
    852           push push
     984        | '{' push
    853985          local_label_declaration_opt                                           // GCC, local labels
    854986          statement_decl_list                                                           // C99, intermix declarations and statements
    855987          pop '}'
    856                 { $$ = new StatementNode( build_compound( $5 ) ); }
     988                { $$ = new StatementNode( build_compound( $4 ) ); }
    857989        ;
    858990
    859991statement_decl_list:                                                                    // C99
    860992        statement_decl
    861         | statement_decl_list push statement_decl
    862                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     993        | statement_decl_list statement_decl
     994                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    863995        ;
    864996
     
    8781010                        $$ = new StatementNode( $2 );
    8791011                }
    880         | statement pop
     1012        | statement
    8811013        ;
    8821014
     
    8931025
    8941026selection_statement:
    895         IF '(' push if_control_expression ')' statement         %prec THEN
    896                 // explicitly deal with the shift/reduce conflict on if/else
    897                 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    898         | IF '(' push if_control_expression ')' statement ELSE statement
    899                 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
     1027                        // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
     1028                        // the inherent S/R conflict with THEN/ELSE.
     1029        push if_statement pop
     1030                { $$ = $2; }
    9001031        | SWITCH '(' comma_expression ')' case_clause
    901                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    902         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    903                 {
    904                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     1032                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
     1033        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     1034                {
     1035                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
    9051036                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    9061037                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    9111042                }
    9121043        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    913                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    914         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    915                 {
    916                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     1044                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
     1045        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     1046                {
     1047                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
    9171048                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    9181049                }
    9191050        ;
    9201051
     1052if_statement:
     1053        IF '(' if_control_expression ')' statement                      %prec THEN
     1054                // explicitly deal with the shift/reduce conflict on if/else
     1055                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
     1056        | IF '(' if_control_expression ')' statement ELSE statement
     1057                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
     1058        ;
     1059
    9211060if_control_expression:
    922         comma_expression pop
    923                 { $$ = new IfCtl( nullptr, $1 ); }
    924         | c_declaration pop                                                                     // no semi-colon
    925                 { $$ = new IfCtl( $1, nullptr ); }
    926         | cfa_declaration pop                                                           // no semi-colon
    927                 { $$ = new IfCtl( $1, nullptr ); }
     1061        comma_expression
     1062                { $$ = new IfCtrl( nullptr, $1 ); }
     1063        | c_declaration                                                                         // no semi-colon
     1064                { $$ = new IfCtrl( $1, nullptr ); }
     1065        | cfa_declaration                                                                       // no semi-colon
     1066                { $$ = new IfCtrl( $1, nullptr ); }
    9281067        | declaration comma_expression                                          // semi-colon separated
    929                 { $$ = new IfCtl( $1, $2 ); }
     1068                { $$ = new IfCtrl( $1, $2 ); }
    9301069        ;
    9311070
     
    9521091        ;
    9531092
     1093//label_list_opt:
     1094//      // empty
     1095//      | identifier_or_type_name ':'
     1096//      | label_list_opt identifier_or_type_name ':'
     1097//      ;
     1098
    9541099case_label_list:                                                                                // CFA
    9551100        case_label
     
    9741119        ;
    9751120
    976 choose_clause_list_opt:                                                                 // CFA
    977         // empty
    978                 { $$ = nullptr; }
    979         | choose_clause_list
    980         ;
    981 
    982 choose_clause_list:                                                                             // CFA
    983         case_label_list fall_through
    984                 { $$ = $1->append_last_case( $2 ); }
    985         | case_label_list statement_list_nodecl fall_through_opt
    986                 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    987         | choose_clause_list case_label_list fall_through
    988                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    989         | choose_clause_list case_label_list statement_list_nodecl fall_through_opt
    990                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    991         ;
    992 
    993 fall_through_opt:                                                                               // CFA
    994         // empty
    995                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
    996         | fall_through
    997         ;
    998 
    999 fall_through_name:                                                                              // CFA
    1000         FALLTHRU
    1001         | FALLTHROUGH
    1002         ;
    1003 
    1004 fall_through:                                                                                   // CFA
    1005         fall_through_name
    1006                 { $$ = nullptr; }
    1007         | fall_through_name ';'
    1008                 { $$ = nullptr; }
    1009         ;
    1010 
    10111121iteration_statement:
    1012         WHILE '(' comma_expression ')' statement
    1013                 { $$ = new StatementNode( build_while( $3, $5 ) ); }
     1122        WHILE '(' push if_control_expression ')' statement pop
     1123                { $$ = new StatementNode( build_while( $4, $6 ) ); }
     1124        | WHILE '(' ')' statement                                                       // CFA => while ( 1 )
     1125                { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); }
    10141126        | DO statement WHILE '(' comma_expression ')' ';'
    1015                 { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1016         | FOR '(' push for_control_expression ')' statement
     1127                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
     1128        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
     1129                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
     1130        | FOR '(' push for_control_expression ')' statement pop
    10171131                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10181132        ;
    10191133
    10201134for_control_expression:
    1021         comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    1022                 { $$ = new ForCtl( $1, $4, $6 ); }
    1023         | declaration comma_expression_opt ';' comma_expression_opt // C99
    1024                 { $$ = new ForCtl( $1, $2, $4 ); }
     1135        comma_expression_opt                                                            // CFA
     1136                {
     1137                        if ( ! $1 ) {                                                           // => for ( ;; )
     1138                                $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr );
     1139                        } else {
     1140                                $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $1->clone(),
     1141                                                         new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
     1142                        } // if
     1143                }
     1144        | constant_expression inclexcl constant_expression      // CFA
     1145                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1146        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1147                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     1148        | comma_expression_opt ';' comma_expression                     // CFA
     1149                {
     1150                        if ( ! $1 ) {
     1151                                SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
     1152                        } else if ( ! $3 ) {
     1153                                SemanticError( yylloc, "Missing loop range." ); $$ = nullptr;
     1154                        } else {
     1155                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
     1156                                        $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $3->clone(),
     1157                                                                 new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
     1158                                } else {
     1159                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     1160                                } // if
     1161                        } // if
     1162                }
     1163        | comma_expression_opt ';' constant_expression inclexcl constant_expression // CFA
     1164                {
     1165                        if ( ! $1 ) {
     1166                                SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
     1167                        } else {
     1168                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
     1169                                        $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
     1170                                } else {
     1171                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     1172                                } // if
     1173                        } // if
     1174                }
     1175        | comma_expression_opt ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1176                {
     1177                        if ( ! $1 ) {
     1178                                SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
     1179                        } else {
     1180                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
     1181                                        $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, $7 );
     1182                                } else {
     1183                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     1184                                } // if
     1185                        } // if
     1186                }
     1187        | comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1188                { $$ = new ForCtrl( $1, $3, $5 ); }
     1189        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
     1190                { $$ = new ForCtrl( $1, $2, $4 ); }
     1191        ;
     1192
     1193inclexcl:
     1194        '~'
     1195                { $$ = OperKinds::LThan; }
     1196        | Erange
     1197                { $$ = OperKinds::LEThan; }
    10251198        ;
    10261199
     
    10321205                // whereas normal operator precedence yields goto (*i)+3;
    10331206                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
     1207                // A semantic check is required to ensure fallthru appears only in the body of a choose statement.
     1208    | fall_through_name ';'                                                             // CFA
     1209                { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }
     1210    | fall_through_name identifier_or_type_name ';'             // CFA
     1211                { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); }
     1212        | fall_through_name DEFAULT ';'                                         // CFA
     1213                { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); }
    10341214        | CONTINUE ';'
    10351215                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
     
    10481228        | RETURN comma_expression_opt ';'
    10491229                { $$ = new StatementNode( build_return( $2 ) ); }
     1230        | RETURN '{' initializer_list_opt comma_opt '}'
     1231                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    10501232        | THROW assignment_expression_opt ';'                           // handles rethrow
    10511233                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    10561238        ;
    10571239
     1240fall_through_name:                                                                              // CFA
     1241        FALLTHRU
     1242        | FALLTHROUGH
     1243        ;
     1244
    10581245with_statement:
    10591246        WITH '(' tuple_expression_list ')' statement
     
    10661253mutex_statement:
    10671254        MUTEX '(' argument_expression_list ')' statement
    1068                 { throw SemanticError("Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME
     1255                { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }
    10691256        ;
    10701257
    10711258when_clause:
    1072         WHEN '(' comma_expression ')'
    1073                 { $$ = $3; }
     1259        WHEN '(' comma_expression ')'                           { $$ = $3; }
    10741260        ;
    10751261
     
    10811267
    10821268waitfor:
    1083         WAITFOR '(' identifier ')'
    1084                 {
    1085                         $$ = new ExpressionNode( new NameExpr( *$3 ) );
    1086                         delete $3;
    1087                 }
    1088         | WAITFOR '(' identifier ',' argument_expression_list ')'
    1089                 {
    1090                         $$ = new ExpressionNode( new NameExpr( *$3 ) );
    1091                         $$->set_last( $5 );
    1092                         delete $3;
    1093                 }
     1269        WAITFOR '(' cast_expression ')'
     1270                { $$ = $3; }
     1271        | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1272                { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    10941273        ;
    10951274
    10961275timeout:
    1097         TIMEOUT '(' comma_expression ')'
    1098                 { $$ = $3; }
     1276        TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
    10991277        ;
    11001278
     
    11091287                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    11101288                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1289        | when_clause_opt timeout statement WOR ELSE statement
     1290                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    11111291        | when_clause_opt timeout statement WOR when_clause ELSE statement
    11121292                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    11301310
    11311311handler_clause:
    1132         handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1133                 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
    1134         | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1135                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
     1312        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1313                { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
     1314        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1315                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
    11361316        ;
    11371317
    11381318handler_predicate_opt:
    1139         //empty
     1319        // empty
    11401320                { $$ = nullptr; }
    1141         | ';' conditional_expression
    1142                 { $$ = $2; }
     1321        | ';' conditional_expression                            { $$ = $2; }
    11431322        ;
    11441323
    11451324handler_key:
    1146         CATCH
    1147                 { $$ = CatchStmt::Terminate; }
    1148         | CATCHRESUME
    1149                 { $$ = CatchStmt::Resume; }
     1325        CATCH                                                                           { $$ = CatchStmt::Terminate; }
     1326        | CATCHRESUME                                                           { $$ = CatchStmt::Resume; }
    11501327        ;
    11511328
    11521329finally_clause:
    1153         FINALLY compound_statement
    1154                 {
    1155                         $$ = new StatementNode( build_finally( $2 ) );
    1156                 }
     1330        FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( $2 ) ); }
    11571331        ;
    11581332
     
    11611335        type_specifier_nobody
    11621336        | type_specifier_nobody declarator
    1163                 {
    1164                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1165                         $$ = $2->addType( $1 );
    1166                 }
     1337                { $$ = $2->addType( $1 ); }
    11671338        | type_specifier_nobody variable_abstract_declarator
    11681339                { $$ = $2->addType( $1 ); }
    11691340        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    1170                 {
    1171                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1172                         $$ = $1->addName( $2 );
    1173                 }
     1341                { $$ = $1->addName( $2 ); }
    11741342        | cfa_abstract_declarator_tuple                                         // CFA
     1343        ;
     1344
     1345enable_disable_statement:
     1346        enable_disable_key identifier_list compound_statement
     1347        ;
     1348
     1349enable_disable_key:
     1350        ENABLE
     1351        | DISABLE
    11751352        ;
    11761353
    11771354asm_statement:
    11781355        ASM asm_volatile_opt '(' string_literal ')' ';'
    1179                 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
     1356                { $$ = new StatementNode( build_asm( $2, $4, 0 ) ); }
    11801357        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    1181                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
     1358                { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }
    11821359        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    1183                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
     1360                { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); }
    11841361        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    1185                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
     1362                { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }
    11861363        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    1187                 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
     1364                { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); }
    11881365        ;
    11891366
     
    12401417
    12411418declaration_list_opt:                                                                   // used at beginning of switch statement
    1242         pop
     1419        // empty
    12431420                { $$ = nullptr; }
    12441421        | declaration_list
     
    12471424declaration_list:
    12481425        declaration
    1249         | declaration_list push declaration
    1250                 { $$ = $1->appendList( $3 ); }
    1251         ;
    1252 
    1253 KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
     1426        | declaration_list declaration
     1427                { $$ = $1->appendList( $2 ); }
     1428        ;
     1429
     1430KR_parameter_list_opt:                                                                  // used to declare parameter types in K&R style functions
    12541431        // empty
    12551432                { $$ = nullptr; }
    1256         | KR_declaration_list
    1257         ;
    1258 
    1259 KR_declaration_list:
     1433        | KR_parameter_list
     1434        ;
     1435
     1436KR_parameter_list:
    12601437        push c_declaration pop ';'
    12611438                { $$ = $2; }
    1262         | KR_declaration_list push c_declaration pop ';'
     1439        | KR_parameter_list push c_declaration pop ';'
    12631440                { $$ = $1->appendList( $3 ); }
    12641441        ;
     
    12751452
    12761453local_label_list:                                                                               // GCC, local label
    1277         no_attr_identifier_or_type_name                         {}
    1278         | local_label_list ',' no_attr_identifier_or_type_name {}
     1454        no_attr_identifier_or_type_name
     1455        | local_label_list ',' no_attr_identifier_or_type_name
    12791456        ;
    12801457
    12811458declaration:                                                                                    // old & new style declarations
    1282         c_declaration pop ';'
    1283         | cfa_declaration pop ';'                                                       // CFA
    1284         | STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1285                 { throw SemanticError("Static assert is currently unimplemented."); $$ = nullptr; }     // FIX ME
    1286         ;
     1459        c_declaration ';'
     1460        | cfa_declaration ';'                                                           // CFA
     1461        | static_assert                                                                         // C11
     1462        ;
     1463
     1464static_assert:
     1465        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
     1466                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1467        | STATICASSERT '(' constant_expression ')' ';'          // CFA
     1468                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }
    12871469
    12881470// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    13071489cfa_variable_declaration:                                                               // CFA
    13081490        cfa_variable_specifier initializer_opt
    1309                 {
    1310                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1311                         $$ = $1->addInitializer( $2 );
    1312                 }
     1491                { $$ = $1->addInitializer( $2 ); }
    13131492        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    13141493                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    13151494                // them as a type_qualifier cannot appear in that context.
    1316                 {
    1317                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1318                         $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
    1319                 }
     1495                { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
    13201496        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1321                 {
    1322                         typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
    1323                         $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
    1324                 }
     1497                { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
    13251498        ;
    13261499
     
    13291502                // storage-class
    13301503        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    1331                 {
    1332                         typedefTable.setNextIdentifier( *$2 );
    1333                         $$ = $1->addName( $2 )->addAsmName( $3 );
    1334                 }
     1504                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
    13351505        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1336                 {
    1337                         typedefTable.setNextIdentifier( *$2 );
    1338                         $$ = $1->addName( $2 )->addAsmName( $3 );
    1339                 }
     1506                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
    13401507        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1341                 {
    1342                         typedefTable.setNextIdentifier( *$3 );
    1343                         $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
    1344                 }
     1508                { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
    13451509        ;
    13461510
    13471511cfa_function_declaration:                                                               // CFA
    13481512        cfa_function_specifier
    1349                 {
    1350                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1351                         $$ = $1;
    1352                 }
    13531513        | type_qualifier_list cfa_function_specifier
    1354                 {
    1355                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1356                         $$ = $2->addQualifiers( $1 );
    1357                 }
     1514                { $$ = $2->addQualifiers( $1 ); }
    13581515        | declaration_qualifier_list cfa_function_specifier
    1359                 {
    1360                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1361                         $$ = $2->addQualifiers( $1 );
    1362                 }
     1516                { $$ = $2->addQualifiers( $1 ); }
    13631517        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    1364                 {
    1365                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1366                         $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
    1367                 }
    1368         | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1518                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
     1519        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13691520                {
    13701521                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13711522                        DeclarationNode * ret = new DeclarationNode;
    13721523                        ret->type = maybeClone( $1->type->base );
    1373                         $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr, true ) );
     1524                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
    13741525                }
    13751526        ;
    13761527
    13771528cfa_function_specifier:                                                                 // CFA
    1378 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
     1529//      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
    13791530//              {
    13801531//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    13811532//              }
    1382 //      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
     1533//      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13831534//              {
    13841535//                      typedefTable.setNextIdentifier( *$5 );
    13851536//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    13861537//              }
    1387 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
     1538//      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13881539//              {
    13891540//                      typedefTable.setNextIdentifier( *$5 );
     
    13931544                // identifier_or_type_name must be broken apart because of the sequence:
    13941545                //
    1395                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1546                //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    13961547                //   '[' ']' type_specifier
    13971548                //
    13981549                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    13991550                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1400         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1551        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    14011552                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1402                 {
    1403                         $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
    1404                 }
    1405         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    1406                 {
    1407                         $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
    1408                 }
     1553                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1554        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1555                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14091556        ;
    14101557
     
    14131560                { $$ = DeclarationNode::newTuple( $3 ); }
    14141561        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    1415                 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
    1416                 // ']'.
     1562                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
    14171563                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    14181564        ;
     
    14211567        TYPEDEF cfa_variable_specifier
    14221568                {
    1423                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1569                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" );
    14241570                        $$ = $2->addTypedef();
    14251571                }
    14261572        | TYPEDEF cfa_function_specifier
    14271573                {
    1428                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1574                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" );
    14291575                        $$ = $2->addTypedef();
    14301576                }
    14311577        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14321578                {
    1433                         typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     1579                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
    14341580                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14351581                }
     
    14421588        TYPEDEF type_specifier declarator
    14431589                {
    1444                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1590                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    14451591                        $$ = $3->addType( $2 )->addTypedef();
    14461592                }
    14471593        | typedef_declaration pop ',' push declarator
    14481594                {
    1449                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1595                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" );
    14501596                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14511597                }
    14521598        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14531599                {
    1454                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1600                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
    14551601                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14561602                }
    14571603        | type_specifier TYPEDEF declarator
    14581604                {
    1459                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1605                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
    14601606                        $$ = $3->addType( $1 )->addTypedef();
    14611607                }
    14621608        | type_specifier TYPEDEF type_qualifier_list declarator
    14631609                {
    1464                         typedefTable.addToEnclosingScope( TypedefTable::TD );
     1610                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
    14651611                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14661612                }
     
    14711617        TYPEDEF no_attr_identifier '=' assignment_expression
    14721618                {
    1473                         typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
    1474                         $$ = DeclarationNode::newName( 0 );                     // unimplemented
     1619                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1620                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    14751621                }
    14761622        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    14771623                {
    1478                         typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
    1479                         $$ = DeclarationNode::newName( 0 );                     // unimplemented
     1624                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1625                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    14801626                }
    14811627        ;
     
    14931639//       declarator asm_name_opt initializer_opt
    14941640//              {
    1495 //                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1641//                      typedefTable.addToEnclosingScope( IDENTIFIER );
    14961642//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
    14971643//              }
    14981644//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    14991645//              {
    1500 //                      typedefTable.addToEnclosingScope( TypedefTable::ID );
     1646//                      typedefTable.addToEnclosingScope( IDENTIFIER );
    15011647//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
    15021648//              }
     
    15051651c_declaration:
    15061652        declaration_specifier declaring_list
    1507                 {
    1508                         $$ = distAttr( $1, $2 );
    1509                 }
     1653                { $$ = distAttr( $1, $2 ); }
    15101654        | typedef_declaration
    15111655        | typedef_expression                                                            // GCC, naming expression type
     
    15171661                // storage-class
    15181662        declarator asm_name_opt initializer_opt
    1519                 {
    1520                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1521                         $$ = $1->addAsmName( $2 )->addInitializer( $3 );
    1522                 }
     1663                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
    15231664        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    1524                 {
    1525                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    1526                         $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
    1527                 }
     1665                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
    15281666        ;
    15291667
     
    15971735
    15981736forall:
    1599         FORALL '('
    1600                 {
    1601                         typedefTable.enterScope();
    1602                 }
    1603           type_parameter_list ')'                                                       // CFA
    1604                 {
    1605                         typedefTable.leaveScope();
    1606                         $$ = DeclarationNode::newForall( $4 );
    1607                 }
     1737        FORALL '(' type_parameter_list ')'                                      // CFA
     1738                { $$ = DeclarationNode::newForall( $3 ); }
    16081739        ;
    16091740
     
    16781809        | LONG
    16791810                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    1680         | ZERO_T
    1681                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
    1682         | ONE_T
    1683                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
    16841811        | VALIST                                                                                        // GCC, __builtin_va_list
    16851812                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     
    17011828basic_type_specifier:
    17021829        direct_type
     1830                // Cannot have type modifiers, e.g., short, long, etc.
    17031831        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
    17041832                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
     
    17061834
    17071835direct_type:
    1708                 // A semantic check is necessary for conflicting type qualifiers.
    17091836        basic_type_name
    17101837        | type_qualifier_list basic_type_name
     
    17251852        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
    17261853                { $$ = DeclarationNode::newAttr( $1, $3 ); }
     1854        | ZERO_T                                                                                        // CFA
     1855                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     1856        | ONE_T                                                                                         // CFA
     1857                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
    17271858        ;
    17281859
     
    17441875                { $$ = $3->addQualifiers( $1 ); }
    17451876        | sue_type_specifier type_qualifier
    1746                 { $$ = $1->addQualifiers( $2 ); }
     1877                {
     1878                        if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type
     1879                        $$ = $1->addQualifiers( $2 );
     1880                }
    17471881        ;
    17481882
     
    17871921                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17881922        | '.' TYPEDEFname
    1789                 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
     1923                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
    17901924        | type_name '.' TYPEDEFname
    1791                 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
     1925                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
    17921926        | typegen_name
    17931927        | '.' typegen_name
    1794                 { $$ = $2; }                                                                    // FIX ME
     1928                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
    17951929        | type_name '.' typegen_name
    1796                 { $$ = $3; }                                                                    // FIX ME
     1930                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
    17971931        ;
    17981932
     
    18161950        ;
    18171951
     1952fred:
     1953        // empty
     1954                { yyy = false; }
     1955        ;
     1956
    18181957aggregate_type:                                                                                 // struct, union
    1819         aggregate_key attribute_list_opt '{' field_declaration_list '}'
    1820                 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1821         | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    1822                 {
    1823                         typedefTable.makeTypedef( *$3 );                        // create typedef
    1824                         if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1958        aggregate_key attribute_list_opt
     1959                { forall = false; }                                                             // reset
     1960          '{' field_declaration_list_opt '}' type_parameters_opt
     1961                { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); }
     1962        | aggregate_key attribute_list_opt no_attr_identifier fred
     1963                {
     1964                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
    18251965                        forall = false;                                                         // reset
    18261966                }
    1827           '{' field_declaration_list '}'
    1828                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1829         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
    1830                 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     1967          '{' field_declaration_list_opt '}' type_parameters_opt
     1968                { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); }
     1969        | aggregate_key attribute_list_opt type_name fred
     1970                {
     1971                        // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one)
     1972                        typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
     1973                        forall = false;                                                         // reset
     1974                }
     1975          '{' field_declaration_list_opt '}' type_parameters_opt
     1976                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); }
    18311977        | aggregate_type_nobody
    18321978        ;
    18331979
     1980type_parameters_opt:
     1981        // empty
     1982                { $$ = nullptr; }                                                               %prec '}'
     1983        | '(' type_list ')'
     1984                { $$ = $2; }
     1985        ;
     1986
    18341987aggregate_type_nobody:                                                                  // struct, union - {...}
    1835         aggregate_key attribute_list_opt no_attr_identifier
    1836                 {
    1837                         typedefTable.makeTypedef( *$3 );
     1988        aggregate_key attribute_list_opt no_attr_identifier fred
     1989                {
     1990                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
     1991                        forall = false;                                                         // reset
    18381992                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18391993                }
    1840         | aggregate_key attribute_list_opt TYPEDEFname
    1841                 {
    1842                         typedefTable.makeTypedef( *$3 );
    1843                         $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    1844                 }
    1845         | aggregate_key attribute_list_opt typegen_name         // CFA
    1846                 {
     1994        | aggregate_key attribute_list_opt type_name fred
     1995                {
     1996                        forall = false;                                                         // reset
    18471997                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
    18481998                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
     
    18572007aggregate_key:
    18582008        STRUCT
    1859                 { $$ = DeclarationNode::Struct; }
     2009                { yyy = true; $$ = DeclarationNode::Struct; }
    18602010        | UNION
    1861                 { $$ = DeclarationNode::Union; }
     2011                { yyy = true; $$ = DeclarationNode::Union; }
     2012        | EXCEPTION
     2013                { yyy = true; $$ = DeclarationNode::Exception; }
    18622014        | COROUTINE
    1863                 { $$ = DeclarationNode::Coroutine; }
     2015                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18642016        | MONITOR
    1865                 { $$ = DeclarationNode::Monitor; }
     2017                { yyy = true; $$ = DeclarationNode::Monitor; }
    18662018        | THREAD
    1867                 { $$ = DeclarationNode::Thread; }
    1868         ;
    1869 
    1870 field_declaration_list:
     2019                { yyy = true; $$ = DeclarationNode::Thread; }
     2020        ;
     2021
     2022field_declaration_list_opt:
    18712023        // empty
    18722024                { $$ = nullptr; }
    1873         | field_declaration_list field_declaration
     2025        | field_declaration_list_opt field_declaration
    18742026                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    18752027        ;
    18762028
    18772029field_declaration:
    1878         cfa_field_declaring_list ';'                                            // CFA, new style field declaration
     2030        type_specifier field_declaring_list_opt ';'
     2031                { $$ = fieldDecl( $1, $2 ); }
     2032        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
     2033                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     2034        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
     2035                {
     2036                        if ( ! $3 ) {                                                           // field declarator ?
     2037                                $3 = DeclarationNode::newName( nullptr );
     2038                        } // if
     2039                        $3->inLine = true;
     2040                        $$ = distAttr( $2, $3 );                                        // mark all fields in list
     2041                        distInl( $3 );
     2042                }
     2043        | typedef_declaration ';'                                                       // CFA
     2044        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18792045        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    1880                 {
    1881                         distExt( $2 );                                                          // mark all fields in list
    1882                         $$ = $2;
    1883                 }
    1884         | type_specifier field_declaring_list ';'
    1885                 {
    1886                         $$ = distAttr( $1, $2 ); }
    1887         | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1888                 {
    1889                         distExt( $3 );                                                          // mark all fields in list
    1890                         $$ = distAttr( $2, $3 );
    1891                 }
     2046                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
     2047        | INLINE cfa_field_abstract_list ';'                            // CFA, new style field declaration
     2048                { $$ = $2; }                                                                    // mark all fields in list
     2049        | cfa_typedef_declaration ';'                                           // CFA
     2050        | static_assert                                                                         // C11
     2051        ;
     2052
     2053field_declaring_list_opt:
     2054        // empty
     2055                { $$ = nullptr; }
     2056        | field_declarator
     2057        | field_declaring_list_opt ',' attribute_list_opt field_declarator
     2058                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2059        ;
     2060
     2061field_declarator:
     2062        bit_subrange_size                                                                       // C special case, no field name
     2063                { $$ = DeclarationNode::newBitfield( $1 ); }
     2064        | variable_declarator bit_subrange_size_opt
     2065                // A semantic check is required to ensure bit_subrange only appears on integral types.
     2066                { $$ = $1->addBitfield( $2 ); }
     2067        | variable_type_redeclarator bit_subrange_size_opt
     2068                // A semantic check is required to ensure bit_subrange only appears on integral types.
     2069                { $$ = $1->addBitfield( $2 ); }
     2070        ;
     2071
     2072field_abstract_list_opt:
     2073        // empty
     2074                { $$ = nullptr; }
     2075        | field_abstract
     2076        | field_abstract_list_opt ',' attribute_list_opt field_abstract
     2077                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2078        ;
     2079
     2080field_abstract:
     2081                //      no bit fields
     2082        variable_abstract_declarator
    18922083        ;
    18932084
    18942085cfa_field_declaring_list:                                                               // CFA, new style field declaration
    1895         cfa_abstract_declarator_tuple                                           // CFA, no field name
    1896         | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
     2086        // bit-fields are handled by C declarations
     2087        cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    18972088                { $$ = $1->addName( $2 ); }
    18982089        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    18992090                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    1900         | cfa_field_declaring_list ','                                          // CFA, no field name
     2091        ;
     2092
     2093cfa_field_abstract_list:                                                                // CFA, new style field declaration
     2094        // bit-fields are handled by C declarations
     2095        cfa_abstract_declarator_tuple
     2096        | cfa_field_abstract_list ','
    19012097                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    1902         ;
    1903 
    1904 field_declaring_list:
    1905         field_declarator
    1906         | field_declaring_list ',' attribute_list_opt field_declarator
    1907                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    1908         ;
    1909 
    1910 field_declarator:
    1911         // empty
    1912                 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
    1913         // '@'
    1914         //      { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
    1915         | bit_subrange_size                                                                     // no field name
    1916                 { $$ = DeclarationNode::newBitfield( $1 ); }
    1917         | variable_declarator bit_subrange_size_opt
    1918                 // A semantic check is required to ensure bit_subrange only appears on base type int.
    1919                 { $$ = $1->addBitfield( $2 ); }
    1920         | variable_type_redeclarator bit_subrange_size_opt
    1921                 // A semantic check is required to ensure bit_subrange only appears on base type int.
    1922                 { $$ = $1->addBitfield( $2 ); }
    1923         | variable_abstract_declarator                                          // CFA, no field name
    19242098        ;
    19252099
     
    19282102                { $$ = nullptr; }
    19292103        | bit_subrange_size
    1930                 { $$ = $1; }
    19312104        ;
    19322105
     
    19382111enum_type:                                                                                              // enum
    19392112        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    1940                 { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
    1941         | ENUM attribute_list_opt no_attr_identifier_or_type_name
     2113                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2114        | ENUM attribute_list_opt no_attr_identifier
    19422115                { typedefTable.makeTypedef( *$3 ); }
    19432116          '{' enumerator_list comma_opt '}'
    19442117                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     2118        | ENUM attribute_list_opt type_name
     2119          '{' enumerator_list comma_opt '}'
     2120                { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
    19452121        | enum_type_nobody
    19462122        ;
    19472123
    19482124enum_type_nobody:                                                                               // enum - {...}
    1949         ENUM attribute_list_opt no_attr_identifier_or_type_name
     2125        ENUM attribute_list_opt no_attr_identifier
    19502126                {
    19512127                        typedefTable.makeTypedef( *$3 );
    19522128                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
     2129                }
     2130        | ENUM attribute_list_opt type_name
     2131                {
     2132                        typedefTable.makeTypedef( *$3->type->symbolic.name );
     2133                        $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 );
    19532134                }
    19542135        ;
     
    19682149        ;
    19692150
    1970 // Minimum of one parameter after which ellipsis is allowed only at the end.
    1971 
    1972 cfa_parameter_type_list_opt:                                                    // CFA
     2151cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
    19732152        // empty
     2153                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     2154        | ELLIPSIS
    19742155                { $$ = nullptr; }
    1975         | cfa_parameter_type_list
    1976         ;
    1977 
    1978 cfa_parameter_type_list:                                                                // CFA, abstract + real
    1979         cfa_abstract_parameter_list
     2156        | cfa_abstract_parameter_list
    19802157        | cfa_parameter_list
    19812158        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
     
    20082185        // empty
    20092186                { $$ = nullptr; }
    2010         | parameter_type_list
    2011         ;
    2012 
    2013 parameter_type_list:
    2014         parameter_list
     2187        | ELLIPSIS
     2188                { $$ = nullptr; }
     2189        | parameter_list
    20152190        | parameter_list pop ',' push ELLIPSIS
    20162191                { $$ = $1->addVarArgs(); }
     
    20542229                // No SUE declaration in parameter list.
    20552230        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    2056                 {
    2057                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2058                         $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    2059                 }
     2231                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    20602232        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    2061                 {
    2062                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2063                         $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    2064                 }
     2233                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    20652234        ;
    20662235
     
    21132282                { $$ = $2; }
    21142283        | '=' VOID
    2115                 { $$ = nullptr; }
     2284                { $$ = new InitializerNode( true ); }
    21162285        | ATassign initializer
    21172286                { $$ = $2->set_maybeConstructed( false ); }
     
    21202289initializer:
    21212290        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
    2122         | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
    2123         ;
    2124 
    2125 initializer_list:
     2291        | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
     2292        ;
     2293
     2294initializer_list_opt:
    21262295        // empty
    21272296                { $$ = nullptr; }
    21282297        | initializer
    21292298        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    2130         | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2131         | initializer_list ',' designation initializer
     2299        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     2300        | initializer_list_opt ',' designation initializer
    21322301                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    21332302        ;
     
    21662335        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    21672336                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2168         | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
     2337        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    21692338                { $$ = $4; }
    21702339        ;
     
    21902359type_parameter_list:                                                                    // CFA
    21912360        type_parameter
    2192                 { $$ = $1; }
    21932361        | type_parameter_list ',' type_parameter
    21942362                { $$ = $1->appendList( $3 ); }
     
    22042372type_parameter:                                                                                 // CFA
    22052373        type_class no_attr_identifier_or_type_name
    2206                 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
     2374                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    22072375          type_initializer_opt assertion_list_opt
    22082376                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    22092377        | type_specifier identifier_parameter_declarator
     2378        | assertion_list
     2379                { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    22102380        ;
    22112381
     
    22242394        // empty
    22252395                { $$ = nullptr; }
    2226         | assertion_list_opt assertion
     2396        | assertion_list
     2397        ;
     2398
     2399assertion_list:                                                                                 // CFA
     2400        assertion
     2401        | assertion_list assertion
    22272402                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    22282403        ;
     
    22302405assertion:                                                                                              // CFA
    22312406        '|' no_attr_identifier_or_type_name '(' type_list ')'
    2232                 {
    2233                         typedefTable.openTrait( *$2 );
    2234                         $$ = DeclarationNode::newTraitUse( $2, $4 );
    2235                 }
    2236         | '|' '{' push trait_declaration_list '}'
     2407                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
     2408        | '|' '{' push trait_declaration_list pop '}'
    22372409                { $$ = $4; }
    2238         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2239                 { $$ = nullptr; }
     2410        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2411        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22402412        ;
    22412413
     
    22442416                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    22452417        | assignment_expression
     2418                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    22462419        | type_list ',' type
    22472420                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    22482421        | type_list ',' assignment_expression
    2249                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2422                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     2423                // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    22502424        ;
    22512425
     
    22692443        no_attr_identifier_or_type_name
    22702444                {
    2271                         typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
     2445                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
    22722446                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22732447                }
    2274         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    2275                 {
    2276                         typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
    2277                         $$ = DeclarationNode::newTypeDecl( $1, $4 );
     2448        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2449                {
     2450                        typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
     2451                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
    22782452                }
    22792453        ;
    22802454
    22812455trait_specifier:                                                                                // CFA
    2282         TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2283                 {
    2284                         typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    2285                         $$ = DeclarationNode::newTrait( $2, $5, 0 );
    2286                 }
    2287         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
    2288                 {
    2289                         typedefTable.enterTrait( *$2 );
    2290                         typedefTable.enterScope();
    2291                 }
    2292           trait_declaration_list '}'
    2293                 {
    2294                         typedefTable.leaveTrait();
    2295                         typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    2296                         $$ = DeclarationNode::newTrait( $2, $5, $10 );
    2297                 }
     2456        TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2457                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
     2458        | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2459                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    22982460        ;
    22992461
    23002462trait_declaration_list:                                                                 // CFA
    23012463        trait_declaration
    2302         | trait_declaration_list push trait_declaration
    2303                 { $$ = $1->appendList( $3 ); }
     2464        | trait_declaration_list pop push trait_declaration
     2465                { $$ = $1->appendList( $4 ); }
    23042466        ;
    23052467
    23062468trait_declaration:                                                                              // CFA
    2307         cfa_trait_declaring_list pop ';'
    2308         | trait_declaring_list pop ';'
     2469        cfa_trait_declaring_list ';'
     2470        | trait_declaring_list ';'
    23092471        ;
    23102472
    23112473cfa_trait_declaring_list:                                                               // CFA
    23122474        cfa_variable_specifier
    2313                 {
    2314                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2315                         $$ = $1;
    2316                 }
    23172475        | cfa_function_specifier
    2318                 {
    2319                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2320                         $$ = $1;
    2321                 }
    23222476        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    2323                 {
    2324                         typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
    2325                         $$ = $1->appendList( $1->cloneType( $5 ) );
    2326                 }
     2477                { $$ = $1->appendList( $1->cloneType( $5 ) ); }
    23272478        ;
    23282479
    23292480trait_declaring_list:                                                                   // CFA
    23302481        type_specifier declarator
    2331                 {
    2332                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2333                         $$ = $2->addType( $1 );
    2334                 }
     2482                { $$ = $2->addType( $1 ); }
    23352483        | trait_declaring_list pop ',' push declarator
    2336                 {
    2337                         typedefTable.addToEnclosingScope2( TypedefTable::ID );
    2338                         $$ = $1->appendList( $1->cloneBaseType( $5 ) );
    2339                 }
     2484                { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
    23402485        ;
    23412486
     
    23432488
    23442489translation_unit:
    2345         // empty
    2346                 {}                                                                                              // empty input file
     2490        // empty, input file
    23472491        | external_definition_list
    23482492                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23502494
    23512495external_definition_list:
    2352         external_definition
    2353         | external_definition_list push external_definition
     2496        push external_definition pop
     2497                { $$ = $2; }
     2498        | external_definition_list push external_definition pop
    23542499                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    23552500        ;
     
    23612506        ;
    23622507
     2508up:
     2509                { typedefTable.up( forall ); forall = false; }
     2510        ;
     2511
     2512down:
     2513                { typedefTable.down(); }
     2514        ;
     2515
    23632516external_definition:
    23642517        declaration
    23652518        | external_function_definition
     2519        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     2520                {
     2521                        distExt( $2 );                                                          // mark all fields in list
     2522                        $$ = $2;
     2523                }
    23662524        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    23672525                {
    2368                         $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) );
     2526                        $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) );
    23692527                }
    23702528        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
    23712529                {
    23722530                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2373                         linkage = LinkageSpec::linkageUpdate( linkage, $2 );
    2374                 }
    2375           '{' external_definition_list_opt '}'
     2531                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
     2532                }
     2533          '{' up external_definition_list_opt down '}'
    23762534                {
    23772535                        linkage = linkageStack.top();
    23782536                        linkageStack.pop();
     2537                        $$ = $6;
     2538                }
     2539        | type_qualifier_list
     2540                {
     2541                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2542                        if ( $1->type->forall ) forall = true;          // remember generic type
     2543                }
     2544          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2545                {
     2546                        distQual( $5, $1 );
     2547                        forall = false;
    23792548                        $$ = $5;
    23802549                }
    2381         | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
    2382                 {
    2383                         distExt( $2 );                                                          // mark all fields in list
    2384                         $$ = $2;
    2385                 }
    2386         | forall '{' external_definition_list '}'                       // CFA, namespace
     2550        | declaration_qualifier_list
     2551                {
     2552                        if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2553                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
     2554                }
     2555          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2556                {
     2557                        distQual( $5, $1 );
     2558                        forall = false;
     2559                        $$ = $5;
     2560                }
     2561        | declaration_qualifier_list type_qualifier_list
     2562                {
     2563                        if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2564                        if ( ($1->type && $1->type->forall) || $2->type->forall ) forall = true; // remember generic type
     2565                }
     2566          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2567                {
     2568                        distQual( $6, $1->addQualifiers( $2 ) );
     2569                        forall = false;
     2570                        $$ = $6;
     2571                }
    23872572        ;
    23882573
     
    23952580                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    23962581        | function_declarator compound_statement
    2397                 {
    2398                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2399                         typedefTable.leaveScope();
    2400                         $$ = $1->addFunctionBody( $2 );
    2401                 }
    2402         | KR_function_declarator KR_declaration_list_opt compound_statement
    2403                 {
    2404                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2405                         typedefTable.leaveScope();
    2406                         $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
    2407                 }
     2582                { $$ = $1->addFunctionBody( $2 ); }
     2583        | KR_function_declarator KR_parameter_list_opt compound_statement
     2584                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24082585        ;
    24092586
    24102587with_clause_opt:
    24112588        // empty
    2412                 { $$ = nullptr; }
     2589                { $$ = nullptr; forall = false; }
    24132590        | WITH '(' tuple_expression_list ')'
    2414                 { $$ = new StatementNode( build_with( $3, nullptr ) ); }
     2591                { $$ = $3; forall = false; }
    24152592        ;
    24162593
     
    24182595        cfa_function_declaration with_clause_opt compound_statement     // CFA
    24192596                {
    2420                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2421                         typedefTable.leaveScope();
    24222597                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    24232598                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     
    24282603                {
    24292604                        rebindForall( $1, $2 );
    2430                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2431                         typedefTable.leaveScope();
     2605                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
     2606                }
     2607        | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
     2608                {
     2609                        rebindForall( $1, $2 );
    24322610                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24332611                }
    24342612                // handles default int return type, OBSOLESCENT (see 1)
    24352613        | type_qualifier_list function_declarator with_clause_opt compound_statement
    2436                 {
    2437                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2438                         typedefTable.leaveScope();
    2439                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2440                 }
     2614                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    24412615                // handles default int return type, OBSOLESCENT (see 1)
    24422616        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    2443                 {
    2444                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2445                         typedefTable.leaveScope();
    2446                         $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    2447                 }
     2617                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
    24482618                // handles default int return type, OBSOLESCENT (see 1)
    24492619        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    2450                 {
    2451                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2452                         typedefTable.leaveScope();
    2453                         $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    2454                 }
     2620                { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24552621
    24562622                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2457         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2623        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24582624                {
    24592625                        rebindForall( $1, $2 );
    2460                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2461                         typedefTable.leaveScope();
    24622626                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    24632627                }
    24642628                // handles default int return type, OBSOLESCENT (see 1)
    2465         | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2466                 {
    2467                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2468                         typedefTable.leaveScope();
    2469                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2470                 }
     2629        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2630                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24712631                // handles default int return type, OBSOLESCENT (see 1)
    2472         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2473                 {
    2474                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2475                         typedefTable.leaveScope();
    2476                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    2477                 }
     2632        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2633                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24782634                // handles default int return type, OBSOLESCENT (see 1)
    2479         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    2480                 {
    2481                         typedefTable.addToEnclosingScope( TypedefTable::ID );
    2482                         typedefTable.leaveScope();
    2483                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    2484                 }
     2635        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2636                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24852637        ;
    24862638
     
    25922744paren_identifier:
    25932745        identifier
    2594                 {
    2595                         typedefTable.setNextIdentifier( *$1 );
    2596                         $$ = DeclarationNode::newName( $1 );
    2597                 }
     2746                { $$ = DeclarationNode::newName( $1 ); }
    25982747        | '(' paren_identifier ')'                                                      // redundant parenthesis
    25992748                { $$ = $2; }
     
    27282877paren_type:
    27292878        typedef
     2879                // hide type name in enclosing scope by variable name
     2880                {
     2881                        // if ( ! typedefTable.existsCurr( *$1->name ) ) {
     2882                                typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );
     2883                        // } else {
     2884                        //      SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr;
     2885                        // } // if
     2886                }
    27302887        | '(' paren_type ')'
    27312888                { $$ = $2; }
     
    27382895                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    27392896        | '(' type_ptr ')' attribute_list_opt
    2740                 { $$ = $2->addQualifiers( $4 ); }
     2897                { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
    27412898        ;
    27422899
     
    28302987typedef:
    28312988        TYPEDEFname
    2832                 {
    2833                         typedefTable.setNextIdentifier( *$1 );
    2834                         $$ = DeclarationNode::newName( $1 );
    2835                 }
     2989                { $$ = DeclarationNode::newName( $1 ); }
    28362990        | TYPEGENname
    2837                 {
    2838                         typedefTable.setNextIdentifier( *$1 );
    2839                         $$ = DeclarationNode::newName( $1 );
    2840                 }
     2991                { $$ = DeclarationNode::newName( $1 ); }
    28412992        ;
    28422993
     
    30233174        '[' ']'
    30243175                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    3025         // multi_array_dimension handles the '[' '*' ']' case
     3176                // multi_array_dimension handles the '[' '*' ']' case
    30263177        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
    30273178                { $$ = DeclarationNode::newVarArray( $3 ); }
    30283179        | '[' push type_qualifier_list pop ']'
    30293180                { $$ = DeclarationNode::newArray( 0, $3, false ); }
    3030         // multi_array_dimension handles the '[' assignment_expression ']' case
     3181                // multi_array_dimension handles the '[' assignment_expression ']' case
    30313182        | '[' push type_qualifier_list assignment_expression pop ']'
    30323183                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     
    31643315//
    31653316//              cfa_abstract_tuple identifier_or_type_name
    3166 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     3317//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    31673318//
    31683319// since a function return type can be syntactically identical to a tuple type:
     
    32233374        '[' push cfa_abstract_parameter_list pop ']'
    32243375                { $$ = DeclarationNode::newTuple( $3 ); }
     3376        | '[' push type_specifier_nobody ELLIPSIS pop ']'
     3377                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
     3378        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
     3379                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    32253380        ;
    32263381
    32273382cfa_abstract_function:                                                                  // CFA
    3228 //      '[' ']' '(' cfa_parameter_type_list_opt ')'
     3383//      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
    32293384//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3230         cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
     3385        cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
    32313386                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    3232         | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
     3387        | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
    32333388                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    32343389        ;
     
    32613416
    32623417%%
     3418
    32633419// ----end of grammar----
    32643420
Note: See TracChangeset for help on using the changeset viewer.