source: src/Parser/parser.yy @ 62c6cfa

Last change on this file since 62c6cfa was 62c6cfa, checked in by JiadaL <j82liang@…>, 11 months ago

Revert "Fix designator value in enumerated array and implemented enumerated array with inlined enume declaration"

This reverts commit c1e66d966aadf6846330871033458d4a398bd576.

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