source: src/Parser/parser.yy @ e891349

Last change on this file since e891349 was b1f2007, checked in by Peter A. Buhr <pabuhr@…>, 7 months ago

first attempt at simplifying SemanticError? and its usage

  • Property mode set to 100644
File size: 175.0 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[9335ecc]7// parser.yy --
[974906e2]8//
[c11e31c]9// Author           : Peter A. Buhr
10// Created On       : Sat Sep  1 20:22:55 2001
[04c78215]11// Last Modified By : Peter A. Buhr
[b1f2007]12// Last Modified On : Sun Nov 26 13:18:06 2023
13// Update Count     : 6398
[974906e2]14//
[c11e31c]15
[de62360d]16// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
17// grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While parts have been
18// copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar.
19// In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax
20// that must be subsequently rejected by semantic checks.  Nevertheless, there are still several semantic checks
21// required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions.
[c11e31c]22
[de62360d]23// Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with
24// the grammar.
[c11e31c]25
26// The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
27//
[9380add]28//   designation with '=' (use ':' instead)
[c11e31c]29//
[9380add]30// This incompatibility is discussed in detail before the "designation" grammar rule.  Most of the syntactic extensions
31// from ANSI90 to ANSI11 C are marked with the comment "C99/C11".
[f9c3100]32
[e16eb460]33// This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions. All of the
[9380add]34// syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall (CFA), which
35// fixes several of C's outstanding problems and extends C with many modern language concepts. All of the syntactic
36// extensions for CFA C are marked with the comment "CFA".
[51b7345]37
38%{
[ec3f9c8]39#define YYDEBUG_LEXER_TEXT( yylval )                                    // lexer loads this up each time
[b87a5ed]40#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
[201aeb9]41#define YYERROR_VERBOSE                                                                 // more information in syntax errors
[51b7345]42
43#undef __GNUC_MINOR__
44
45#include <cstdio>
[9feb34b]46#include <sstream>
[51b7345]47#include <stack>
[9ed4f94]48using namespace std;
49
[c468150]50#include "DeclarationNode.h"                            // for DeclarationNode, ...
51#include "ExpressionNode.h"                             // for ExpressionNode, ...
52#include "InitializerNode.h"                            // for InitializerNode, ...
53#include "ParserTypes.h"
54#include "StatementNode.h"                              // for build_...
[984dce6]55#include "TypedefTable.h"
[1db21619]56#include "TypeData.h"
[9ed4f94]57#include "Common/SemanticError.h"                                               // error_str
[513e165]58#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
[51b7345]59
[ae2f2ae]60// lex uses __null in a boolean context, it's fine.
[0bd46fd]61#ifdef __clang__
[09f34a84]62#pragma GCC diagnostic ignored "-Wparentheses-equality"
[0bd46fd]63#endif
[ae2f2ae]64
[cbaee0d]65extern DeclarationNode * parseTree;
[bb7422a]66extern ast::Linkage::Spec linkage;
[0da3e2c]67extern TypedefTable typedefTable;
68
[bb7422a]69stack<ast::Linkage::Spec> linkageStack;
[7bf7fb9]70
[15697ff]71bool appendStr( string & to, string & from ) {
72        // 1. Multiple strings are concatenated into a single string but not combined internally. The reason is that
[ea0c5e3]73        //    "\x12" "3" is treated as 2 characters versus 1 because "escape sequences are converted into single members of
[15697ff]74        //    the execution character set just prior to adjacent string literal concatenation" (C11, Section 6.4.5-8). It is
75        //    easier to let the C compiler handle this case.
76        //
77        // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
78        //    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
[efc8f3e]79        //    e.g., u"a" U"b" L"c" is disallowed.
[15697ff]80
81        if ( from[0] != '"' ) {                                                         // encoding ?
82                if ( to[0] != '"' ) {                                                   // encoding ?
[ea0c5e3]83                        if ( to[0] != from[0] || to[1] != from[1] ) { // different encodings ?
[15697ff]84                                yyerror( "non-matching string encodings for string-literal concatenation" );
85                                return false;                                                   // parse error, must call YYERROR in action
[ea0c5e3]86                        } else if ( from[1] == '8' ) {
87                                from.erase( 0, 1 );                                             // remove 2nd encoding
[15697ff]88                        } // if
89                } else {
[ea0c5e3]90                        if ( from[1] == '8' ) {                                         // move encoding to start
91                                to = "u8" + to;
92                                from.erase( 0, 1 );                                             // remove 2nd encoding
93                        } else {
94                                to = from[0] + to;
95                        } // if
[15697ff]96                } // if
97                from.erase( 0, 1 );                                                             // remove 2nd encoding
98        } // if
99        to += " " + from;                                                                       // concatenated into single string
100        return true;
[7bf7fb9]101} // appendStr
[c0aa336]102
[d8454b9]103DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
104        // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
105        assert( declList );
[b2ddaf3]106        // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
[55266c7]107        DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
[b2ddaf3]108        // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
109        // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
[d8454b9]110
[55266c7]111        for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
[c0aa336]112                cl->cloneBaseType( cur );
113        } // for
114        declList->addType( cl );
[b2ddaf3]115        // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
[c0aa336]116        return declList;
117} // distAttr
118
119void distExt( DeclarationNode * declaration ) {
120        // distribute EXTENSION across all declarations
121        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
122                iter->set_extension( true );
123        } // for
124} // distExt
[fdca7c6]125
[e07caa2]126void distInl( DeclarationNode * declaration ) {
[5695645]127        // distribute INLINE across all declarations
[e07caa2]128        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
129                iter->set_inLine( true );
130        } // for
131} // distInl
132
[4c3ee8d]133void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
[284da8c]134        // distribute qualifiers across all non-variable declarations in a distribution statemement
[4c3ee8d]135        for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
[284da8c]136                // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since
137                // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To
138                // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to
139                // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers.
140                DeclarationNode * clone = qualifiers->clone();
141                if ( qualifiers->type ) {                                               // forall clause ? (handles SC)
142                        if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?
143                                swap( clone->type->forall, iter->type->aggregate.params );
144                                iter->addQualifiers( clone );
145                        } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?
146                                // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together.
147                                DeclarationNode newnode;
148                                swap( newnode.type, iter->type->aggInst.aggregate );
149                                swap( clone->type->forall, newnode.type->aggregate.params );
150                                newnode.addQualifiers( clone );
151                                swap( newnode.type, iter->type->aggInst.aggregate );
152                        } else if ( iter->type->kind == TypeData::Function ) { // routines ?
153                                swap( clone->type->forall, iter->type->forall );
154                                iter->addQualifiers( clone );
155                        } // if
156                } else {                                                                                // just SC qualifiers
157                        iter->addQualifiers( clone );
158                } // if
[4c3ee8d]159        } // for
[284da8c]160        delete qualifiers;
161} // distQual
[4c3ee8d]162
[c38ae92]163// There is an ambiguity for inline generic-routine return-types and generic routines.
164//   forall( otype T ) struct S { int i; } bar( T ) {}
165// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
166//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
[7fdb94e]167// Currently, the forall is associated with the routine, and the generic type has to be separately defined:
168//   forall( otype T ) struct S { int T; };
169//   forall( otype W ) bar( W ) {}
[c38ae92]170
171void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
[7fdb94e]172        if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
[c38ae92]173                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
174                declSpec->type->aggregate.params = nullptr;
175        } // if
176} // rebindForall
177
[60a8062]178string * build_postfix_name( string * name ) {
179        *name = string("__postfix_func_") + *name;
180        return name;
[dc7db63]181} // build_postfix_name
182
[f7e4db27]183DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
184        if ( ! fieldList ) {                                                            // field declarator ?
[553772b]185                if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
[f7e4db27]186                        stringstream ss;
[d8454b9]187                        // printf( "fieldDecl1 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
[f7e4db27]188                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
189                        return nullptr;
190                } // if
[d8454b9]191                // printf( "fieldDecl2 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
[f7e4db27]192                fieldList = DeclarationNode::newName( nullptr );
193        } // if
[d8454b9]194//      return distAttr( typeSpec, fieldList );                         // mark all fields in list
195
196        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
197        DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
198        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
199        return temp;
[f7e4db27]200} // fieldDecl
201
[bb7422a]202#define NEW_ZERO new ExpressionNode( build_constantInteger( yylloc, *new string( "0" ) ) )
203#define NEW_ONE  new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) )
[52be5948]204#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
[55266c7]205#define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
206#define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized."
207#define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized."
[d78c238]208
[1cdc052]209static ForCtrl * makeForCtrl(
[bb7422a]210                const CodeLocation & location,
[1cdc052]211                DeclarationNode * init,
212                enum OperKinds compop,
213                ExpressionNode * comp,
214                ExpressionNode * inc ) {
215        // Wrap both comp/inc if they are non-null.
[bb7422a]216        if ( comp ) comp = new ExpressionNode( build_binary_val( location,
[1cdc052]217                compop,
[bb7422a]218                new ExpressionNode( build_varref( location, new string( *init->name ) ) ),
[1cdc052]219                comp ) );
[bb7422a]220        if ( inc ) inc = new ExpressionNode( build_binary_val( location,
[1cdc052]221                // choose += or -= for upto/downto
222                compop == OperKinds::LThan || compop == OperKinds::LEThan ? OperKinds::PlusAssn : OperKinds::MinusAssn,
[bb7422a]223                new ExpressionNode( build_varref( location, new string( *init->name ) ) ),
[1cdc052]224                inc ) );
225        // The StatementNode call frees init->name, it must happen later.
226        return new ForCtrl( new StatementNode( init ), comp, inc );
227}
228
[bb7422a]229ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
[d78c238]230        if ( index->initializer ) {
[55266c7]231                SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
[d78c238]232        } // if
233        if ( index->next ) {
[55266c7]234                SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." );
[d78c238]235        } // if
[1cdc052]236        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
[bb7422a]237        return makeForCtrl( location, initDecl, compop, comp, inc );
[d78c238]238} // forCtrl
239
[bb7422a]240ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
241        ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get());
242        if ( constant && (constant->rep == "0" || constant->rep == "1") ) {
243                type = new ExpressionNode( new ast::CastExpr( location, maybeMoveBuild(type), new ast::BasicType( ast::BasicType::SignedInt ) ) );
[0982a05]244        } // if
[1cdc052]245        DeclarationNode * initDecl = distAttr(
246                DeclarationNode::newTypeof( type, true ),
247                DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) )
248        );
[bb7422a]249        return makeForCtrl( location, initDecl, compop, comp, inc );
[f271bdd]250} // forCtrl
251
[bb7422a]252ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
253        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) {
254                return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
255        } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) {
256                if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
257                        return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
[6d01d89]258                } else {
[55266c7]259                        SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
[6d01d89]260                } // if
[f1aeede]261        } else {
[b1f2007]262                SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
[f1aeede]263        } // if
[f271bdd]264} // forCtrl
265
[996c8ed]266static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
[b1f2007]267        SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n"
268                                   "Possible cause is misspelled type name or missing generic parameter.",
269                                   identifier1.c_str(), identifier2.c_str(), kind );
[996c8ed]270} // IdentifierBeforeIdentifier
271
272static void IdentifierBeforeType( string & identifier, const char * kind ) {
[b1f2007]273        SemanticError( yylloc, "syntax error, identifier \"%s\" cannot appear before a %s.\n"
274                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter.",
275                                   identifier.c_str(), kind );
[996c8ed]276} // IdentifierBeforeType
277
[24711a3]278bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
[d48e529]279
[201aeb9]280// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
281#define YYLLOC_DEFAULT(Cur, Rhs, N)                                                                                             \
282if ( N ) {                                                                                                                                              \
283        (Cur).first_line   = YYRHSLOC( Rhs, 1 ).first_line;                                                     \
284        (Cur).first_column = YYRHSLOC( Rhs, 1 ).first_column;                                           \
285        (Cur).last_line    = YYRHSLOC( Rhs, N ).last_line;                                                      \
286        (Cur).last_column  = YYRHSLOC( Rhs, N ).last_column;                                            \
287        (Cur).filename     = YYRHSLOC( Rhs, 1 ).filename;                                                       \
288} else {                                                                                                                                                \
289        (Cur).first_line   = (Cur).last_line = YYRHSLOC( Rhs, 0 ).last_line;            \
290        (Cur).first_column = (Cur).last_column = YYRHSLOC( Rhs, 0 ).last_column;        \
291        (Cur).filename     = YYRHSLOC( Rhs, 0 ).filename;                                                       \
292}
[51b7345]293%}
294
[15697ff]295%define parse.error verbose
296
[201aeb9]297// Types declaration for productions
[7cf8006]298
[0982a05]299%union {
[a67b60e]300        Token tok;
[32d6fdc]301        ExpressionNode * expr;
[a67b60e]302        DeclarationNode * decl;
[bb7422a]303        ast::AggregateDecl::Aggregate aggKey;
304        ast::TypeDecl::Kind tclass;
[32d6fdc]305        StatementNode * stmt;
[6611177]306        ClauseNode * clause;
[bb7422a]307        ast::WaitForStmt * wfs;
[6e1e2d0]308    ast::WaitUntilStmt::ClauseNode * wucn;
[473d1da0]309        CondCtl * ifctl;
[32d6fdc]310        ForCtrl * forctl;
311        LabelNode * labels;
312        InitializerNode * init;
313        OperKinds oper;
[a67b60e]314        std::string * str;
[32d6fdc]315        bool is_volatile;
316        EnumHiding enum_hiding;
317        ast::ExceptionKind except_kind;
[bb7422a]318        ast::GenericExpr * genexpr;
[a67b60e]319}
320
[bb7422a]321// ************************ TERMINAL TOKENS ********************************
[51b7345]322
[c11e31c]323// keywords
[51b7345]324%token TYPEDEF
[a7c90d4]325%token EXTERN STATIC AUTO REGISTER
[59c7e3e]326%token THREADLOCALGCC THREADLOCALC11                                    // GCC, C11
[a7c90d4]327%token INLINE FORTRAN                                                                   // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
328%token NORETURN                                                                                 // C11
[51b7345]329%token CONST VOLATILE
[b87a5ed]330%token RESTRICT                                                                                 // C99
[a7c90d4]331%token ATOMIC                                                                                   // C11
[1f652a7]332%token FORALL MUTEX VIRTUAL VTABLE COERCE                               // CFA
[72457b6]333%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
[b87a5ed]334%token BOOL COMPLEX IMAGINARY                                                   // C99
[f1da02c]335%token INT128 UINT128 uuFLOAT80 uuFLOAT128                              // GCC
[e15853c]336%token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
[15f769c]337%token DECIMAL32 DECIMAL64 DECIMAL128                                   // GCC
[72457b6]338%token ZERO_T ONE_T                                                                             // CFA
[59c7e3e]339%token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE                   // GCC
[1f652a7]340%token OFFSETOF BASETYPEOF TYPEID                                               // CFA
[51b7345]341%token ENUM STRUCT UNION
[c27fb59]342%token EXCEPTION                                                                                // CFA
[553772b]343%token GENERATOR COROUTINE MONITOR THREAD                               // CFA
[a7c90d4]344%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
[25744d2]345// %token RESUME                                                                                        // CFA
[1f652a7]346%token LABEL                                                                                    // GCC
[25744d2]347%token SUSPEND                                                                                  // CFA
[b87a5ed]348%token ATTRIBUTE EXTENSION                                                              // GCC
[51b7345]349%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
[466787a]350%token CHOOSE FALLTHRU FALLTHROUGH WITH WHEN WAITFOR WAITUNTIL // CFA
[11ab0b4a]351%token CORUN COFOR
[4744074]352%token DISABLE ENABLE TRY THROW THROWRESUME AT                  // CFA
[b87a5ed]353%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
[a7c90d4]354%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
[51b7345]355
[c11e31c]356// names and constants: lexer differentiates between identifier and typedef names
[9fd9d015]357%token<tok> IDENTIFIER          TYPEDIMname             TYPEDEFname             TYPEGENname
358%token<tok> TIMEOUT                     WAND    WOR                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
[9fb1367]359%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
[61fc4f6]360%token<tok> DIRECTIVE
[1b29996]361// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
362// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
363// converted into the tuple index (.)(1). e.g., 3.x
[930f69e]364%token<tok>     FLOATING_DECIMALconstant        FLOATING_FRACTIONconstant       FLOATINGconstant
[51b7345]365
[c11e31c]366// multi-character operators
[b87a5ed]367%token ARROW                                                                                    // ->
368%token ICR DECR                                                                                 // ++   --
369%token LS RS                                                                                    // <<   >>
370%token LE GE EQ NE                                                                              // <=   >=      ==      !=
371%token ANDAND OROR                                                                              // &&   ||
372%token ELLIPSIS                                                                                 // ...
373
[e5f2a67]374%token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
[b87a5ed]375%token PLUSassign       MINUSassign                                                     // +=   -=
376%token LSassign         RSassign                                                        // <<=  >>=
377%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
[51b7345]378
[d69f4bb4]379%token ErangeUpEq       ErangeDown      ErangeDownEq                    // ~=   -~      -~=
[e7aed49]380%token ATassign                                                                                 // @=
[097e2b0]381
[e16eb460]382%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
[5b2edbc]383%type<tok> quasi_keyword
[32d6fdc]384%type<expr> string_literal
[ab57786]385%type<str> string_literal_list
[51b7345]386
[71a422a]387%type<enum_hiding> hide_opt                             visible_hide_opt
[7cf8006]388
[c11e31c]389// expressions
[32d6fdc]390%type<expr> constant
[71a422a]391%type<expr> tuple                                               tuple_expression_list
[32d6fdc]392%type<oper> ptrref_operator                             unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
393%type<expr> primary_expression                  postfix_expression                      unary_expression
[71a422a]394%type<expr> cast_expression_list                cast_expression                         exponential_expression          multiplicative_expression       additive_expression
395%type<expr> shift_expression                    relational_expression           equality_expression
[32d6fdc]396%type<expr> AND_expression                              exclusive_OR_expression         inclusive_OR_expression
397%type<expr> logical_AND_expression              logical_OR_expression
398%type<expr> conditional_expression              constant_expression                     assignment_expression           assignment_expression_opt
[71a422a]399%type<expr> comma_expression                    comma_expression_opt
400%type<expr> argument_expression_list_opt argument_expression_list       argument_expression                     default_initializer_opt
[473d1da0]401%type<ifctl> conditional_declaration
[71a422a]402%type<forctl> for_control_expression    for_control_expression_list
[32d6fdc]403%type<oper> upupeq updown updowneq downupdowneq
404%type<expr> subrange
[c0aa336]405%type<decl> asm_name_opt
[71a422a]406%type<expr> asm_operands_opt                    asm_operands_list                       asm_operand
[32d6fdc]407%type<labels> label_list
408%type<expr> asm_clobbers_list_opt
409%type<is_volatile> asm_volatile_opt
410%type<expr> handler_predicate_opt
[67d4e37]411%type<genexpr> generic_association              generic_assoc_list
[51b7345]412
[c11e31c]413// statements
[71a422a]414%type<stmt> statement                                   labeled_statement                       compound_statement
[32d6fdc]415%type<stmt> statement_decl                              statement_decl_list                     statement_list_nodecl
416%type<stmt> selection_statement                 if_statement
[71a422a]417%type<clause> switch_clause_list_opt    switch_clause_list
[32d6fdc]418%type<expr> case_value
[71a422a]419%type<clause> case_clause                               case_value_list                         case_label      case_label_list
[32d6fdc]420%type<stmt> iteration_statement                 jump_statement
[71a422a]421%type<stmt> expression_statement                asm_statement
[32d6fdc]422%type<stmt> with_statement
423%type<expr> with_clause_opt
[11ab0b4a]424%type<stmt> corun_statement                             cofor_statement
[32d6fdc]425%type<stmt> exception_statement
[6611177]426%type<clause> handler_clause                    finally_clause
[32d6fdc]427%type<except_kind> handler_key
428%type<stmt> mutex_statement
429%type<expr> when_clause                                 when_clause_opt                         waitfor         waituntil               timeout
[71a422a]430%type<stmt> waitfor_statement                   waituntil_statement
[c86b08d]431%type<wfs> wor_waitfor_clause
[6e1e2d0]432%type<wucn> waituntil_clause                    wand_waituntil_clause       wor_waituntil_clause
[51b7345]433
[c11e31c]434// declarations
[c0aa336]435%type<decl> abstract_declarator abstract_ptr abstract_array abstract_function array_dimension multi_array_dimension
[59c7e3e]436%type<decl> abstract_parameter_declarator_opt abstract_parameter_declarator abstract_parameter_ptr abstract_parameter_array abstract_parameter_function array_parameter_dimension array_parameter_1st_dimension
[c0aa336]437%type<decl> abstract_parameter_declaration
[51b7345]438
[e307e12]439%type<aggKey> aggregate_key aggregate_data aggregate_control
[d0ffed1]440%type<decl> aggregate_type aggregate_type_nobody
[51b7345]441
[9997fee]442%type<decl> assertion assertion_list assertion_list_opt
[51b7345]443
[32d6fdc]444%type<expr> bit_subrange_size_opt bit_subrange_size
[51b7345]445
[84d58c5]446%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
[1f652a7]447%type<decl> vtable vtable_opt default_opt
[51b7345]448
[4040425]449%type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
[51b7345]450
451%type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list
[d0ffed1]452%type<decl> declaration_specifier declaration_specifier_nobody declarator declaring_list
[51b7345]453
[d0ffed1]454%type<decl> elaborated_type elaborated_type_nobody
[51b7345]455
[d0ffed1]456%type<decl> enumerator_list enum_type enum_type_nobody
[32d6fdc]457%type<init> enumerator_value_opt
[51b7345]458
[3d56d15b]459%type<decl> external_definition external_definition_list external_definition_list_opt
460
461%type<decl> exception_declaration
[51b7345]462
[e07caa2]463%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
[32d6fdc]464%type<expr> field field_name_list field_name fraction_constants_opt
[51b7345]465
[4d51835]466%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
[51b7345]467
[d3bc0ad]468%type<decl> identifier_parameter_declarator identifier_parameter_ptr identifier_parameter_array identifier_parameter_function
469%type<decl> identifier_list
[51b7345]470
[c0aa336]471%type<decl> cfa_abstract_array cfa_abstract_declarator_no_tuple cfa_abstract_declarator_tuple
472%type<decl> cfa_abstract_function cfa_abstract_parameter_declaration cfa_abstract_parameter_list
473%type<decl> cfa_abstract_ptr cfa_abstract_tuple
[51b7345]474
[c0aa336]475%type<decl> cfa_array_parameter_1st_dimension
[51b7345]476
[679e644]477%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
[c0aa336]478%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
[51b7345]479
[c0aa336]480%type<decl> cfa_identifier_parameter_array cfa_identifier_parameter_declarator_no_tuple
481%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
[51b7345]482
[40de461]483%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
[51b7345]484
[c0aa336]485%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
[51b7345]486
[b9be000b]487%type<decl> c_declaration static_assert
[c0aa336]488%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
[35718a9]489%type<decl> KR_parameter_list KR_parameter_list_opt
[51b7345]490
[2a8427c6]491%type<decl> parameter_declaration parameter_list parameter_type_list_opt
[51b7345]492
[2871210]493%type<decl> paren_identifier paren_type
[51b7345]494
[0da3e2c]495%type<decl> storage_class storage_class_list
[51b7345]496
[d0ffed1]497%type<decl> sue_declaration_specifier sue_declaration_specifier_nobody sue_type_specifier sue_type_specifier_nobody
[51b7345]498
[5a51798]499%type<tclass> type_class new_type_class
[51b7345]500%type<decl> type_declarator type_declarator_name type_declaring_list
501
[84d58c5]502%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
[f9c3100]503%type<decl> typedef_name typedef_declaration typedef_expression
[c0aa336]504
[1f771fc]505%type<decl> variable_type_redeclarator variable_type_ptr variable_type_array variable_type_function
506%type<decl> general_function_declarator function_type_redeclarator function_type_array function_type_no_ptr function_type_ptr
[c0aa336]507
508%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
[51b7345]509
[84d58c5]510%type<decl> type type_no_function
511%type<decl> type_parameter type_parameter_list type_initializer_opt
[51b7345]512
[32d6fdc]513%type<expr> type_parameters_opt type_list array_type_list
[51b7345]514
[a16a7ec]515%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
[f9c3100]516%type<decl> type_specifier type_specifier_nobody
[51b7345]517
[c0aa336]518%type<decl> variable_declarator variable_ptr variable_array variable_function
519%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
[51b7345]520
[f9c3100]521%type<decl> attribute_list_opt attribute_list attribute attribute_name_list attribute_name
[1db21619]522
[c11e31c]523// initializers
[32d6fdc]524%type<init>  initializer initializer_list_opt initializer_opt
[51b7345]525
[c11e31c]526// designators
[32d6fdc]527%type<expr>  designator designator_list designation
[51b7345]528
529
[65d6de4]530// Handle shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string is ambiguous:
531//   .---------.                                matches IF '(' comma_expression ')' statement . (reduce)
532//   if ( C ) S1 else S2
533//   `-----------------'                matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
[5b2edbc]534// Similar issues exit with the waitfor statement.
[51b7345]535
[9fd9d015]536// Order of these lines matters (low-to-high precedence). THEN is left associative over WAND/WOR/TIMEOUT/ELSE, WAND/WOR
537// is left associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
[9fb1367]538%precedence THEN                // rule precedence for IF/WAITFOR statement
[9fd9d015]539%precedence ANDAND              // token precedence for start of WAND in WAITFOR statement
540%precedence WAND                // token precedence for start of WAND in WAITFOR statement
541%precedence OROR                // token precedence for start of WOR in WAITFOR statement
[9fb1367]542%precedence WOR                 // token precedence for start of WOR in WAITFOR statement
543%precedence TIMEOUT             // token precedence for start of TIMEOUT in WAITFOR statement
544%precedence CATCH               // token precedence for start of TIMEOUT in WAITFOR statement
545%precedence RECOVER             // token precedence for start of TIMEOUT in WAITFOR statement
546%precedence CATCHRESUME // token precedence for start of TIMEOUT in WAITFOR statement
547%precedence FIXUP               // token precedence for start of TIMEOUT in WAITFOR statement
548%precedence FINALLY             // token precedence for start of TIMEOUT in WAITFOR statement
549%precedence ELSE                // token precedence for start of else clause in IF/WAITFOR statement
550
[51b7345]551
[65d6de4]552// Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous:
553//   forall( otype T ) struct Foo { T v; };
554//       .-----.                                matches pointer to function returning a generic (which is impossible without a type)
555//   Foo ( *fp )( int );
556//   `---'                                              matches start of TYPEGENname '('
[fc20514]557// must be:
[a16a7ec]558//   Foo( int ) ( *fp )( int );
[fc20514]559// The same problem occurs here:
560//   forall( otype T ) struct Foo { T v; } ( *fp )( int );
561// must be:
562//   forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int );
[65d6de4]563
564// Order of these lines matters (low-to-high precedence).
565%precedence TYPEGENname
[284da8c]566%precedence '}'
[65d6de4]567%precedence '('
568
[c786e1d]569// %precedence RESUME
570// %precedence '{'
571// %precedence ')'
572
[f38e7d7]573%locations                                                                                              // support location tracking for error messages
[930f69e]574
[b87a5ed]575%start translation_unit                                                                 // parse-tree root
[51b7345]576
577%%
[e1d66c84]578// ************************ Namespace Management ********************************
[c11e31c]579
[3d26610]580// The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
581// which are lexically identical.
[c11e31c]582//
[3d26610]583//   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
584//   foo f;           // to allow it to appear in this context
[c11e31c]585//
[3d26610]586// While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
587// between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
588// scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
589// generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
590// must be distinguished by the lexical scanner.
[c11e31c]591//
[3d26610]592// Since the scanner cannot distinguish among the different classes of identifiers without some context information,
593// there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
594// scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
595// each context that introduces a name scope, a new level is created in the type table and that level is popped on
596// exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
597// This requires distinguishing between type names that are local to the current declaration scope and those that
598// persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
[c11e31c]599//
[3d26610]600// The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
601// the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
602// around the list separator.
603//
[71a422a]604//  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[3d26610]605//      push               pop   push                   pop
[51b7345]606
607push:
[ab57786]608                { typedefTable.enterScope(); }
[4d51835]609        ;
[51b7345]610
611pop:
[ab57786]612                { typedefTable.leaveScope(); }
[4d51835]613        ;
[51b7345]614
[e1d66c84]615// ************************ CONSTANTS ********************************
[51b7345]616
617constant:
[de62360d]618                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
[bb7422a]619        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( yylloc, *$1 ) ); }
620        | FLOATING_DECIMALconstant                                      { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); }
621        | FLOATING_FRACTIONconstant                                     { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); }
622        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); }
623        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( yylloc, *$1 ) ); }
[4d51835]624        ;
[51b7345]625
[5b2edbc]626quasi_keyword:                                                                                  // CFA
627        TIMEOUT
[9fd9d015]628        | WAND
[5b2edbc]629        | WOR
[9fb1367]630        | CATCH
631        | RECOVER
632        | CATCHRESUME
633        | FIXUP
634        | FINALLY
[5b2edbc]635        ;
636
[033ff37]637identifier:
[4d51835]638        IDENTIFIER
[5b2edbc]639        | quasi_keyword
[e16eb460]640        ;
641
642identifier_at:
643        identifier
[679e644]644        | '@'                                                                                           // CFA
645                { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
[4d51835]646        ;
[51b7345]647
[ab57786]648string_literal:
[32d6fdc]649        string_literal_list                                                     { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); }
[ab57786]650        ;
651
[b87a5ed]652string_literal_list:                                                                    // juxtaposed strings are concatenated
[ab57786]653        STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
[7bf7fb9]654        | string_literal_list STRINGliteral
655                {
[15697ff]656                        if ( ! appendStr( *$1, *$2 ) ) YYERROR;         // append 2nd juxtaposed string to 1st
[7bf7fb9]657                        delete $2;                                                                      // allocated by lexer
[ab57786]658                        $$ = $1;                                                                        // conversion from tok to str
[7bf7fb9]659                }
[4d51835]660        ;
[51b7345]661
[e1d66c84]662// ************************ EXPRESSIONS ********************************
[51b7345]663
664primary_expression:
[4d51835]665        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
[bb7422a]666                { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); }
[5b2edbc]667        | quasi_keyword
[bb7422a]668                { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); }
[6e50a6b]669        | TYPEDIMname                                                                           // CFA, generic length argument
670                // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); }
671                // { $$ = new ExpressionNode( build_varref( $1 ) ); }
[bb7422a]672                { $$ = new ExpressionNode( build_dimensionref( yylloc, $1 ) ); }
[1b29996]673        | tuple
[4d51835]674        | '(' comma_expression ')'
675                { $$ = $2; }
676        | '(' compound_statement ')'                                            // GCC, lambda expression
[bb7422a]677                { $$ = new ExpressionNode( new ast::StmtExpr( yylloc, dynamic_cast<ast::CompoundStmt *>( maybeMoveBuild( $2 ) ) ) ); }
[033ff37]678        | type_name '.' identifier                                                      // CFA, nested type
[bb7422a]679                { $$ = new ExpressionNode( build_qualified_expr( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
[679e644]680        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
[203c667]681                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
[24c3b67]682        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
[d807ca28]683                {
684                        // add the missing control expression to the GenericExpr and return it
[702e826]685                        $5->control = maybeMoveBuild( $3 );
[d807ca28]686                        $$ = new ExpressionNode( $5 );
687                }
[c786e1d]688        // | RESUME '(' comma_expression ')'
689        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
690        // | RESUME '(' comma_expression ')' compound_statement
691        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
[65ef0cd]692        | IDENTIFIER IDENTIFIER                                                         // invalid syntax rule
[b1f2007]693                { IdentifierBeforeIdentifier( *$1.str, *$2.str, "expression" ); $$ = nullptr; }
[65ef0cd]694        | IDENTIFIER type_qualifier                                                     // invalid syntax rule
[996c8ed]695                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
[65ef0cd]696        | IDENTIFIER storage_class                                                      // invalid syntax rule
[996c8ed]697                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
[65ef0cd]698        | IDENTIFIER basic_type_name                                            // invalid syntax rule
[996c8ed]699                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[65ef0cd]700        | IDENTIFIER TYPEDEFname                                                        // invalid syntax rule
[996c8ed]701                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[65ef0cd]702        | IDENTIFIER TYPEGENname                                                        // invalid syntax rule
[996c8ed]703                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[24c3b67]704        ;
705
706generic_assoc_list:                                                                             // C11
[d807ca28]707        generic_association
[24c3b67]708        | generic_assoc_list ',' generic_association
[d807ca28]709                {
710                        // steal the association node from the singleton and delete the wrapper
[bb7422a]711                        assert( 1 == $3->associations.size() );
712                        $1->associations.push_back( $3->associations.front() );
[d807ca28]713                        delete $3;
714                        $$ = $1;
715                }
[24c3b67]716        ;
717
718generic_association:                                                                    // C11
719        type_no_function ':' assignment_expression
[d807ca28]720                {
721                        // create a GenericExpr wrapper with one association pair
[bb7422a]722                        $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuildType( $1 ), maybeMoveBuild( $3 ) } } );
[d807ca28]723                }
[24c3b67]724        | DEFAULT ':' assignment_expression
[bb7422a]725                { $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuild( $3 ) } } ); }
[4d51835]726        ;
[51b7345]727
728postfix_expression:
[4d51835]729        primary_expression
[1d71208]730        | postfix_expression '[' assignment_expression ',' tuple_expression_list ']'
[59c7e3e]731                // Historic, transitional: Disallow commas in subscripts.
732                // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
733                // Current: Commas in subscripts make tuples.
[bb7422a]734                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
[7fdb94e]735        | postfix_expression '[' assignment_expression ']'
[c6b1105]736                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
[de62360d]737                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
738                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
739                // equivalent to the old x[i,j].
[bb7422a]740                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
[d824715]741        | constant '[' assignment_expression ']'                        // 3[a], 'a'[a], 3.5[a]
[bb7422a]742                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
[d824715]743        | string_literal '[' assignment_expression ']'          // "abc"[3], 3["abc"]
[32d6fdc]744                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
[cbbd8fd7]745        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
[bd3d9e4]746                {
747                        Token fn;
748                        fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
[bb7422a]749                        $$ = new ExpressionNode( new ast::ConstructorExpr( yylloc, build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
[bd3d9e4]750                }
[cbbd8fd7]751        | postfix_expression '(' argument_expression_list_opt ')'
[bb7422a]752                { $$ = new ExpressionNode( build_func( yylloc, $1, $3 ) ); }
[59c7e3e]753        | VA_ARG '(' primary_expression ',' declaration_specifier_nobody abstract_parameter_declarator_opt ')'
754                // { SemanticError( yylloc, "va_arg is currently unimplemented." ); $$ = nullptr; }
[bb7422a]755                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, new string( "__builtin_va_arg") ) ),
[59c7e3e]756                                                                                           (ExpressionNode *)($3->set_last( (ExpressionNode *)($6 ? $6->addType( $5 ) : $5) )) ) ); }
[948fdef]757        | postfix_expression '`' identifier                                     // CFA, postfix call
[bb7422a]758                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
[948fdef]759        | constant '`' identifier                                                       // CFA, postfix call
[bb7422a]760                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
[948fdef]761        | string_literal '`' identifier                                         // CFA, postfix call
[32d6fdc]762                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
[033ff37]763        | postfix_expression '.' identifier
[bb7422a]764                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
[df22130]765        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
[bb7422a]766                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
[930f69e]767        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
[bb7422a]768                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 ) ) ); }
[679e644]769        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
[bb7422a]770                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); }
[e307e12]771        | postfix_expression '.' aggregate_control
[bb7422a]772                { $$ = new ExpressionNode( build_keyword_cast( yylloc, $3, $1 ) ); }
[033ff37]773        | postfix_expression ARROW identifier
[bb7422a]774                { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
[861799c]775        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
[bb7422a]776                { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
[679e644]777        | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
[bb7422a]778                { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); }
[4d51835]779        | postfix_expression ICR
[bb7422a]780                { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::IncrPost, $1 ) ); }
[4d51835]781        | postfix_expression DECR
[bb7422a]782                { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::DecrPost, $1 ) ); }
[7fdb94e]783        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
[bb7422a]784                { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, new InitializerNode( $5, true ) ) ); }
[7fdb94e]785        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
[bb7422a]786                { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
[cbbd8fd7]787        | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call
[097e2b0]788                {
[9706554]789                        Token fn;
[ecb27a7]790                        fn.str = new string( "^?{}" );                          // location undefined
[bb7422a]791                        $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );
[097e2b0]792                }
[4d51835]793        ;
[51b7345]794
[cbbd8fd7]795argument_expression_list_opt:
[757ffed]796        // empty
797                { $$ = nullptr; }
[e16eb460]798        | argument_expression_list
799        ;
800
801argument_expression_list:
802        argument_expression
[cbbd8fd7]803        | argument_expression_list_opt ',' argument_expression
[4a063df]804                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
[4d51835]805        ;
[51b7345]806
807argument_expression:
[757ffed]808        '@'                                                                                                     // CFA, default parameter
[679e644]809                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
[9fd9d015]810                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
[4d51835]811        | assignment_expression
812        ;
[b87a5ed]813
[679e644]814field_name_list:                                                                                // CFA, tuple field selector
[4d51835]815        field
[4a063df]816        | field_name_list ',' field                                     { $$ = (ExpressionNode *)($1->set_last( $3 )); }
[4d51835]817        ;
[b87a5ed]818
819field:                                                                                                  // CFA, tuple field selector
[faddbd8]820        field_name
[930f69e]821        | FLOATING_DECIMALconstant field
[bb7422a]822                { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), maybeMoveBuild( $2 ) ) ); }
[679e644]823        | FLOATING_DECIMALconstant '[' field_name_list ']'
[bb7422a]824                { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), build_tuple( yylloc, $3 ) ) ); }
[faddbd8]825        | field_name '.' field
[bb7422a]826                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); }
[679e644]827        | field_name '.' '[' field_name_list ']'
[bb7422a]828                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); }
[faddbd8]829        | field_name ARROW field
[bb7422a]830                { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); }
[679e644]831        | field_name ARROW '[' field_name_list ']'
[bb7422a]832                { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); }
[4d51835]833        ;
[51b7345]834
[faddbd8]835field_name:
[df22130]836        INTEGERconstant fraction_constants_opt
[bb7422a]837                { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_constantInteger( yylloc, *$1 ), $2 ) ); }
[df22130]838        | FLOATINGconstant fraction_constants_opt
[bb7422a]839                { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_field_name_FLOATINGconstant( yylloc, *$1 ), $2 ) ); }
[e16eb460]840        | identifier_at fraction_constants_opt                          // CFA, allow anonymous fields
[4cb935e]841                {
[bb7422a]842                        $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_varref( yylloc, $1 ), $2 ) );
[84d58c5]843                }
[1b29996]844        ;
845
[df22130]846fraction_constants_opt:
[1b29996]847        // empty
[8780e30]848                { $$ = nullptr; }
[df22130]849        | fraction_constants_opt FLOATING_FRACTIONconstant
[8780e30]850                {
[bb7422a]851                        ast::Expr * constant = build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 );
852                        $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( yylloc, $1, constant ) ) : new ExpressionNode( constant );
[8780e30]853                }
[faddbd8]854        ;
855
[51b7345]856unary_expression:
[4d51835]857        postfix_expression
[c6b1105]858                // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires
859                // semantics checks, e.g., ++3, 3--, *3, &&3
[51b1202]860        | constant
[ab57786]861        | string_literal
[32d6fdc]862                { $$ = $1; }
[4d51835]863        | EXTENSION cast_expression                                                     // GCC
[e04ef3a]864                { $$ = $2->set_extension( true ); }
[c6b1105]865                // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:
866                //              { * X; }         // dereference X
867                //              { * int X; } // CFA declaration of pointer to int
[51e076e]868        | ptrref_operator cast_expression                                       // CFA
[9706554]869                {
870                        switch ( $1 ) {
[bb7422a]871                        case OperKinds::AddressOf:
872                                $$ = new ExpressionNode( new ast::AddressExpr( maybeMoveBuild( $2 ) ) );
[9706554]873                                break;
[bb7422a]874                        case OperKinds::PointTo:
875                                $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) );
[9706554]876                                break;
[bb7422a]877                        case OperKinds::And:
878                                $$ = new ExpressionNode( new ast::AddressExpr( new ast::AddressExpr( maybeMoveBuild( $2 ) ) ) );
[5809461]879                                break;
[bb7422a]880                        default:
[9706554]881                                assert( false );
882                        }
883                }
[4d51835]884        | unary_operator cast_expression
[bb7422a]885                { $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) ); }
[dd51906]886        | ICR unary_expression
[bb7422a]887                { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Incr, $2 ) ); }
[dd51906]888        | DECR unary_expression
[bb7422a]889                { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Decr, $2 ) ); }
[4d51835]890        | SIZEOF unary_expression
[bb7422a]891                { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuild( $2 ) ) ); }
[84d58c5]892        | SIZEOF '(' type_no_function ')'
[bb7422a]893                { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
[d1625f8]894        | ALIGNOF unary_expression                                                      // GCC, variable alignment
[bb7422a]895                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuild( $2 ) ) ); }
[a2e0687]896        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
[bb7422a]897                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
[033ff37]898        | OFFSETOF '(' type_no_function ',' identifier ')'
[bb7422a]899                { $$ = new ExpressionNode( build_offsetOf( yylloc, $3, build_varref( yylloc, $5 ) ) ); }
[1f652a7]900        | TYPEID '(' type_no_function ')'
901                {
902                        SemanticError( yylloc, "typeid name is currently unimplemented." ); $$ = nullptr;
903                        // $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) );
904                }
[4d51835]905        ;
[51b7345]906
[dd51906]907ptrref_operator:
[d9e2280]908        '*'                                                                                     { $$ = OperKinds::PointTo; }
909        | '&'                                                                           { $$ = OperKinds::AddressOf; }
[c6b1105]910                // GCC, address of label must be handled by semantic check for ref,ref,label
[9f07232]911        | ANDAND                                                                        { $$ = OperKinds::And; }
[dd51906]912        ;
913
[51b7345]914unary_operator:
[d9e2280]915        '+'                                                                                     { $$ = OperKinds::UnPlus; }
916        | '-'                                                                           { $$ = OperKinds::UnMinus; }
917        | '!'                                                                           { $$ = OperKinds::Neg; }
918        | '~'                                                                           { $$ = OperKinds::BitNeg; }
[4d51835]919        ;
[51b7345]920
921cast_expression:
[4d51835]922        unary_expression
[84d58c5]923        | '(' type_no_function ')' cast_expression
[bb7422a]924                { $$ = new ExpressionNode( build_cast( yylloc, $2, $4 ) ); }
[e307e12]925        | '(' aggregate_control '&' ')' cast_expression         // CFA
[bb7422a]926                { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); }
[24711a3]927        | '(' aggregate_control '*' ')' cast_expression         // CFA
[bb7422a]928                { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); }
[fae90d5]929        | '(' VIRTUAL ')' cast_expression                                       // CFA
[bb7422a]930                { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); }
[fae90d5]931        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
[bb7422a]932                { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }
[1528a2c]933        | '(' RETURN type_no_function ')' cast_expression       // CFA
[24d6572]934                { $$ = new ExpressionNode( build_cast( yylloc, $3, $5, ast::CastExpr::Return ) ); }
[1528a2c]935        | '(' COERCE type_no_function ')' cast_expression       // CFA
936                { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; }
937        | '(' qualifier_cast_list ')' cast_expression           // CFA
938                { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; }
[84d58c5]939//      | '(' type_no_function ')' tuple
[bb7422a]940//              { $$ = new ast::ExpressionNode( build_cast( yylloc, $2, $4 ) ); }
[4d51835]941        ;
[51b7345]942
[1528a2c]943qualifier_cast_list:
944        cast_modifier type_qualifier_name
945        | cast_modifier MUTEX
946        | qualifier_cast_list cast_modifier type_qualifier_name
947        | qualifier_cast_list cast_modifier MUTEX
948        ;
949
950cast_modifier:
951        '-'
952        | '+'
953        ;
954
[994d080]955exponential_expression:
[4d51835]956        cast_expression
[994d080]957        | exponential_expression '\\' cast_expression
[bb7422a]958                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Exp, $1, $3 ) ); }
[994d080]959        ;
960
961multiplicative_expression:
962        exponential_expression
963        | multiplicative_expression '*' exponential_expression
[bb7422a]964                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mul, $1, $3 ) ); }
[994d080]965        | multiplicative_expression '/' exponential_expression
[bb7422a]966                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Div, $1, $3 ) ); }
[994d080]967        | multiplicative_expression '%' exponential_expression
[bb7422a]968                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mod, $1, $3 ) ); }
[4d51835]969        ;
[51b7345]970
971additive_expression:
[4d51835]972        multiplicative_expression
973        | additive_expression '+' multiplicative_expression
[bb7422a]974                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Plus, $1, $3 ) ); }
[4d51835]975        | additive_expression '-' multiplicative_expression
[bb7422a]976                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Minus, $1, $3 ) ); }
[4d51835]977        ;
[51b7345]978
979shift_expression:
[4d51835]980        additive_expression
981        | shift_expression LS additive_expression
[bb7422a]982                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LShift, $1, $3 ) ); }
[4d51835]983        | shift_expression RS additive_expression
[bb7422a]984                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::RShift, $1, $3 ) ); }
[4d51835]985        ;
[51b7345]986
987relational_expression:
[4d51835]988        shift_expression
989        | relational_expression '<' shift_expression
[bb7422a]990                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LThan, $1, $3 ) ); }
[4d51835]991        | relational_expression '>' shift_expression
[bb7422a]992                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GThan, $1, $3 ) ); }
[4d51835]993        | relational_expression LE shift_expression
[bb7422a]994                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LEThan, $1, $3 ) ); }
[4d51835]995        | relational_expression GE shift_expression
[bb7422a]996                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GEThan, $1, $3 ) ); }
[4d51835]997        ;
[51b7345]998
999equality_expression:
[4d51835]1000        relational_expression
1001        | equality_expression EQ relational_expression
[bb7422a]1002                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Eq, $1, $3 ) ); }
[4d51835]1003        | equality_expression NE relational_expression
[bb7422a]1004                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Neq, $1, $3 ) ); }
[4d51835]1005        ;
[51b7345]1006
1007AND_expression:
[4d51835]1008        equality_expression
1009        | AND_expression '&' equality_expression
[bb7422a]1010                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitAnd, $1, $3 ) ); }
[4d51835]1011        ;
[51b7345]1012
1013exclusive_OR_expression:
[4d51835]1014        AND_expression
1015        | exclusive_OR_expression '^' AND_expression
[bb7422a]1016                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Xor, $1, $3 ) ); }
[4d51835]1017        ;
[51b7345]1018
1019inclusive_OR_expression:
[4d51835]1020        exclusive_OR_expression
1021        | inclusive_OR_expression '|' exclusive_OR_expression
[bb7422a]1022                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitOr, $1, $3 ) ); }
[4d51835]1023        ;
[51b7345]1024
1025logical_AND_expression:
[4d51835]1026        inclusive_OR_expression
1027        | logical_AND_expression ANDAND inclusive_OR_expression
[bb7422a]1028                { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::AndExpr ) ); }
[4d51835]1029        ;
[51b7345]1030
1031logical_OR_expression:
[4d51835]1032        logical_AND_expression
1033        | logical_OR_expression OROR logical_AND_expression
[bb7422a]1034                { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::OrExpr ) ); }
[4d51835]1035        ;
[51b7345]1036
1037conditional_expression:
[4d51835]1038        logical_OR_expression
1039        | logical_OR_expression '?' comma_expression ':' conditional_expression
[bb7422a]1040                { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); }
[fae90d5]1041                // FIX ME: computes $1 twice
[4d51835]1042        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
[a983cbf]1043                { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
[4d51835]1044        ;
[51b7345]1045
1046constant_expression:
[4d51835]1047        conditional_expression
1048        ;
[51b7345]1049
1050assignment_expression:
[4d51835]1051                // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
1052        conditional_expression
1053        | unary_expression assignment_operator assignment_expression
[9867cdb]1054                {
[25744d2]1055//                      if ( $2 == OperKinds::AtAssn ) {
1056//                              SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr;
1057//                      } else {
[bb7422a]1058                                $$ = new ExpressionNode( build_binary_val( yylloc, $2, $1, $3 ) );
[25744d2]1059//                      } // if
[9867cdb]1060                }
[7fdb94e]1061        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
[fae90d5]1062                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
[4d51835]1063        ;
[51b7345]1064
1065assignment_expression_opt:
[4d51835]1066        // empty
[d1625f8]1067                { $$ = nullptr; }
[4d51835]1068        | assignment_expression
1069        ;
[b87a5ed]1070
[9706554]1071assignment_operator:
[f9c3100]1072        simple_assignment_operator
1073        | compound_assignment_operator
1074        ;
1075
1076simple_assignment_operator:
[d9e2280]1077        '='                                                                                     { $$ = OperKinds::Assign; }
[f9c3100]1078        | ATassign                                                                      { $$ = OperKinds::AtAssn; } // CFA
1079        ;
1080
1081compound_assignment_operator:
1082        EXPassign                                                                       { $$ = OperKinds::ExpAssn; }
[d9e2280]1083        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
1084        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
1085        | MODassign                                                                     { $$ = OperKinds::ModAssn; }
1086        | PLUSassign                                                            { $$ = OperKinds::PlusAssn; }
1087        | MINUSassign                                                           { $$ = OperKinds::MinusAssn; }
1088        | LSassign                                                                      { $$ = OperKinds::LSAssn; }
1089        | RSassign                                                                      { $$ = OperKinds::RSAssn; }
1090        | ANDassign                                                                     { $$ = OperKinds::AndAssn; }
1091        | ERassign                                                                      { $$ = OperKinds::ERAssn; }
1092        | ORassign                                                                      { $$ = OperKinds::OrAssn; }
[413ad05]1093        ;
[9706554]1094
[b87a5ed]1095tuple:                                                                                                  // CFA, tuple
[de62360d]1096                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
[c0aa336]1097                // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array
[1b29996]1098//      '[' ']'
1099//              { $$ = new ExpressionNode( build_tuple() ); }
[13e8427]1100//      | '[' push assignment_expression pop ']'
[1b29996]1101//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
[17238fd]1102        '[' ',' tuple_expression_list ']'
[bb7422a]1103                { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
[17238fd]1104        | '[' push assignment_expression pop ',' tuple_expression_list ']'
[bb7422a]1105                { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $6 ) ) )); }
[4d51835]1106        ;
[51b7345]1107
1108tuple_expression_list:
[0a6d8204]1109        assignment_expression
1110        | '@'                                                                                           // CFA
1111                { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
1112        | tuple_expression_list ',' assignment_expression
[4a063df]1113                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
[0a6d8204]1114        | tuple_expression_list ',' '@'
1115                { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
[4d51835]1116        ;
[51b7345]1117
1118comma_expression:
[4d51835]1119        assignment_expression
[9706554]1120        | comma_expression ',' assignment_expression
[bb7422a]1121                { $$ = new ExpressionNode( new ast::CommaExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
[4d51835]1122        ;
[51b7345]1123
1124comma_expression_opt:
[4d51835]1125        // empty
[58dd019]1126                { $$ = nullptr; }
[4d51835]1127        | comma_expression
1128        ;
[51b7345]1129
[e1d66c84]1130// ************************** STATEMENTS *******************************
[51b7345]1131
1132statement:
[4d51835]1133        labeled_statement
1134        | compound_statement
[c0a33d2]1135        | expression_statement
[4d51835]1136        | selection_statement
1137        | iteration_statement
1138        | jump_statement
[8b47e50]1139        | with_statement
[b6b3c42]1140        | mutex_statement
[5b2edbc]1141        | waitfor_statement
[9fd9d015]1142        | waituntil_statement
[11ab0b4a]1143        | corun_statement
1144        | cofor_statement
[4d51835]1145        | exception_statement
[2a8427c6]1146        | enable_disable_statement
[fae90d5]1147                { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; }
[4d51835]1148        | asm_statement
[61fc4f6]1149        | DIRECTIVE
[bb7422a]1150                { $$ = new StatementNode( build_directive( yylloc, $1 ) ); }
[b9be000b]1151        ;
[51b7345]1152
1153labeled_statement:
[033ff37]1154                // labels cannot be identifiers 0 or 1
[44a81853]1155        identifier_or_type_name ':' attribute_list_opt statement
[bb7422a]1156                { $$ = $4->add_label( yylloc, $1, $3 ); }
[0442f93f]1157        | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule
[afe9e45]1158                {
[b1f2007]1159                        SemanticError( yylloc, "syntx error, label \"%s\" must be associated with a statement, "
1160                                                   "where a declaration, case, or default is not a statement.\n"
1161                                                   "Move the label or terminate with a semicolon.", $1.str->c_str() );
[afe9e45]1162                        $$ = nullptr;
1163                }
[4d51835]1164        ;
[51b7345]1165
1166compound_statement:
[4d51835]1167        '{' '}'
[bb7422a]1168                { $$ = new StatementNode( build_compound( yylloc, (StatementNode *)0 ) ); }
[35718a9]1169        | '{' push
[5e25953]1170          local_label_declaration_opt                                           // GCC, local labels appear at start of block
[9bd6105]1171          statement_decl_list                                                           // C99, intermix declarations and statements
[c0aa336]1172          pop '}'
[bb7422a]1173                { $$ = new StatementNode( build_compound( yylloc, $4 ) ); }
[4d51835]1174        ;
[b87a5ed]1175
[9bd6105]1176statement_decl_list:                                                                    // C99
1177        statement_decl
[35718a9]1178        | statement_decl_list statement_decl
[6d01d89]1179                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
[4d51835]1180        ;
[51b7345]1181
[9bd6105]1182statement_decl:
[4d51835]1183        declaration                                                                                     // CFA, new & old style declarations
[e82aa9df]1184                { $$ = new StatementNode( $1 ); }
[4d51835]1185        | EXTENSION declaration                                                         // GCC
[6d01d89]1186                { distExt( $2 ); $$ = new StatementNode( $2 ); }
[4d51835]1187        | function_definition
[e82aa9df]1188                { $$ = new StatementNode( $1 ); }
[c0aa336]1189        | EXTENSION function_definition                                         // GCC
[6d01d89]1190                { distExt( $2 ); $$ = new StatementNode( $2 ); }
[35718a9]1191        | statement
[4d51835]1192        ;
[51b7345]1193
[9bd6105]1194statement_list_nodecl:
[4d51835]1195        statement
[9bd6105]1196        | statement_list_nodecl statement
[6d01d89]1197                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
[0442f93f]1198        | statement_list_nodecl error                                           // invalid syntax rule
[55266c7]1199                { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
[4d51835]1200        ;
[51b7345]1201
1202expression_statement:
[4d51835]1203        comma_expression_opt ';'
[bb7422a]1204                { $$ = new StatementNode( build_expr( yylloc, $1 ) ); }
[4d51835]1205        ;
[51b7345]1206
1207selection_statement:
[3d26610]1208                        // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
1209                        // the inherent S/R conflict with THEN/ELSE.
1210        push if_statement pop
1211                { $$ = $2; }
[4cc585b]1212        | SWITCH '(' comma_expression ')' case_clause
[bb7422a]1213                { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); }
[35718a9]1214        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
[4e06c1e]1215                {
[bb7422a]1216                        StatementNode *sw = new StatementNode( build_switch( yylloc, true, $3, $8 ) );
[4e06c1e]1217                        // The semantics of the declaration list is changed to include associated initialization, which is performed
1218                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
1219                        // statement around the switch.  Statements after the initial declaration list can never be executed, and
[8688ce1]1220                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
1221                        // statement.
[bb7422a]1222                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
[4e06c1e]1223                }
[0442f93f]1224        | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule error
[55266c7]1225                { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
[4d51835]1226        | CHOOSE '(' comma_expression ')' case_clause           // CFA
[bb7422a]1227                { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); }
[35718a9]1228        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
[4e06c1e]1229                {
[bb7422a]1230                        StatementNode *sw = new StatementNode( build_switch( yylloc, false, $3, $8 ) );
1231                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
[4e06c1e]1232                }
[0442f93f]1233        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
[55266c7]1234                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
[4d51835]1235        ;
[b87a5ed]1236
[3d26610]1237if_statement:
[473d1da0]1238        IF '(' conditional_declaration ')' statement            %prec THEN
[3d26610]1239                // explicitly deal with the shift/reduce conflict on if/else
[bb7422a]1240                { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); }
[473d1da0]1241        | IF '(' conditional_declaration ')' statement ELSE statement
[bb7422a]1242                { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); }
[3d26610]1243        ;
1244
[473d1da0]1245conditional_declaration:
[35718a9]1246        comma_expression
[473d1da0]1247                { $$ = new CondCtl( nullptr, $1 ); }
[35718a9]1248        | c_declaration                                                                         // no semi-colon
[473d1da0]1249                { $$ = new CondCtl( $1, nullptr ); }
[35718a9]1250        | cfa_declaration                                                                       // no semi-colon
[473d1da0]1251                { $$ = new CondCtl( $1, nullptr ); }
[6d49ea3]1252        | declaration comma_expression                                          // semi-colon separated
[473d1da0]1253                { $$ = new CondCtl( $1, $2 ); }
[9fd9d015]1254        ;
[936e9f4]1255
[de62360d]1256// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
1257// clause allows a list of values and subranges.
[b87a5ed]1258
1259case_value:                                                                                             // CFA
[4d51835]1260        constant_expression                                                     { $$ = $1; }
1261        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
[bb7422a]1262                { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
[4d51835]1263        | subrange                                                                                      // CFA, subrange
1264        ;
[b87a5ed]1265
1266case_value_list:                                                                                // CFA
[6611177]1267        case_value                                                                      { $$ = new ClauseNode( build_case( yylloc, $1 ) ); }
[064e3ff]1268                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
[6611177]1269        | case_value_list ',' case_value                        { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); }
[4d51835]1270        ;
[b87a5ed]1271
1272case_label:                                                                                             // CFA
[0442f93f]1273        CASE error                                                                                      // invalid syntax rule
[55266c7]1274                { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; }
[5c216b4]1275        | CASE case_value_list ':'                                      { $$ = $2; }
[0442f93f]1276        | CASE case_value_list error                                            // invalid syntax rule
[55266c7]1277                { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; }
[6611177]1278        | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
[4d51835]1279                // A semantic check is required to ensure only one default clause per switch/choose statement.
[65ef0cd]1280        | DEFAULT error                                                                         //  invalid syntax rule
[55266c7]1281                { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; }
[4d51835]1282        ;
[b87a5ed]1283
1284case_label_list:                                                                                // CFA
[4d51835]1285        case_label
[6611177]1286        | case_label_list case_label                            { $$ = $1->set_last( $2 ); }
[4d51835]1287        ;
[b87a5ed]1288
1289case_clause:                                                                                    // CFA
[bb7422a]1290        case_label_list statement                                       { $$ = $1->append_last_case( maybe_build_compound( yylloc, $2 ) ); }
[4d51835]1291        ;
[b87a5ed]1292
1293switch_clause_list_opt:                                                                 // CFA
[4d51835]1294        // empty
[58dd019]1295                { $$ = nullptr; }
[4d51835]1296        | switch_clause_list
1297        ;
[b87a5ed]1298
1299switch_clause_list:                                                                             // CFA
[9bd6105]1300        case_label_list statement_list_nodecl
[bb7422a]1301                { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); }
[9bd6105]1302        | switch_clause_list case_label_list statement_list_nodecl
[6611177]1303                { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); }
[4d51835]1304        ;
[b87a5ed]1305
[51b7345]1306iteration_statement:
[5695645]1307        WHILE '(' ')' statement                                                         %prec THEN // CFA => while ( 1 )
[bb7422a]1308                { $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) ); }
[5695645]1309        | WHILE '(' ')' statement ELSE statement                        // CFA
[86b8d16]1310                {
[bb7422a]1311                        $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) );
[3d937e2]1312                        SemanticWarning( yylloc, Warning::SuperfluousElse );
[86b8d16]1313                }
[473d1da0]1314        | WHILE '(' conditional_declaration ')' statement       %prec THEN
[bb7422a]1315                { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
[473d1da0]1316        | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA
[bb7422a]1317                { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); }
[f271bdd]1318        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
[bb7422a]1319                { $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) ); }
[5695645]1320        | DO statement WHILE '(' ')' ELSE statement                     // CFA
[86b8d16]1321                {
[bb7422a]1322                        $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) );
[3d937e2]1323                        SemanticWarning( yylloc, Warning::SuperfluousElse );
[86b8d16]1324                }
1325        | DO statement WHILE '(' comma_expression ')' ';'
[bb7422a]1326                { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ) ) ); }
[efc8f3e]1327        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
[bb7422a]1328                { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ), $8 ) ); }
[86b8d16]1329        | FOR '(' ')' statement                                                         %prec THEN // CFA => for ( ;; )
[bb7422a]1330                { $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) ); }
[86b8d16]1331        | FOR '(' ')' statement ELSE statement                          // CFA
1332                {
[bb7422a]1333                        $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) );
[3d937e2]1334                        SemanticWarning( yylloc, Warning::SuperfluousElse );
[86b8d16]1335                }
[efc8f3e]1336        | FOR '(' for_control_expression_list ')' statement     %prec THEN
[bb7422a]1337                { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
[efc8f3e]1338        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
[bb7422a]1339                { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); }
[a73c16e]1340        ;
1341
[6d01d89]1342for_control_expression_list:
1343        for_control_expression
1344        | for_control_expression_list ':' for_control_expression
[67d4e37]1345                // ForCtrl + ForCtrl:
1346                //    init + init => multiple declaration statements that are hoisted
1347                //    condition + condition => (expression) && (expression)
1348                //    change + change => (expression), (expression)
1349                {
1350                        $1->init->set_last( $3->init );
1351                        if ( $1->condition ) {
1352                                if ( $3->condition ) {
[bb7422a]1353                                        $1->condition->expr.reset( new ast::LogicalExpr( yylloc, $1->condition->expr.release(), $3->condition->expr.release(), ast::AndExpr ) );
[67d4e37]1354                                } // if
1355                        } else $1->condition = $3->condition;
1356                        if ( $1->change ) {
1357                                if ( $3->change ) {
[bb7422a]1358                                        $1->change->expr.reset( new ast::CommaExpr( yylloc, $1->change->expr.release(), $3->change->expr.release() ) );
[67d4e37]1359                                } // if
1360                        } else $1->change = $3->change;
1361                        $$ = $1;
1362                }
[6d01d89]1363        ;
1364
[51b7345]1365for_control_expression:
[6d01d89]1366        ';' comma_expression_opt ';' comma_expression_opt
[1cdc052]1367                { $$ = new ForCtrl( nullptr, $2, $4 ); }
[6d01d89]1368        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
[1cdc052]1369                {
[bb7422a]1370                        StatementNode * init = $1 ? new StatementNode( new ast::ExprStmt( yylloc, maybeMoveBuild( $1 ) ) ) : nullptr;
[1cdc052]1371                        $$ = new ForCtrl( init, $3, $5 );
1372                }
[6d01d89]1373        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
[1cdc052]1374                { $$ = new ForCtrl( new StatementNode( $1 ), $2, $4 ); }
[67d4e37]1375
[aa122e9]1376        | '@' ';' comma_expression                                                      // CFA, empty loop-index
[1cdc052]1377                { $$ = new ForCtrl( nullptr, $3, nullptr ); }
[aa122e9]1378        | '@' ';' comma_expression ';' comma_expression         // CFA, empty loop-index
[1cdc052]1379                { $$ = new ForCtrl( nullptr, $3, $5 ); }
[51fbba5]1380
[aa122e9]1381        | comma_expression                                                                      // CFA, anonymous loop-index
[bb7422a]1382                { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); }
[aa122e9]1383        | downupdowneq comma_expression                                         // CFA, anonymous loop-index
[bb7422a]1384                { $$ = forCtrl( yylloc, $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); }
[52be5948]1385
[aa122e9]1386        | comma_expression updowneq comma_expression            // CFA, anonymous loop-index
[bb7422a]1387                { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); }
[aa122e9]1388        | '@' updowneq comma_expression                                         // CFA, anonymous loop-index
[dbedd71]1389                {
[4fee301]1390                        if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1391                        else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, NEW_ONE );
[dbedd71]1392                }
[aa122e9]1393        | comma_expression updowneq '@'                                         // CFA, anonymous loop-index
[dbedd71]1394                {
[4fee301]1395                        if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[ed9a1ae]1396                        else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[dbedd71]1397                }
[aa122e9]1398        | comma_expression updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index
[bb7422a]1399                { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); }
[aa122e9]1400        | '@' updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index
[dbedd71]1401                {
[4fee301]1402                        if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1403                        else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, $5 );
[dbedd71]1404                }
[aa122e9]1405        | comma_expression updowneq '@' '~' comma_expression // CFA, anonymous loop-index
[dbedd71]1406                {
[4fee301]1407                        if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[ed9a1ae]1408                        else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[dbedd71]1409                }
[65ef0cd]1410        | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rule
[4fee301]1411                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[65ef0cd]1412        | '@' updowneq '@'                                                                      // CFA, invalid syntax rule
[4fee301]1413                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[65ef0cd]1414        | '@' updowneq comma_expression '~' '@'                         // CFA, invalid syntax rule
[4fee301]1415                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[65ef0cd]1416        | comma_expression updowneq '@' '~' '@'                         // CFA, invalid syntax rule
[4fee301]1417                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[65ef0cd]1418        | '@' updowneq '@' '~' '@'                                                      // CFA, invalid syntax rule
[4fee301]1419                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
[52be5948]1420
[f1aeede]1421        | comma_expression ';' comma_expression                         // CFA
[bb7422a]1422                { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }
[d78c238]1423        | comma_expression ';' downupdowneq comma_expression // CFA
[bb7422a]1424                { $$ = forCtrl( yylloc, $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); }
[52be5948]1425
[d78c238]1426        | comma_expression ';' comma_expression updowneq comma_expression // CFA
[bb7422a]1427                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); }
[dbedd71]1428        | comma_expression ';' '@' updowneq comma_expression // CFA
1429                {
[4fee301]1430                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1431                        else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, NEW_ONE );
[dbedd71]1432                }
[52be5948]1433        | comma_expression ';' comma_expression updowneq '@' // CFA
1434                {
[4fee301]1435                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1436                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1437                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
[52be5948]1438                }
[65ef0cd]1439        | comma_expression ';' '@' updowneq '@'                         // CFA, invalid syntax rule
[55266c7]1440                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
[d78c238]1441
1442        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
[bb7422a]1443                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }
[65ef0cd]1444        | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, invalid syntax rule
[dbedd71]1445                {
[4fee301]1446                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1447                        else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, $7 );
[dbedd71]1448                }
[52be5948]1449        | comma_expression ';' comma_expression updowneq '@' '~' comma_expression // CFA
1450                {
[4fee301]1451                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1452                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1453                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 );
[52be5948]1454                }
1455        | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA
[bb7422a]1456                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }
[65ef0cd]1457        | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rule
[dbedd71]1458                {
[4fee301]1459                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1460                        else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, nullptr );
[dbedd71]1461                }
[52be5948]1462        | comma_expression ';' comma_expression updowneq '@' '~' '@' // CFA
[d78c238]1463                {
[4fee301]1464                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1465                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1466                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr );
[d78c238]1467                }
[dbedd71]1468        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
[55266c7]1469                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
[d78c238]1470
1471        | declaration comma_expression                                          // CFA
[bb7422a]1472                { $$ = forCtrl( yylloc, $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); }
[d78c238]1473        | declaration downupdowneq comma_expression                     // CFA
[bb7422a]1474                { $$ = forCtrl( yylloc, $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); }
[52be5948]1475
[d78c238]1476        | declaration comma_expression updowneq comma_expression // CFA
[bb7422a]1477                { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); }
[dbedd71]1478        | declaration '@' updowneq comma_expression                     // CFA
1479                {
[4fee301]1480                        if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1481                        else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, NEW_ONE );
[dbedd71]1482                }
[52be5948]1483        | declaration comma_expression updowneq '@'                     // CFA
1484                {
[4fee301]1485                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1486                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1487                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE );
[52be5948]1488                }
[d78c238]1489
1490        | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA
[bb7422a]1491                { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); }
[dbedd71]1492        | declaration '@' updowneq comma_expression '~' comma_expression // CFA
1493                {
[4fee301]1494                        if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1495                        else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, $6 );
[dbedd71]1496                }
[52be5948]1497        | declaration comma_expression updowneq '@' '~' comma_expression // CFA
1498                {
[4fee301]1499                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1500                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1501                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 );
[52be5948]1502                }
1503        | declaration comma_expression updowneq comma_expression '~' '@' // CFA
[bb7422a]1504                { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); }
[dbedd71]1505        | declaration '@' updowneq comma_expression '~' '@' // CFA
1506                {
[4fee301]1507                        if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
[bb7422a]1508                        else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, nullptr );
[dbedd71]1509                }
[52be5948]1510        | declaration comma_expression updowneq '@' '~' '@'     // CFA
[d78c238]1511                {
[4fee301]1512                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
[55266c7]1513                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
[bb7422a]1514                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr );
[d78c238]1515                }
[65ef0cd]1516        | declaration '@' updowneq '@' '~' '@'                          // CFA, invalid syntax rule
[55266c7]1517                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
[67d4e37]1518
[ca33b15]1519        | comma_expression ';' TYPEDEFname                                      // CFA, array type
1520                {
[d78c238]1521                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
1522                        //$$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr );
[ca33b15]1523                }
[d78c238]1524        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
1525                {
[55266c7]1526                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
[0442f93f]1527                                SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
[55266c7]1528                        }
[d78c238]1529                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
1530                }
[9fd9d015]1531        ;
[98337569]1532
[d78c238]1533downupdowneq:
1534        ErangeDown
1535                { $$ = OperKinds::GThan; }
1536        | ErangeUpEq
1537                { $$ = OperKinds::LEThan; }
1538        | ErangeDownEq
1539                { $$ = OperKinds::GEThan; }
[9fd9d015]1540        ;
[51b7345]1541
[d78c238]1542updown:
[cc22003]1543        '~'
1544                { $$ = OperKinds::LThan; }
[d69f4bb4]1545        | ErangeDown
1546                { $$ = OperKinds::GThan; }
[9fd9d015]1547        ;
[d78c238]1548
1549updowneq:
1550        updown
1551        | ErangeUpEq
1552                { $$ = OperKinds::LEThan; }
[d69f4bb4]1553        | ErangeDownEq
1554                { $$ = OperKinds::GEThan; }
[9fd9d015]1555        ;
[cc22003]1556
[51b7345]1557jump_statement:
[44a81853]1558        GOTO identifier_or_type_name ';'
[bb7422a]1559                { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Goto ) ); }
[4d51835]1560        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
[4e06c1e]1561                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
[de62360d]1562                // whereas normal operator precedence yields goto (*i)+3;
[e82aa9df]1563                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
[6a276a0]1564                // A semantic check is required to ensure fallthru appears only in the body of a choose statement.
[ec3f9c8]1565        | fall_through_name ';'                                                         // CFA
[bb7422a]1566                { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThrough ) ); }
[ec3f9c8]1567        | fall_through_name identifier_or_type_name ';'         // CFA
[bb7422a]1568                { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::FallThrough ) ); }
[6a276a0]1569        | fall_through_name DEFAULT ';'                                         // CFA
[bb7422a]1570                { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThroughDefault ) ); }
[4d51835]1571        | CONTINUE ';'
[de62360d]1572                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[bb7422a]1573                { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Continue ) ); }
[44a81853]1574        | CONTINUE identifier_or_type_name ';'                          // CFA, multi-level continue
[de62360d]1575                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
1576                // the target of the transfer appears only at the start of an iteration statement.
[bb7422a]1577                { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Continue ) ); }
[4d51835]1578        | BREAK ';'
[de62360d]1579                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[bb7422a]1580                { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Break ) ); }
[44a81853]1581        | BREAK identifier_or_type_name ';'                                     // CFA, multi-level exit
[de62360d]1582                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
1583                // the target of the transfer appears only at the start of an iteration statement.
[bb7422a]1584                { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Break ) ); }
[4d51835]1585        | RETURN comma_expression_opt ';'
[bb7422a]1586                { $$ = new StatementNode( build_return( yylloc, $2 ) ); }
[c786e1d]1587        | RETURN '{' initializer_list_opt comma_opt '}' ';'
[fae90d5]1588                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
[37cdd97]1589        | SUSPEND ';'
[bb7422a]1590                { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::None ) ); }
[9306559f]1591        | SUSPEND compound_statement
[bb7422a]1592                { $$ = new StatementNode( build_suspend( yylloc, $2, ast::SuspendStmt::None ) ); }
[37cdd97]1593        | SUSPEND COROUTINE ';'
[bb7422a]1594                { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Coroutine ) ); }
[37cdd97]1595        | SUSPEND COROUTINE compound_statement
[bb7422a]1596                { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Coroutine ) ); }
[37cdd97]1597        | SUSPEND GENERATOR ';'
[bb7422a]1598                { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Generator ) ); }
[37cdd97]1599        | SUSPEND GENERATOR compound_statement
[bb7422a]1600                { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Generator ) ); }
[8cc5cb0]1601        | THROW assignment_expression_opt ';'                           // handles rethrow
[bb7422a]1602                { $$ = new StatementNode( build_throw( yylloc, $2 ) ); }
[8cc5cb0]1603        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
[bb7422a]1604                { $$ = new StatementNode( build_resume( yylloc, $2 ) ); }
[8cc5cb0]1605        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
[daf1af8]1606                { $$ = new StatementNode( build_resume_at( $2, $4 ) ); }
[4d51835]1607        ;
[51b7345]1608
[6a276a0]1609fall_through_name:                                                                              // CFA
1610        FALLTHRU
1611        | FALLTHROUGH
1612        ;
1613
[8b47e50]1614with_statement:
[5b2edbc]1615        WITH '(' tuple_expression_list ')' statement
[bb7422a]1616                { $$ = new StatementNode( build_with( yylloc, $3, $5 ) ); }
[5b2edbc]1617        ;
1618
[bf20567]1619// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so possibly change syntax to "with mutex".
[b6b3c42]1620mutex_statement:
[bf20567]1621        MUTEX '(' argument_expression_list_opt ')' statement
1622                {
[55266c7]1623                        if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; }
[bb7422a]1624                        $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) );
[bf20567]1625                }
[b6b3c42]1626        ;
1627
[51d6d6a]1628when_clause:
[6a276a0]1629        WHEN '(' comma_expression ')'                           { $$ = $3; }
[51d6d6a]1630        ;
1631
[5b2edbc]1632when_clause_opt:
1633        // empty
[135b431]1634                { $$ = nullptr; }
[51d6d6a]1635        | when_clause
[5b2edbc]1636        ;
1637
[4a063df]1638cast_expression_list:
1639        cast_expression
1640        | cast_expression_list ',' cast_expression
[a491a3c]1641                // { $$ = (ExpressionNode *)($1->set_last( $3 )); }
1642                { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; }
[5b2edbc]1643        ;
1644
1645timeout:
[9fd9d015]1646        TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
[5b2edbc]1647        ;
1648
[9fd9d015]1649wor:
1650        OROR
1651        | WOR
1652
1653waitfor:
1654        WAITFOR '(' cast_expression ')'
1655                { $$ = $3; }
1656        | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
1657                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
[5b2edbc]1658        ;
1659
[9fd9d015]1660wor_waitfor_clause:
[51d6d6a]1661        when_clause_opt waitfor statement                                       %prec THEN
[9fd9d015]1662                // Called first: create header for WaitForStmt.
[bb7422a]1663                { $$ = build_waitfor( yylloc, new ast::WaitForStmt( yylloc ), $1, $2, maybe_build_compound( yylloc, $3 ) ); }
[70056ed]1664        | wor_waitfor_clause wor when_clause_opt waitfor statement
[bb7422a]1665                { $$ = build_waitfor( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); }
[9fd9d015]1666        | wor_waitfor_clause wor when_clause_opt ELSE statement
[bb7422a]1667                { $$ = build_waitfor_else( yylloc, $1, $3, maybe_build_compound( yylloc, $5 ) ); }
[9fd9d015]1668        | wor_waitfor_clause wor when_clause_opt timeout statement      %prec THEN
[bb7422a]1669                { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); }
[afe9e45]1670        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
[65ef0cd]1671        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rule
[55266c7]1672                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
[9fd9d015]1673        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
[bb7422a]1674                { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); }
[5b2edbc]1675        ;
1676
1677waitfor_statement:
[9fd9d015]1678        wor_waitfor_clause                                                                      %prec THEN
1679                { $$ = new StatementNode( $1 ); }
1680        ;
1681
1682wand:
1683        ANDAND
1684        | WAND
1685        ;
1686
1687waituntil:
[04c78215]1688        WAITUNTIL '(' comma_expression ')'
[9fd9d015]1689                { $$ = $3; }
1690        ;
1691
1692waituntil_clause:
1693        when_clause_opt waituntil statement
[c86b08d]1694                { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); }
[9fd9d015]1695        | '(' wor_waituntil_clause ')'
[c86b08d]1696                { $$ = $2; }
[9fd9d015]1697        ;
1698
1699wand_waituntil_clause:
1700        waituntil_clause                                                                        %prec THEN
[c86b08d]1701                { $$ = $1; }
[9fd9d015]1702        | waituntil_clause wand wand_waituntil_clause
[c86b08d]1703                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); }
[9fd9d015]1704        ;
1705
1706wor_waituntil_clause:
1707        wand_waituntil_clause
[c86b08d]1708                { $$ = $1; }
[70056ed]1709        | wor_waituntil_clause wor wand_waituntil_clause
[c86b08d]1710                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); }
[9fd9d015]1711        | wor_waituntil_clause wor when_clause_opt ELSE statement
[c86b08d]1712                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
[9fd9d015]1713        ;
1714
1715waituntil_statement:
1716        wor_waituntil_clause                                                            %prec THEN
[f259682]1717                { $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) ); }
[8b47e50]1718        ;
1719
[11ab0b4a]1720corun_statement:
1721        CORUN statement
[eb779d5]1722                { $$ = new StatementNode( build_corun( yylloc, $2 ) ); }
[11ab0b4a]1723        ;
1724
1725cofor_statement:
1726        COFOR '(' for_control_expression_list ')' statement
[3d9d017]1727                { $$ = new StatementNode( build_cofor( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
[11ab0b4a]1728        ;
1729
[51b7345]1730exception_statement:
[bb7422a]1731        TRY compound_statement handler_clause                                   %prec THEN
1732                { $$ = new StatementNode( build_try( yylloc, $2, $3, nullptr ) ); }
[4d51835]1733        | TRY compound_statement finally_clause
[bb7422a]1734                { $$ = new StatementNode( build_try( yylloc, $2, nullptr, $3 ) ); }
[cfaabe2c]1735        | TRY compound_statement handler_clause finally_clause
[bb7422a]1736                { $$ = new StatementNode( build_try( yylloc, $2, $3, $4 ) ); }
[4d51835]1737        ;
[51b7345]1738
1739handler_clause:
[098f7ff]1740        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
[6611177]1741                { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
[098f7ff]1742        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
[6611177]1743                { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
[994d080]1744        ;
1745
1746handler_predicate_opt:
[7fdb94e]1747        // empty
[cbce272]1748                { $$ = nullptr; }
[6a276a0]1749        | ';' conditional_expression                            { $$ = $2; }
[307a732]1750        ;
1751
1752handler_key:
[bb7422a]1753        CATCH                                                                           { $$ = ast::Terminate; }
1754        | RECOVER                                                                       { $$ = ast::Terminate; }
1755        | CATCHRESUME                                                           { $$ = ast::Resume; }
1756        | FIXUP                                                                         { $$ = ast::Resume; }
[4d51835]1757        ;
[51b7345]1758
1759finally_clause:
[6611177]1760        FINALLY compound_statement                                      { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); }
[4d51835]1761        ;
[51b7345]1762
1763exception_declaration:
[d0ffed1]1764                // No SUE declaration in parameter list.
1765        type_specifier_nobody
1766        | type_specifier_nobody declarator
[c0a33d2]1767                { $$ = $2->addType( $1 ); }
[d0ffed1]1768        | type_specifier_nobody variable_abstract_declarator
[4d51835]1769                { $$ = $2->addType( $1 ); }
[033ff37]1770        | cfa_abstract_declarator_tuple identifier                      // CFA
[c0a33d2]1771                { $$ = $1->addName( $2 ); }
[c0aa336]1772        | cfa_abstract_declarator_tuple                                         // CFA
[4d51835]1773        ;
[51b7345]1774
[2a8427c6]1775enable_disable_statement:
1776        enable_disable_key identifier_list compound_statement
1777        ;
1778
1779enable_disable_key:
1780        ENABLE
1781        | DISABLE
1782        ;
1783
[51b7345]1784asm_statement:
[ab57786]1785        ASM asm_volatile_opt '(' string_literal ')' ';'
[bb7422a]1786                { $$ = new StatementNode( build_asm( yylloc, $2, $4, nullptr ) ); }
[ab57786]1787        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
[bb7422a]1788                { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6 ) ); }
[ab57786]1789        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
[bb7422a]1790                { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8 ) ); }
[ab57786]1791        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
[bb7422a]1792                { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8, $10 ) ); }
[ab57786]1793        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
[bb7422a]1794                { $$ = new StatementNode( build_asm( yylloc, $2, $5, nullptr, $8, $10, $12 ) ); }
[7f5566b]1795        ;
1796
1797asm_volatile_opt:                                                                               // GCC
1798        // empty
1799                { $$ = false; }
1800        | VOLATILE
1801                { $$ = true; }
[4d51835]1802        ;
[b87a5ed]1803
1804asm_operands_opt:                                                                               // GCC
[4d51835]1805        // empty
[58dd019]1806                { $$ = nullptr; }                                                               // use default argument
[4d51835]1807        | asm_operands_list
1808        ;
[b87a5ed]1809
1810asm_operands_list:                                                                              // GCC
[4d51835]1811        asm_operand
1812        | asm_operands_list ',' asm_operand
[4a063df]1813                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
[4d51835]1814        ;
[b87a5ed]1815
1816asm_operand:                                                                                    // GCC
[ab57786]1817        string_literal '(' constant_expression ')'
[32d6fdc]1818                { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
[665f432]1819        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
[bb7422a]1820                {
[32d6fdc]1821                        $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );
[bb7422a]1822                        delete $2.str;
1823                }
[7f5566b]1824        ;
1825
[4e06c1e]1826asm_clobbers_list_opt:                                                                  // GCC
[7f5566b]1827        // empty
[58dd019]1828                { $$ = nullptr; }                                                               // use default argument
[ab57786]1829        | string_literal
[32d6fdc]1830                { $$ = $1; }
[ab57786]1831        | asm_clobbers_list_opt ',' string_literal
[32d6fdc]1832                { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); }
[4d51835]1833        ;
[b87a5ed]1834
[7f5566b]1835label_list:
[033ff37]1836        identifier
[ab57786]1837                {
[bb7422a]1838                        $$ = new LabelNode(); $$->labels.emplace_back( yylloc, *$1 );
[ab57786]1839                        delete $1;                                                                      // allocated by lexer
1840                }
[033ff37]1841        | label_list ',' identifier
[ab57786]1842                {
[bb7422a]1843                        $$ = $1; $1->labels.emplace_back( yylloc, *$3 );
[ab57786]1844                        delete $3;                                                                      // allocated by lexer
1845                }
[4d51835]1846        ;
[51b7345]1847
[e1d66c84]1848// ****************************** DECLARATIONS *********************************
[51b7345]1849
[b87a5ed]1850declaration_list_opt:                                                                   // used at beginning of switch statement
[35718a9]1851        // empty
[58dd019]1852                { $$ = nullptr; }
[4d51835]1853        | declaration_list
1854        ;
[51b7345]1855
1856declaration_list:
[4d51835]1857        declaration
[35718a9]1858        | declaration_list declaration
1859                { $$ = $1->appendList( $2 ); }
[4d51835]1860        ;
[51b7345]1861
[407bde5]1862KR_parameter_list_opt:                                                                  // used to declare parameter types in K&R style functions
[4cc585b]1863        // empty
[58dd019]1864                { $$ = nullptr; }
[35718a9]1865        | KR_parameter_list
[4d51835]1866        ;
[51b7345]1867
[35718a9]1868KR_parameter_list:
[c25f16b]1869        c_declaration ';'
1870                { $$ = $1; }
1871        | KR_parameter_list c_declaration ';'
1872                { $$ = $1->appendList( $2 ); }
[4d51835]1873        ;
[b87a5ed]1874
[51b1202]1875local_label_declaration_opt:                                                    // GCC, local label
[4d51835]1876        // empty
[51b1202]1877        | local_label_declaration_list
[4d51835]1878        ;
[b87a5ed]1879
[51b1202]1880local_label_declaration_list:                                                   // GCC, local label
1881        LABEL local_label_list ';'
1882        | local_label_declaration_list LABEL local_label_list ';'
[4d51835]1883        ;
[b87a5ed]1884
[51b1202]1885local_label_list:                                                                               // GCC, local label
[033ff37]1886        identifier_or_type_name
1887        | local_label_list ',' identifier_or_type_name
[4d51835]1888        ;
[b87a5ed]1889
[936e9f4]1890declaration:                                                                                    // old & new style declarations
[35718a9]1891        c_declaration ';'
[d8454b9]1892                {
1893                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
[9fd9d015]1894                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
[d8454b9]1895                        //   printf( "\tattr %s\n", attr->name.c_str() );
1896                        // } // for
1897                }
[35718a9]1898        | cfa_declaration ';'                                                           // CFA
[b47b827]1899        | static_assert                                                                         // C11
[4d51835]1900        ;
[b87a5ed]1901
[b9be000b]1902static_assert:
1903        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
[32d6fdc]1904                { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); }
[b47b827]1905        | STATICASSERT '(' constant_expression ')' ';'          // CFA
[bb7422a]1906                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); }
[b9be000b]1907
[de62360d]1908// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
1909// declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to
1910// the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration
1911// modifiers are interpreted from left to right and the entire type specification is distributed across all variables in
1912// the declaration list (as in Pascal).  ANSI C and the new CFA declarations may appear together in the same program
1913// block, but cannot be mixed within a specific declaration.
[c11e31c]1914//
[b87a5ed]1915//                      CFA                                     C
1916//              [10] int x;                     int x[10];              // array of 10 integers
1917//              [10] * char y;          char *y[10];    // array of 10 pointers to char
1918
[c0aa336]1919cfa_declaration:                                                                                // CFA
[4cc585b]1920        cfa_variable_declaration
1921        | cfa_typedef_declaration
1922        | cfa_function_declaration
1923        | type_declaring_list
[2501ae5]1924                { SemanticError( yylloc, "otype declaration is currently unimplemented." ); $$ = nullptr; }
[4cc585b]1925        | trait_specifier
[4d51835]1926        ;
[b87a5ed]1927
[c0aa336]1928cfa_variable_declaration:                                                               // CFA
1929        cfa_variable_specifier initializer_opt
[7fdb94e]1930                { $$ = $1->addInitializer( $2 ); }
[c0aa336]1931        | declaration_qualifier_list cfa_variable_specifier initializer_opt
[de62360d]1932                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
1933                // them as a type_qualifier cannot appear in that context.
[7fdb94e]1934                { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
[c0aa336]1935        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
[7fdb94e]1936                { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
[4d51835]1937        ;
[b87a5ed]1938
[c0aa336]1939cfa_variable_specifier:                                                                 // CFA
[de62360d]1940                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1941                // storage-class
[c0aa336]1942        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
[7fdb94e]1943                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
[c0aa336]1944        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
[7fdb94e]1945                { $$ = $1->addName( $2 )->addAsmName( $3 ); }
[c0aa336]1946        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
[7fdb94e]1947                { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
[4d51835]1948        ;
[b87a5ed]1949
[c0aa336]1950cfa_function_declaration:                                                               // CFA
1951        cfa_function_specifier
1952        | type_qualifier_list cfa_function_specifier
[7fdb94e]1953                { $$ = $2->addQualifiers( $1 ); }
[c0aa336]1954        | declaration_qualifier_list cfa_function_specifier
[7fdb94e]1955                { $$ = $2->addQualifiers( $1 ); }
[c0aa336]1956        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
[7fdb94e]1957                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
[40de461]1958        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
[4d51835]1959                {
[481115f]1960                        // Append the return type at the start (left-hand-side) to each identifier in the list.
1961                        DeclarationNode * ret = new DeclarationNode;
1962                        ret->type = maybeClone( $1->type->base );
[40de461]1963                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
[4d51835]1964                }
1965        ;
[b87a5ed]1966
[c0aa336]1967cfa_function_specifier:                                                                 // CFA
[40de461]1968//      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
[1b29996]1969//              {
[a5f9444]1970//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, nullptr, true );
[1b29996]1971//              }
[40de461]1972//      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
[2871210]1973//              {
1974//                      typedefTable.setNextIdentifier( *$5 );
[a5f9444]1975//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
[2871210]1976//              }
[40de461]1977//      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
[2871210]1978//              {
1979//                      typedefTable.setNextIdentifier( *$5 );
[a5f9444]1980//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
[2871210]1981//              }
1982//      | '[' ']' typegen_name
1983                // identifier_or_type_name must be broken apart because of the sequence:
[4d51835]1984                //
[40de461]1985                //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
[4d51835]1986                //   '[' ']' type_specifier
1987                //
[2871210]1988                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
1989                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
[c744563a]1990        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
[c0aa336]1991                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
[a5f9444]1992                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
[c744563a]1993        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
[a5f9444]1994                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
[4d51835]1995        ;
[b87a5ed]1996
[c0aa336]1997cfa_function_return:                                                                    // CFA
[c0a33d2]1998        '[' push cfa_parameter_list pop ']'
1999                { $$ = DeclarationNode::newTuple( $3 ); }
2000        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
[b048dc3]2001                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'.
[c0a33d2]2002                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
[4d51835]2003        ;
[b87a5ed]2004
[c0aa336]2005cfa_typedef_declaration:                                                                // CFA
2006        TYPEDEF cfa_variable_specifier
[4d51835]2007                {
[71a422a]2008                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "cfa_typedef_declaration 1" );
[4d51835]2009                        $$ = $2->addTypedef();
2010                }
[c0aa336]2011        | TYPEDEF cfa_function_specifier
[4d51835]2012                {
[71a422a]2013                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "cfa_typedef_declaration 2" );
[4d51835]2014                        $$ = $2->addTypedef();
2015                }
[033ff37]2016        | cfa_typedef_declaration pop ',' push identifier
[4d51835]2017                {
[71a422a]2018                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "cfa_typedef_declaration 3" );
[4d51835]2019                        $$ = $1->appendList( $1->cloneType( $5 ) );
2020                }
2021        ;
[b87a5ed]2022
[de62360d]2023// Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as
2024// a separate form of declaration, which syntactically precludes storage-class specifiers and initialization.
[51b7345]2025
2026typedef_declaration:
[4d51835]2027        TYPEDEF type_specifier declarator
2028                {
[71a422a]2029                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 1" );
[ac235a8]2030                        if ( $2->type->forall || ($2->type->kind == TypeData::Aggregate && $2->type->aggregate.params) ) {
2031                                SemanticError( yylloc, "forall qualifier in typedef is currently unimplemented." ); $$ = nullptr;
2032                        } else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3
[4d51835]2033                }
[c25f16b]2034        | typedef_declaration ',' declarator
[4d51835]2035                {
[c25f16b]2036                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" );
2037                        $$ = $1->appendList( $1->cloneBaseType( $3 )->addTypedef() );
[4d51835]2038                }
[de62360d]2039        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
[ac235a8]2040                { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
[4d51835]2041        | type_specifier TYPEDEF declarator
[ac235a8]2042                { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
[4d51835]2043        | type_specifier TYPEDEF type_qualifier_list declarator
[ac235a8]2044                { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; }
[4d51835]2045        ;
[b87a5ed]2046
[721f17a]2047typedef_expression:
[25744d2]2048                // deprecated GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
[033ff37]2049        TYPEDEF identifier '=' assignment_expression
[4d51835]2050                {
[ac235a8]2051                        SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
[4d51835]2052                }
[c25f16b]2053        | typedef_expression ',' identifier '=' assignment_expression
[4d51835]2054                {
[ac235a8]2055                        SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
[4d51835]2056                }
2057        ;
[51b7345]2058
[c0aa336]2059c_declaration:
[4cc585b]2060        declaration_specifier declaring_list
[7fdb94e]2061                { $$ = distAttr( $1, $2 ); }
[4cc585b]2062        | typedef_declaration
[25744d2]2063        | typedef_expression                                                            // deprecated GCC, naming expression type
[4cc585b]2064        | sue_declaration_specifier
[0bcd707]2065                {
2066                        assert( $1->type );
[1a73dbb]2067                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
[55266c7]2068                                SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
[1a73dbb]2069                        }
2070                        // enums are never empty declarations because there must have at least one enumeration.
2071                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
[55266c7]2072                                SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
[0bcd707]2073                        }
2074                }
[4d51835]2075        ;
[51b7345]2076
2077declaring_list:
[de62360d]2078                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
2079                // storage-class
[1f771fc]2080        variable_declarator asm_name_opt initializer_opt
[7fdb94e]2081                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
[1f771fc]2082        | variable_type_redeclarator asm_name_opt initializer_opt
[7fdb94e]2083                { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
[1f771fc]2084
2085        | general_function_declarator asm_name_opt
2086                { $$ = $1->addAsmName( $2 )->addInitializer( nullptr ); }
2087        | general_function_declarator asm_name_opt '=' VOID
2088                { $$ = $1->addAsmName( $2 )->addInitializer( new InitializerNode( true ) ); }
2089
[4d51835]2090        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
[7fdb94e]2091                { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
[4d51835]2092        ;
[b87a5ed]2093
[1f771fc]2094general_function_declarator:
2095        function_type_redeclarator
2096        | function_declarator
2097        ;
2098
[b87a5ed]2099declaration_specifier:                                                                  // type specifier + storage class
[4d51835]2100        basic_declaration_specifier
[84d58c5]2101        | type_declaration_specifier
[79a6b17]2102        | sue_declaration_specifier
[0442f93f]2103        | sue_declaration_specifier invalid_types                       // invalid syntax rule
[79a6b17]2104                {
[b1f2007]2105                        SemanticError( yylloc, "syntax error, expecting ';' at end of \"%s\" declaration.",
2106                                                   $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ) );
[79a6b17]2107                        $$ = nullptr;
2108                }
2109        ;
2110
2111invalid_types:
2112        aggregate_key
2113        | basic_type_name
2114        | indirect_type
[4d51835]2115        ;
[b87a5ed]2116
[d0ffed1]2117declaration_specifier_nobody:                                                   // type specifier + storage class - {...}
2118                // Preclude SUE declarations in restricted scopes:
2119                //
2120                //    int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
2121                //
2122                // because it is impossible to call f due to name equivalence.
2123        basic_declaration_specifier
2124        | sue_declaration_specifier_nobody
[84d58c5]2125        | type_declaration_specifier
[d0ffed1]2126        ;
2127
2128type_specifier:                                                                                 // type specifier
[4d51835]2129        basic_type_specifier
2130        | sue_type_specifier
[84d58c5]2131        | type_type_specifier
[4d51835]2132        ;
[b87a5ed]2133
[d0ffed1]2134type_specifier_nobody:                                                                  // type specifier - {...}
2135                // Preclude SUE declarations in restricted scopes:
2136                //
2137                //    int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
2138                //
2139                // because it is impossible to call f due to name equivalence.
2140        basic_type_specifier
2141        | sue_type_specifier_nobody
[84d58c5]2142        | type_type_specifier
[d0ffed1]2143        ;
2144
[b87a5ed]2145type_qualifier_list_opt:                                                                // GCC, used in asm_statement
[4d51835]2146        // empty
[58dd019]2147                { $$ = nullptr; }
[4d51835]2148        | type_qualifier_list
2149        ;
[51b7345]2150
2151type_qualifier_list:
[de62360d]2152                // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration.
[4d51835]2153                //
[de62360d]2154                // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same
2155                // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it
2156                // appeared only once.
[4d51835]2157        type_qualifier
2158        | type_qualifier_list type_qualifier
2159                { $$ = $1->addQualifiers( $2 ); }
2160        ;
[51b7345]2161
2162type_qualifier:
[4d51835]2163        type_qualifier_name
[b1f2007]2164        | attribute                                                                                     // trick handles most attribute locations
[4d51835]2165        ;
[51b7345]2166
2167type_qualifier_name:
[4d51835]2168        CONST
[36e6f10]2169                { $$ = DeclarationNode::newTypeQualifier( ast::CV::Const ); }
[4d51835]2170        | RESTRICT
[36e6f10]2171                { $$ = DeclarationNode::newTypeQualifier( ast::CV::Restrict ); }
[4d51835]2172        | VOLATILE
[36e6f10]2173                { $$ = DeclarationNode::newTypeQualifier( ast::CV::Volatile ); }
[4d51835]2174        | ATOMIC
[36e6f10]2175                { $$ = DeclarationNode::newTypeQualifier( ast::CV::Atomic ); }
[a16a7ec]2176        | forall
[7a24d76]2177                { $$ = DeclarationNode::newForall( $1 ); }
[a16a7ec]2178        ;
2179
2180forall:
[35718a9]2181        FORALL '(' type_parameter_list ')'                                      // CFA
[7a24d76]2182                { $$ = $3; }
[4d51835]2183        ;
[51b7345]2184
2185declaration_qualifier_list:
[4d51835]2186        storage_class_list
[de62360d]2187        | type_qualifier_list storage_class_list                        // remaining OBSOLESCENT (see 2 )
[4d51835]2188                { $$ = $1->addQualifiers( $2 ); }
2189        | declaration_qualifier_list type_qualifier_list storage_class_list
2190                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
2191        ;
[51b7345]2192
2193storage_class_list:
[de62360d]2194                // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that
2195                // only one of each is specified, except for inline, which can appear with the others.
[4d51835]2196                //
[de62360d]2197                // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration
2198                // specifiers in a declaration.
[4d51835]2199        storage_class
2200        | storage_class_list storage_class
2201                { $$ = $1->addQualifiers( $2 ); }
2202        ;
[51b7345]2203
2204storage_class:
[4d51835]2205        EXTERN
[36e6f10]2206                { $$ = DeclarationNode::newStorageClass( ast::Storage::Extern ); }
[4d51835]2207        | STATIC
[36e6f10]2208                { $$ = DeclarationNode::newStorageClass( ast::Storage::Static ); }
[4d51835]2209        | AUTO
[36e6f10]2210                { $$ = DeclarationNode::newStorageClass( ast::Storage::Auto ); }
[4d51835]2211        | REGISTER
[36e6f10]2212                { $$ = DeclarationNode::newStorageClass( ast::Storage::Register ); }
[ed9a1ae]2213        | THREADLOCALGCC                                                                                // GCC
[36e6f10]2214                { $$ = DeclarationNode::newStorageClass( ast::Storage::ThreadLocalGcc ); }
[ed9a1ae]2215        | THREADLOCALC11                                                                                // C11
[36e6f10]2216                { $$ = DeclarationNode::newStorageClass( ast::Storage::ThreadLocalC11 ); }
[dd020c0]2217                // Put function specifiers here to simplify parsing rules, but separate them semantically.
[4d51835]2218        | INLINE                                                                                        // C99
[36e6f10]2219                { $$ = DeclarationNode::newFuncSpecifier( ast::Function::Inline ); }
[4d51835]2220        | FORTRAN                                                                                       // C99
[36e6f10]2221                { $$ = DeclarationNode::newFuncSpecifier( ast::Function::Fortran ); }
[68cd1ce]2222        | NORETURN                                                                                      // C11
[36e6f10]2223                { $$ = DeclarationNode::newFuncSpecifier( ast::Function::Noreturn ); }
[4d51835]2224        ;
[51b7345]2225
2226basic_type_name:
[201aeb9]2227        VOID
[4d51835]2228                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
2229        | BOOL                                                                                          // C99
2230                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
[201aeb9]2231        | CHAR
2232                { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
2233        | INT
2234                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
2235        | INT128
2236                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }
[f1da02c]2237        | UINT128
2238                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); }
[201aeb9]2239        | FLOAT
2240                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
2241        | DOUBLE
2242                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
[e15853c]2243        | uuFLOAT80
2244                { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); }
2245        | uuFLOAT128
2246                { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); }
2247        | uFLOAT16
2248                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); }
2249        | uFLOAT32
2250                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); }
2251        | uFLOAT32X
2252                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); }
2253        | uFLOAT64
2254                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); }
2255        | uFLOAT64X
2256                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); }
2257        | uFLOAT128
2258                { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); }
[15f769c]2259        | DECIMAL32
2260                { SemanticError( yylloc, "_Decimal32 is currently unimplemented." ); $$ = nullptr; }
2261        | DECIMAL64
2262                { SemanticError( yylloc, "_Decimal64 is currently unimplemented." ); $$ = nullptr; }
2263        | DECIMAL128
2264                { SemanticError( yylloc, "_Decimal128 is currently unimplemented." ); $$ = nullptr; }
[4d51835]2265        | COMPLEX                                                                                       // C99
[5b639ee]2266                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
[4d51835]2267        | IMAGINARY                                                                                     // C99
[5b639ee]2268                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
[201aeb9]2269        | SIGNED
2270                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
2271        | UNSIGNED
2272                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
2273        | SHORT
2274                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
2275        | LONG
2276                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
[59c7e3e]2277        | VA_LIST                                                                                       // GCC, __builtin_va_list
[72457b6]2278                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
[f673c13c]2279        | AUTO_TYPE
2280                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); }
[1f652a7]2281        | vtable
2282        ;
2283
2284vtable_opt:
2285        // empty
2286                { $$ = nullptr; }
[9380add]2287        | vtable
[1f652a7]2288        ;
2289
2290vtable:
[8f6f3729]2291        VTABLE '(' type_name ')' default_opt
[93bbbc4]2292                { $$ = DeclarationNode::newVtableType( $3 ); }
2293                // { SemanticError( yylloc, "vtable is currently unimplemented." ); $$ = nullptr; }
[1f652a7]2294        ;
2295
2296default_opt:
2297        // empty
2298                { $$ = nullptr; }
2299        | DEFAULT
2300                { SemanticError( yylloc, "vtable default is currently unimplemented." ); $$ = nullptr; }
[4d51835]2301        ;
[51b7345]2302
2303basic_declaration_specifier:
[4d51835]2304                // A semantic check is necessary for conflicting storage classes.
2305        basic_type_specifier
2306        | declaration_qualifier_list basic_type_specifier
2307                { $$ = $2->addQualifiers( $1 ); }
2308        | basic_declaration_specifier storage_class                     // remaining OBSOLESCENT (see 2)
2309                { $$ = $1->addQualifiers( $2 ); }
2310        | basic_declaration_specifier storage_class type_qualifier_list
2311                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
2312        | basic_declaration_specifier storage_class basic_type_specifier
2313                { $$ = $3->addQualifiers( $2 )->addType( $1 ); }
2314        ;
[51b7345]2315
2316basic_type_specifier:
[84d58c5]2317        direct_type
[f38e7d7]2318                // Cannot have type modifiers, e.g., short, long, etc.
[84d58c5]2319        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
[4d51835]2320                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
2321        ;
[51b7345]2322
[84d58c5]2323direct_type:
[4d51835]2324        basic_type_name
2325        | type_qualifier_list basic_type_name
2326                { $$ = $2->addQualifiers( $1 ); }
[84d58c5]2327        | direct_type type_qualifier
[4d51835]2328                { $$ = $1->addQualifiers( $2 ); }
[84d58c5]2329        | direct_type basic_type_name
[4d51835]2330                { $$ = $1->addType( $2 ); }
2331        ;
[51b7345]2332
[84d58c5]2333indirect_type:
[b6ad601]2334        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
[4d51835]2335                { $$ = $3; }
[b6ad601]2336        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
[4d51835]2337                { $$ = DeclarationNode::newTypeof( $3 ); }
[b6ad601]2338        | BASETYPEOF '(' type ')'                                                       // CFA: basetypeof( x ) y;
[bb7422a]2339                { $$ = DeclarationNode::newTypeof( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ), true ); }
[b6ad601]2340        | BASETYPEOF '(' comma_expression ')'                           // CFA: basetypeof( a+b ) y;
2341                { $$ = DeclarationNode::newTypeof( $3, true ); }
[f38e7d7]2342        | ZERO_T                                                                                        // CFA
2343                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
2344        | ONE_T                                                                                         // CFA
2345                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
[4d51835]2346        ;
[51b7345]2347
[d0ffed1]2348sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
[4d51835]2349        sue_type_specifier
[d8454b9]2350                {
2351                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
[9fd9d015]2352                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
[d8454b9]2353                        //   printf( "\tattr %s\n", attr->name.c_str() );
2354                        // } // for
2355                }
[4d51835]2356        | declaration_qualifier_list sue_type_specifier
2357                { $$ = $2->addQualifiers( $1 ); }
2358        | sue_declaration_specifier storage_class                       // remaining OBSOLESCENT (see 2)
2359                { $$ = $1->addQualifiers( $2 ); }
2360        | sue_declaration_specifier storage_class type_qualifier_list
2361                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
2362        ;
[51b7345]2363
[d0ffed1]2364sue_type_specifier:                                                                             // struct, union, enum + type specifier
2365        elaborated_type
[d8454b9]2366                {
2367                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
[9fd9d015]2368                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
[d8454b9]2369                        //   printf( "\tattr %s\n", attr->name.c_str() );
2370                        // } // for
2371                }
[fdca7c6]2372        | type_qualifier_list
2373                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
2374          elaborated_type
2375                { $$ = $3->addQualifiers( $1 ); }
[4d51835]2376        | sue_type_specifier type_qualifier
[284da8c]2377                {
2378                        if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type
2379                        $$ = $1->addQualifiers( $2 );
2380                }
[4d51835]2381        ;
[51b7345]2382
[d0ffed1]2383sue_declaration_specifier_nobody:                                               // struct, union, enum - {...} + storage class + type specifier
2384        sue_type_specifier_nobody
2385        | declaration_qualifier_list sue_type_specifier_nobody
2386                { $$ = $2->addQualifiers( $1 ); }
2387        | sue_declaration_specifier_nobody storage_class        // remaining OBSOLESCENT (see 2)
2388                { $$ = $1->addQualifiers( $2 ); }
2389        | sue_declaration_specifier_nobody storage_class type_qualifier_list
2390                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
2391        ;
2392
2393sue_type_specifier_nobody:                                                              // struct, union, enum - {...} + type specifier
2394        elaborated_type_nobody
2395        | type_qualifier_list elaborated_type_nobody
2396                { $$ = $2->addQualifiers( $1 ); }
2397        | sue_type_specifier_nobody type_qualifier
2398                { $$ = $1->addQualifiers( $2 ); }
2399        ;
2400
[84d58c5]2401type_declaration_specifier:
2402        type_type_specifier
2403        | declaration_qualifier_list type_type_specifier
[4d51835]2404                { $$ = $2->addQualifiers( $1 ); }
[84d58c5]2405        | type_declaration_specifier storage_class                      // remaining OBSOLESCENT (see 2)
[4d51835]2406                { $$ = $1->addQualifiers( $2 ); }
[84d58c5]2407        | type_declaration_specifier storage_class type_qualifier_list
[4d51835]2408                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
2409        ;
[b87a5ed]2410
[84d58c5]2411type_type_specifier:                                                                    // typedef types
2412        type_name
2413        | type_qualifier_list type_name
2414                { $$ = $2->addQualifiers( $1 ); }
2415        | type_type_specifier type_qualifier
2416                { $$ = $1->addQualifiers( $2 ); }
2417        ;
2418
2419type_name:
[4d51835]2420        TYPEDEFname
2421                { $$ = DeclarationNode::newFromTypedef( $1 ); }
[84d58c5]2422        | '.' TYPEDEFname
[47498bd]2423                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
[84d58c5]2424        | type_name '.' TYPEDEFname
[c5d7701]2425                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
[84d58c5]2426        | typegen_name
2427        | '.' typegen_name
[47498bd]2428                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
[84d58c5]2429        | type_name '.' typegen_name
[c5d7701]2430                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
[84d58c5]2431        ;
2432
2433typegen_name:                                                                                   // CFA
[65d6de4]2434        TYPEGENname
2435                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
2436        | TYPEGENname '(' ')'
[67cf18c]2437                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
2438        | TYPEGENname '(' type_list ')'
[84d58c5]2439                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
[4d51835]2440        ;
[51b7345]2441
[d0ffed1]2442elaborated_type:                                                                                // struct, union, enum
[c0aa336]2443        aggregate_type
[d8454b9]2444                {
2445                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
[9fd9d015]2446                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
[d8454b9]2447                        //   printf( "\tattr %s\n", attr->name.c_str() );
2448                        // } // for
2449                }
[c0aa336]2450        | enum_type
[4d51835]2451        ;
[51b7345]2452
[d0ffed1]2453elaborated_type_nobody:                                                                 // struct, union, enum - {...}
2454        aggregate_type_nobody
2455        | enum_type_nobody
2456        ;
2457
2458aggregate_type:                                                                                 // struct, union
[fc20514]2459        aggregate_key attribute_list_opt
2460                { forall = false; }                                                             // reset
2461          '{' field_declaration_list_opt '}' type_parameters_opt
[777ed2b]2462                { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); }
[73f04fd]2463        | aggregate_key attribute_list_opt identifier
[fdca7c6]2464                {
[71a422a]2465                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 1" );
[fdca7c6]2466                        forall = false;                                                         // reset
2467                }
[284da8c]2468          '{' field_declaration_list_opt '}' type_parameters_opt
[d8454b9]2469                {
2470                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
2471                }
[f9c3100]2472        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
[407bde5]2473                {
[71a422a]2474                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 2" );
[407bde5]2475                        forall = false;                                                         // reset
2476                }
[284da8c]2477          '{' field_declaration_list_opt '}' type_parameters_opt
[f9c3100]2478                {
2479                        DeclarationNode::newFromTypedef( $3 );
2480                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
2481                }
2482        | aggregate_key attribute_list_opt TYPEGENname          // unqualified type name
2483                {
[71a422a]2484                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 3" );
[f9c3100]2485                        forall = false;                                                         // reset
2486                }
2487          '{' field_declaration_list_opt '}' type_parameters_opt
2488                {
2489                        DeclarationNode::newFromTypeGen( $3, nullptr );
2490                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
2491                }
[d0ffed1]2492        | aggregate_type_nobody
2493        ;
2494
[284da8c]2495type_parameters_opt:
2496        // empty
2497                { $$ = nullptr; }                                                               %prec '}'
2498        | '(' type_list ')'
2499                { $$ = $2; }
2500        ;
2501
[d0ffed1]2502aggregate_type_nobody:                                                                  // struct, union - {...}
[73f04fd]2503        aggregate_key attribute_list_opt identifier
[84d58c5]2504                {
[71a422a]2505                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type_nobody" );
[9997fee]2506                        forall = false;                                                         // reset
[84d58c5]2507                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
2508                }
[73f04fd]2509        | aggregate_key attribute_list_opt type_name
[65d6de4]2510                {
[fc20514]2511                        forall = false;                                                         // reset
[65d6de4]2512                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
2513                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
2514                        // delete newFromTypeGen.
[9fa61f5]2515                        if ( $3->type->kind == TypeData::SymbolicInst && ! $3->type->symbolic.isTypedef ) {
2516                                $$ = $3->addQualifiers( $2 );
2517                        } else {
2518                                $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );
2519                                $3->type->symbolic.name = nullptr;                      // copied to $$
2520                                $3->type->symbolic.actuals = nullptr;
2521                                delete $3;
2522                        }
[65d6de4]2523                }
[4d51835]2524        ;
[51b7345]2525
2526aggregate_key:
[e307e12]2527        aggregate_data
2528        | aggregate_control
2529        ;
2530
2531aggregate_data:
[1f652a7]2532        STRUCT vtable_opt
[bb7422a]2533                { $$ = ast::AggregateDecl::Struct; }
[c0aa336]2534        | UNION
[bb7422a]2535                { $$ = ast::AggregateDecl::Union; }
[e307e12]2536        | EXCEPTION                                                                                     // CFA
[bb7422a]2537                { $$ = ast::AggregateDecl::Exception; }
2538          //            { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = ast::AggregateDecl::NoAggregate; }
[e307e12]2539        ;
2540
2541aggregate_control:                                                                              // CFA
[cbbd8fd7]2542        MONITOR
[bb7422a]2543                { $$ = ast::AggregateDecl::Monitor; }
[cbbd8fd7]2544        | MUTEX STRUCT
[bb7422a]2545                { $$ = ast::AggregateDecl::Monitor; }
[cbbd8fd7]2546        | GENERATOR
[bb7422a]2547                { $$ = ast::AggregateDecl::Generator; }
[cbbd8fd7]2548        | MUTEX GENERATOR
[bb7422a]2549                {
2550                        SemanticError( yylloc, "monitor generator is currently unimplemented." );
2551                        $$ = ast::AggregateDecl::NoAggregate;
2552                }
[d3bc0ad]2553        | COROUTINE
[bb7422a]2554                { $$ = ast::AggregateDecl::Coroutine; }
[cbbd8fd7]2555        | MUTEX COROUTINE
[bb7422a]2556                {
2557                        SemanticError( yylloc, "monitor coroutine is currently unimplemented." );
2558                        $$ = ast::AggregateDecl::NoAggregate;
2559                }
[d3bc0ad]2560        | THREAD
[bb7422a]2561                { $$ = ast::AggregateDecl::Thread; }
[cbbd8fd7]2562        | MUTEX THREAD
[bb7422a]2563                {
2564                        SemanticError( yylloc, "monitor thread is currently unimplemented." );
2565                        $$ = ast::AggregateDecl::NoAggregate;
2566                }
[4d51835]2567        ;
[51b7345]2568
[7fdb94e]2569field_declaration_list_opt:
[5d125e4]2570        // empty
[58dd019]2571                { $$ = nullptr; }
[7fdb94e]2572        | field_declaration_list_opt field_declaration
[a7741435]2573                { $$ = $1 ? $1->appendList( $2 ) : $2; }
[4d51835]2574        ;
[51b7345]2575
2576field_declaration:
[679e644]2577        type_specifier field_declaring_list_opt ';'
[d8454b9]2578                {
2579                        // printf( "type_specifier1 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
2580                        $$ = fieldDecl( $1, $2 );
2581                        // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
[9fd9d015]2582                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
[d8454b9]2583                        //   printf( "\tattr %s\n", attr->name.c_str() );
2584                        // } // for
2585                }
[0442f93f]2586        | type_specifier field_declaring_list_opt '}'           // invalid syntax rule
[55266c7]2587                {
[b1f2007]2588                        SemanticError( yylloc, "syntax error, expecting ';' at end of previous declaration." );
[55266c7]2589                        $$ = nullptr;
2590                }
[679e644]2591        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
[f7e4db27]2592                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
[466787a]2593        | STATIC type_specifier field_declaring_list_opt ';' // CFA
[9fd9d015]2594                { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
[e07caa2]2595        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
[679e644]2596                {
[dea36ee]2597                        if ( ! $3 ) {                                                           // field declarator ?
2598                                $3 = DeclarationNode::newName( nullptr );
2599                        } // if
[679a260]2600                        $3->inLine = true;
[679e644]2601                        $$ = distAttr( $2, $3 );                                        // mark all fields in list
[e07caa2]2602                        distInl( $3 );
[8f91c9ae]2603                }
[e307e12]2604        | INLINE aggregate_control ';'                                          // CFA
[9fd9d015]2605                { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
[46fa473]2606        | typedef_declaration ';'                                                       // CFA
2607        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
2608        | EXTENSION cfa_field_declaring_list ';'                        // GCC
2609                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
[679e644]2610        | INLINE cfa_field_abstract_list ';'                            // CFA, new style field declaration
2611                { $$ = $2; }                                                                    // mark all fields in list
[46fa473]2612        | cfa_typedef_declaration ';'                                           // CFA
[b47b827]2613        | static_assert                                                                         // C11
[4d51835]2614        ;
[b87a5ed]2615
[679e644]2616field_declaring_list_opt:
2617        // empty
2618                { $$ = nullptr; }
2619        | field_declarator
2620        | field_declaring_list_opt ',' attribute_list_opt field_declarator
[c0aa336]2621                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
[4d51835]2622        ;
[51b7345]2623
[679e644]2624field_declarator:
[e07caa2]2625        bit_subrange_size                                                                       // C special case, no field name
[4d51835]2626                { $$ = DeclarationNode::newBitfield( $1 ); }
2627        | variable_declarator bit_subrange_size_opt
[679e644]2628                // A semantic check is required to ensure bit_subrange only appears on integral types.
[4d51835]2629                { $$ = $1->addBitfield( $2 ); }
[c6b1105]2630        | variable_type_redeclarator bit_subrange_size_opt
[679e644]2631                // A semantic check is required to ensure bit_subrange only appears on integral types.
[4d51835]2632                { $$ = $1->addBitfield( $2 ); }
[1f771fc]2633        | function_type_redeclarator bit_subrange_size_opt
2634                // A semantic check is required to ensure bit_subrange only appears on integral types.
2635                { $$ = $1->addBitfield( $2 ); }
[679e644]2636        ;
2637
[e07caa2]2638field_abstract_list_opt:
2639        // empty
[dea36ee]2640                { $$ = nullptr; }
[e07caa2]2641        | field_abstract
2642        | field_abstract_list_opt ',' attribute_list_opt field_abstract
[679e644]2643                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
2644        ;
2645
[e07caa2]2646field_abstract:
[f7e4db27]2647                //      no bit fields
[e07caa2]2648        variable_abstract_declarator
[679e644]2649        ;
2650
2651cfa_field_declaring_list:                                                               // CFA, new style field declaration
[f7e4db27]2652        // bit-fields are handled by C declarations
[033ff37]2653        cfa_abstract_declarator_tuple identifier_or_type_name
[679e644]2654                { $$ = $1->addName( $2 ); }
[033ff37]2655        | cfa_field_declaring_list ',' identifier_or_type_name
[679e644]2656                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
2657        ;
2658
2659cfa_field_abstract_list:                                                                // CFA, new style field declaration
[f7e4db27]2660        // bit-fields are handled by C declarations
[679e644]2661        cfa_abstract_declarator_tuple
2662        | cfa_field_abstract_list ','
2663                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
[4d51835]2664        ;
[51b7345]2665
2666bit_subrange_size_opt:
[4d51835]2667        // empty
[58dd019]2668                { $$ = nullptr; }
[4d51835]2669        | bit_subrange_size
2670        ;
[51b7345]2671
2672bit_subrange_size:
[c786e1d]2673        ':' assignment_expression
[4d51835]2674                { $$ = $2; }
2675        ;
[51b7345]2676
[9e7236f4]2677enum_type:
[f9c3100]2678        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
[b0d9ff7]2679                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
[d7874052]2680        | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
2681                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
[f9c3100]2682        | ENUM attribute_list_opt identifier
[71a422a]2683                { typedefTable.makeTypedef( *$3, "enum_type 1" ); }
[c7f12a4]2684          hide_opt '{' enumerator_list comma_opt '}'
[910e1d0]2685                { $$ = DeclarationNode::newEnum( $3, $7, true, false, nullptr, $5 )->addQualifiers( $2 ); }
[d7874052]2686        | ENUM attribute_list_opt typedef_name hide_opt '{' enumerator_list comma_opt '}' // unqualified type name
[e4d7c1c]2687                { $$ = DeclarationNode::newEnum( $3->name, $6, true, false, nullptr, $4 )->addQualifiers( $2 ); }
[f9c3100]2688        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
[9fd9d015]2689                {
[55266c7]2690                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) {
2691                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
2692                        }
[b0d9ff7]2693                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
2694                }
[d7874052]2695        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name
2696                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
[b0d9ff7]2697        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
2698                {
2699                        $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 );
[8bea701]2700                }
[d7874052]2701        | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
2702                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
[9e7236f4]2703        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
[8bea701]2704                {
[92355883]2705                        if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {
[55266c7]2706                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
2707                        }
[71a422a]2708                        typedefTable.makeTypedef( *$6, "enum_type 2" );
[8bea701]2709                }
[c7f12a4]2710          hide_opt '{' enumerator_list comma_opt '}'
[8bea701]2711                {
[e4d7c1c]2712                        $$ = DeclarationNode::newEnum( $6, $11, true, true, $3, $9 )->addQualifiers( $5 )->addQualifiers( $7 );
[8bea701]2713                }
[d7874052]2714        | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt hide_opt '{' enumerator_list comma_opt '}'
[b0d9ff7]2715                {
[e4d7c1c]2716                        $$ = DeclarationNode::newEnum( $5, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );
[0bd46fd]2717                }
[d7874052]2718        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt hide_opt '{' enumerator_list comma_opt '}'
[8bea701]2719                {
[e4d7c1c]2720                        $$ = DeclarationNode::newEnum( $6->name, $10, true, true, $3, $8 )->addQualifiers( $5 )->addQualifiers( $7 );
[b0d9ff7]2721                }
[d7874052]2722        | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt hide_opt '{' enumerator_list comma_opt '}'
[b0d9ff7]2723                {
[e4d7c1c]2724                        $$ = DeclarationNode::newEnum( $5->name, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );
[8bea701]2725                }
[d0ffed1]2726        | enum_type_nobody
2727        ;
2728
[c7f12a4]2729hide_opt:
2730        // empty
[7cf8006]2731                { $$ = EnumHiding::Visible; }
[c7f12a4]2732        | '!'
[7cf8006]2733                { $$ = EnumHiding::Hide; }
[c7f12a4]2734        ;
2735
[d0ffed1]2736enum_type_nobody:                                                                               // enum - {...}
[f9c3100]2737        ENUM attribute_list_opt identifier
[71a422a]2738                {
2739                        typedefTable.makeTypedef( *$3, "enum_type_nobody 1" );
2740                        $$ = DeclarationNode::newEnum( $3, nullptr, false, false )->addQualifiers( $2 );
2741                }
[0bd46fd]2742        | ENUM attribute_list_opt type_name
[71a422a]2743                {
2744                        typedefTable.makeTypedef( *$3->type->symbolic.name, "enum_type_nobody 2" );
2745                        $$ = DeclarationNode::newEnum( $3->type->symbolic.name, nullptr, false, false )->addQualifiers( $2 );
2746                }
[4d51835]2747        ;
[51b7345]2748
2749enumerator_list:
[7cf8006]2750        visible_hide_opt identifier_or_type_name enumerator_value_opt
[c7f12a4]2751                { $$ = DeclarationNode::newEnumValueGeneric( $2, $3 ); }
[f9c3100]2752        | INLINE type_name
[1e30df7]2753                { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); }
[7cf8006]2754        | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt
[c7f12a4]2755                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
[f9c3100]2756        | enumerator_list ',' INLINE type_name enumerator_value_opt
[374cb117]2757                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }
[4d51835]2758        ;
[51b7345]2759
[7cf8006]2760visible_hide_opt:
[c7f12a4]2761        hide_opt
2762        | '^'
[7cf8006]2763                { $$ = EnumHiding::Visible; }
[c7f12a4]2764        ;
2765
[51b7345]2766enumerator_value_opt:
[4d51835]2767        // empty
[58dd019]2768                { $$ = nullptr; }
[7991c7d]2769        | '=' constant_expression                                       { $$ = new InitializerNode( $2 ); }
2770        | '=' '{' initializer_list_opt comma_opt '}' { $$ = new InitializerNode( $3, true ); }
2771        // | simple_assignment_operator initializer
2772        //      { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); }
[4d51835]2773        ;
[51b7345]2774
[5a51798]2775cfa_parameter_ellipsis_list_opt:                                                // CFA, abstract + real
[4d51835]2776        // empty
[2a8427c6]2777                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
2778        | ELLIPSIS
[58dd019]2779                { $$ = nullptr; }
[2a8427c6]2780        | cfa_abstract_parameter_list
[c0aa336]2781        | cfa_parameter_list
[c0a33d2]2782        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
2783                { $$ = $1->appendList( $5 ); }
2784        | cfa_abstract_parameter_list pop ',' push ELLIPSIS
[4d51835]2785                { $$ = $1->addVarArgs(); }
[c0a33d2]2786        | cfa_parameter_list pop ',' push ELLIPSIS
[4d51835]2787                { $$ = $1->addVarArgs(); }
2788        ;
[b87a5ed]2789
[c0aa336]2790cfa_parameter_list:                                                                             // CFA
2791                // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
2792                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
2793        cfa_parameter_declaration
[c0a33d2]2794        | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
2795                { $$ = $1->appendList( $5 ); }
2796        | cfa_parameter_list pop ',' push cfa_parameter_declaration
2797                { $$ = $1->appendList( $5 ); }
2798        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
2799                { $$ = $1->appendList( $5 )->appendList( $9 ); }
[4d51835]2800        ;
[b87a5ed]2801
[c0aa336]2802cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
2803        cfa_abstract_parameter_declaration
[c0a33d2]2804        | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
2805                { $$ = $1->appendList( $5 ); }
[4d51835]2806        ;
[51b7345]2807
2808parameter_type_list_opt:
[4d51835]2809        // empty
[58dd019]2810                { $$ = nullptr; }
[2a8427c6]2811        | ELLIPSIS
2812                { $$ = nullptr; }
2813        | parameter_list
[71a422a]2814        | parameter_list ',' ELLIPSIS
[4d51835]2815                { $$ = $1->addVarArgs(); }
2816        ;
[b87a5ed]2817
2818parameter_list:                                                                                 // abstract + real
[4d51835]2819        abstract_parameter_declaration
2820        | parameter_declaration
[71a422a]2821        | parameter_list ',' abstract_parameter_declaration
2822                { $$ = $1->appendList( $3 ); }
2823        | parameter_list ',' parameter_declaration
2824                { $$ = $1->appendList( $3 ); }
[4d51835]2825        ;
[51b7345]2826
[de62360d]2827// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
[2871210]2828// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
[51b7345]2829
[c0aa336]2830cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
[4d51835]2831        parameter_declaration
[5a51798]2832        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initializer_opt
[4d51835]2833                { $$ = $1->addName( $2 ); }
[5a51798]2834        | cfa_abstract_tuple identifier_or_type_name default_initializer_opt
[c0aa336]2835                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
[4d51835]2836                { $$ = $1->addName( $2 ); }
[5a51798]2837        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initializer_opt
[4d51835]2838                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
[c0aa336]2839        | cfa_function_specifier
[4d51835]2840        ;
[b87a5ed]2841
[c0aa336]2842cfa_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
[0ac8d07]2843        abstract_parameter_declaration
[c0aa336]2844        | cfa_identifier_parameter_declarator_no_tuple
2845        | cfa_abstract_tuple
2846                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
2847        | type_qualifier_list cfa_abstract_tuple
[4d51835]2848                { $$ = $2->addQualifiers( $1 ); }
[c0aa336]2849        | cfa_abstract_function
[4d51835]2850        ;
[51b7345]2851
2852parameter_declaration:
[d0ffed1]2853                // No SUE declaration in parameter list.
[5a51798]2854        declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt
[7fdb94e]2855                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
[5a51798]2856        | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt
[7fdb94e]2857                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
[4d51835]2858        ;
[51b7345]2859
2860abstract_parameter_declaration:
[5a51798]2861        declaration_specifier_nobody default_initializer_opt
[e7cc8cb]2862                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
[5a51798]2863        | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt
[e7cc8cb]2864                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
[4d51835]2865        ;
[51b7345]2866
[c11e31c]2867// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
[de62360d]2868// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
2869// identifiers.  The ANSI-style parameter-list can redefine a typedef name.
[51b7345]2870
[b87a5ed]2871identifier_list:                                                                                // K&R-style parameter list => no types
[033ff37]2872        identifier
[4d51835]2873                { $$ = DeclarationNode::newName( $1 ); }
[033ff37]2874        | identifier_list ',' identifier
[4d51835]2875                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
2876        ;
[51b7345]2877
[2871210]2878identifier_or_type_name:
[4d51835]2879        identifier
2880        | TYPEDEFname
2881        | TYPEGENname
2882        ;
[51b7345]2883
[84d58c5]2884type_no_function:                                                                               // sizeof, alignof, cast (constructor)
[c0aa336]2885        cfa_abstract_declarator_tuple                                           // CFA
[9fa61f5]2886        | type_specifier                                                                        // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing
[c0aa336]2887        | type_specifier abstract_declarator
[4d51835]2888                { $$ = $2->addType( $1 ); }
2889        ;
[b87a5ed]2890
[84d58c5]2891type:                                                                                                   // typeof, assertion
2892        type_no_function
[c0aa336]2893        | cfa_abstract_function                                                         // CFA
[4d51835]2894        ;
[51b7345]2895
2896initializer_opt:
[4d51835]2897        // empty
[58dd019]2898                { $$ = nullptr; }
[f9c3100]2899        | simple_assignment_operator initializer        { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); }
2900        | '=' VOID                                                                      { $$ = new InitializerNode( true ); }
[63b3279]2901        | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
[4d51835]2902        ;
[51b7345]2903
2904initializer:
[de62360d]2905        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
[7fdb94e]2906        | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
[4d51835]2907        ;
[51b7345]2908
[7fdb94e]2909initializer_list_opt:
[097e2b0]2910        // empty
[58dd019]2911                { $$ = nullptr; }
[097e2b0]2912        | initializer
[4d51835]2913        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
[7fdb94e]2914        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
[63b3279]2915        | initializer_list_opt ',' designation initializer { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
[4d51835]2916        ;
[b87a5ed]2917
[de62360d]2918// There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of
2919// '=' to separator the designator from the initializer value, as in:
[c11e31c]2920//
[b87a5ed]2921//              int x[10] = { [1] = 3 };
[c11e31c]2922//
[de62360d]2923// The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment.  To disambiguate this case, CFA
2924// changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for
2925// field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to
2926// shift/reduce conflicts
[51b7345]2927
2928designation:
[4d51835]2929        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
[e16eb460]2930        | identifier_at ':'                                                                     // GCC, field name
[bb7422a]2931                { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); }
[4d51835]2932        ;
[51b7345]2933
[b87a5ed]2934designator_list:                                                                                // C99
[4d51835]2935        designator
[2871210]2936        | designator_list designator
[4a063df]2937                { $$ = (ExpressionNode *)($1->set_last( $2 )); }
[d1625f8]2938        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
[4d51835]2939        ;
[51b7345]2940
2941designator:
[e16eb460]2942        '.' identifier_at                                                                       // C99, field name
[bb7422a]2943                { $$ = new ExpressionNode( build_varref( yylloc, $2 ) ); }
[c0a33d2]2944        | '[' push assignment_expression pop ']'                        // C99, single array element
[de62360d]2945                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
[d1625f8]2946                { $$ = $3; }
[c0a33d2]2947        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
2948                { $$ = $3; }
2949        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
[bb7422a]2950                { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); }
[679e644]2951        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
[c0a33d2]2952                { $$ = $4; }
[4d51835]2953        ;
[51b7345]2954
[de62360d]2955// The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters,
2956// rather than an object-oriented type system. This required four groups of extensions:
[c11e31c]2957//
2958// Overloading: function, data, and operator identifiers may be overloaded.
2959//
[3ca7ef3]2960// Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
[de62360d]2961//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
2962//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
[c11e31c]2963//
[de62360d]2964// Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call
2965//     site. A polymorphic function is not a template; it is a function, with an address and a type.
[c11e31c]2966//
2967// Specifications and Assertions: Specifications are collections of declarations parameterized by one or more
[de62360d]2968//     types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass
2969//     hierarchies. Unlike classes, they can define relationships between types.  Assertions declare that a type or
2970//     types provide the operations declared by a specification.  Assertions are normally used to declare requirements
2971//     on type arguments of polymorphic functions.
[c11e31c]2972
[b87a5ed]2973type_parameter_list:                                                                    // CFA
[67cf18c]2974        type_parameter
2975        | type_parameter_list ',' type_parameter
[4d51835]2976                { $$ = $1->appendList( $3 ); }
2977        ;
[b87a5ed]2978
[84d58c5]2979type_initializer_opt:                                                                   // CFA
2980        // empty
2981                { $$ = nullptr; }
2982        | '=' type
2983                { $$ = $2; }
2984        ;
2985
[b87a5ed]2986type_parameter:                                                                                 // CFA
[033ff37]2987        type_class identifier_or_type_name
[408ab79]2988                {
[71a422a]2989                        typedefTable.addToScope( *$2, TYPEDEFname, "type_parameter 1" );
[bb7422a]2990                        if ( $1 == ast::TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); }
2991                        if ( $1 == ast::TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); }
2992                        if ( $1 == ast::TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); }
[fd54fef]2993                }
[5a51798]2994          type_initializer_opt assertion_list_opt
[67cf18c]2995                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
[5a51798]2996        | identifier_or_type_name new_type_class
[71a422a]2997                { typedefTable.addToScope( *$1, TYPEDEFname, "type_parameter 2" ); }
[5a51798]2998          type_initializer_opt assertion_list_opt
2999                { $$ = DeclarationNode::newTypeParam( $2, $1 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
3000        | '[' identifier_or_type_name ']'
[b66d14a]3001                {
[71a422a]3002                        typedefTable.addToScope( *$2, TYPEDIMname, "type_parameter 3" );
[bb7422a]3003                        $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dimension, $2 );
[b66d14a]3004                }
[5a51798]3005        // | type_specifier identifier_parameter_declarator
[9997fee]3006        | assertion_list
[bb7422a]3007                { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
[4d51835]3008        ;
[b87a5ed]3009
[5a51798]3010new_type_class:                                                                                 // CFA
3011        // empty
[bb7422a]3012                { $$ = ast::TypeDecl::Otype; }
[5a51798]3013        | '&'
[bb7422a]3014                { $$ = ast::TypeDecl::Dtype; }
[5a51798]3015        | '*'
[bb7422a]3016                { $$ = ast::TypeDecl::DStype; }                                         // dtype + sized
[2ac218d]3017        // | '(' '*' ')'
[bb7422a]3018        //      { $$ = ast::TypeDecl::Ftype; }
[5a51798]3019        | ELLIPSIS
[bb7422a]3020                { $$ = ast::TypeDecl::Ttype; }
[5a51798]3021        ;
3022
[b87a5ed]3023type_class:                                                                                             // CFA
[4040425]3024        OTYPE
[bb7422a]3025                { $$ = ast::TypeDecl::Otype; }
[4d51835]3026        | DTYPE
[bb7422a]3027                { $$ = ast::TypeDecl::Dtype; }
[8f60f0b]3028        | FTYPE
[bb7422a]3029                { $$ = ast::TypeDecl::Ftype; }
[8f60f0b]3030        | TTYPE
[bb7422a]3031                { $$ = ast::TypeDecl::Ttype; }
[4d51835]3032        ;
[b87a5ed]3033
3034assertion_list_opt:                                                                             // CFA
[4d51835]3035        // empty
[58dd019]3036                { $$ = nullptr; }
[9997fee]3037        | assertion_list
3038        ;
3039
3040assertion_list:                                                                                 // CFA
3041        assertion
3042        | assertion_list assertion
[3ca7ef3]3043                { $$ = $1->appendList( $2 ); }
[4d51835]3044        ;
[b87a5ed]3045
3046assertion:                                                                                              // CFA
[033ff37]3047        '|' identifier_or_type_name '(' type_list ')'
[7fdb94e]3048                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
[13e8427]3049        | '|' '{' push trait_declaration_list pop '}'
[4d51835]3050                { $$ = $4; }
[35718a9]3051        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
3052        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
[4d51835]3053        ;
[b87a5ed]3054
[84d58c5]3055type_list:                                                                                              // CFA
3056        type
[bb7422a]3057                { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); }
[4d51835]3058        | assignment_expression
[84d58c5]3059        | type_list ',' type
[bb7422a]3060                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); }
[84d58c5]3061        | type_list ',' assignment_expression
[6e50a6b]3062                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
[4d51835]3063        ;
[b87a5ed]3064
3065type_declaring_list:                                                                    // CFA
[4040425]3066        OTYPE type_declarator
[4d51835]3067                { $$ = $2; }
[4040425]3068        | storage_class_list OTYPE type_declarator
[4d51835]3069                { $$ = $3->addQualifiers( $1 ); }
3070        | type_declaring_list ',' type_declarator
[a7c90d4]3071                { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
[4d51835]3072        ;
[b87a5ed]3073
3074type_declarator:                                                                                // CFA
[4d51835]3075        type_declarator_name assertion_list_opt
3076                { $$ = $1->addAssertions( $2 ); }
[84d58c5]3077        | type_declarator_name assertion_list_opt '=' type
[4d51835]3078                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
3079        ;
[b87a5ed]3080
3081type_declarator_name:                                                                   // CFA
[033ff37]3082        identifier_or_type_name
[4d51835]3083                {
[71a422a]3084                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "type_declarator_name 1" );
[a5f9444]3085                        $$ = DeclarationNode::newTypeDecl( $1, nullptr );
[4d51835]3086                }
[033ff37]3087        | identifier_or_type_name '(' type_parameter_list ')'
[4d51835]3088                {
[71a422a]3089                        typedefTable.addToEnclosingScope( *$1, TYPEGENname, "type_declarator_name 2" );
[35718a9]3090                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
[4d51835]3091                }
3092        ;
[b87a5ed]3093
[4040425]3094trait_specifier:                                                                                // CFA
[033ff37]3095        TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}'
[8a97248]3096                {
[3d937e2]3097                        SemanticWarning( yylloc, Warning::DeprecTraitSyntax );
[8a97248]3098                        $$ = DeclarationNode::newTrait( $2, $4, nullptr );
3099                }
3100        | forall TRAIT identifier_or_type_name '{' '}'          // alternate
[7a24d76]3101                { $$ = DeclarationNode::newTrait( $3, $1, nullptr ); }
[033ff37]3102        | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
[8a97248]3103                {
[3d937e2]3104                        SemanticWarning( yylloc, Warning::DeprecTraitSyntax );
[8a97248]3105                        $$ = DeclarationNode::newTrait( $2, $4, $8 );
3106                }
[7a24d76]3107        | forall TRAIT identifier_or_type_name '{' push trait_declaration_list pop '}' // alternate
3108                { $$ = DeclarationNode::newTrait( $3, $1, $6 ); }
[4d51835]3109        ;
[b87a5ed]3110
[84d58c5]3111trait_declaration_list:                                                                 // CFA
[4040425]3112        trait_declaration
[13e8427]3113        | trait_declaration_list pop push trait_declaration
3114                { $$ = $1->appendList( $4 ); }
[4d51835]3115        ;
[b87a5ed]3116
[84d58c5]3117trait_declaration:                                                                              // CFA
[13e8427]3118        cfa_trait_declaring_list ';'
3119        | trait_declaring_list ';'
[4d51835]3120        ;
[b87a5ed]3121
[c0aa336]3122cfa_trait_declaring_list:                                                               // CFA
3123        cfa_variable_specifier
3124        | cfa_function_specifier
3125        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
[7fdb94e]3126                { $$ = $1->appendList( $1->cloneType( $5 ) ); }
[4d51835]3127        ;
[b87a5ed]3128
[4040425]3129trait_declaring_list:                                                                   // CFA
[4d51835]3130        type_specifier declarator
[7fdb94e]3131                { $$ = $2->addType( $1 ); }
[4040425]3132        | trait_declaring_list pop ',' push declarator
[7fdb94e]3133                { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
[4d51835]3134        ;
[51b7345]3135
[e1d66c84]3136// **************************** EXTERNAL DEFINITIONS *****************************
[51b7345]3137
3138translation_unit:
[3d56d15b]3139        // empty, input file
[4d51835]3140        | external_definition_list
[a7741435]3141                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
[4d51835]3142        ;
[51b7345]3143
3144external_definition_list:
[35718a9]3145        push external_definition pop
3146                { $$ = $2; }
[fc20514]3147        | external_definition_list push external_definition pop
3148                { $$ = $1 ? $1->appendList( $3 ) : $3; }
[4d51835]3149        ;
[51b7345]3150
3151external_definition_list_opt:
[4d51835]3152        // empty
[58dd019]3153                { $$ = nullptr; }
[3d56d15b]3154        | external_definition_list
3155        ;
3156
3157up:
[fc20514]3158                { typedefTable.up( forall ); forall = false; }
[3d56d15b]3159        ;
3160
3161down:
3162                { typedefTable.down(); }
[4d51835]3163        ;
[51b7345]3164
3165external_definition:
[2d019af]3166        DIRECTIVE
[bb7422a]3167                { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( yylloc, $1 ) ) ); }
[2d019af]3168        | declaration
[1a73dbb]3169                {
3170                        // Variable declarations of anonymous types requires creating a unique type-name across multiple translation
3171                        // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
3172                        // disallowed at the moment.
[bb7422a]3173                        if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
[1a73dbb]3174                                if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
3175                                        SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
3176                                } else if ( $1->type->aggInst.aggregate->aggregate.anon ) { // handles struct or union
3177                                        SemanticError( yylloc, "extern anonymous struct/union is currently unimplemented." ); $$ = nullptr;
3178                                }
3179                        }
3180                }
[996c8ed]3181        | IDENTIFIER IDENTIFIER
3182                { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; }
[65ef0cd]3183        | IDENTIFIER type_qualifier                                                     // invalid syntax rule
[996c8ed]3184                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
[65ef0cd]3185        | IDENTIFIER storage_class                                                      // invalid syntax rule
[996c8ed]3186                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
[65ef0cd]3187        | IDENTIFIER basic_type_name                                            // invalid syntax rule
[996c8ed]3188                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[65ef0cd]3189        | IDENTIFIER TYPEDEFname                                                        // invalid syntax rule
[996c8ed]3190                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[65ef0cd]3191        | IDENTIFIER TYPEGENname                                                        // invalid syntax rule
[996c8ed]3192                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
[4d51835]3193        | external_function_definition
[ecae5860]3194        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
3195                {
3196                        distExt( $2 );                                                          // mark all fields in list
3197                        $$ = $2;
3198                }
[e994912]3199        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
[bb7422a]3200                { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( yylloc, false, $3, nullptr ) ) ); }
[aac37fa]3201        | EXTERN STRINGliteral
3202                {
3203                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
[bb7422a]3204                        linkage = ast::Linkage::update( yylloc, linkage, $2 );
[aac37fa]3205                }
[ae2f2ae]3206          up external_definition down
[aac37fa]3207                {
3208                        linkage = linkageStack.top();
3209                        linkageStack.pop();
3210                        $$ = $5;
3211                }
[c0aa336]3212        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
[4d51835]3213                {
[3b8e52c]3214                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
[bb7422a]3215                        linkage = ast::Linkage::update( yylloc, linkage, $2 );
[4d51835]3216                }
[3d56d15b]3217          '{' up external_definition_list_opt down '}'
[4d51835]3218                {
3219                        linkage = linkageStack.top();
3220                        linkageStack.pop();
[3d56d15b]3221                        $$ = $6;
[8e9cbb2]3222                }
[b2ddaf3]3223        // global distribution
[9997fee]3224        | type_qualifier_list
3225                {
[55266c7]3226                        if ( $1->type->qualifiers.any() ) {
3227                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
3228                        }
[fc20514]3229                        if ( $1->type->forall ) forall = true;          // remember generic type
[3d56d15b]3230                }
3231          '{' up external_definition_list_opt down '}'          // CFA, namespace
3232                {
[4c3ee8d]3233                        distQual( $5, $1 );
[9fd9d015]3234                        forall = false;
[3d56d15b]3235                        $$ = $5;
[9997fee]3236                }
3237        | declaration_qualifier_list
3238                {
[55266c7]3239                        if ( $1->type && $1->type->qualifiers.any() ) {
3240                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
3241                        }
[fc20514]3242                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
[3d56d15b]3243                }
3244          '{' up external_definition_list_opt down '}'          // CFA, namespace
3245                {
[4c3ee8d]3246                        distQual( $5, $1 );
[9fd9d015]3247                        forall = false;
[3d56d15b]3248                        $$ = $5;
[9997fee]3249                }
3250        | declaration_qualifier_list type_qualifier_list
3251                {
[55266c7]3252                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) {
3253                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
3254                        }
[b2ddaf3]3255                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
[9997fee]3256                }
[3d56d15b]3257          '{' up external_definition_list_opt down '}'          // CFA, namespace
[9997fee]3258                {
[284da8c]3259                        distQual( $6, $1->addQualifiers( $2 ) );
[9fd9d015]3260                        forall = false;
[3d56d15b]3261                        $$ = $6;
[9997fee]3262                }
[4d51835]3263        ;
3264
3265external_function_definition:
3266        function_definition
[de62360d]3267                // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
[c6b1105]3268                // legacy code with global functions missing the type-specifier for the return type, and assuming "int".
3269                // Parsing is possible because function_definition does not appear in the context of an expression (nested
3270                // functions preclude this concession, i.e., all nested function must have a return type). A function prototype
3271                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
[4d51835]3272        | function_declarator compound_statement
[c0a33d2]3273                { $$ = $1->addFunctionBody( $2 ); }
[35718a9]3274        | KR_function_declarator KR_parameter_list_opt compound_statement
[c0a33d2]3275                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
[4d51835]3276        ;
[51b7345]3277
[8b47e50]3278with_clause_opt:
3279        // empty
[9997fee]3280                { $$ = nullptr; forall = false; }
[d8454b9]3281        | WITH '(' tuple_expression_list ')' attribute_list_opt
3282                {
3283                        $$ = $3; forall = false;
3284                        if ( $5 ) {
[55266c7]3285                                SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
[d8454b9]3286                                $$ = nullptr;
3287                        } // if
3288                }
[8b47e50]3289        ;
3290
[51b7345]3291function_definition:
[8b47e50]3292        cfa_function_declaration with_clause_opt compound_statement     // CFA
[4d51835]3293                {
[481115f]3294                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
3295                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
[5fcba14]3296                        $1->get_last()->addFunctionBody( $3, $2 );
[481115f]3297                        $$ = $1;
[4d51835]3298                }
[8b47e50]3299        | declaration_specifier function_declarator with_clause_opt compound_statement
[4d51835]3300                {
[c38ae92]3301                        rebindForall( $1, $2 );
[7fdb94e]3302                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
3303                }
[1f771fc]3304        | declaration_specifier function_type_redeclarator with_clause_opt compound_statement
[7fdb94e]3305                {
3306                        rebindForall( $1, $2 );
[5fcba14]3307                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
[4d51835]3308                }
[a16a7ec]3309                // handles default int return type, OBSOLESCENT (see 1)
[8b47e50]3310        | type_qualifier_list function_declarator with_clause_opt compound_statement
[c0a33d2]3311                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
[a16a7ec]3312                // handles default int return type, OBSOLESCENT (see 1)
[8b47e50]3313        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
[c0a33d2]3314                { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); }
[a16a7ec]3315                // handles default int return type, OBSOLESCENT (see 1)
[8b47e50]3316        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
[c0a33d2]3317                { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); }
[4d51835]3318
3319                // Old-style K&R function definition, OBSOLESCENT (see 4)
[35718a9]3320        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
[4d51835]3321                {
[c38ae92]3322                        rebindForall( $1, $2 );
[5fcba14]3323                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
[4d51835]3324                }
[a16a7ec]3325                // handles default int return type, OBSOLESCENT (see 1)
[35718a9]3326        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
[c0a33d2]3327                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
[a16a7ec]3328                // handles default int return type, OBSOLESCENT (see 1)
[35718a9]3329        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
[c0a33d2]3330                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
[a16a7ec]3331                // handles default int return type, OBSOLESCENT (see 1)
[35718a9]3332        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
[c0a33d2]3333                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
[4d51835]3334        ;
[51b7345]3335
3336declarator:
[4d51835]3337        variable_declarator
[c6b1105]3338        | variable_type_redeclarator
[4d51835]3339        | function_declarator
[1f771fc]3340        | function_type_redeclarator
[4d51835]3341        ;
[51b7345]3342
3343subrange:
[4d51835]3344        constant_expression '~' constant_expression                     // CFA, integer subrange
[bb7422a]3345                { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
[4d51835]3346        ;
[b87a5ed]3347
3348asm_name_opt:                                                                                   // GCC
[4d51835]3349        // empty
[58dd019]3350                { $$ = nullptr; }
3351        | ASM '(' string_literal ')' attribute_list_opt
[c0aa336]3352                {
3353                        DeclarationNode * name = new DeclarationNode();
[32d6fdc]3354                        name->asmName = maybeMoveBuild( $3 );
[c0aa336]3355                        $$ = name->addQualifiers( $5 );
3356                }
[4d51835]3357        ;
[b87a5ed]3358
3359attribute_list_opt:                                                                             // GCC
[4d51835]3360        // empty
[58dd019]3361                { $$ = nullptr; }
[4d51835]3362        | attribute_list
3363        ;
[b87a5ed]3364
3365attribute_list:                                                                                 // GCC
[4d51835]3366        attribute
3367        | attribute_list attribute
[1db21619]3368                { $$ = $2->addQualifiers( $1 ); }
[4d51835]3369        ;
[b87a5ed]3370
3371attribute:                                                                                              // GCC
[44a81853]3372        ATTRIBUTE '(' '(' attribute_name_list ')' ')'
3373                { $$ = $4; }
[4d51835]3374        ;
[b87a5ed]3375
[44a81853]3376attribute_name_list:                                                                    // GCC
3377        attribute_name
3378        | attribute_name_list ',' attribute_name
[c0aa336]3379                { $$ = $3->addQualifiers( $1 ); }
[4d51835]3380        ;
[b87a5ed]3381
[44a81853]3382attribute_name:                                                                                 // GCC
[4d51835]3383        // empty
[44a81853]3384                { $$ = nullptr; }
3385        | attr_name
3386                { $$ = DeclarationNode::newAttribute( $1 ); }
[cbbd8fd7]3387        | attr_name '(' argument_expression_list_opt ')'
[44a81853]3388                { $$ = DeclarationNode::newAttribute( $1, $3 ); }
[4d51835]3389        ;
[b87a5ed]3390
[44a81853]3391attr_name:                                                                                              // GCC
3392        IDENTIFIER
[5b2edbc]3393        | quasi_keyword
[44a81853]3394        | TYPEDEFname
3395        | TYPEGENname
[114014c]3396        | FALLTHROUGH
3397                { $$ = Token{ new string( "fallthrough" ), { nullptr, -1 } }; }
[44a81853]3398        | CONST
[9ff56e7]3399                { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
[4d51835]3400        ;
[51b7345]3401
[c11e31c]3402// ============================================================================
[de62360d]3403// The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary
3404// because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as
3405// in:
[c11e31c]3406//
[b87a5ed]3407//              int (*f())[10] { ... };
3408//              ... (*f())[3] += 1;             // definition mimics usage
[c11e31c]3409//
[de62360d]3410// Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of
3411// the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context.
[c11e31c]3412// ============================================================================
3413
3414// ----------------------------------------------------------------------------
[de62360d]3415// The set of valid declarators before a compound statement for defining a function is less than the set of declarators
3416// to define a variable or function prototype, e.g.:
[c11e31c]3417//
[b87a5ed]3418//              valid declaration               invalid definition
3419//              -----------------               ------------------
[4d51835]3420//              int f;                                  int f {}
3421//              int *f;                                 int *f {}
[b87a5ed]3422//              int f[10];                              int f[10] {}
[4d51835]3423//              int (*f)(int);                  int (*f)(int) {}
[c11e31c]3424//
[de62360d]3425// To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence
3426// variable_declarator and function_declarator.
[c11e31c]3427// ----------------------------------------------------------------------------
3428
[de62360d]3429// This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes
3430// declaring an array of functions versus a pointer to an array of functions.
[51b7345]3431
[5e25953]3432paren_identifier:
[e16eb460]3433        identifier_at
[5e25953]3434                { $$ = DeclarationNode::newName( $1 ); }
3435        | '(' paren_identifier ')'                                                      // redundant parenthesis
3436                { $$ = $2; }
3437        ;
3438
[51b7345]3439variable_declarator:
[4d51835]3440        paren_identifier attribute_list_opt
[1db21619]3441                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3442        | variable_ptr
3443        | variable_array attribute_list_opt
[1db21619]3444                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3445        | variable_function attribute_list_opt
[1db21619]3446                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3447        ;
[51b7345]3448
3449variable_ptr:
[dd51906]3450        ptrref_operator variable_declarator
[a5f9444]3451                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3452        | ptrref_operator type_qualifier_list variable_declarator
[ce8c12f]3453                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]3454        | '(' variable_ptr ')' attribute_list_opt                       // redundant parenthesis
3455                { $$ = $2->addQualifiers( $4 ); }
3456        | '(' attribute_list variable_ptr ')' attribute_list_opt // redundant parenthesis
3457                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
[4d51835]3458        ;
[51b7345]3459
3460variable_array:
[4d51835]3461        paren_identifier array_dimension
3462                { $$ = $1->addArray( $2 ); }
3463        | '(' variable_ptr ')' array_dimension
3464                { $$ = $2->addArray( $4 ); }
[5e25953]3465        | '(' attribute_list variable_ptr ')' array_dimension
3466                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[9fd9d015]3467        | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
[4d51835]3468                { $$ = $2->addArray( $4 ); }
[5e25953]3469        | '(' attribute_list variable_array ')' multi_array_dimension // redundant parenthesis
3470                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[4d51835]3471        | '(' variable_array ')'                                                        // redundant parenthesis
3472                { $$ = $2; }
[5e25953]3473        | '(' attribute_list variable_array ')'                         // redundant parenthesis
3474                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3475        ;
[51b7345]3476
3477variable_function:
[71a422a]3478        '(' variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3479                { $$ = $2->addParamList( $5 ); }
3480        | '(' attribute_list variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3481                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
[4d51835]3482        | '(' variable_function ')'                                                     // redundant parenthesis
3483                { $$ = $2; }
[5e25953]3484        | '(' attribute_list variable_function ')'                      // redundant parenthesis
3485                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3486        ;
[51b7345]3487
[c6b1105]3488// This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is
3489// no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist
3490// is the same scope.  The pattern precludes returning arrays and functions versus pointers to arrays and functions.
[51b7345]3491
3492function_declarator:
[4d51835]3493        function_no_ptr attribute_list_opt
[1db21619]3494                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3495        | function_ptr
3496        | function_array attribute_list_opt
[1db21619]3497                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3498        ;
[51b7345]3499
3500function_no_ptr:
[71a422a]3501        paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3502                { $$ = $1->addParamList( $3 ); }
3503        | '(' function_ptr ')' '(' parameter_type_list_opt ')'
3504                { $$ = $2->addParamList( $5 ); }
3505        | '(' attribute_list function_ptr ')' '(' parameter_type_list_opt ')'
3506                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
[4d51835]3507        | '(' function_no_ptr ')'                                                       // redundant parenthesis
3508                { $$ = $2; }
[5e25953]3509        | '(' attribute_list function_no_ptr ')'                        // redundant parenthesis
3510                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3511        ;
[51b7345]3512
3513function_ptr:
[dd51906]3514        ptrref_operator function_declarator
[a5f9444]3515                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3516        | ptrref_operator type_qualifier_list function_declarator
[ce8c12f]3517                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]3518        | '(' function_ptr ')' attribute_list_opt
3519                { $$ = $2->addQualifiers( $4 ); }
3520        | '(' attribute_list function_ptr ')' attribute_list_opt
3521                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
[4d51835]3522        ;
[51b7345]3523
3524function_array:
[4d51835]3525        '(' function_ptr ')' array_dimension
3526                { $$ = $2->addArray( $4 ); }
[5e25953]3527        | '(' attribute_list function_ptr ')' array_dimension
3528                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[4d51835]3529        | '(' function_array ')' multi_array_dimension          // redundant parenthesis
3530                { $$ = $2->addArray( $4 ); }
[5e25953]3531        | '(' attribute_list function_array ')' multi_array_dimension // redundant parenthesis
3532                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[4d51835]3533        | '(' function_array ')'                                                        // redundant parenthesis
3534                { $$ = $2; }
[5e25953]3535        | '(' attribute_list function_array ')'                         // redundant parenthesis
3536                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3537        ;
[51b7345]3538
[c0aa336]3539// This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4)
3540//
3541//   f( a, b, c ) int a, *b, c[]; {}
3542//
3543// that is not redefining a typedef name (see function_declarator for additional comments). The pattern precludes
3544// returning arrays and functions versus pointers to arrays and functions.
[51b7345]3545
[c0aa336]3546KR_function_declarator:
3547        KR_function_no_ptr
3548        | KR_function_ptr
3549        | KR_function_array
[4d51835]3550        ;
[51b7345]3551
[c0aa336]3552KR_function_no_ptr:
[4d51835]3553        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
3554                { $$ = $1->addIdList( $3 ); }
[71a422a]3555        | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')'
3556                { $$ = $2->addParamList( $5 ); }
3557        | '(' attribute_list KR_function_ptr ')' '(' parameter_type_list_opt ')'
3558                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
[c0aa336]3559        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
[4d51835]3560                { $$ = $2; }
[5e25953]3561        | '(' attribute_list KR_function_no_ptr ')'                     // redundant parenthesis
3562                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3563        ;
[51b7345]3564
[c0aa336]3565KR_function_ptr:
3566        ptrref_operator KR_function_declarator
[a5f9444]3567                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c0aa336]3568        | ptrref_operator type_qualifier_list KR_function_declarator
[ce8c12f]3569                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]3570        | '(' KR_function_ptr ')'
[4d51835]3571                { $$ = $2; }
[5e25953]3572        | '(' attribute_list KR_function_ptr ')'
3573                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3574        ;
[51b7345]3575
[c0aa336]3576KR_function_array:
3577        '(' KR_function_ptr ')' array_dimension
[4d51835]3578                { $$ = $2->addArray( $4 ); }
[5e25953]3579        | '(' attribute_list KR_function_ptr ')' array_dimension
3580                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[c0aa336]3581        | '(' KR_function_array ')' multi_array_dimension       // redundant parenthesis
[4d51835]3582                { $$ = $2->addArray( $4 ); }
[5e25953]3583        | '(' attribute_list KR_function_array ')' multi_array_dimension // redundant parenthesis
3584                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[c0aa336]3585        | '(' KR_function_array ')'                                                     // redundant parenthesis
[4d51835]3586                { $$ = $2; }
[5e25953]3587        | '(' attribute_list KR_function_array ')'                      // redundant parenthesis
3588                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3589        ;
[51b7345]3590
[1f771fc]3591// This pattern parses a declaration for a variable that redefines a type name, e.g.:
[c11e31c]3592//
[b87a5ed]3593//              typedef int foo;
3594//              {
3595//                 int foo; // redefine typedef name in new scope
3596//              }
[51b7345]3597
[2871210]3598paren_type:
[f9c3100]3599        typedef_name
[c4f68dc]3600                {
[f9c3100]3601                        // hide type name in enclosing scope by variable name
[71a422a]3602                        typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "paren_type" );
[c4f68dc]3603                }
[2871210]3604        | '(' paren_type ')'
[4d51835]3605                { $$ = $2; }
3606        ;
[51b7345]3607
[5e25953]3608variable_type_redeclarator:
3609        paren_type attribute_list_opt
3610                { $$ = $1->addQualifiers( $2 ); }
[1f771fc]3611        | variable_type_ptr
3612        | variable_type_array attribute_list_opt
[5e25953]3613                { $$ = $1->addQualifiers( $2 ); }
[1f771fc]3614        | variable_type_function attribute_list_opt
[5e25953]3615                { $$ = $1->addQualifiers( $2 ); }
3616        ;
3617
[1f771fc]3618variable_type_ptr:
[c6b1105]3619        ptrref_operator variable_type_redeclarator
[a5f9444]3620                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c6b1105]3621        | ptrref_operator type_qualifier_list variable_type_redeclarator
[ce8c12f]3622                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[1f771fc]3623        | '(' variable_type_ptr ')' attribute_list_opt          // redundant parenthesis
[5e25953]3624                { $$ = $2->addQualifiers( $4 ); }
[1f771fc]3625        | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis
[5e25953]3626                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
[4d51835]3627        ;
[51b7345]3628
[1f771fc]3629variable_type_array:
[2871210]3630        paren_type array_dimension
[4d51835]3631                { $$ = $1->addArray( $2 ); }
[1f771fc]3632        | '(' variable_type_ptr ')' array_dimension
[4d51835]3633                { $$ = $2->addArray( $4 ); }
[1f771fc]3634        | '(' attribute_list variable_type_ptr ')' array_dimension
[5e25953]3635                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[1f771fc]3636        | '(' variable_type_array ')' multi_array_dimension     // redundant parenthesis
[4d51835]3637                { $$ = $2->addArray( $4 ); }
[1f771fc]3638        | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis
[5e25953]3639                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
[1f771fc]3640        | '(' variable_type_array ')'                                           // redundant parenthesis
[4d51835]3641                { $$ = $2; }
[1f771fc]3642        | '(' attribute_list variable_type_array ')'            // redundant parenthesis
[5e25953]3643                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3644        ;
[51b7345]3645
[1f771fc]3646variable_type_function:
[71a422a]3647        '(' variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3648                { $$ = $2->addParamList( $5 ); }
3649        | '(' attribute_list variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3650                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
[1f771fc]3651        | '(' variable_type_function ')'                                        // redundant parenthesis
3652                { $$ = $2; }
3653        | '(' attribute_list variable_type_function ')'         // redundant parenthesis
3654                { $$ = $3->addQualifiers( $2 ); }
3655        ;
3656
3657// This pattern parses a declaration for a function prototype that redefines a type name.  It precludes declaring an
3658// array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to
3659// arrays and functions.
3660
3661function_type_redeclarator:
3662        function_type_no_ptr attribute_list_opt
3663                { $$ = $1->addQualifiers( $2 ); }
3664        | function_type_ptr
3665        | function_type_array attribute_list_opt
3666                { $$ = $1->addQualifiers( $2 ); }
3667        ;
3668
3669function_type_no_ptr:
[71a422a]3670        paren_type '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3671                { $$ = $1->addParamList( $3 ); }
3672        | '(' function_type_ptr ')' '(' parameter_type_list_opt ')'
3673                { $$ = $2->addParamList( $5 ); }
3674        | '(' attribute_list function_type_ptr ')' '(' parameter_type_list_opt ')'
3675                { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); }
[1f771fc]3676        | '(' function_type_no_ptr ')'                                          // redundant parenthesis
[4d51835]3677                { $$ = $2; }
[1f771fc]3678        | '(' attribute_list function_type_no_ptr ')'           // redundant parenthesis
3679                { $$ = $3->addQualifiers( $2 ); }
3680        ;
3681
3682function_type_ptr:
3683        ptrref_operator function_type_redeclarator
3684                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
3685        | ptrref_operator type_qualifier_list function_type_redeclarator
3686                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
3687        | '(' function_type_ptr ')' attribute_list_opt
3688                { $$ = $2->addQualifiers( $4 ); }
3689        | '(' attribute_list function_type_ptr ')' attribute_list_opt
3690                { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); }
3691        ;
3692
3693function_type_array:
3694        '(' function_type_ptr ')' array_dimension
3695                { $$ = $2->addArray( $4 ); }
3696        | '(' attribute_list function_type_ptr ')' array_dimension
3697                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
3698        | '(' function_type_array ')' multi_array_dimension     // redundant parenthesis
3699                { $$ = $2->addArray( $4 ); }
3700        | '(' attribute_list function_type_array ')' multi_array_dimension // redundant parenthesis
3701                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
3702        | '(' function_type_array ')'                                           // redundant parenthesis
[4d51835]3703                { $$ = $2; }
[1f771fc]3704        | '(' attribute_list function_type_array ')'            // redundant parenthesis
[5e25953]3705                { $$ = $3->addQualifiers( $2 ); }
[4d51835]3706        ;
[51b7345]3707
[c0aa336]3708// This pattern parses a declaration for a parameter variable of a function prototype or actual that is not redefining a
3709// typedef name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes
3710// declaring an array of functions versus a pointer to an array of functions, and returning arrays and functions versus
3711// pointers to arrays and functions.
[51b7345]3712
3713identifier_parameter_declarator:
[4d51835]3714        paren_identifier attribute_list_opt
[1db21619]3715                { $$ = $1->addQualifiers( $2 ); }
[b6b3c42]3716        | '&' MUTEX paren_identifier attribute_list_opt
[36e6f10]3717                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
[4d51835]3718        | identifier_parameter_ptr
3719        | identifier_parameter_array attribute_list_opt
[1db21619]3720                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3721        | identifier_parameter_function attribute_list_opt
[1db21619]3722                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3723        ;
[51b7345]3724
3725identifier_parameter_ptr:
[dd51906]3726        ptrref_operator identifier_parameter_declarator
[a5f9444]3727                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3728        | ptrref_operator type_qualifier_list identifier_parameter_declarator
[ce8c12f]3729                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]3730        | '(' identifier_parameter_ptr ')' attribute_list_opt // redundant parenthesis
[c0aa336]3731                { $$ = $2->addQualifiers( $4 ); }
[4d51835]3732        ;
[51b7345]3733
3734identifier_parameter_array:
[4d51835]3735        paren_identifier array_parameter_dimension
3736                { $$ = $1->addArray( $2 ); }
3737        | '(' identifier_parameter_ptr ')' array_dimension
3738                { $$ = $2->addArray( $4 ); }
3739        | '(' identifier_parameter_array ')' multi_array_dimension // redundant parenthesis
3740                { $$ = $2->addArray( $4 ); }
3741        | '(' identifier_parameter_array ')'                            // redundant parenthesis
3742                { $$ = $2; }
3743        ;
[51b7345]3744
3745identifier_parameter_function:
[71a422a]3746        paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3747                { $$ = $1->addParamList( $3 ); }
3748        | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3749                { $$ = $2->addParamList( $5 ); }
[4d51835]3750        | '(' identifier_parameter_function ')'                         // redundant parenthesis
3751                { $$ = $2; }
3752        ;
[b87a5ed]3753
[de62360d]3754// This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name,
3755// e.g.:
[c11e31c]3756//
[b87a5ed]3757//              typedef int foo;
[114014c]3758//              forall( otype T ) struct foo;
[b87a5ed]3759//              int f( int foo ); // redefine typedef name in new scope
[c11e31c]3760//
[c0aa336]3761// and allows the C99 array options, which can only appear in a parameter list.
[51b7345]3762
[2871210]3763type_parameter_redeclarator:
[f9c3100]3764        typedef_name attribute_list_opt
[1db21619]3765                { $$ = $1->addQualifiers( $2 ); }
[f9c3100]3766        | '&' MUTEX typedef_name attribute_list_opt
[36e6f10]3767                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
[2871210]3768        | type_parameter_ptr
3769        | type_parameter_array attribute_list_opt
[1db21619]3770                { $$ = $1->addQualifiers( $2 ); }
[2871210]3771        | type_parameter_function attribute_list_opt
[1db21619]3772                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3773        ;
[51b7345]3774
[f9c3100]3775typedef_name:
[4d51835]3776        TYPEDEFname
[7fdb94e]3777                { $$ = DeclarationNode::newName( $1 ); }
[2871210]3778        | TYPEGENname
[7fdb94e]3779                { $$ = DeclarationNode::newName( $1 ); }
[4d51835]3780        ;
[51b7345]3781
[2871210]3782type_parameter_ptr:
[dd51906]3783        ptrref_operator type_parameter_redeclarator
[a5f9444]3784                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3785        | ptrref_operator type_qualifier_list type_parameter_redeclarator
[ce8c12f]3786                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]3787        | '(' type_parameter_ptr ')' attribute_list_opt         // redundant parenthesis
[c0aa336]3788                { $$ = $2->addQualifiers( $4 ); }
[4d51835]3789        ;
[51b7345]3790
[2871210]3791type_parameter_array:
[f9c3100]3792        typedef_name array_parameter_dimension
[4d51835]3793                { $$ = $1->addArray( $2 ); }
[2871210]3794        | '(' type_parameter_ptr ')' array_parameter_dimension
[4d51835]3795                { $$ = $2->addArray( $4 ); }
3796        ;
[51b7345]3797
[2871210]3798type_parameter_function:
[71a422a]3799        typedef_name '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3800                { $$ = $1->addParamList( $3 ); }
3801        | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3802                { $$ = $2->addParamList( $5 ); }
[4d51835]3803        ;
[b87a5ed]3804
[de62360d]3805// This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to
3806// which the type applies, e.g.:
[c11e31c]3807//
[b87a5ed]3808//              sizeof( int );
[c0aa336]3809//              sizeof( int * );
[b87a5ed]3810//              sizeof( int [10] );
[c0aa336]3811//              sizeof( int (*)() );
3812//              sizeof( int () );
[c11e31c]3813//
[de62360d]3814// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
3815// and functions versus pointers to arrays and functions.
[51b7345]3816
3817abstract_declarator:
[4d51835]3818        abstract_ptr
3819        | abstract_array attribute_list_opt
[1db21619]3820                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3821        | abstract_function attribute_list_opt
[1db21619]3822                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3823        ;
[51b7345]3824
3825abstract_ptr:
[dd51906]3826        ptrref_operator
[a5f9444]3827                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
[dd51906]3828        | ptrref_operator type_qualifier_list
[ce8c12f]3829                { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]3830        | ptrref_operator abstract_declarator
[a5f9444]3831                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3832        | ptrref_operator type_qualifier_list abstract_declarator
[ce8c12f]3833                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]3834        | '(' abstract_ptr ')' attribute_list_opt
3835                { $$ = $2->addQualifiers( $4 ); }
[4d51835]3836        ;
[51b7345]3837
3838abstract_array:
[4d51835]3839        array_dimension
3840        | '(' abstract_ptr ')' array_dimension
3841                { $$ = $2->addArray( $4 ); }
3842        | '(' abstract_array ')' multi_array_dimension          // redundant parenthesis
3843                { $$ = $2->addArray( $4 ); }
3844        | '(' abstract_array ')'                                                        // redundant parenthesis
3845                { $$ = $2; }
3846        ;
[51b7345]3847
3848abstract_function:
[71a422a]3849        '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
3850                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
3851        | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3852                { $$ = $2->addParamList( $5 ); }
[4d51835]3853        | '(' abstract_function ')'                                                     // redundant parenthesis
3854                { $$ = $2; }
3855        ;
[51b7345]3856
3857array_dimension:
[4d51835]3858                // Only the first dimension can be empty.
[2871210]3859        '[' ']'
[a5f9444]3860                { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); }
[2871210]3861        | '[' ']' multi_array_dimension
[a5f9444]3862                { $$ = DeclarationNode::newArray( nullptr, nullptr, false )->addArray( $3 ); }
[910e1d0]3863                // Cannot use constant_expression because of tuples => semantic check
[d41735a]3864        | '[' push assignment_expression pop ',' comma_expression ']' // CFA
[a5f9444]3865                { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); }
[6a99803]3866                // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
[d41735a]3867        | '[' push array_type_list pop ']'                                      // CFA
[0b0a285]3868                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
[4d51835]3869        | multi_array_dimension
3870        ;
[51b7345]3871
[d41735a]3872array_type_list:
3873        basic_type_name
[bb7422a]3874                { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); }
[d41735a]3875        | type_name
[bb7422a]3876                { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); }
[d41735a]3877        | assignment_expression upupeq assignment_expression
3878        | array_type_list ',' basic_type_name
[bb7422a]3879                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); }
3880        | array_type_list ',' type_name
3881                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); }
[d41735a]3882        | array_type_list ',' assignment_expression upupeq assignment_expression
3883        ;
3884
3885upupeq:
3886        '~'
3887                { $$ = OperKinds::LThan; }
3888        | ErangeUpEq
3889                { $$ = OperKinds::LEThan; }
[9fd9d015]3890        ;
[d41735a]3891
[51b7345]3892multi_array_dimension:
[c0a33d2]3893        '[' push assignment_expression pop ']'
[a5f9444]3894                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
[c0a33d2]3895        | '[' push '*' pop ']'                                                          // C99
[4d51835]3896                { $$ = DeclarationNode::newVarArray( 0 ); }
[c0a33d2]3897        | multi_array_dimension '[' push assignment_expression pop ']'
[a5f9444]3898                { $$ = $1->addArray( DeclarationNode::newArray( $4, nullptr, false ) ); }
[c0a33d2]3899        | multi_array_dimension '[' push '*' pop ']'            // C99
[4d51835]3900                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
3901        ;
[51b7345]3902
[c11e31c]3903// This pattern parses a declaration of a parameter abstract variable or function prototype, i.e., there is no
3904// identifier to which the type applies, e.g.:
3905//
[c0aa336]3906//              int f( int );                   // not handled here
3907//              int f( int * );                 // abstract function-prototype parameter; no parameter name specified
3908//              int f( int (*)() );             // abstract function-prototype parameter; no parameter name specified
[b87a5ed]3909//              int f( int (int) );             // abstract function-prototype parameter; no parameter name specified
[c11e31c]3910//
[de62360d]3911// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
[c0aa336]3912// and functions versus pointers to arrays and functions. In addition, the pattern handles the
3913// special meaning of parenthesis around a typedef name:
3914//
3915//              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
3916//              parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
3917//              not as redundant parentheses around the identifier."
3918//
3919// For example:
3920//
3921//              typedef float T;
3922//              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator
3923//              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator
3924//              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator
3925//              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator
3926//
3927// In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
3928// not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
3929// functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
3930// functions.
[51b7345]3931
[59c7e3e]3932abstract_parameter_declarator_opt:
3933        // empty
3934                { $$ = nullptr; }
3935        | abstract_parameter_declarator
3936        ;
3937
[51b7345]3938abstract_parameter_declarator:
[4d51835]3939        abstract_parameter_ptr
[b6b3c42]3940        | '&' MUTEX attribute_list_opt
[36e6f10]3941                { $$ = DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf )->addQualifiers( $3 ); }
[4d51835]3942        | abstract_parameter_array attribute_list_opt
[1db21619]3943                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3944        | abstract_parameter_function attribute_list_opt
[1db21619]3945                { $$ = $1->addQualifiers( $2 ); }
[4d51835]3946        ;
[51b7345]3947
3948abstract_parameter_ptr:
[dd51906]3949        ptrref_operator
[ce8c12f]3950                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
[dd51906]3951        | ptrref_operator type_qualifier_list
[ce8c12f]3952                { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]3953        | ptrref_operator abstract_parameter_declarator
[ce8c12f]3954                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]3955        | ptrref_operator type_qualifier_list abstract_parameter_declarator
[ce8c12f]3956                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]3957        | '(' abstract_parameter_ptr ')' attribute_list_opt     // redundant parenthesis
[c0aa336]3958                { $$ = $2->addQualifiers( $4 ); }
[4d51835]3959        ;
[51b7345]3960
3961abstract_parameter_array:
[4d51835]3962        array_parameter_dimension
3963        | '(' abstract_parameter_ptr ')' array_parameter_dimension
3964                { $$ = $2->addArray( $4 ); }
3965        | '(' abstract_parameter_array ')' multi_array_dimension // redundant parenthesis
3966                { $$ = $2->addArray( $4 ); }
3967        | '(' abstract_parameter_array ')'                                      // redundant parenthesis
3968                { $$ = $2; }
3969        ;
[51b7345]3970
3971abstract_parameter_function:
[71a422a]3972        '(' parameter_type_list_opt ')'                 // empty parameter list OBSOLESCENT (see 3)
3973                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
3974        | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
3975                { $$ = $2->addParamList( $5 ); }
[4d51835]3976        | '(' abstract_parameter_function ')'                           // redundant parenthesis
3977                { $$ = $2; }
3978        ;
[51b7345]3979
3980array_parameter_dimension:
[4d51835]3981                // Only the first dimension can be empty or have qualifiers.
3982        array_parameter_1st_dimension
3983        | array_parameter_1st_dimension multi_array_dimension
3984                { $$ = $1->addArray( $2 ); }
3985        | multi_array_dimension
3986        ;
[51b7345]3987
[c11e31c]3988// The declaration of an array parameter has additional syntax over arrays in normal variable declarations:
3989//
[de62360d]3990//              ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in
3991//              a declaration of a function parameter with an array type, and then only in the outermost array type derivation."
[51b7345]3992
3993array_parameter_1st_dimension:
[2871210]3994        '[' ']'
[a5f9444]3995                { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); }
[13e8427]3996                // multi_array_dimension handles the '[' '*' ']' case
[c0a33d2]3997        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
3998                { $$ = DeclarationNode::newVarArray( $3 ); }
3999        | '[' push type_qualifier_list pop ']'
[a5f9444]4000                { $$ = DeclarationNode::newArray( nullptr, $3, false ); }
[13e8427]4001                // multi_array_dimension handles the '[' assignment_expression ']' case
[c0a33d2]4002        | '[' push type_qualifier_list assignment_expression pop ']'
4003                { $$ = DeclarationNode::newArray( $4, $3, false ); }
4004        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
4005                { $$ = DeclarationNode::newArray( $5, $4, true ); }
4006        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
4007                { $$ = DeclarationNode::newArray( $5, $3, true ); }
[4d51835]4008        ;
[b87a5ed]4009
[c0aa336]4010// This pattern parses a declaration of an abstract variable, but does not allow "int ()" for a function pointer.
[c11e31c]4011//
[71a422a]4012//   struct S {
4013//       int;
4014//       int *;
4015//       int [10];
4016//       int (*)();
4017//   };
[51b7345]4018
4019variable_abstract_declarator:
[4d51835]4020        variable_abstract_ptr
4021        | variable_abstract_array attribute_list_opt
[1db21619]4022                { $$ = $1->addQualifiers( $2 ); }
[4d51835]4023        | variable_abstract_function attribute_list_opt
[1db21619]4024                { $$ = $1->addQualifiers( $2 ); }
[4d51835]4025        ;
[51b7345]4026
4027variable_abstract_ptr:
[dd51906]4028        ptrref_operator
[a5f9444]4029                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
[dd51906]4030        | ptrref_operator type_qualifier_list
[ce8c12f]4031                { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]4032        | ptrref_operator variable_abstract_declarator
[a5f9444]4033                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]4034        | ptrref_operator type_qualifier_list variable_abstract_declarator
[ce8c12f]4035                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[5e25953]4036        | '(' variable_abstract_ptr ')' attribute_list_opt      // redundant parenthesis
[c0aa336]4037                { $$ = $2->addQualifiers( $4 ); }
[4d51835]4038        ;
[51b7345]4039
4040variable_abstract_array:
[4d51835]4041        array_dimension
4042        | '(' variable_abstract_ptr ')' array_dimension
4043                { $$ = $2->addArray( $4 ); }
4044        | '(' variable_abstract_array ')' multi_array_dimension // redundant parenthesis
4045                { $$ = $2->addArray( $4 ); }
4046        | '(' variable_abstract_array ')'                                       // redundant parenthesis
4047                { $$ = $2; }
4048        ;
[51b7345]4049
4050variable_abstract_function:
[71a422a]4051        '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
4052                { $$ = $2->addParamList( $5 ); }
[4d51835]4053        | '(' variable_abstract_function ')'                            // redundant parenthesis
4054                { $$ = $2; }
4055        ;
[b87a5ed]4056
[de62360d]4057// This pattern parses a new-style declaration for a parameter variable or function prototype that is either an
4058// identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.
[b87a5ed]4059
[c0aa336]4060cfa_identifier_parameter_declarator_tuple:                              // CFA
4061        cfa_identifier_parameter_declarator_no_tuple
4062        | cfa_abstract_tuple
4063        | type_qualifier_list cfa_abstract_tuple
[4d51835]4064                { $$ = $2->addQualifiers( $1 ); }
4065        ;
[b87a5ed]4066
[c0aa336]4067cfa_identifier_parameter_declarator_no_tuple:                   // CFA
4068        cfa_identifier_parameter_ptr
4069        | cfa_identifier_parameter_array
[4d51835]4070        ;
[b87a5ed]4071
[c0aa336]4072cfa_identifier_parameter_ptr:                                                   // CFA
[d0ffed1]4073                // No SUE declaration in parameter list.
4074        ptrref_operator type_specifier_nobody
[a5f9444]4075                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[d0ffed1]4076        | type_qualifier_list ptrref_operator type_specifier_nobody
[ce8c12f]4077                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]4078        | ptrref_operator cfa_abstract_function
[a5f9444]4079                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c0aa336]4080        | type_qualifier_list ptrref_operator cfa_abstract_function
[ce8c12f]4081                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]4082        | ptrref_operator cfa_identifier_parameter_declarator_tuple
[a5f9444]4083                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c0aa336]4084        | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple
[ce8c12f]4085                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[4d51835]4086        ;
[b87a5ed]4087
[c0aa336]4088cfa_identifier_parameter_array:                                                 // CFA
[de62360d]4089                // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
4090                // shift/reduce conflict with new-style empty (void) function return type.
[d0ffed1]4091        '[' ']' type_specifier_nobody
[a5f9444]4092                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[d0ffed1]4093        | cfa_array_parameter_1st_dimension type_specifier_nobody
[4d51835]4094                { $$ = $2->addNewArray( $1 ); }
[d0ffed1]4095        | '[' ']' multi_array_dimension type_specifier_nobody
[a5f9444]4096                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[d0ffed1]4097        | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier_nobody
[4d51835]4098                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
[d0ffed1]4099        | multi_array_dimension type_specifier_nobody
[4d51835]4100                { $$ = $2->addNewArray( $1 ); }
[9059213]4101
[c0aa336]4102        | '[' ']' cfa_identifier_parameter_ptr
[a5f9444]4103                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]4104        | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr
[4d51835]4105                { $$ = $2->addNewArray( $1 ); }
[c0aa336]4106        | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr
[a5f9444]4107                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]4108        | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr
[4d51835]4109                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
[c0aa336]4110        | multi_array_dimension cfa_identifier_parameter_ptr
[4d51835]4111                { $$ = $2->addNewArray( $1 ); }
4112        ;
[51b7345]4113
[c0aa336]4114cfa_array_parameter_1st_dimension:
[c0a33d2]4115        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
4116                { $$ = DeclarationNode::newVarArray( $3 ); }
4117        | '[' push type_qualifier_list assignment_expression pop ']'
4118                { $$ = DeclarationNode::newArray( $4, $3, false ); }
4119        | '[' push declaration_qualifier_list assignment_expression pop ']'
[4d51835]4120                // declaration_qualifier_list must be used because of shift/reduce conflict with
4121                // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
4122                // appear in this context.
[c0a33d2]4123                { $$ = DeclarationNode::newArray( $4, $3, true ); }
4124        | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
4125                { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
[4d51835]4126        ;
[b87a5ed]4127
[de62360d]4128// This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no
4129// identifier to which the type applies, e.g.:
[c11e31c]4130//
[b87a5ed]4131//              [int] f( int );                         // abstract variable parameter; no parameter name specified
4132//              [int] f( [int] (int) );         // abstract function-prototype parameter; no parameter name specified
[c11e31c]4133//
4134// These rules need LR(3):
4135//
[c0aa336]4136//              cfa_abstract_tuple identifier_or_type_name
[40de461]4137//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
[c11e31c]4138//
4139// since a function return type can be syntactically identical to a tuple type:
4140//
[b87a5ed]4141//              [int, int] t;
4142//              [int, int] f( int );
[c11e31c]4143//
[2871210]4144// Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
[c0aa336]4145// cfa_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
4146// lookahead. To accomplish this, cfa_abstract_declarator has an entry point without tuple, and tuple declarations are
4147// duplicated when appearing with cfa_function_specifier.
[b87a5ed]4148
[c0aa336]4149cfa_abstract_declarator_tuple:                                                  // CFA
4150        cfa_abstract_tuple
4151        | type_qualifier_list cfa_abstract_tuple
[4d51835]4152                { $$ = $2->addQualifiers( $1 ); }
[c0aa336]4153        | cfa_abstract_declarator_no_tuple
[4d51835]4154        ;
[b87a5ed]4155
[c0aa336]4156cfa_abstract_declarator_no_tuple:                                               // CFA
4157        cfa_abstract_ptr
4158        | cfa_abstract_array
[4d51835]4159        ;
[b87a5ed]4160
[c0aa336]4161cfa_abstract_ptr:                                                                               // CFA
[dd51906]4162        ptrref_operator type_specifier
[a5f9444]4163                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]4164        | type_qualifier_list ptrref_operator type_specifier
[ce8c12f]4165                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]4166        | ptrref_operator cfa_abstract_function
[a5f9444]4167                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c0aa336]4168        | type_qualifier_list ptrref_operator cfa_abstract_function
[ce8c12f]4169                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]4170        | ptrref_operator cfa_abstract_declarator_tuple
[a5f9444]4171                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[c0aa336]4172        | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple
[ce8c12f]4173                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[4d51835]4174        ;
[b87a5ed]4175
[c0aa336]4176cfa_abstract_array:                                                                             // CFA
[de62360d]4177                // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
4178                // empty (void) function return type.
[2871210]4179        '[' ']' type_specifier
[2298f728]4180                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[2871210]4181        | '[' ']' multi_array_dimension type_specifier
[2298f728]4182                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[4d51835]4183        | multi_array_dimension type_specifier
4184                { $$ = $2->addNewArray( $1 ); }
[c0aa336]4185        | '[' ']' cfa_abstract_ptr
[2298f728]4186                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]4187        | '[' ']' multi_array_dimension cfa_abstract_ptr
[2298f728]4188                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]4189        | multi_array_dimension cfa_abstract_ptr
[4d51835]4190                { $$ = $2->addNewArray( $1 ); }
4191        ;
[b87a5ed]4192
[c0aa336]4193cfa_abstract_tuple:                                                                             // CFA
[c0a33d2]4194        '[' push cfa_abstract_parameter_list pop ']'
4195                { $$ = DeclarationNode::newTuple( $3 ); }
[35718a9]4196        | '[' push type_specifier_nobody ELLIPSIS pop ']'
[13e8427]4197                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
[35718a9]4198        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
[13e8427]4199                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
[4d51835]4200        ;
[b87a5ed]4201
[c0aa336]4202cfa_abstract_function:                                                                  // CFA
[40de461]4203//      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
[1b29996]4204//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
[40de461]4205        cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
[c0a33d2]4206                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
[40de461]4207        | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
[c0a33d2]4208                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
[4d51835]4209        ;
[b87a5ed]4210
[de62360d]4211// 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in
4212//    each declaration, and in the specifier-qualifier list in each structure declaration and type name."
[c11e31c]4213//
[de62360d]4214// 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of
4215//    the declaration specifiers in a declaration is an obsolescent feature."
[c11e31c]4216//
4217// 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not
4218//    prototype-format parameter type declarators) is an obsolescent feature."
4219//
[de62360d]4220// 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and
4221//    declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
[51b7345]4222
[e1d66c84]4223// ************************ MISCELLANEOUS ********************************
[51b7345]4224
[b87a5ed]4225comma_opt:                                                                                              // redundant comma
[4d51835]4226        // empty
4227        | ','
4228        ;
[51b7345]4229
[5a51798]4230default_initializer_opt:
[4d51835]4231        // empty
[58dd019]4232                { $$ = nullptr; }
[4d51835]4233        | '=' assignment_expression
4234                { $$ = $2; }
4235        ;
[51b7345]4236
4237%%
[a1c9ddd]4238
[c11e31c]4239// ----end of grammar----
[51b7345]4240
[c11e31c]4241// Local Variables: //
[b87a5ed]4242// mode: c++ //
[de62360d]4243// tab-width: 4 //
[c11e31c]4244// compile-command: "make install" //
4245// End: //
Note: See TracBrowser for help on using the repository browser.