Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rcc22003 r5fcba14  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  8 17:50:07 2018
    13 // Update Count     : 3998
     12// Last Modified On : Mon Nov 27 17:23:35 2017
     13// Update Count     : 2992
    1414//
    1515
     
    115115} // distExt
    116116
    117 void 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 
    124 void 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 
    154117// There is an ambiguity for inline generic-routine return-types and generic routines.
    155118//   forall( otype T ) struct S { int i; } bar( T ) {}
    156119// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
    157120//   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 ) {}
    161121
    162122void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
    163         if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
     123        if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
    164124                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
    165125                declSpec->type->aggregate.params = nullptr;
     
    167127} // rebindForall
    168128
    169 NameExpr * 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 
    175 DeclarationNode * 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 
    188 ForCtrl * 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 
    196 bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
     129bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    197130
    198131// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    225158        WaitForStmt * wfs;
    226159        Expression * constant;
    227         IfCtrl * ifctl;
    228         ForCtrl * fctl;
    229         enum OperKinds compop;
     160        IfCtl * ifctl;
     161        ForCtl * fctl;
    230162        LabelNode * label;
    231163        InitializerNode * in;
     
    234166        bool flag;
    235167        CatchStmt::Kind catch_kind;
    236         GenericExpr * genexpr;
    237168}
    238169
     
    256187%token TYPEOF LABEL                                                                             // GCC
    257188%token ENUM STRUCT UNION
    258 %token EXCEPTION                                                                                // CFA
    259189%token COROUTINE MONITOR THREAD                                                 // CFA
    260190%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
     
    271201%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    272202%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
    273 %token<tok> DIRECTIVE
    274203// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
    275204// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
     
    290219%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    291220
    292 %token Erange                                                                                   // ~=
    293221%token ATassign                                                                                 // @=
    294222
     
    313241%type<ifctl> if_control_expression
    314242%type<fctl> for_control_expression
    315 %type<compop> inclexcl
    316243%type<en> subrange
    317244%type<decl> asm_name_opt
     
    321248%type<flag> asm_volatile_opt
    322249%type<en> handler_predicate_opt
    323 %type<genexpr> generic_association generic_assoc_list
    324250
    325251// statements
    326252%type<sn> statement                                             labeled_statement                       compound_statement
    327253%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    328 %type<sn> selection_statement                   if_statement
    329 %type<sn> switch_clause_list_opt                switch_clause_list
     254%type<sn> selection_statement
     255%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    330256%type<en> case_value
    331257%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
     258%type<sn> fall_through                                  fall_through_opt
    332259%type<sn> iteration_statement                   jump_statement
    333260%type<sn> expression_statement                  asm_statement
    334 %type<sn> with_statement
    335 %type<en> with_clause_opt
     261%type<sn> with_statement                                with_clause_opt
    336262%type<sn> exception_statement                   handler_clause                          finally_clause
    337263%type<catch_kind> handler_key
     
    349275%type<decl> aggregate_type aggregate_type_nobody
    350276
    351 %type<decl> assertion assertion_list assertion_list_opt
     277%type<decl> assertion assertion_list_opt
    352278
    353279%type<en>   bit_subrange_size_opt bit_subrange_size
     
    365291%type<en> enumerator_value_opt
    366292
    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
     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
    373297
    374298%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    383307%type<decl> cfa_array_parameter_1st_dimension
    384308
    385 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
     309%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
    386310%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    387311
     
    389313%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    390314
    391 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
     315%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt
    392316
    393317%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
    394318
    395 %type<decl> c_declaration static_assert
     319%type<decl> c_declaration
    396320%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    397 %type<decl> KR_parameter_list KR_parameter_list_opt
    398 
    399 %type<decl> parameter_declaration parameter_list parameter_type_list_opt
     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
    400325
    401326%type<decl> paren_identifier paren_type
     
    418343%type<decl> type_parameter type_parameter_list type_initializer_opt
    419344
    420 %type<en> type_parameters_opt type_list
     345%type<en> type_list
    421346
    422347%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    429354
    430355// initializers
    431 %type<in>  initializer initializer_list_opt initializer_opt
     356%type<in>  initializer initializer_list initializer_opt
    432357
    433358// designators
     
    453378//   Foo ( *fp )( int );
    454379//   `---'                                              matches start of TYPEGENname '('
    455 // must be:
     380// Must be:
    456381//   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 );
    461382
    462383// Order of these lines matters (low-to-high precedence).
    463384%precedence TYPEGENname
    464 %precedence '}'
    465385%precedence '('
    466386
    467 %locations                                                                                              // support location tracking for error messages
     387%locations                      // support location tracking for error messages
    468388
    469389%start translation_unit                                                                 // parse-tree root
     
    472392//************************* Namespace Management ********************************
    473393
    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
     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.
    500420
    501421push:
     
    523443        ;
    524444
     445identifier:
     446        IDENTIFIER
     447        | ATTR_IDENTIFIER                                                                       // CFA
     448        | quasi_keyword
     449        ;
     450
    525451no_attr_identifier:
    526452        IDENTIFIER
    527453        | quasi_keyword
    528         | '@'                                                                                           // CFA
    529                 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
    530         ;
    531 
    532 identifier:
    533         no_attr_identifier
    534         | ATTR_IDENTIFIER                                                                       // CFA
    535454        ;
    536455
     
    561480        | '(' compound_statement ')'                                            // GCC, lambda expression
    562481                { $$ = 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 ) ); }
    573482        | type_name '.' no_attr_identifier                                      // CFA, nested type
    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 
    585 generic_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 
    596 generic_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) } } ); }
     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
    604486        ;
    605487
    606488postfix_expression:
    607489        primary_expression
    608         | postfix_expression '[' assignment_expression ']'
     490        | postfix_expression '[' push assignment_expression pop ']'
    609491                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    610492                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    611493                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    612494                // equivalent to the old x[i,j].
    613                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
     495                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
    614496        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    615497                {
     
    622504        | postfix_expression '.' no_attr_identifier
    623505                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    624         | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
    625                 { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger( *$3 ) ) ); }
     506        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
     507                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    626508        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    627509                { $$ = 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 ) ) ); }
    630510        | postfix_expression ARROW no_attr_identifier
    631511                {
    632512                        $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    633513                }
     514        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
     515                        { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    634516        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    635517                { $$ = 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 ) ) ); }
    638518        | postfix_expression ICR
    639519                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    640520        | postfix_expression DECR
    641521                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    642         | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
     522        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    643523                { $$ = 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 ) ) ); }
    646524        | '^' primary_expression '{' argument_expression_list '}' // CFA
    647525                {
     
    661539        // empty
    662540                { $$ = nullptr; }
    663         | '?'                                                                                           // CFA, default parameter
    664                 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    665                 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     541        // | '@'                                                                                                // use default argument
     542        //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    666543        | assignment_expression
    667544        ;
    668545
    669 field_name_list:                                                                                // CFA, tuple field selector
     546field_list:                                                                                             // CFA, tuple field selector
    670547        field
    671         | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     548        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    672549        ;
    673550
     
    676553        | FLOATING_DECIMALconstant field
    677554                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    678         | FLOATING_DECIMALconstant '[' field_name_list ']'
    679                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
     555        | FLOATING_DECIMALconstant '[' push field_list pop ']'
     556                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
    680557        | field_name '.' field
    681558                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    682         | field_name '.' '[' field_name_list ']'
    683                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     559        | field_name '.' '[' push field_list pop ']'
     560                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    684561        | field_name ARROW field
    685562                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    686         | field_name ARROW '[' field_name_list ']'
    687                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     563        | field_name ARROW '[' push field_list pop ']'
     564                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    688565        ;
    689566
    690567field_name:
    691         INTEGERconstant fraction_constants_opt
     568        INTEGERconstant fraction_constants
    692569                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); }
    693         | FLOATINGconstant fraction_constants_opt
     570        | FLOATINGconstant fraction_constants
    694571                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    695         | no_attr_identifier fraction_constants_opt
     572        | no_attr_identifier fraction_constants
    696573                {
    697574                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    699576        ;
    700577
    701 fraction_constants_opt:
     578fraction_constants:
    702579        // empty
    703580                { $$ = nullptr; }
    704         | fraction_constants_opt FLOATING_FRACTIONconstant
     581        | fraction_constants FLOATING_FRACTIONconstant
    705582                {
    706583                        Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
     
    714591                // semantics checks, e.g., ++3, 3--, *3, &&3
    715592        | constant
     593                { $$ = $1; }
    716594        | string_literal
    717595                { $$ = new ExpressionNode( $1 ); }
     
    779657        | '(' type_no_function ')' cast_expression
    780658                { $$ = 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 ) ); }
    787659                // VIRTUAL cannot be opt because of look ahead issues
    788         | '(' VIRTUAL ')' cast_expression                                       // CFA
     660        | '(' VIRTUAL ')' cast_expression
    789661                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    790         | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
     662        | '(' VIRTUAL type_no_function ')' cast_expression
    791663                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
    792664//      | '(' type_no_function ')' tuple
     
    880752        | logical_OR_expression '?' comma_expression ':' conditional_expression
    881753                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    882                 // FIX ME: computes $1 twice
     754                // FIX ME: this hack computes $1 twice
    883755        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    884756                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
     
    894766        | unary_expression assignment_operator assignment_expression
    895767                { $$ = 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; }
    898768        ;
    899769
     
    925795//      '[' ']'
    926796//              { $$ = new ExpressionNode( build_tuple() ); }
    927 //      | '[' push assignment_expression pop ']'
     797//      '[' push assignment_expression pop ']'
    928798//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    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 ) ) ); }
     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 ) ) ); }
    933803        ;
    934804
     
    956826        labeled_statement
    957827        | compound_statement
    958         | expression_statement
     828        | expression_statement                                          { $$ = $1; }
    959829        | selection_statement
    960830        | iteration_statement
     
    964834        | waitfor_statement
    965835        | exception_statement
    966         | enable_disable_statement
    967                 { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; }
    968836        | asm_statement
    969         | DIRECTIVE
    970                 { $$ = new StatementNode( build_directive( $1 ) ); }
    971         ;
    972837
    973838labeled_statement:
     
    982847        '{' '}'
    983848                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    984         | '{' push
     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
    985853          local_label_declaration_opt                                           // GCC, local labels
    986854          statement_decl_list                                                           // C99, intermix declarations and statements
    987855          pop '}'
    988                 { $$ = new StatementNode( build_compound( $4 ) ); }
     856                { $$ = new StatementNode( build_compound( $5 ) ); }
    989857        ;
    990858
    991859statement_decl_list:                                                                    // C99
    992860        statement_decl
    993         | statement_decl_list statement_decl
    994                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     861        | statement_decl_list push statement_decl
     862                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    995863        ;
    996864
     
    1010878                        $$ = new StatementNode( $2 );
    1011879                }
    1012         | statement
     880        | statement pop
    1013881        ;
    1014882
     
    1025893
    1026894selection_statement:
    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; }
     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 ) ); }
    1031900        | SWITCH '(' comma_expression ')' case_clause
    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 ) );
     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 ) );
    1036905                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    1037906                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    1042911                }
    1043912        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    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 ) );
     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 ) );
    1048917                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    1049918                }
    1050919        ;
    1051920
    1052 if_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 
    1060921if_control_expression:
    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 ); }
     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 ); }
    1067928        | declaration comma_expression                                          // semi-colon separated
    1068                 { $$ = new IfCtrl( $1, $2 ); }
     929                { $$ = new IfCtl( $1, $2 ); }
    1069930        ;
    1070931
     
    1091952        ;
    1092953
    1093 //label_list_opt:
    1094 //      // empty
    1095 //      | identifier_or_type_name ':'
    1096 //      | label_list_opt identifier_or_type_name ':'
    1097 //      ;
    1098 
    1099954case_label_list:                                                                                // CFA
    1100955        case_label
     
    1119974        ;
    1120975
     976choose_clause_list_opt:                                                                 // CFA
     977        // empty
     978                { $$ = nullptr; }
     979        | choose_clause_list
     980        ;
     981
     982choose_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
     993fall_through_opt:                                                                               // CFA
     994        // empty
     995                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
     996        | fall_through
     997        ;
     998
     999fall_through_name:                                                                              // CFA
     1000        FALLTHRU
     1001        | FALLTHROUGH
     1002        ;
     1003
     1004fall_through:                                                                                   // CFA
     1005        fall_through_name
     1006                { $$ = nullptr; }
     1007        | fall_through_name ';'
     1008                { $$ = nullptr; }
     1009        ;
     1010
    11211011iteration_statement:
    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 ) ); }
     1012        WHILE '(' comma_expression ')' statement
     1013                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    11261014        | DO statement WHILE '(' comma_expression ')' ';'
    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
     1015                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
     1016        | FOR '(' push for_control_expression ')' statement
    11311017                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    11321018        ;
    11331019
    11341020for_control_expression:
    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 
    1193 inclexcl:
    1194         '~'
    1195                 { $$ = OperKinds::LThan; }
    1196         | Erange
    1197                 { $$ = OperKinds::LEThan; }
     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 ); }
    11981025        ;
    11991026
     
    12051032                // whereas normal operator precedence yields goto (*i)+3;
    12061033                { $$ = 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 ) ); }
    12141034        | CONTINUE ';'
    12151035                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
     
    12281048        | RETURN comma_expression_opt ';'
    12291049                { $$ = new StatementNode( build_return( $2 ) ); }
    1230         | RETURN '{' initializer_list_opt comma_opt '}'
    1231                 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    12321050        | THROW assignment_expression_opt ';'                           // handles rethrow
    12331051                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    12381056        ;
    12391057
    1240 fall_through_name:                                                                              // CFA
    1241         FALLTHRU
    1242         | FALLTHROUGH
    1243         ;
    1244 
    12451058with_statement:
    12461059        WITH '(' tuple_expression_list ')' statement
     
    12531066mutex_statement:
    12541067        MUTEX '(' argument_expression_list ')' statement
    1255                 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }
     1068                { throw SemanticError("Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME
    12561069        ;
    12571070
    12581071when_clause:
    1259         WHEN '(' comma_expression ')'                           { $$ = $3; }
     1072        WHEN '(' comma_expression ')'
     1073                { $$ = $3; }
    12601074        ;
    12611075
     
    12671081
    12681082waitfor:
    1269         WAITFOR '(' cast_expression ')'
    1270                 { $$ = $3; }
    1271         | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1272                 { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     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                }
    12731094        ;
    12741095
    12751096timeout:
    1276         TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
     1097        TIMEOUT '(' comma_expression ')'
     1098                { $$ = $3; }
    12771099        ;
    12781100
     
    12871109                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    12881110                // "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; }
    12911111        | when_clause_opt timeout statement WOR when_clause ELSE statement
    12921112                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    13101130
    13111131handler_clause:
    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 ) ) ); }
     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 ) ) ); }
    13161136        ;
    13171137
    13181138handler_predicate_opt:
    1319         // empty
     1139        //empty
    13201140                { $$ = nullptr; }
    1321         | ';' conditional_expression                            { $$ = $2; }
     1141        | ';' conditional_expression
     1142                { $$ = $2; }
    13221143        ;
    13231144
    13241145handler_key:
    1325         CATCH                                                                           { $$ = CatchStmt::Terminate; }
    1326         | CATCHRESUME                                                           { $$ = CatchStmt::Resume; }
     1146        CATCH
     1147                { $$ = CatchStmt::Terminate; }
     1148        | CATCHRESUME
     1149                { $$ = CatchStmt::Resume; }
    13271150        ;
    13281151
    13291152finally_clause:
    1330         FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( $2 ) ); }
     1153        FINALLY compound_statement
     1154                {
     1155                        $$ = new StatementNode( build_finally( $2 ) );
     1156                }
    13311157        ;
    13321158
     
    13351161        type_specifier_nobody
    13361162        | type_specifier_nobody declarator
    1337                 { $$ = $2->addType( $1 ); }
     1163                {
     1164                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1165                        $$ = $2->addType( $1 );
     1166                }
    13381167        | type_specifier_nobody variable_abstract_declarator
    13391168                { $$ = $2->addType( $1 ); }
    13401169        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    1341                 { $$ = $1->addName( $2 ); }
     1170                {
     1171                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1172                        $$ = $1->addName( $2 );
     1173                }
    13421174        | cfa_abstract_declarator_tuple                                         // CFA
    1343         ;
    1344 
    1345 enable_disable_statement:
    1346         enable_disable_key identifier_list compound_statement
    1347         ;
    1348 
    1349 enable_disable_key:
    1350         ENABLE
    1351         | DISABLE
    13521175        ;
    13531176
    13541177asm_statement:
    13551178        ASM asm_volatile_opt '(' string_literal ')' ';'
    1356                 { $$ = new StatementNode( build_asm( $2, $4, 0 ) ); }
     1179                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    13571180        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    1358                 { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }
     1181                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    13591182        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    1360                 { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); }
     1183                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    13611184        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    1362                 { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }
     1185                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    13631186        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    1364                 { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); }
     1187                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    13651188        ;
    13661189
     
    14171240
    14181241declaration_list_opt:                                                                   // used at beginning of switch statement
     1242        pop
     1243                { $$ = nullptr; }
     1244        | declaration_list
     1245        ;
     1246
     1247declaration_list:
     1248        declaration
     1249        | declaration_list push declaration
     1250                { $$ = $1->appendList( $3 ); }
     1251        ;
     1252
     1253KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    14191254        // empty
    14201255                { $$ = nullptr; }
    1421         | declaration_list
    1422         ;
    1423 
    1424 declaration_list:
    1425         declaration
    1426         | declaration_list declaration
    1427                 { $$ = $1->appendList( $2 ); }
    1428         ;
    1429 
    1430 KR_parameter_list_opt:                                                                  // used to declare parameter types in K&R style functions
    1431         // empty
    1432                 { $$ = nullptr; }
    1433         | KR_parameter_list
    1434         ;
    1435 
    1436 KR_parameter_list:
     1256        | KR_declaration_list
     1257        ;
     1258
     1259KR_declaration_list:
    14371260        push c_declaration pop ';'
    14381261                { $$ = $2; }
    1439         | KR_parameter_list push c_declaration pop ';'
     1262        | KR_declaration_list push c_declaration pop ';'
    14401263                { $$ = $1->appendList( $3 ); }
    14411264        ;
     
    14521275
    14531276local_label_list:                                                                               // GCC, local label
    1454         no_attr_identifier_or_type_name
    1455         | local_label_list ',' no_attr_identifier_or_type_name
     1277        no_attr_identifier_or_type_name                         {}
     1278        | local_label_list ',' no_attr_identifier_or_type_name {}
    14561279        ;
    14571280
    14581281declaration:                                                                                    // old & new style declarations
    1459         c_declaration ';'
    1460         | cfa_declaration ';'                                                           // CFA
    1461         | static_assert                                                                         // C11
    1462         ;
    1463 
    1464 static_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( "\"\"" ) ) ); }
     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        ;
    14691287
    14701288// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    14891307cfa_variable_declaration:                                                               // CFA
    14901308        cfa_variable_specifier initializer_opt
    1491                 { $$ = $1->addInitializer( $2 ); }
     1309                {
     1310                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1311                        $$ = $1->addInitializer( $2 );
     1312                }
    14921313        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    14931314                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    14941315                // them as a type_qualifier cannot appear in that context.
    1495                 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
     1316                {
     1317                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1318                        $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
     1319                }
    14961320        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1497                 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
     1321                {
     1322                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     1323                        $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
     1324                }
    14981325        ;
    14991326
     
    15021329                // storage-class
    15031330        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    1504                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1331                {
     1332                        typedefTable.setNextIdentifier( *$2 );
     1333                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1334                }
    15051335        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1506                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1336                {
     1337                        typedefTable.setNextIdentifier( *$2 );
     1338                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1339                }
    15071340        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1508                 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
     1341                {
     1342                        typedefTable.setNextIdentifier( *$3 );
     1343                        $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
     1344                }
    15091345        ;
    15101346
    15111347cfa_function_declaration:                                                               // CFA
    15121348        cfa_function_specifier
     1349                {
     1350                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1351                        $$ = $1;
     1352                }
    15131353        | type_qualifier_list cfa_function_specifier
    1514                 { $$ = $2->addQualifiers( $1 ); }
     1354                {
     1355                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1356                        $$ = $2->addQualifiers( $1 );
     1357                }
    15151358        | declaration_qualifier_list cfa_function_specifier
    1516                 { $$ = $2->addQualifiers( $1 ); }
     1359                {
     1360                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1361                        $$ = $2->addQualifiers( $1 );
     1362                }
    15171363        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    1518                 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1519         | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     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 ')'
    15201369                {
    15211370                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    15221371                        DeclarationNode * ret = new DeclarationNode;
    15231372                        ret->type = maybeClone( $1->type->base );
    1524                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
     1373                        $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr, true ) );
    15251374                }
    15261375        ;
    15271376
    15281377cfa_function_specifier:                                                                 // CFA
    1529 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
     1378//      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
    15301379//              {
    15311380//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    15321381//              }
    1533 //      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1382//      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
    15341383//              {
    15351384//                      typedefTable.setNextIdentifier( *$5 );
    15361385//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    15371386//              }
    1538 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1387//      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
    15391388//              {
    15401389//                      typedefTable.setNextIdentifier( *$5 );
     
    15441393                // identifier_or_type_name must be broken apart because of the sequence:
    15451394                //
    1546                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     1395                //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    15471396                //   '[' ']' type_specifier
    15481397                //
    15491398                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    15501399                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1551         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1400        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    15521401                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    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 ); }
     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                }
    15561409        ;
    15571410
     
    15601413                { $$ = DeclarationNode::newTuple( $3 ); }
    15611414        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    1562                 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
     1415                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
     1416                // ']'.
    15631417                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    15641418        ;
     
    15671421        TYPEDEF cfa_variable_specifier
    15681422                {
    1569                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" );
     1423                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    15701424                        $$ = $2->addTypedef();
    15711425                }
    15721426        | TYPEDEF cfa_function_specifier
    15731427                {
    1574                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" );
     1428                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    15751429                        $$ = $2->addTypedef();
    15761430                }
    15771431        | cfa_typedef_declaration pop ',' push no_attr_identifier
    15781432                {
    1579                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
     1433                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
    15801434                        $$ = $1->appendList( $1->cloneType( $5 ) );
    15811435                }
     
    15881442        TYPEDEF type_specifier declarator
    15891443                {
    1590                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
     1444                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    15911445                        $$ = $3->addType( $2 )->addTypedef();
    15921446                }
    15931447        | typedef_declaration pop ',' push declarator
    15941448                {
    1595                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" );
     1449                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    15961450                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    15971451                }
    15981452        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    15991453                {
    1600                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
     1454                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    16011455                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    16021456                }
    16031457        | type_specifier TYPEDEF declarator
    16041458                {
    1605                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
     1459                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    16061460                        $$ = $3->addType( $1 )->addTypedef();
    16071461                }
    16081462        | type_specifier TYPEDEF type_qualifier_list declarator
    16091463                {
    1610                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
     1464                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    16111465                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    16121466                }
     
    16171471        TYPEDEF no_attr_identifier '=' assignment_expression
    16181472                {
    1619                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1620                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1473                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
     1474                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    16211475                }
    16221476        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    16231477                {
    1624                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1625                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1478                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     1479                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    16261480                }
    16271481        ;
     
    16391493//       declarator asm_name_opt initializer_opt
    16401494//              {
    1641 //                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1495//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
    16421496//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
    16431497//              }
    16441498//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    16451499//              {
    1646 //                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1500//                      typedefTable.addToEnclosingScope( TypedefTable::ID );
    16471501//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
    16481502//              }
     
    16511505c_declaration:
    16521506        declaration_specifier declaring_list
    1653                 { $$ = distAttr( $1, $2 ); }
     1507                {
     1508                        $$ = distAttr( $1, $2 );
     1509                }
    16541510        | typedef_declaration
    16551511        | typedef_expression                                                            // GCC, naming expression type
     
    16611517                // storage-class
    16621518        declarator asm_name_opt initializer_opt
    1663                 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     1519                {
     1520                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1521                        $$ = $1->addAsmName( $2 )->addInitializer( $3 );
     1522                }
    16641523        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    1665                 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     1524                {
     1525                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1526                        $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
     1527                }
    16661528        ;
    16671529
     
    17351597
    17361598forall:
    1737         FORALL '(' type_parameter_list ')'                                      // CFA
    1738                 { $$ = DeclarationNode::newForall( $3 ); }
     1599        FORALL '('
     1600                {
     1601                        typedefTable.enterScope();
     1602                }
     1603          type_parameter_list ')'                                                       // CFA
     1604                {
     1605                        typedefTable.leaveScope();
     1606                        $$ = DeclarationNode::newForall( $4 );
     1607                }
    17391608        ;
    17401609
     
    18091678        | LONG
    18101679                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
     1680        | ZERO_T
     1681                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     1682        | ONE_T
     1683                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
    18111684        | VALIST                                                                                        // GCC, __builtin_va_list
    18121685                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     
    18281701basic_type_specifier:
    18291702        direct_type
    1830                 // Cannot have type modifiers, e.g., short, long, etc.
    18311703        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
    18321704                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
     
    18341706
    18351707direct_type:
     1708                // A semantic check is necessary for conflicting type qualifiers.
    18361709        basic_type_name
    18371710        | type_qualifier_list basic_type_name
     
    18521725        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
    18531726                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1854         | ZERO_T                                                                                        // CFA
    1855                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
    1856         | ONE_T                                                                                         // CFA
    1857                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
    18581727        ;
    18591728
     
    18751744                { $$ = $3->addQualifiers( $1 ); }
    18761745        | sue_type_specifier type_qualifier
    1877                 {
    1878                         if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type
    1879                         $$ = $1->addQualifiers( $2 );
    1880                 }
     1746                { $$ = $1->addQualifiers( $2 ); }
    18811747        ;
    18821748
     
    19211787                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    19221788        | '.' TYPEDEFname
    1923                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
     1789                { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
    19241790        | type_name '.' TYPEDEFname
    1925                 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
     1791                { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
    19261792        | typegen_name
    19271793        | '.' typegen_name
    1928                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
     1794                { $$ = $2; }                                                                    // FIX ME
    19291795        | type_name '.' typegen_name
    1930                 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
     1796                { $$ = $3; }                                                                    // FIX ME
    19311797        ;
    19321798
     
    19501816        ;
    19511817
    1952 fred:
    1953         // empty
    1954                 { yyy = false; }
    1955         ;
    1956 
    19571818aggregate_type:                                                                                 // struct, union
    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
     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
    19651825                        forall = false;                                                         // reset
    19661826                }
    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 ); }
     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 ); }
    19771831        | aggregate_type_nobody
    19781832        ;
    19791833
    1980 type_parameters_opt:
    1981         // empty
    1982                 { $$ = nullptr; }                                                               %prec '}'
    1983         | '(' type_list ')'
    1984                 { $$ = $2; }
    1985         ;
    1986 
    19871834aggregate_type_nobody:                                                                  // struct, union - {...}
    1988         aggregate_key attribute_list_opt no_attr_identifier fred
    1989                 {
    1990                         typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
    1991                         forall = false;                                                         // reset
     1835        aggregate_key attribute_list_opt no_attr_identifier
     1836                {
     1837                        typedefTable.makeTypedef( *$3 );
    19921838                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    19931839                }
    1994         | aggregate_key attribute_list_opt type_name fred
    1995                 {
    1996                         forall = false;                                                         // reset
     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                {
    19971847                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
    19981848                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
     
    20071857aggregate_key:
    20081858        STRUCT
    2009                 { yyy = true; $$ = DeclarationNode::Struct; }
     1859                { $$ = DeclarationNode::Struct; }
    20101860        | UNION
    2011                 { yyy = true; $$ = DeclarationNode::Union; }
    2012         | EXCEPTION
    2013                 { yyy = true; $$ = DeclarationNode::Exception; }
     1861                { $$ = DeclarationNode::Union; }
    20141862        | COROUTINE
    2015                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1863                { $$ = DeclarationNode::Coroutine; }
    20161864        | MONITOR
    2017                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1865                { $$ = DeclarationNode::Monitor; }
    20181866        | THREAD
    2019                 { yyy = true; $$ = DeclarationNode::Thread; }
    2020         ;
    2021 
    2022 field_declaration_list_opt:
     1867                { $$ = DeclarationNode::Thread; }
     1868        ;
     1869
     1870field_declaration_list:
    20231871        // empty
    20241872                { $$ = nullptr; }
    2025         | field_declaration_list_opt field_declaration
     1873        | field_declaration_list field_declaration
    20261874                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    20271875        ;
    20281876
    20291877field_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
     1878        cfa_field_declaring_list ';'                                            // CFA, new style field declaration
    20451879        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    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 
    2053 field_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 
    2061 field_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 
    2072 field_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 
    2080 field_abstract:
    2081                 //      no bit fields
    2082         variable_abstract_declarator
     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                }
    20831892        ;
    20841893
    20851894cfa_field_declaring_list:                                                               // CFA, new style field declaration
    2086         // bit-fields are handled by C declarations
    2087         cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
     1895        cfa_abstract_declarator_tuple                                           // CFA, no field name
     1896        | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    20881897                { $$ = $1->addName( $2 ); }
    20891898        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    20901899                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    2091         ;
    2092 
    2093 cfa_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 ','
     1900        | cfa_field_declaring_list ','                                          // CFA, no field name
    20971901                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
     1902        ;
     1903
     1904field_declaring_list:
     1905        field_declarator
     1906        | field_declaring_list ',' attribute_list_opt field_declarator
     1907                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     1908        ;
     1909
     1910field_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
    20981924        ;
    20991925
     
    21021928                { $$ = nullptr; }
    21031929        | bit_subrange_size
     1930                { $$ = $1; }
    21041931        ;
    21051932
     
    21111938enum_type:                                                                                              // enum
    21121939        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2113                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2114         | ENUM attribute_list_opt no_attr_identifier
     1940                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
     1941        | ENUM attribute_list_opt no_attr_identifier_or_type_name
    21151942                { typedefTable.makeTypedef( *$3 ); }
    21161943          '{' enumerator_list comma_opt '}'
    21171944                { $$ = 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 ); }
    21211945        | enum_type_nobody
    21221946        ;
    21231947
    21241948enum_type_nobody:                                                                               // enum - {...}
    2125         ENUM attribute_list_opt no_attr_identifier
     1949        ENUM attribute_list_opt no_attr_identifier_or_type_name
    21261950                {
    21271951                        typedefTable.makeTypedef( *$3 );
    21281952                        $$ = 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 );
    21341953                }
    21351954        ;
     
    21491968        ;
    21501969
    2151 cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
     1970// Minimum of one parameter after which ellipsis is allowed only at the end.
     1971
     1972cfa_parameter_type_list_opt:                                                    // CFA
    21521973        // empty
    2153                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
    2154         | ELLIPSIS
    21551974                { $$ = nullptr; }
    2156         | cfa_abstract_parameter_list
     1975        | cfa_parameter_type_list
     1976        ;
     1977
     1978cfa_parameter_type_list:                                                                // CFA, abstract + real
     1979        cfa_abstract_parameter_list
    21571980        | cfa_parameter_list
    21581981        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
     
    21852008        // empty
    21862009                { $$ = nullptr; }
    2187         | ELLIPSIS
    2188                 { $$ = nullptr; }
    2189         | parameter_list
     2010        | parameter_type_list
     2011        ;
     2012
     2013parameter_type_list:
     2014        parameter_list
    21902015        | parameter_list pop ',' push ELLIPSIS
    21912016                { $$ = $1->addVarArgs(); }
     
    22292054                // No SUE declaration in parameter list.
    22302055        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    2231                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2056                {
     2057                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2058                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2059                }
    22322060        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    2233                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2061                {
     2062                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2063                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2064                }
    22342065        ;
    22352066
     
    22822113                { $$ = $2; }
    22832114        | '=' VOID
    2284                 { $$ = new InitializerNode( true ); }
     2115                { $$ = nullptr; }
    22852116        | ATassign initializer
    22862117                { $$ = $2->set_maybeConstructed( false ); }
     
    22892120initializer:
    22902121        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
    2291         | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
    2292         ;
    2293 
    2294 initializer_list_opt:
     2122        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
     2123        ;
     2124
     2125initializer_list:
    22952126        // empty
    22962127                { $$ = nullptr; }
    22972128        | initializer
    22982129        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    2299         | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2300         | initializer_list_opt ',' designation initializer
     2130        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     2131        | initializer_list ',' designation initializer
    23012132                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    23022133        ;
     
    23352166        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    23362167                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2337         | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
     2168        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    23382169                { $$ = $4; }
    23392170        ;
     
    23592190type_parameter_list:                                                                    // CFA
    23602191        type_parameter
     2192                { $$ = $1; }
    23612193        | type_parameter_list ',' type_parameter
    23622194                { $$ = $1->appendList( $3 ); }
     
    23722204type_parameter:                                                                                 // CFA
    23732205        type_class no_attr_identifier_or_type_name
    2374                 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
     2206                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    23752207          type_initializer_opt assertion_list_opt
    23762208                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    23772209        | type_specifier identifier_parameter_declarator
    2378         | assertion_list
    2379                 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    23802210        ;
    23812211
     
    23942224        // empty
    23952225                { $$ = nullptr; }
    2396         | assertion_list
    2397         ;
    2398 
    2399 assertion_list:                                                                                 // CFA
    2400         assertion
    2401         | assertion_list assertion
     2226        | assertion_list_opt assertion
    24022227                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    24032228        ;
     
    24052230assertion:                                                                                              // CFA
    24062231        '|' no_attr_identifier_or_type_name '(' type_list ')'
    2407                 { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    2408         | '|' '{' push trait_declaration_list pop '}'
     2232                {
     2233                        typedefTable.openTrait( *$2 );
     2234                        $$ = DeclarationNode::newTraitUse( $2, $4 );
     2235                }
     2236        | '|' '{' push trait_declaration_list '}'
    24092237                { $$ = $4; }
    2410         // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2411         //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2238        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
     2239                { $$ = nullptr; }
    24122240        ;
    24132241
     
    24162244                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    24172245        | assignment_expression
    2418                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24192246        | type_list ',' type
    24202247                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    24212248        | type_list ',' assignment_expression
    2422                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
    2423                 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2249                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    24242250        ;
    24252251
     
    24432269        no_attr_identifier_or_type_name
    24442270                {
    2445                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
     2271                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
    24462272                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    24472273                }
    2448         | no_attr_identifier_or_type_name '(' type_parameter_list ')'
    2449                 {
    2450                         typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
    2451                         $$ = DeclarationNode::newTypeDecl( $1, $3 );
     2274        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
     2275                {
     2276                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     2277                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    24522278                }
    24532279        ;
    24542280
    24552281trait_specifier:                                                                                // CFA
    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 ); }
     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                }
    24602298        ;
    24612299
    24622300trait_declaration_list:                                                                 // CFA
    24632301        trait_declaration
    2464         | trait_declaration_list pop push trait_declaration
    2465                 { $$ = $1->appendList( $4 ); }
     2302        | trait_declaration_list push trait_declaration
     2303                { $$ = $1->appendList( $3 ); }
    24662304        ;
    24672305
    24682306trait_declaration:                                                                              // CFA
    2469         cfa_trait_declaring_list ';'
    2470         | trait_declaring_list ';'
     2307        cfa_trait_declaring_list pop ';'
     2308        | trait_declaring_list pop ';'
    24712309        ;
    24722310
    24732311cfa_trait_declaring_list:                                                               // CFA
    24742312        cfa_variable_specifier
     2313                {
     2314                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2315                        $$ = $1;
     2316                }
    24752317        | cfa_function_specifier
     2318                {
     2319                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2320                        $$ = $1;
     2321                }
    24762322        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    2477                 { $$ = $1->appendList( $1->cloneType( $5 ) ); }
     2323                {
     2324                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     2325                        $$ = $1->appendList( $1->cloneType( $5 ) );
     2326                }
    24782327        ;
    24792328
    24802329trait_declaring_list:                                                                   // CFA
    24812330        type_specifier declarator
    2482                 { $$ = $2->addType( $1 ); }
     2331                {
     2332                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2333                        $$ = $2->addType( $1 );
     2334                }
    24832335        | trait_declaring_list pop ',' push declarator
    2484                 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
     2336                {
     2337                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2338                        $$ = $1->appendList( $1->cloneBaseType( $5 ) );
     2339                }
    24852340        ;
    24862341
     
    24882343
    24892344translation_unit:
    2490         // empty, input file
     2345        // empty
     2346                {}                                                                                              // empty input file
    24912347        | external_definition_list
    24922348                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    24942350
    24952351external_definition_list:
    2496         push external_definition pop
    2497                 { $$ = $2; }
    2498         | external_definition_list push external_definition pop
     2352        external_definition
     2353        | external_definition_list push external_definition
    24992354                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    25002355        ;
     
    25062361        ;
    25072362
    2508 up:
    2509                 { typedefTable.up( forall ); forall = false; }
    2510         ;
    2511 
    2512 down:
    2513                 { typedefTable.down(); }
    2514         ;
    2515 
    25162363external_definition:
    25172364        declaration
    25182365        | external_function_definition
     2366        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
     2367                {
     2368                        $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) );
     2369                }
     2370        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
     2371                {
     2372                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
     2373                        linkage = LinkageSpec::linkageUpdate( linkage, $2 );
     2374                }
     2375          '{' external_definition_list_opt '}'
     2376                {
     2377                        linkage = linkageStack.top();
     2378                        linkageStack.pop();
     2379                        $$ = $5;
     2380                }
    25192381        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
    25202382                {
     
    25222384                        $$ = $2;
    25232385                }
    2524         | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    2525                 {
    2526                         $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) );
    2527                 }
    2528         | EXTERN STRINGliteral                                                          // C++-style linkage specifier
    2529                 {
    2530                         linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2531                         linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    2532                 }
    2533           '{' up external_definition_list_opt down '}'
    2534                 {
    2535                         linkage = linkageStack.top();
    2536                         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;
    2548                         $$ = $5;
    2549                 }
    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                 }
     2386        | forall '{' external_definition_list '}'                       // CFA, namespace
    25722387        ;
    25732388
     
    25802395                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    25812396        | function_declarator compound_statement
    2582                 { $$ = $1->addFunctionBody( $2 ); }
    2583         | KR_function_declarator KR_parameter_list_opt compound_statement
    2584                 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
     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                }
    25852408        ;
    25862409
    25872410with_clause_opt:
    25882411        // empty
    2589                 { $$ = nullptr; forall = false; }
     2412                { $$ = nullptr; }
    25902413        | WITH '(' tuple_expression_list ')'
    2591                 { $$ = $3; forall = false; }
     2414                { $$ = new StatementNode( build_with( $3, nullptr ) ); }
    25922415        ;
    25932416
     
    25952418        cfa_function_declaration with_clause_opt compound_statement     // CFA
    25962419                {
     2420                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2421                        typedefTable.leaveScope();
    25972422                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    25982423                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     
    26032428                {
    26042429                        rebindForall( $1, $2 );
    2605                         $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    2606                 }
    2607         | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
    2608                 {
    2609                         rebindForall( $1, $2 );
     2430                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2431                        typedefTable.leaveScope();
    26102432                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    26112433                }
    26122434                // handles default int return type, OBSOLESCENT (see 1)
    26132435        | type_qualifier_list function_declarator with_clause_opt compound_statement
    2614                 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
     2436                {
     2437                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2438                        typedefTable.leaveScope();
     2439                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     2440                }
    26152441                // handles default int return type, OBSOLESCENT (see 1)
    26162442        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    2617                 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
     2443                {
     2444                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2445                        typedefTable.leaveScope();
     2446                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     2447                }
    26182448                // handles default int return type, OBSOLESCENT (see 1)
    26192449        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    2620                 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
     2450                {
     2451                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2452                        typedefTable.leaveScope();
     2453                        $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
     2454                }
    26212455
    26222456                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2623         | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2457        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    26242458                {
    26252459                        rebindForall( $1, $2 );
     2460                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2461                        typedefTable.leaveScope();
    26262462                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    26272463                }
    26282464                // handles default int return type, OBSOLESCENT (see 1)
    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 ); }
     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                }
    26312471                // handles default int return type, OBSOLESCENT (see 1)
    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 ); }
     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                }
    26342478                // handles default int return type, OBSOLESCENT (see 1)
    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 ); }
     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                }
    26372485        ;
    26382486
     
    27442592paren_identifier:
    27452593        identifier
    2746                 { $$ = DeclarationNode::newName( $1 ); }
     2594                {
     2595                        typedefTable.setNextIdentifier( *$1 );
     2596                        $$ = DeclarationNode::newName( $1 );
     2597                }
    27472598        | '(' paren_identifier ')'                                                      // redundant parenthesis
    27482599                { $$ = $2; }
     
    28772728paren_type:
    28782729        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                 }
    28872730        | '(' paren_type ')'
    28882731                { $$ = $2; }
     
    28952738                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    28962739        | '(' type_ptr ')' attribute_list_opt
    2897                 { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
     2740                { $$ = $2->addQualifiers( $4 ); }
    28982741        ;
    28992742
     
    29872830typedef:
    29882831        TYPEDEFname
    2989                 { $$ = DeclarationNode::newName( $1 ); }
     2832                {
     2833                        typedefTable.setNextIdentifier( *$1 );
     2834                        $$ = DeclarationNode::newName( $1 );
     2835                }
    29902836        | TYPEGENname
    2991                 { $$ = DeclarationNode::newName( $1 ); }
     2837                {
     2838                        typedefTable.setNextIdentifier( *$1 );
     2839                        $$ = DeclarationNode::newName( $1 );
     2840                }
    29922841        ;
    29932842
     
    31743023        '[' ']'
    31753024                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    3176                 // multi_array_dimension handles the '[' '*' ']' case
     3025        // multi_array_dimension handles the '[' '*' ']' case
    31773026        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
    31783027                { $$ = DeclarationNode::newVarArray( $3 ); }
    31793028        | '[' push type_qualifier_list pop ']'
    31803029                { $$ = DeclarationNode::newArray( 0, $3, false ); }
    3181                 // multi_array_dimension handles the '[' assignment_expression ']' case
     3030        // multi_array_dimension handles the '[' assignment_expression ']' case
    31823031        | '[' push type_qualifier_list assignment_expression pop ']'
    31833032                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     
    33153164//
    33163165//              cfa_abstract_tuple identifier_or_type_name
    3317 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
     3166//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    33183167//
    33193168// since a function return type can be syntactically identical to a tuple type:
     
    33743223        '[' push cfa_abstract_parameter_list pop ']'
    33753224                { $$ = 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; }
    33803225        ;
    33813226
    33823227cfa_abstract_function:                                                                  // CFA
    3383 //      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
     3228//      '[' ']' '(' cfa_parameter_type_list_opt ')'
    33843229//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3385         cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3230        cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
    33863231                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    3387         | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
     3232        | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
    33883233                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    33893234        ;
     
    34163261
    34173262%%
    3418 
    34193263// ----end of grammar----
    34203264
Note: See TracChangeset for help on using the changeset viewer.