source: src/Parser/parser.yy @ 9fd9d015

ADTast-experimental
Last change on this file since 9fd9d015 was 9fd9d015, checked in by Peter A. Buhr <pabuhr@…>, 13 months ago

formatting, add new waituntil grammar, rewrite waitfor grammar, simplify waitfor build-routines to match new grammar

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