source: src/Parser/parser.yy @ 02e5ab6

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 02e5ab6 was 02e5ab6, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

add preprocessor flag -DCFORALL=1, add syntax for constructor/destructor

  • Property mode set to 100644
File size: 102.4 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[c11e31c]7// cfa.y --
8//
9// Author           : Peter A. Buhr
10// Created On       : Sat Sep  1 20:22:55 2001
11// Last Modified By : Peter A. Buhr
[02e5ab6]12// Last Modified On : Mon Sep 28 18:18:32 2015
13// Update Count     : 1402
[c11e31c]14//
15
[de62360d]16// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
17// grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While parts have been
18// copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar.
19// In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax
20// that must be subsequently rejected by semantic checks.  Nevertheless, there are still several semantic checks
21// required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions.
[c11e31c]22
[de62360d]23// Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with
24// the grammar.
[c11e31c]25
26// The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
27//
28// 1. designation with '=' (use ':' instead)
29//
[de62360d]30// Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has
31// two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
[c11e31c]32//
33// 1. nested functions
34// 2. generalized lvalues
35// 3. designation with and without '=' (use ':' instead)
36// 4. attributes not allowed in parenthesis of declarator
37//
[de62360d]38// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
39// (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the
40// syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable
41// parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation"
42// grammar rule.
[51b7345]43
44%{
[b87a5ed]45#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
46#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
[8a95629]47extern char *yytext;
[51b7345]48
49#undef __GNUC_MINOR__
50
51#include <cstdio>
52#include <stack>
53#include "TypedefTable.h"
54#include "lex.h"
55#include "ParseNode.h"
[1db21619]56#include "TypeData.h"
[51b7345]57#include "LinkageSpec.h"
58
[b87a5ed]59DeclarationNode *theTree = 0;                                                   // the resulting parse tree
[51b7345]60LinkageSpec::Type linkage = LinkageSpec::Cforall;
61std::stack< LinkageSpec::Type > linkageStack;
62TypedefTable typedefTable;
63%}
64
[c11e31c]65//************************* TERMINAL TOKENS ********************************
[51b7345]66
[c11e31c]67// keywords
[51b7345]68%token TYPEDEF
69%token AUTO EXTERN REGISTER STATIC
[b87a5ed]70%token INLINE                                                                                   // C99
71%token FORTRAN                                                                                  // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
[51b7345]72%token CONST VOLATILE
[b87a5ed]73%token RESTRICT                                                                                 // C99
74%token FORALL LVALUE                                                                    // CFA
[51b7345]75%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
[b87a5ed]76%token BOOL COMPLEX IMAGINARY                                                   // C99
77%token TYPEOF LABEL                                                                             // GCC
[51b7345]78%token ENUM STRUCT UNION
[b87a5ed]79%token TYPE FTYPE DTYPE CONTEXT                                                 // CFA
[51b7345]80%token SIZEOF
[b87a5ed]81%token ATTRIBUTE EXTENSION                                                              // GCC
[51b7345]82%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
[02e5ab6]83%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
[b87a5ed]84%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
[c11e31c]85%token ALIGNAS ALIGNOF ATOMIC GENERIC NORETURN STATICASSERT THREADLOCAL // C11
[51b7345]86
[c11e31c]87// names and constants: lexer differentiates between identifier and typedef names
[b87a5ed]88%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
89%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
90%token<tok> INTEGERconstant             FLOATINGconstant                CHARACTERconstant               STRINGliteral
91%token<tok> ZERO                                ONE                                             // CFA
[51b7345]92
[c11e31c]93// multi-character operators
[b87a5ed]94%token ARROW                                                                                    // ->
95%token ICR DECR                                                                                 // ++   --
96%token LS RS                                                                                    // <<   >>
97%token LE GE EQ NE                                                                              // <=   >=      ==      !=
98%token ANDAND OROR                                                                              // &&   ||
99%token ELLIPSIS                                                                                 // ...
100
101%token MULTassign       DIVassign       MODassign                               // *=   /=      %=/
102%token PLUSassign       MINUSassign                                                     // +=   -=
103%token LSassign         RSassign                                                        // <<=  >>=
104%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
[51b7345]105
[c11e31c]106// Types declaration
[51b7345]107%union
108{
[b87a5ed]109        Token tok;
110        ParseNode *pn;
111        ExpressionNode *en;
112        DeclarationNode *decl;
[68cd1ce]113        DeclarationNode::Aggregate aggKey;
[b87a5ed]114        DeclarationNode::TypeClass tclass;
115        StatementNode *sn;
116        ConstantNode *constant;
[7f5566b]117        LabelNode *label;
[b87a5ed]118        InitializerNode *in;
[7f5566b]119        bool flag;
[51b7345]120}
121
[02e5ab6]122%type<tok> identifier  no_01_identifier  no_attr_identifier no_attr_identifier_01  zero_one
[2871210]123%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
[51b7345]124%type<constant> string_literal_list
125
[c11e31c]126// expressions
[51b7345]127%type<constant> constant
[b87a5ed]128%type<en> tuple                                                 tuple_expression_list
129%type<en> unary_operator                                assignment_operator
130%type<en> primary_expression                    postfix_expression                      unary_expression
131%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
132%type<en> relational_expression                 equality_expression                     AND_expression                          exclusive_OR_expression
133%type<en> inclusive_OR_expression               logical_AND_expression          logical_OR_expression           conditional_expression
134%type<en> constant_expression                   assignment_expression           assignment_expression_opt
135%type<en> comma_expression                              comma_expression_opt
136%type<en> argument_expression_list              argument_expression                     for_control_expression          assignment_opt
[51b7345]137%type<en> subrange
[7f5566b]138%type<en> asm_operands_opt asm_operands_list asm_operand
139%type<label> label_list
140%type<constant> asm_clobbers_list_opt
141%type<flag> asm_volatile_opt
[51b7345]142
[c11e31c]143// statements
[b87a5ed]144%type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
[02e5ab6]145%type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement                   ctor_dtor
[b87a5ed]146%type<sn> fall_through_opt                              fall_through
147%type<sn> statement                                             statement_list
148%type<sn> block_item_list                               block_item
[51b7345]149%type<sn> case_clause
[b87a5ed]150%type<en> case_value                                    case_value_list
151%type<sn> case_label                                    case_label_list
152%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
153%type<pn> handler_list                                  handler_clause                          finally_clause
[51b7345]154
[c11e31c]155// declarations
[51b7345]156%type<decl> abstract_array abstract_declarator abstract_function abstract_parameter_array
157%type<decl> abstract_parameter_declaration abstract_parameter_declarator abstract_parameter_function
158%type<decl> abstract_parameter_ptr abstract_ptr
159
160%type<aggKey> aggregate_key
161%type<decl>  aggregate_name
162
163%type<decl> array_dimension array_parameter_1st_dimension array_parameter_dimension multi_array_dimension
164
165%type<decl> assertion assertion_list_opt
166
167%type<en>   bit_subrange_size_opt bit_subrange_size
168
169%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type_name indirect_type_name
170
171%type<decl> context_declaration context_declaration_list context_declaring_list context_specifier
172
173%type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list
174%type<decl> declaration_specifier declarator declaring_list
175
176%type<decl> elaborated_type_name
177
178%type<decl> enumerator_list enum_name
179%type<en> enumerator_value_opt
180
181%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
182
183%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
184%type<en> field field_list
185
[4d51835]186%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
[51b7345]187
188%type<decl> identifier_parameter_array identifier_parameter_declarator identifier_parameter_function
189%type<decl> identifier_parameter_ptr identifier_list
190
191%type<decl> new_abstract_array new_abstract_declarator_no_tuple new_abstract_declarator_tuple
192%type<decl> new_abstract_function new_abstract_parameter_declaration new_abstract_parameter_list
193%type<decl> new_abstract_ptr new_abstract_tuple
194
195%type<decl> new_array_parameter_1st_dimension
196
197%type<decl> new_context_declaring_list new_declaration new_field_declaring_list
198%type<decl> new_function_declaration new_function_return new_function_specifier
199
200%type<decl> new_identifier_parameter_array new_identifier_parameter_declarator_no_tuple
201%type<decl> new_identifier_parameter_declarator_tuple new_identifier_parameter_ptr
202
203%type<decl> new_parameter_declaration new_parameter_list new_parameter_type_list new_parameter_type_list_opt
204
205%type<decl> new_typedef_declaration new_variable_declaration new_variable_specifier
206
207%type<decl> old_declaration old_declaration_list old_declaration_list_opt old_function_array
208%type<decl> old_function_declarator old_function_no_ptr old_function_ptr
209
210%type<decl> parameter_declaration parameter_list parameter_type_list
211%type<decl> parameter_type_list_opt
212
[2871210]213%type<decl> paren_identifier paren_type
[51b7345]214
215%type<decl> storage_class storage_class_name storage_class_list
216
217%type<decl> sue_declaration_specifier sue_type_specifier
218
219%type<tclass> type_class
220%type<decl> type_declarator type_declarator_name type_declaring_list
221
[2871210]222%type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression
223%type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr
224%type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier
225%type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
[51b7345]226
227%type<decl> type_name type_name_no_function
228%type<decl> type_parameter type_parameter_list
229
230%type<en> type_name_list
231
232%type<decl> type_qualifier type_qualifier_name type_qualifier_list type_qualifier_list_opt type_specifier
233
234%type<decl> variable_abstract_array variable_abstract_declarator variable_abstract_function
235%type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr
236
[1db21619]237%type<decl> attribute_list_opt attribute_list attribute
238
[c11e31c]239// initializers
[51b7345]240%type<in>  initializer initializer_list initializer_opt
241
[c11e31c]242// designators
[51b7345]243%type<en>  designator designator_list designation
244
245
[b87a5ed]246// Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string
247// is ambiguous:
248// .---------.                          matches IF '(' comma_expression ')' statement
[c11e31c]249// if ( C ) S1 else S2
[b87a5ed]250// `-----------------'          matches IF '(' comma_expression ')' statement ELSE statement */
[51b7345]251
[c11e31c]252%nonassoc THEN  // rule precedence for IF '(' comma_expression ')' statement
253%nonassoc ELSE  // token precedence for start of else clause in IF statement
[51b7345]254
[b87a5ed]255%start translation_unit                                                                 // parse-tree root
[51b7345]256
257%%
[c11e31c]258//************************* Namespace Management ********************************
259
[de62360d]260// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
261// "identifier" and "TYPEDEFname" that are lexically identical.  While it is possible to write a purely context-free
262// grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.  Hence, this
263// grammar uses the ANSI style.
[c11e31c]264//
[de62360d]265// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
266// introduced through "forall" qualifiers), and by introducing "type generators" -- parametrized types.  This latter
267// type name creates a third class of identifiers that must be distinguished by the scanner.
[c11e31c]268//
[de62360d]269// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
270// accesses a data structure (the TypedefTable) to allow classification of an identifier that it has just read.
271// Semantic actions during the parser update this data structure when the class of identifiers change.
[c11e31c]272//
[de62360d]273// Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
274// local scope; it must revert to its original class at the end of the block.  Since type names can be local to a
275// particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are
276// local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
277// "typedef" or "type" declarations).
[c11e31c]278//
[de62360d]279// The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
280// scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
281// within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point
282// of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
283// enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
284// rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around
285// "push" and "pop" nonterminals to resolve conflicts of this sort.
[51b7345]286
287push:
[4d51835]288                {
289                        typedefTable.enterScope();
290                }
291        ;
[51b7345]292
293pop:
[4d51835]294                {
295                        typedefTable.leaveScope();
296                }
297        ;
[51b7345]298
[c11e31c]299//************************* CONSTANTS ********************************
[51b7345]300
301constant:
[de62360d]302                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
[59db689]303        INTEGERconstant                                                         { $$ = new ConstantNode( ConstantNode::Integer, $1 ); }
304        | FLOATINGconstant                                                      { $$ = new ConstantNode( ConstantNode::Float, $1 ); }
305        | CHARACTERconstant                                                     { $$ = new ConstantNode( ConstantNode::Character, $1 ); }
[4d51835]306        ;
[51b7345]307
308identifier:
[4d51835]309        IDENTIFIER
310        | ATTR_IDENTIFIER                                                                       // CFA
311        | zero_one                                                                                      // CFA
312        ;
[51b7345]313
314no_01_identifier:
[4d51835]315        IDENTIFIER
316        | ATTR_IDENTIFIER                                                                       // CFA
317        ;
[51b7345]318
319no_attr_identifier:
[4d51835]320        IDENTIFIER
321        ;
[51b7345]322
[02e5ab6]323no_attr_identifier_01:
324        IDENTIFIER
325        | zero_one
326        ;
327
[b87a5ed]328zero_one:                                                                                               // CFA
[4d51835]329        ZERO
330        | ONE
331        ;
[51b7345]332
[b87a5ed]333string_literal_list:                                                                    // juxtaposed strings are concatenated
[59db689]334        STRINGliteral                                                           { $$ = new ConstantNode( ConstantNode::String, $1 ); }
335        | string_literal_list STRINGliteral                     { $$ = $1->appendstr( $2 ); }
[4d51835]336        ;
[51b7345]337
[c11e31c]338//************************* EXPRESSIONS ********************************
[51b7345]339
340primary_expression:
[4d51835]341        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
[de62360d]342                { $$ = new VarRefNode( $1 ); }
[4d51835]343        | zero_one
[de62360d]344                { $$ = new VarRefNode( $1 ); }
[4d51835]345        | '(' comma_expression ')'
346                { $$ = $2; }
347        | '(' compound_statement ')'                                            // GCC, lambda expression
[de62360d]348                { $$ = new ValofExprNode( $2 ); }
[4d51835]349        ;
[51b7345]350
351postfix_expression:
[4d51835]352        primary_expression
353        | postfix_expression '[' push assignment_expression pop ']'
[de62360d]354                // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a
355                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
356                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
357                // equivalent to the old x[i,j].
358                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4 ); }
[4d51835]359        | postfix_expression '(' argument_expression_list ')'
[de62360d]360                { $$ = new CompositeExprNode( $1, $3 ); }
[4d51835]361        | postfix_expression '.' no_attr_identifier
[de62360d]362                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3 )); }
[4d51835]363        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
364        | postfix_expression ARROW no_attr_identifier
[de62360d]365                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3 )); }
[4d51835]366        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
367        | postfix_expression ICR
[de62360d]368                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1 ); }
[4d51835]369        | postfix_expression DECR
[de62360d]370                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); }
[4d51835]371                // GCC has priority: cast_expression
372        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99
373                { $$ = 0; }
374        ;
[51b7345]375
376argument_expression_list:
[4d51835]377        argument_expression
378        | argument_expression_list ',' argument_expression
[de62360d]379                { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
[4d51835]380        ;
[51b7345]381
382argument_expression:
[4d51835]383        // empty
384                { $$ = 0; }                                                                             // use default argument
385        | assignment_expression
386        | no_attr_identifier ':' assignment_expression
[7f5566b]387                { $$ = $3->set_argName( $1 ); }
[2871210]388                // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient
[de62360d]389                // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used
390                // with an appropriate semantic check.
[4d51835]391        | '[' push assignment_expression pop ']' ':' assignment_expression
[7f5566b]392                { $$ = $7->set_argName( $3 ); }
[4d51835]393        | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression
[7f5566b]394                { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }
[4d51835]395        ;
[b87a5ed]396
397field_list:                                                                                             // CFA, tuple field selector
[4d51835]398        field
399        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_link( $3 ); }
400        ;
[b87a5ed]401
402field:                                                                                                  // CFA, tuple field selector
[4d51835]403        no_attr_identifier
404                { $$ = new VarRefNode( $1 ); }
405        | no_attr_identifier '.' field
[de62360d]406                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3 ); }
[4d51835]407        | no_attr_identifier '.' '[' push field_list pop ']'
[de62360d]408                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5 ); }
[4d51835]409        | no_attr_identifier ARROW field
[de62360d]410                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3 ); }
[4d51835]411        | no_attr_identifier ARROW '[' push field_list pop ']'
[de62360d]412                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5 ); }
[4d51835]413        ;
[51b7345]414
415unary_expression:
[4d51835]416        postfix_expression
[51b1202]417        // first location where constant/string can have operator applied: sizeof 3/sizeof "abc"
418        // still requires semantics checks, e.g., ++3, 3--, *3, &&3
419        | constant
420                { $$ = $1; }
421        | string_literal_list
422                { $$ = $1; }
[4d51835]423        | ICR unary_expression
[de62360d]424                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); }
[4d51835]425        | DECR unary_expression
[de62360d]426                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); }
[4d51835]427        | EXTENSION cast_expression                                                     // GCC
428                { $$ = $2; }
429        | unary_operator cast_expression
[de62360d]430                { $$ = new CompositeExprNode( $1, $2 ); }
[4d51835]431        | '!' cast_expression
[de62360d]432                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2 ); }
[4d51835]433        | '*' cast_expression                                                           // CFA
[de62360d]434                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2 ); }
[4d51835]435                // '*' is is separated from unary_operator because of shift/reduce conflict in:
436                //              { * X; } // dereference X
437                //              { * int X; } // CFA declaration of pointer to int
438                // '&' must be moved here if C++ reference variables are supported.
439        | SIZEOF unary_expression
[de62360d]440                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); }
[4d51835]441        | SIZEOF '(' type_name_no_function ')'
[de62360d]442                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); }
[4d51835]443        | ATTR_IDENTIFIER
[de62360d]444                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); }
[4d51835]445        | ATTR_IDENTIFIER '(' type_name ')'
[de62360d]446                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 )); }
[4d51835]447        | ATTR_IDENTIFIER '(' argument_expression ')'
[de62360d]448                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); }
[4d51835]449        | ALIGNOF unary_expression                                                      // GCC, variable alignment
[de62360d]450                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2 ); }
[4d51835]451        | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
[02e5ab6]452                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); }
[4d51835]453        | ANDAND no_attr_identifier                                                     // GCC, address of label
[02e5ab6]454                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); }
[4d51835]455        ;
[51b7345]456
457unary_operator:
[de62360d]458        '&'                                                                                     { $$ = new OperatorNode( OperatorNode::AddressOf ); }
459        | '+'                                                                           { $$ = new OperatorNode( OperatorNode::UnPlus ); }
460        | '-'                                                                           { $$ = new OperatorNode( OperatorNode::UnMinus ); }
461        | '~'                                                                           { $$ = new OperatorNode( OperatorNode::BitNeg ); }
[4d51835]462        ;
[51b7345]463
464cast_expression:
[4d51835]465        unary_expression
466        | '(' type_name_no_function ')' cast_expression
[de62360d]467                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); }
[4d51835]468        | '(' type_name_no_function ')' tuple
[de62360d]469                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); }
[4d51835]470        ;
[51b7345]471
472multiplicative_expression:
[4d51835]473        cast_expression
474        | multiplicative_expression '*' cast_expression
[de62360d]475                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3 ); }
[4d51835]476        | multiplicative_expression '/' cast_expression
[de62360d]477                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3 ); }
[4d51835]478        | multiplicative_expression '%' cast_expression
[de62360d]479                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3 ); }
[4d51835]480        ;
[51b7345]481
482additive_expression:
[4d51835]483        multiplicative_expression
484        | additive_expression '+' multiplicative_expression
[de62360d]485                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3 ); }
[4d51835]486        | additive_expression '-' multiplicative_expression
[de62360d]487                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3 ); }
[4d51835]488        ;
[51b7345]489
490shift_expression:
[4d51835]491        additive_expression
492        | shift_expression LS additive_expression
[de62360d]493                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3 ); }
[4d51835]494        | shift_expression RS additive_expression
[de62360d]495                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3 ); }
[4d51835]496        ;
[51b7345]497
498relational_expression:
[4d51835]499        shift_expression
500        | relational_expression '<' shift_expression
[de62360d]501                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3 ); }
[4d51835]502        | relational_expression '>' shift_expression
[de62360d]503                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3 ); }
[4d51835]504        | relational_expression LE shift_expression
[de62360d]505                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3 ); }
[4d51835]506        | relational_expression GE shift_expression
[de62360d]507                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3 ); }
[4d51835]508        ;
[51b7345]509
510equality_expression:
[4d51835]511        relational_expression
512        | equality_expression EQ relational_expression
[de62360d]513                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3 ); }
[4d51835]514        | equality_expression NE relational_expression
[de62360d]515                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3 ); }
[4d51835]516        ;
[51b7345]517
518AND_expression:
[4d51835]519        equality_expression
520        | AND_expression '&' equality_expression
[de62360d]521                { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3 ); }
[4d51835]522        ;
[51b7345]523
524exclusive_OR_expression:
[4d51835]525        AND_expression
526        | exclusive_OR_expression '^' AND_expression
[de62360d]527                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3 ); }
[4d51835]528        ;
[51b7345]529
530inclusive_OR_expression:
[4d51835]531        exclusive_OR_expression
532        | inclusive_OR_expression '|' exclusive_OR_expression
[de62360d]533                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3 ); }
[4d51835]534        ;
[51b7345]535
536logical_AND_expression:
[4d51835]537        inclusive_OR_expression
538        | logical_AND_expression ANDAND inclusive_OR_expression
[de62360d]539                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3 ); }
[4d51835]540        ;
[51b7345]541
542logical_OR_expression:
[4d51835]543        logical_AND_expression
544        | logical_OR_expression OROR logical_AND_expression
[de62360d]545                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3 ); }
[4d51835]546        ;
[51b7345]547
548conditional_expression:
[4d51835]549        logical_OR_expression
550        | logical_OR_expression '?' comma_expression ':' conditional_expression
[de62360d]551                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); }
[4d51835]552        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
[de62360d]553                { $$=new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); }
[4d51835]554        | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
[de62360d]555                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); }
[4d51835]556        ;
[51b7345]557
558constant_expression:
[4d51835]559        conditional_expression
560        ;
[51b7345]561
562assignment_expression:
[4d51835]563                // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
564        conditional_expression
565        | unary_expression '=' assignment_expression
[de62360d]566                { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); }
[4d51835]567        | unary_expression assignment_operator assignment_expression
[de62360d]568                { $$ =new CompositeExprNode( $2, $1, $3 ); }
[4d51835]569        | tuple assignment_opt                                                          // CFA, tuple expression
[de62360d]570                { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); }
[4d51835]571        ;
[51b7345]572
573assignment_expression_opt:
[4d51835]574        // empty
575                { $$ = new NullExprNode; }
576        | assignment_expression
577        ;
[b87a5ed]578
579tuple:                                                                                                  // CFA, tuple
[de62360d]580                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
581                // comma_expression in new_identifier_parameter_array and new_abstract_array
[2871210]582        '[' ']'
[4d51835]583                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); }
584        | '[' push assignment_expression pop ']'
585                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3 ); }
586        | '[' push ',' tuple_expression_list pop ']'
587                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ); }
588        | '[' push assignment_expression ',' tuple_expression_list pop ']'
589                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); }
590        ;
[51b7345]591
592tuple_expression_list:
[4d51835]593        assignment_expression_opt
594        | tuple_expression_list ',' assignment_expression_opt
595                { $$ = (ExpressionNode *)$1->set_link( $3 ); }
596        ;
[51b7345]597
598assignment_operator:
[de62360d]599        MULTassign                                                                      { $$ = new OperatorNode( OperatorNode::MulAssn ); }
600        | DIVassign                                                                     { $$ = new OperatorNode( OperatorNode::DivAssn ); }
601        | MODassign                                                                     { $$ = new OperatorNode( OperatorNode::ModAssn ); }
602        | PLUSassign                                                            { $$ = new OperatorNode( OperatorNode::PlusAssn ); }
603        | MINUSassign                                                           { $$ = new OperatorNode( OperatorNode::MinusAssn ); }
604        | LSassign                                                                      { $$ = new OperatorNode( OperatorNode::LSAssn ); }
605        | RSassign                                                                      { $$ = new OperatorNode( OperatorNode::RSAssn ); }
606        | ANDassign                                                                     { $$ = new OperatorNode( OperatorNode::AndAssn ); }
607        | ERassign                                                                      { $$ = new OperatorNode( OperatorNode::ERAssn ); }
608        | ORassign                                                                      { $$ = new OperatorNode( OperatorNode::OrAssn ); }
[4d51835]609        ;
[51b7345]610
611comma_expression:
[4d51835]612        assignment_expression
[de62360d]613        | comma_expression ',' assignment_expression    // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); }
614                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3 ); }
[4d51835]615        ;
[51b7345]616
617comma_expression_opt:
[4d51835]618        // empty
619                { $$ = 0; }
620        | comma_expression
621        ;
[51b7345]622
[c11e31c]623//*************************** STATEMENTS *******************************
[51b7345]624
625statement:
[4d51835]626        labeled_statement
627        | compound_statement
628        | expression_statement                                          { $$ = $1; }
629        | selection_statement
630        | iteration_statement
631        | jump_statement
632        | exception_statement
633        | asm_statement
[02e5ab6]634        | ctor_dtor
[4d51835]635        ;
[51b7345]636
637labeled_statement:
[4d51835]638        no_attr_identifier ':' attribute_list_opt statement
[1db21619]639                {
640                        $$ = $4->add_label( $1 );
641                }
[4d51835]642        ;
[51b7345]643
644compound_statement:
[4d51835]645        '{' '}'
646                { $$ = new CompoundStmtNode( (StatementNode *)0 ); }
647        | '{'
[de62360d]648                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
649                // requires its own scope
[4d51835]650          push push
[51b1202]651          local_label_declaration_opt                                           // GCC, local labels
[4d51835]652          block_item_list pop '}'                                                       // C99, intermix declarations and statements
653                { $$ = new CompoundStmtNode( $5 ); }
654        ;
[b87a5ed]655
656block_item_list:                                                                                // C99
[4d51835]657        block_item
658        | block_item_list push block_item
[de62360d]659                { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } }
[4d51835]660        ;
[51b7345]661
662block_item:
[4d51835]663        declaration                                                                                     // CFA, new & old style declarations
664                { $$ = new StatementNode( $1 ); }
665        | EXTENSION declaration                                                         // GCC
666                { $$ = new StatementNode( $2 ); }
667        | function_definition
668                { $$ = new StatementNode( $1 ); }
669        | statement pop
670        ;
[51b7345]671
672statement_list:
[4d51835]673        statement
674        | statement_list statement
[de62360d]675                { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } }
[4d51835]676        ;
[51b7345]677
678expression_statement:
[4d51835]679        comma_expression_opt ';'
[de62360d]680                { $$ = new StatementNode( StatementNode::Exp, $1, 0 ); }
[4d51835]681        ;
[51b7345]682
683selection_statement:
[4d51835]684        IF '(' comma_expression ')' statement                           %prec THEN
685                // explicitly deal with the shift/reduce conflict on if/else
[de62360d]686                { $$ = new StatementNode( StatementNode::If, $3, $5 ); }
[4d51835]687        | IF '(' comma_expression ')' statement ELSE statement
[de62360d]688                { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7 )) ); }
[4d51835]689        | SWITCH '(' comma_expression ')' case_clause           // CFA
[de62360d]690                { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); }
[4d51835]691        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
[de62360d]692                { $$ = new StatementNode( StatementNode::Switch, $3, $8 ); /* xxx */ }
693                // The semantics of the declaration list is changed to include any associated initialization, which is performed
694                // *before* the transfer to the appropriate case clause.  Statements after the initial declaration list can
695                // never be executed, and therefore, are removed from the grammar even though C allows it.
[4d51835]696        | CHOOSE '(' comma_expression ')' case_clause           // CFA
[de62360d]697                { $$ = new StatementNode( StatementNode::Choose, $3, $5 ); }
[4d51835]698        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
[de62360d]699                { $$ = new StatementNode( StatementNode::Choose, $3, $8 ); }
[4d51835]700        ;
[b87a5ed]701
[de62360d]702// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
703// clause allows a list of values and subranges.
[b87a5ed]704
705case_value:                                                                                             // CFA
[4d51835]706        constant_expression                                                     { $$ = $1; }
707        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
[de62360d]708                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); }
[4d51835]709        | subrange                                                                                      // CFA, subrange
710        ;
[b87a5ed]711
712case_value_list:                                                                                // CFA
[4d51835]713        case_value
714        | case_value_list ',' case_value
[de62360d]715                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3 ) ); }
[4d51835]716        ;
[b87a5ed]717
718case_label:                                                                                             // CFA
[de62360d]719        CASE case_value_list ':'                                        { $$ = new StatementNode( StatementNode::Case, $2, 0 ); }
720        | DEFAULT ':'                                                           { $$ = new StatementNode( StatementNode::Default ); }
[4d51835]721                // A semantic check is required to ensure only one default clause per switch/choose statement.
722        ;
[b87a5ed]723
724case_label_list:                                                                                // CFA
[4d51835]725        case_label
[de62360d]726        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_link( $2 )); }
[4d51835]727        ;
[b87a5ed]728
729case_clause:                                                                                    // CFA
[de62360d]730        case_label_list statement                                       { $$ = $1->append_last_case( $2 ); }
[4d51835]731        ;
[b87a5ed]732
733switch_clause_list_opt:                                                                 // CFA
[4d51835]734        // empty
735                { $$ = 0; }
736        | switch_clause_list
737        ;
[b87a5ed]738
739switch_clause_list:                                                                             // CFA
[4d51835]740        case_label_list statement_list
[de62360d]741                { $$ = $1->append_last_case( $2 ); }
[4d51835]742        | switch_clause_list case_label_list statement_list
[de62360d]743                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
[4d51835]744        ;
[b87a5ed]745
746choose_clause_list_opt:                                                                 // CFA
[4d51835]747        // empty
748                { $$ = 0; }
749        | choose_clause_list
750        ;
[b87a5ed]751
752choose_clause_list:                                                                             // CFA
[4d51835]753        case_label_list fall_through
[de62360d]754                { $$ = $1->append_last_case( $2 ); }
[4d51835]755        | case_label_list statement_list fall_through_opt
[de62360d]756                { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3 ))); }
[4d51835]757        | choose_clause_list case_label_list fall_through
[de62360d]758                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
[4d51835]759        | choose_clause_list case_label_list statement_list fall_through_opt
[de62360d]760                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case((StatementNode *)mkList((*$3,*$4 ))))); }
[4d51835]761        ;
[b87a5ed]762
763fall_through_opt:                                                                               // CFA
[4d51835]764        // empty
765                { $$ = 0; }
766        | fall_through
767        ;
[b87a5ed]768
769fall_through:                                                                                   // CFA
[7f5566b]770        FALLTHRU                                                                        { $$ = new StatementNode( StatementNode::Fallthru ); }
771        | FALLTHRU ';'                                                          { $$ = new StatementNode( StatementNode::Fallthru ); }
[4d51835]772        ;
[51b7345]773
774iteration_statement:
[4d51835]775        WHILE '(' comma_expression ')' statement
[de62360d]776                { $$ = new StatementNode( StatementNode::While, $3, $5 ); }
[4d51835]777        | DO statement WHILE '(' comma_expression ')' ';'
[de62360d]778                { $$ = new StatementNode( StatementNode::Do, $5, $2 ); }
[4d51835]779        | FOR '(' push for_control_expression ')' statement
[de62360d]780                { $$ = new StatementNode( StatementNode::For, $4, $6 ); }
[4d51835]781        ;
[51b7345]782
783for_control_expression:
[4d51835]784        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
[de62360d]785                { $$ = new ForCtlExprNode( $1, $4, $6 ); }
[4d51835]786        | declaration comma_expression_opt ';' comma_expression_opt // C99
[de62360d]787                { $$ = new ForCtlExprNode( $1, $2, $4 ); }
[4d51835]788        ;
[51b7345]789
790jump_statement:
[4d51835]791        GOTO no_attr_identifier ';'
[de62360d]792                { $$ = new StatementNode( StatementNode::Goto, $2 ); }
[4d51835]793        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
[de62360d]794                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3 );
795                // whereas normal operator precedence yields goto (*i)+3;
796                { $$ = new StatementNode( StatementNode::Goto, $3 ); }
[4d51835]797        | CONTINUE ';'
[de62360d]798                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[7f5566b]799                { $$ = new StatementNode( StatementNode::Continue ); }
[4d51835]800        | CONTINUE no_attr_identifier ';'                                       // CFA, multi-level continue
[de62360d]801                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
802                // the target of the transfer appears only at the start of an iteration statement.
803                { $$ = new StatementNode( StatementNode::Continue, $2 ); }
[4d51835]804        | BREAK ';'
[de62360d]805                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[7f5566b]806                { $$ = new StatementNode( StatementNode::Break ); }
[4d51835]807        | BREAK no_attr_identifier ';'                                          // CFA, multi-level exit
[de62360d]808                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
809                // the target of the transfer appears only at the start of an iteration statement.
810                { $$ = new StatementNode( StatementNode::Break, $2 ); }
[4d51835]811        | RETURN comma_expression_opt ';'
[de62360d]812                { $$ = new StatementNode( StatementNode::Return, $2, 0 ); }
[02e5ab6]813        | THROW assignment_expression_opt ';'
[de62360d]814                { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
[02e5ab6]815//      | THROW ';'
816//              { $$ = new StatementNode( StatementNode::Throw ); }
817        | THROWRESUME assignment_expression_opt ';'
818                { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
819        | THROWRESUME assignment_expression_opt AT assignment_expression ';'
820                { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
821//      | THROWRESUME ';'
822//              { $$ = new StatementNode( StatementNode::Throw ); }
[4d51835]823        ;
[51b7345]824
825exception_statement:
[4d51835]826        TRY compound_statement handler_list
[de62360d]827                { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
[4d51835]828        | TRY compound_statement finally_clause
[de62360d]829                { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
[4d51835]830        | TRY compound_statement handler_list finally_clause
831                {
[de62360d]832                        $3->set_link( $4 );
833                        $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 ))));
[4d51835]834                }
835        ;
[51b7345]836
837handler_list:
[4d51835]838                // There must be at least one catch clause
839        handler_clause
[de62360d]840                // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
[4d51835]841        | CATCH '(' ELLIPSIS ')' compound_statement
842                { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
843        | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
844                { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
[02e5ab6]845        | CATCHRESUME '(' ELLIPSIS ')' compound_statement
846                { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
847        | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
848                { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
[4d51835]849        ;
[51b7345]850
851handler_clause:
[4d51835]852        CATCH '(' push push exception_declaration pop ')' compound_statement pop
[de62360d]853                { $$ = StatementNode::newCatchStmt( $5, $8 ); }
[4d51835]854        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
[de62360d]855                { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
[02e5ab6]856        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
857                { $$ = StatementNode::newCatchStmt( $5, $8 ); }
858        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
859                { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
[4d51835]860        ;
[51b7345]861
862finally_clause:
[4d51835]863        FINALLY compound_statement
864                {
[de62360d]865                        $$ = new StatementNode( StatementNode::Finally, 0, $2 );
[4d51835]866                        std::cout << "Just created a finally node" << std::endl;
867                }
868        ;
[51b7345]869
870exception_declaration:
[4d51835]871                // A semantic check is required to ensure type_specifier does not create a new type, e.g.:
872                //
873                //              catch ( struct { int i; } x ) ...
874                //
875                // This new type cannot catch any thrown type because of name equivalence among types.
876        type_specifier
877        | type_specifier declarator
878                {
879                        typedefTable.addToEnclosingScope( TypedefTable::ID );
880                        $$ = $2->addType( $1 );
881                }
882        | type_specifier variable_abstract_declarator
883                { $$ = $2->addType( $1 ); }
884        | new_abstract_declarator_tuple no_attr_identifier      // CFA
885                {
886                        typedefTable.addToEnclosingScope( TypedefTable::ID );
887                        $$ = $1->addName( $2 );
888                }
889        | new_abstract_declarator_tuple                                         // CFA
890        ;
[51b7345]891
892asm_statement:
[7f5566b]893        ASM asm_volatile_opt '(' string_literal_list ')' ';'
894                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); }
895        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
896                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); }
897        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
898                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); }
899        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
900                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); }
901        | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
902        { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); }
903        ;
904
905asm_volatile_opt:                                                                               // GCC
906        // empty
907                { $$ = false; }
908        | VOLATILE
909                { $$ = true; }
[4d51835]910        ;
[b87a5ed]911
912asm_operands_opt:                                                                               // GCC
[4d51835]913        // empty
[7f5566b]914                { $$ = 0; }                                                                             // use default argument
[4d51835]915        | asm_operands_list
916        ;
[b87a5ed]917
918asm_operands_list:                                                                              // GCC
[4d51835]919        asm_operand
920        | asm_operands_list ',' asm_operand
[7f5566b]921                { $$ = (ExpressionNode *)$1->set_link( $3 ); }
[4d51835]922        ;
[b87a5ed]923
924asm_operand:                                                                                    // GCC
[7f5566b]925        string_literal_list '(' constant_expression ')'
926                { $$ = new AsmExprNode( 0, $1, $3 ); }
927        | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
928                { $$ = new AsmExprNode( $2, $4, $6 ); }
929        ;
930
931asm_clobbers_list_opt:                                                                          // GCC
932        // empty
933                { $$ = 0; }                                                                             // use default argument
934        | string_literal_list
935                { $$ = $1; }
936        | asm_clobbers_list_opt ',' string_literal_list
937                { $$ = (ConstantNode *)$1->set_link( $3 ); }
[4d51835]938        ;
[b87a5ed]939
[7f5566b]940label_list:
941        no_attr_identifier
942                { $$ = new LabelNode(); $$->append_label( $1 ); }
943        | label_list ',' no_attr_identifier
944                { $$ = $1; $1->append_label( $3 ); }
[4d51835]945        ;
[51b7345]946
[02e5ab6]947ctor_dtor:                                                                                              // CFA, constructor/destructor
948        no_attr_identifier_01 '{' argument_expression_list '}' ';'
949                {
950                        Token fn; fn.str = new std::string( "?{}" ); fn.loc = $1.loc;
951                        $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ),
952                                   (ExpressionNode *)((new CompositeExprNode( new OperatorNode( OperatorNode::AddressOf ), new VarRefNode( $1 ) ))->set_link( $3 )) ), 0 );
953                }
954        | '^' no_attr_identifier_01 '{' '}' ';'
955                {
956                        Token fn; fn.str = new std::string( "^?{}" ); fn.loc = $2.loc;
957                        $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ),
958                                   new CompositeExprNode( new OperatorNode( OperatorNode::AddressOf ), new VarRefNode( $2 ) ) ), 0 );
959                }
960        ;
961
[c11e31c]962//******************************* DECLARATIONS *********************************
[51b7345]963
[b87a5ed]964declaration_list_opt:                                                                   // used at beginning of switch statement
[4d51835]965        pop
966                { $$ = 0; }
967        | declaration_list
968        ;
[51b7345]969
970declaration_list:
[4d51835]971        declaration
972        | declaration_list push declaration
973                { $$ = $1->appendList( $3 ); }
974        ;
[51b7345]975
[b87a5ed]976old_declaration_list_opt:                                                               // used to declare parameter types in K&R style functions
[4d51835]977        pop
978                { $$ = 0; }
979        | old_declaration_list
980        ;
[51b7345]981
982old_declaration_list:
[4d51835]983        old_declaration
984        | old_declaration_list push old_declaration
985                { $$ = $1->appendList( $3 ); }
986        ;
[b87a5ed]987
[51b1202]988local_label_declaration_opt:                                                    // GCC, local label
[4d51835]989        // empty
[51b1202]990        | local_label_declaration_list
[4d51835]991        ;
[b87a5ed]992
[51b1202]993local_label_declaration_list:                                                   // GCC, local label
994        LABEL local_label_list ';'
995        | local_label_declaration_list LABEL local_label_list ';'
[4d51835]996        ;
[b87a5ed]997
[51b1202]998local_label_list:                                                                               // GCC, local label
[7f5566b]999        no_attr_identifier_or_type_name                         {}
[51b1202]1000        | local_label_list ',' no_attr_identifier_or_type_name {}
[4d51835]1001        ;
[b87a5ed]1002
1003declaration:                                                                                    // CFA, new & old style declarations
[4d51835]1004        new_declaration
1005        | old_declaration
1006        ;
[b87a5ed]1007
[de62360d]1008// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
1009// declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to
1010// the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration
1011// modifiers are interpreted from left to right and the entire type specification is distributed across all variables in
1012// the declaration list (as in Pascal).  ANSI C and the new CFA declarations may appear together in the same program
1013// block, but cannot be mixed within a specific declaration.
[c11e31c]1014//
[b87a5ed]1015//                      CFA                                     C
1016//              [10] int x;                     int x[10];              // array of 10 integers
1017//              [10] * char y;          char *y[10];    // array of 10 pointers to char
1018
1019new_declaration:                                                                                // CFA
[4d51835]1020        new_variable_declaration pop ';'
1021        | new_typedef_declaration pop ';'
1022        | new_function_declaration pop ';'
1023        | type_declaring_list pop ';'
1024        | context_specifier pop ';'
1025        ;
[b87a5ed]1026
1027new_variable_declaration:                                                               // CFA
[4d51835]1028        new_variable_specifier initializer_opt
1029                {
1030                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1031                        $$ = $1;
1032                }
1033        | declaration_qualifier_list new_variable_specifier initializer_opt
[de62360d]1034                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
1035                // them as a type_qualifier cannot appear in that context.
[4d51835]1036                {
1037                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1038                        $$ = $2->addQualifiers( $1 );
1039                }
[2871210]1040        | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt
[4d51835]1041                {
1042                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
1043                        $$ = $1->appendList( $1->cloneType( $5 ) );
1044                }
1045        ;
[b87a5ed]1046
1047new_variable_specifier:                                                                 // CFA
[de62360d]1048                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1049                // storage-class
[2871210]1050        new_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
[4d51835]1051                {
1052                        typedefTable.setNextIdentifier( *$2 );
1053                        $$ = $1->addName( $2 );
1054                }
[2871210]1055        | new_abstract_tuple identifier_or_type_name asm_name_opt
[4d51835]1056                {
1057                        typedefTable.setNextIdentifier( *$2 );
1058                        $$ = $1->addName( $2 );
1059                }
[2871210]1060        | type_qualifier_list new_abstract_tuple identifier_or_type_name asm_name_opt
[4d51835]1061                {
1062                        typedefTable.setNextIdentifier( *$3 );
1063                        $$ = $2->addQualifiers( $1 )->addName( $3 );
1064                }
1065        ;
[b87a5ed]1066
1067new_function_declaration:                                                               // CFA
[4d51835]1068        new_function_specifier
1069                {
1070                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1071                        $$ = $1;
1072                }
1073        | type_qualifier_list new_function_specifier
1074                {
1075                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1076                        $$ = $2->addQualifiers( $1 );
1077                }
1078        | declaration_qualifier_list new_function_specifier
1079                {
1080                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1081                        $$ = $2->addQualifiers( $1 );
1082                }
1083        | declaration_qualifier_list type_qualifier_list new_function_specifier
1084                {
1085                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1086                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
1087                }
[2871210]1088        | new_function_declaration pop ',' push identifier_or_type_name
[4d51835]1089                {
1090                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
1091                        $$ = $1->appendList( $1->cloneType( $5 ) );
1092                }
1093        ;
[b87a5ed]1094
1095new_function_specifier:                                                                 // CFA
[2871210]1096        '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict
[4d51835]1097                {
[2871210]1098                        $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
[4d51835]1099                }
[2871210]1100//      '[' ']' identifier '(' push new_parameter_type_list_opt pop ')'
1101//              {
1102//                      typedefTable.setNextIdentifier( *$5 );
1103//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1104//              }
1105//      | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')'
1106//              {
1107//                      typedefTable.setNextIdentifier( *$5 );
1108//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1109//              }
1110//      | '[' ']' typegen_name
1111                // identifier_or_type_name must be broken apart because of the sequence:
[4d51835]1112                //
[2871210]1113                //   '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
[4d51835]1114                //   '[' ']' type_specifier
1115                //
[2871210]1116                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
1117                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
1118        | new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
[de62360d]1119                // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator).
[4d51835]1120                {
1121                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1122                }
[2871210]1123        | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
[4d51835]1124                {
1125                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1126                }
1127        ;
[b87a5ed]1128
1129new_function_return:                                                                    // CFA
[4d51835]1130        '[' push new_parameter_list pop ']'
1131                { $$ = DeclarationNode::newTuple( $3 ); }
1132        | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']'
[de62360d]1133                // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the
1134                // ']'.
[4d51835]1135                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
1136        ;
[b87a5ed]1137
1138new_typedef_declaration:                                                                // CFA
[4d51835]1139        TYPEDEF new_variable_specifier
1140                {
[de62360d]1141                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1142                        $$ = $2->addTypedef();
1143                }
1144        | TYPEDEF new_function_specifier
1145                {
[de62360d]1146                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1147                        $$ = $2->addTypedef();
1148                }
1149        | new_typedef_declaration pop ',' push no_attr_identifier
1150                {
[de62360d]1151                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
[4d51835]1152                        $$ = $1->appendList( $1->cloneType( $5 ) );
1153                }
1154        ;
[b87a5ed]1155
[de62360d]1156// Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as
1157// a separate form of declaration, which syntactically precludes storage-class specifiers and initialization.
[51b7345]1158
1159typedef_declaration:
[4d51835]1160        TYPEDEF type_specifier declarator
1161                {
[de62360d]1162                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1163                        $$ = $3->addType( $2 )->addTypedef();
1164                }
1165        | typedef_declaration pop ',' push declarator
1166                {
[de62360d]1167                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1168                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
1169                }
[de62360d]1170        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
[4d51835]1171                {
[de62360d]1172                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1173                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
1174                }
1175        | type_specifier TYPEDEF declarator
1176                {
[de62360d]1177                        typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1178                        $$ = $3->addType( $1 )->addTypedef();
1179                }
1180        | type_specifier TYPEDEF type_qualifier_list declarator
1181                {
[de62360d]1182                        typedefTable.addToEnclosingScope( TypedefTable::TD );
1183                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
[4d51835]1184                }
1185        ;
[b87a5ed]1186
[721f17a]1187typedef_expression:
1188                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
[4d51835]1189        TYPEDEF no_attr_identifier '=' assignment_expression
1190                {
[de62360d]1191                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
[4d51835]1192                        $$ = DeclarationNode::newName( 0 ); // XXX
1193                }
1194        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
1195                {
[de62360d]1196                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
[4d51835]1197                        $$ = DeclarationNode::newName( 0 ); // XXX
1198                }
1199        ;
[51b7345]1200
1201old_declaration:
[4d51835]1202        declaring_list pop ';'
1203        | typedef_declaration pop ';'
1204        | typedef_expression pop ';'                                            // GCC, naming expression type
1205        | sue_declaration_specifier pop ';'
1206        ;
[51b7345]1207
1208declaring_list:
[de62360d]1209                // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1210                // storage-class
[4d51835]1211        declaration_specifier declarator asm_name_opt initializer_opt
1212                {
1213                        typedefTable.addToEnclosingScope( TypedefTable::ID );
[de62360d]1214                        $$ = ( $2->addType( $1 ))->addInitializer( $4 );
[4d51835]1215                }
1216        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
1217                {
1218                        typedefTable.addToEnclosingScope( TypedefTable::ID );
[de62360d]1219                        $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer( $6 ) ) );
[4d51835]1220                }
1221        ;
[b87a5ed]1222
1223declaration_specifier:                                                                  // type specifier + storage class
[4d51835]1224        basic_declaration_specifier
1225        | sue_declaration_specifier
1226        | typedef_declaration_specifier
1227        | typegen_declaration_specifier
1228        ;
[b87a5ed]1229
1230type_specifier:                                                                                 // declaration specifier - storage class
[4d51835]1231        basic_type_specifier
1232        | sue_type_specifier
1233        | typedef_type_specifier
1234        | typegen_type_specifier
1235        ;
[b87a5ed]1236
1237type_qualifier_list_opt:                                                                // GCC, used in asm_statement
[4d51835]1238        // empty
1239                { $$ = 0; }
1240        | type_qualifier_list
1241        ;
[51b7345]1242
1243type_qualifier_list:
[de62360d]1244                // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration.
[4d51835]1245                //
[de62360d]1246                // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same
1247                // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it
1248                // appeared only once.
[4d51835]1249        type_qualifier
1250        | type_qualifier_list type_qualifier
1251                { $$ = $1->addQualifiers( $2 ); }
1252        ;
[51b7345]1253
1254type_qualifier:
[4d51835]1255        type_qualifier_name
1256        | attribute
[1db21619]1257        //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
[4d51835]1258        ;
[51b7345]1259
1260type_qualifier_name:
[4d51835]1261        CONST
1262                { $$ = DeclarationNode::newQualifier( DeclarationNode::Const ); }
1263        | RESTRICT
1264                { $$ = DeclarationNode::newQualifier( DeclarationNode::Restrict ); }
1265        | VOLATILE
1266                { $$ = DeclarationNode::newQualifier( DeclarationNode::Volatile ); }
1267        | LVALUE                                                                                        // CFA
1268                { $$ = DeclarationNode::newQualifier( DeclarationNode::Lvalue ); }
1269        | ATOMIC
1270                { $$ = DeclarationNode::newQualifier( DeclarationNode::Atomic ); }
1271        | FORALL '('
1272                {
1273                        typedefTable.enterScope();
1274                }
1275          type_parameter_list ')'                                                       // CFA
1276                {
1277                        typedefTable.leaveScope();
1278                        $$ = DeclarationNode::newForall( $4 );
1279                }
1280        ;
[51b7345]1281
1282declaration_qualifier_list:
[4d51835]1283        storage_class_list
[de62360d]1284        | type_qualifier_list storage_class_list                        // remaining OBSOLESCENT (see 2 )
[4d51835]1285                { $$ = $1->addQualifiers( $2 ); }
1286        | declaration_qualifier_list type_qualifier_list storage_class_list
1287                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1288        ;
[51b7345]1289
1290storage_class_list:
[de62360d]1291                // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that
1292                // only one of each is specified, except for inline, which can appear with the others.
[4d51835]1293                //
[de62360d]1294                // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration
1295                // specifiers in a declaration.
[4d51835]1296        storage_class
1297        | storage_class_list storage_class
1298                { $$ = $1->addQualifiers( $2 ); }
1299        ;
[51b7345]1300
1301storage_class:
[4d51835]1302        storage_class_name
1303        ;
[51b7345]1304
1305storage_class_name:
[4d51835]1306        EXTERN
1307                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
1308        | STATIC
1309                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Static ); }
1310        | AUTO
1311                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Auto ); }
1312        | REGISTER
1313                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }
1314        | INLINE                                                                                        // C99
1315                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
1316        | FORTRAN                                                                                       // C99
1317                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); }
[68cd1ce]1318        | NORETURN                                                                                      // C11
1319                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
1320        | THREADLOCAL                                                                           // C11
1321                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }
[4d51835]1322        ;
[51b7345]1323
1324basic_type_name:
[4d51835]1325        CHAR
1326                { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
1327        | DOUBLE
1328                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
1329        | FLOAT
1330                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
1331        | INT
1332                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
1333        | LONG
1334                { $$ = DeclarationNode::newModifier( DeclarationNode::Long ); }
1335        | SHORT
1336                { $$ = DeclarationNode::newModifier( DeclarationNode::Short ); }
1337        | SIGNED
1338                { $$ = DeclarationNode::newModifier( DeclarationNode::Signed ); }
1339        | UNSIGNED
1340                { $$ = DeclarationNode::newModifier( DeclarationNode::Unsigned ); }
1341        | VOID
1342                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
1343        | BOOL                                                                                          // C99
1344                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
1345        | COMPLEX                                                                                       // C99
1346                { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
1347        | IMAGINARY                                                                                     // C99
1348                { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
1349        ;
[51b7345]1350
1351basic_declaration_specifier:
[4d51835]1352                // A semantic check is necessary for conflicting storage classes.
1353        basic_type_specifier
1354        | declaration_qualifier_list basic_type_specifier
1355                { $$ = $2->addQualifiers( $1 ); }
1356        | basic_declaration_specifier storage_class                     // remaining OBSOLESCENT (see 2)
1357                { $$ = $1->addQualifiers( $2 ); }
1358        | basic_declaration_specifier storage_class type_qualifier_list
1359                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1360        | basic_declaration_specifier storage_class basic_type_specifier
1361                { $$ = $3->addQualifiers( $2 )->addType( $1 ); }
1362        ;
[51b7345]1363
1364basic_type_specifier:
[4d51835]1365        direct_type_name
1366        | type_qualifier_list_opt indirect_type_name type_qualifier_list_opt
1367                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
1368        ;
[51b7345]1369
1370direct_type_name:
[4d51835]1371                // A semantic check is necessary for conflicting type qualifiers.
1372        basic_type_name
1373        | type_qualifier_list basic_type_name
1374                { $$ = $2->addQualifiers( $1 ); }
1375        | direct_type_name type_qualifier
1376                { $$ = $1->addQualifiers( $2 ); }
1377        | direct_type_name basic_type_name
1378                { $$ = $1->addType( $2 ); }
1379        ;
[51b7345]1380
1381indirect_type_name:
[4d51835]1382        TYPEOF '(' type_name ')'                                                        // GCC: typeof(x) y;
1383                { $$ = $3; }
1384        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
1385                { $$ = DeclarationNode::newTypeof( $3 ); }
1386        | ATTR_TYPEGENname '(' type_name ')'                            // CFA: e.g., @type(x) y;
1387                { $$ = DeclarationNode::newAttr( $1, $3 ); }
1388        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
1389                { $$ = DeclarationNode::newAttr( $1, $3 ); }
1390        ;
[51b7345]1391
1392sue_declaration_specifier:
[4d51835]1393        sue_type_specifier
1394        | declaration_qualifier_list sue_type_specifier
1395                { $$ = $2->addQualifiers( $1 ); }
1396        | sue_declaration_specifier storage_class                       // remaining OBSOLESCENT (see 2)
1397                { $$ = $1->addQualifiers( $2 ); }
1398        | sue_declaration_specifier storage_class type_qualifier_list
1399                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1400        ;
[51b7345]1401
1402sue_type_specifier:
[4d51835]1403        elaborated_type_name                                                            // struct, union, enum
1404        | type_qualifier_list elaborated_type_name
1405                { $$ = $2->addQualifiers( $1 ); }
1406        | sue_type_specifier type_qualifier
1407                { $$ = $1->addQualifiers( $2 ); }
1408        ;
[51b7345]1409
1410typedef_declaration_specifier:
[4d51835]1411        typedef_type_specifier
1412        | declaration_qualifier_list typedef_type_specifier
1413                { $$ = $2->addQualifiers( $1 ); }
1414        | typedef_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
1415                { $$ = $1->addQualifiers( $2 ); }
1416        | typedef_declaration_specifier storage_class type_qualifier_list
1417                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1418        ;
[b87a5ed]1419
1420typedef_type_specifier:                                                                 // typedef types
[4d51835]1421        TYPEDEFname
1422                { $$ = DeclarationNode::newFromTypedef( $1 ); }
1423        | type_qualifier_list TYPEDEFname
1424                { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); }
1425        | typedef_type_specifier type_qualifier
1426                { $$ = $1->addQualifiers( $2 ); }
1427        ;
[51b7345]1428
1429elaborated_type_name:
[4d51835]1430        aggregate_name
1431        | enum_name
1432        ;
[51b7345]1433
1434aggregate_name:
[4d51835]1435        aggregate_key '{' field_declaration_list '}'
[721f17a]1436                { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3 ); }
[2871210]1437        | aggregate_key no_attr_identifier_or_type_name
[721f17a]1438                { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0 ); }
[2871210]1439        | aggregate_key no_attr_identifier_or_type_name '{' field_declaration_list '}'
[721f17a]1440                { $$ = DeclarationNode::newAggregate( $1, $2, 0, $4 ); }
1441        | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
1442                { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); }
[2871210]1443        | aggregate_key typegen_name                                            // CFA, S/R conflict
1444                { $$ = $2; }
[4d51835]1445        ;
[51b7345]1446
1447aggregate_key:
[4d51835]1448        STRUCT attribute_list_opt
1449                { $$ = DeclarationNode::Struct; }
1450        | UNION attribute_list_opt
1451                { $$ = DeclarationNode::Union; }
1452        ;
[51b7345]1453
1454field_declaration_list:
[4d51835]1455        field_declaration
1456                { $$ = $1; }
1457        | field_declaration_list field_declaration
1458                { $$ = $1->appendList( $2 ); }
1459        ;
[51b7345]1460
1461field_declaration:
[4d51835]1462        new_field_declaring_list ';'                                            // CFA, new style field declaration
1463        | EXTENSION new_field_declaring_list ';'                        // GCC
1464                { $$ = $2; }
1465        | field_declaring_list ';'
1466        | EXTENSION field_declaring_list ';'                            // GCC
1467                { $$ = $2; }
1468        ;
[b87a5ed]1469
1470new_field_declaring_list:                                                               // CFA, new style field declaration
[4d51835]1471        new_abstract_declarator_tuple                                           // CFA, no field name
[2871210]1472        | new_abstract_declarator_tuple no_attr_identifier_or_type_name
[4d51835]1473                { $$ = $1->addName( $2 ); }
[2871210]1474        | new_field_declaring_list ',' no_attr_identifier_or_type_name
[4d51835]1475                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
1476        | new_field_declaring_list ','                                          // CFA, no field name
1477                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
1478        ;
[51b7345]1479
1480field_declaring_list:
[4d51835]1481        type_specifier field_declarator
1482                { $$ = $2->addType( $1 ); }
1483        | field_declaring_list ',' attribute_list_opt field_declarator
1484                { $$ = $1->appendList( $1->cloneBaseType( $4 ) ); }
1485        ;
[51b7345]1486
1487field_declarator:
[4d51835]1488        // empty
1489                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
1490        | bit_subrange_size                                                                     // no field name
1491                { $$ = DeclarationNode::newBitfield( $1 ); }
1492        | variable_declarator bit_subrange_size_opt
1493                // A semantic check is required to ensure bit_subrange only appears on base type int.
1494                { $$ = $1->addBitfield( $2 ); }
[2871210]1495        | type_redeclarator bit_subrange_size_opt
[4d51835]1496                // A semantic check is required to ensure bit_subrange only appears on base type int.
1497                { $$ = $1->addBitfield( $2 ); }
1498        | variable_abstract_declarator                                          // CFA, no field name
1499        ;
[51b7345]1500
1501bit_subrange_size_opt:
[4d51835]1502        // empty
1503                { $$ = 0; }
1504        | bit_subrange_size
1505                { $$ = $1; }
1506        ;
[51b7345]1507
1508bit_subrange_size:
[4d51835]1509        ':' constant_expression
1510                { $$ = $2; }
1511        ;
[51b7345]1512
1513enum_key:
[4d51835]1514        ENUM attribute_list_opt
1515        ;
[51b7345]1516
1517enum_name:
[4d51835]1518        enum_key '{' enumerator_list comma_opt '}'
1519                { $$ = DeclarationNode::newEnum( 0, $3 ); }
[2871210]1520        | enum_key no_attr_identifier_or_type_name '{' enumerator_list comma_opt '}'
[4d51835]1521                { $$ = DeclarationNode::newEnum( $2, $4 ); }
[2871210]1522        | enum_key no_attr_identifier_or_type_name
[4d51835]1523                { $$ = DeclarationNode::newEnum( $2, 0 ); }
1524        ;
[51b7345]1525
1526enumerator_list:
[2871210]1527        no_attr_identifier_or_type_name enumerator_value_opt
[4d51835]1528                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
[2871210]1529        | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
[4d51835]1530                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
1531        ;
[51b7345]1532
1533enumerator_value_opt:
[4d51835]1534        // empty
1535                { $$ = 0; }
1536        | '=' constant_expression
1537                { $$ = $2; }
1538        ;
[51b7345]1539
[c11e31c]1540// Minimum of one parameter after which ellipsis is allowed only at the end.
[51b7345]1541
[b87a5ed]1542new_parameter_type_list_opt:                                                    // CFA
[4d51835]1543        // empty
1544                { $$ = 0; }
1545        | new_parameter_type_list
1546        ;
[b87a5ed]1547
1548new_parameter_type_list:                                                                // CFA, abstract + real
[4d51835]1549        new_abstract_parameter_list
1550        | new_parameter_list
1551        | new_parameter_list pop ',' push new_abstract_parameter_list
1552                { $$ = $1->appendList( $5 ); }
1553        | new_abstract_parameter_list pop ',' push ELLIPSIS
1554                { $$ = $1->addVarArgs(); }
1555        | new_parameter_list pop ',' push ELLIPSIS
1556                { $$ = $1->addVarArgs(); }
1557        ;
[b87a5ed]1558
1559new_parameter_list:                                                                             // CFA
[de62360d]1560                // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last new_abstract_parameter_list is
1561                // factored out from new_parameter_list, flattening the rules to get lookahead to the ']'.
[4d51835]1562        new_parameter_declaration
1563        | new_abstract_parameter_list pop ',' push new_parameter_declaration
1564                { $$ = $1->appendList( $5 ); }
1565        | new_parameter_list pop ',' push new_parameter_declaration
1566                { $$ = $1->appendList( $5 ); }
1567        | new_parameter_list pop ',' push new_abstract_parameter_list pop ',' push new_parameter_declaration
1568                { $$ = $1->appendList( $5 )->appendList( $9 ); }
1569        ;
[b87a5ed]1570
1571new_abstract_parameter_list:                                                    // CFA, new & old style abstract
[4d51835]1572        new_abstract_parameter_declaration
1573        | new_abstract_parameter_list pop ',' push new_abstract_parameter_declaration
1574                { $$ = $1->appendList( $5 ); }
1575        ;
[51b7345]1576
1577parameter_type_list_opt:
[4d51835]1578        // empty
1579                { $$ = 0; }
1580        | parameter_type_list
1581        ;
[51b7345]1582
1583parameter_type_list:
[4d51835]1584        parameter_list
1585        | parameter_list pop ',' push ELLIPSIS
1586                { $$ = $1->addVarArgs(); }
1587        ;
[b87a5ed]1588
1589parameter_list:                                                                                 // abstract + real
[4d51835]1590        abstract_parameter_declaration
1591        | parameter_declaration
1592        | parameter_list pop ',' push abstract_parameter_declaration
1593                { $$ = $1->appendList( $5 ); }
1594        | parameter_list pop ',' push parameter_declaration
1595                { $$ = $1->appendList( $5 ); }
1596        ;
[51b7345]1597
[de62360d]1598// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
[2871210]1599// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
[51b7345]1600
[b87a5ed]1601new_parameter_declaration:                                                              // CFA, new & old style parameter declaration
[4d51835]1602        parameter_declaration
[2871210]1603        | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
[4d51835]1604                { $$ = $1->addName( $2 ); }
[2871210]1605        | new_abstract_tuple identifier_or_type_name assignment_opt
[4d51835]1606                // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).
1607                { $$ = $1->addName( $2 ); }
[2871210]1608        | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt
[4d51835]1609                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
1610        | new_function_specifier
1611        ;
[b87a5ed]1612
1613new_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
[4d51835]1614        abstract_parameter_declaration
1615        | new_identifier_parameter_declarator_no_tuple
1616        | new_abstract_tuple
1617                // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).
1618        | type_qualifier_list new_abstract_tuple
1619                { $$ = $2->addQualifiers( $1 ); }
1620        | new_abstract_function
1621        ;
[51b7345]1622
1623parameter_declaration:
[4d51835]1624        declaration_specifier identifier_parameter_declarator assignment_opt
1625                {
1626                        typedefTable.addToEnclosingScope( TypedefTable::ID );
[de62360d]1627                        $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) );
[4d51835]1628                }
[2871210]1629        | declaration_specifier type_parameter_redeclarator assignment_opt
[4d51835]1630                {
1631                        typedefTable.addToEnclosingScope( TypedefTable::ID );
[de62360d]1632                        $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) );
[4d51835]1633                }
1634        ;
[51b7345]1635
1636abstract_parameter_declaration:
[4d51835]1637        declaration_specifier
1638        | declaration_specifier abstract_parameter_declarator
1639                { $$ = $2->addType( $1 ); }
1640        ;
[51b7345]1641
[c11e31c]1642// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
[de62360d]1643// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
1644// identifiers.  The ANSI-style parameter-list can redefine a typedef name.
[51b7345]1645
[b87a5ed]1646identifier_list:                                                                                // K&R-style parameter list => no types
[4d51835]1647        no_attr_identifier
1648                { $$ = DeclarationNode::newName( $1 ); }
1649        | identifier_list ',' no_attr_identifier
1650                { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
1651        ;
[51b7345]1652
[2871210]1653identifier_or_type_name:
[4d51835]1654        identifier
1655        | TYPEDEFname
1656        | TYPEGENname
1657        ;
[51b7345]1658
[2871210]1659no_01_identifier_or_type_name:
[4d51835]1660        no_01_identifier
1661        | TYPEDEFname
1662        | TYPEGENname
1663        ;
[51b7345]1664
[2871210]1665no_attr_identifier_or_type_name:
[4d51835]1666        no_attr_identifier
1667        | TYPEDEFname
[721f17a]1668        | TYPEGENname
[4d51835]1669        ;
[b87a5ed]1670
1671type_name_no_function:                                                                  // sizeof, alignof, cast (constructor)
[4d51835]1672        new_abstract_declarator_tuple                                           // CFA
1673        | type_specifier
1674        | type_specifier variable_abstract_declarator
1675                { $$ = $2->addType( $1 ); }
1676        ;
[b87a5ed]1677
1678type_name:                                                                                              // typeof, assertion
[4d51835]1679        new_abstract_declarator_tuple                                           // CFA
1680        | new_abstract_function                                                         // CFA
1681        | type_specifier
1682        | type_specifier abstract_declarator
1683                { $$ = $2->addType( $1 ); }
1684        ;
[51b7345]1685
1686initializer_opt:
[4d51835]1687        // empty
1688                { $$ = 0; }
[2871210]1689        | '=' initializer
1690                { $$ = $2; }
[4d51835]1691        ;
[51b7345]1692
1693initializer:
[de62360d]1694        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
1695        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
[4d51835]1696        ;
[51b7345]1697
1698initializer_list:
[4d51835]1699        initializer
1700        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
[de62360d]1701        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_link( $3 ) ); }
[4d51835]1702        | initializer_list ',' designation initializer
[de62360d]1703                { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); }
[4d51835]1704        ;
[b87a5ed]1705
[de62360d]1706// There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of
1707// '=' to separator the designator from the initializer value, as in:
[c11e31c]1708//
[b87a5ed]1709//              int x[10] = { [1] = 3 };
[c11e31c]1710//
[de62360d]1711// The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment.  To disambiguate this case, CFA
1712// changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for
1713// field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to
1714// shift/reduce conflicts
[51b7345]1715
1716designation:
[4d51835]1717        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
[2871210]1718        | no_attr_identifier_or_type_name ':'                           // GCC, field name
1719                { $$ = new VarRefNode( $1 ); }
[4d51835]1720        ;
[51b7345]1721
[b87a5ed]1722designator_list:                                                                                // C99
[4d51835]1723        designator
[2871210]1724        | designator_list designator
1725                { $$ = (ExpressionNode *)( $1->set_link( $2 )); }
[de62360d]1726        //| designator_list designator                                          { $$ = new CompositeExprNode( $1, $2 ); }
[4d51835]1727        ;
[51b7345]1728
1729designator:
[02e5ab6]1730        // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0
[51b1202]1731        // only ".0" and ".1" allowed => semantic check
1732        FLOATINGconstant
1733                { $$ = new DesignatorNode( new VarRefNode( $1 ) ); }
1734        | '.' no_attr_identifier_or_type_name                           // C99, field name
1735                { $$ = new DesignatorNode( new VarRefNode( $2 ) ); }
[4d51835]1736        | '[' push assignment_expression pop ']'                        // C99, single array element
[de62360d]1737                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
[51b1202]1738                { $$ = new DesignatorNode( $3, true ); }
[4d51835]1739        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
[51b1202]1740                { $$ = new DesignatorNode( $3, true ); }
[4d51835]1741        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
[51b1202]1742                { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true ); }
[4d51835]1743        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
[51b1202]1744                { $$ = new DesignatorNode( $4 ); }
[4d51835]1745        ;
[51b7345]1746
[de62360d]1747// The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters,
1748// rather than an object-oriented type system. This required four groups of extensions:
[c11e31c]1749//
1750// Overloading: function, data, and operator identifiers may be overloaded.
1751//
[de62360d]1752// Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
1753//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
1754//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
[c11e31c]1755//
[de62360d]1756// Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call
1757//     site. A polymorphic function is not a template; it is a function, with an address and a type.
[c11e31c]1758//
1759// Specifications and Assertions: Specifications are collections of declarations parameterized by one or more
[de62360d]1760//     types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass
1761//     hierarchies. Unlike classes, they can define relationships between types.  Assertions declare that a type or
1762//     types provide the operations declared by a specification.  Assertions are normally used to declare requirements
1763//     on type arguments of polymorphic functions.
[c11e31c]1764
[b87a5ed]1765typegen_declaration_specifier:                                                  // CFA
[4d51835]1766        typegen_type_specifier
1767        | declaration_qualifier_list typegen_type_specifier
1768                { $$ = $2->addQualifiers( $1 ); }
1769        | typegen_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
1770                { $$ = $1->addQualifiers( $2 ); }
1771        | typegen_declaration_specifier storage_class type_qualifier_list
1772                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1773        ;
[b87a5ed]1774
1775typegen_type_specifier:                                                                 // CFA
[2871210]1776        typegen_name
1777        | type_qualifier_list typegen_name
1778                { $$ = $2->addQualifiers( $1 ); }
[4d51835]1779        | typegen_type_specifier type_qualifier
1780                { $$ = $1->addQualifiers( $2 ); }
1781        ;
[b87a5ed]1782
[2871210]1783typegen_name:                                                                                   // CFA
1784        TYPEGENname '(' type_name_list ')'
1785                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
1786        ;
1787
[b87a5ed]1788type_parameter_list:                                                                    // CFA
[4d51835]1789        type_parameter assignment_opt
1790        | type_parameter_list ',' type_parameter assignment_opt
1791                { $$ = $1->appendList( $3 ); }
1792        ;
[b87a5ed]1793
1794type_parameter:                                                                                 // CFA
[2871210]1795        type_class no_attr_identifier_or_type_name
1796                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
[4d51835]1797          assertion_list_opt
1798                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
1799        | type_specifier identifier_parameter_declarator
1800        ;
[b87a5ed]1801
1802type_class:                                                                                             // CFA
[4d51835]1803        TYPE
1804                { $$ = DeclarationNode::Type; }
1805        | DTYPE
1806                { $$ = DeclarationNode::Ftype; }
1807        | FTYPE
1808                { $$ = DeclarationNode::Dtype; }
1809        ;
[b87a5ed]1810
1811assertion_list_opt:                                                                             // CFA
[4d51835]1812        // empty
1813                { $$ = 0; }
1814        | assertion_list_opt assertion
1815                { $$ = $1 == 0 ? $2 : $1->appendList( $2 ); }
1816        ;
[b87a5ed]1817
1818assertion:                                                                                              // CFA
[2871210]1819        '|' no_attr_identifier_or_type_name '(' type_name_list ')'
[4d51835]1820                {
[2871210]1821                        typedefTable.openContext( *$2 );
[4d51835]1822                        $$ = DeclarationNode::newContextUse( $2, $4 );
1823                }
1824        | '|' '{' push context_declaration_list '}'
1825                { $$ = $4; }
1826        | '|' '(' push type_parameter_list pop ')' '{' push context_declaration_list '}' '(' type_name_list ')'
1827                { $$ = 0; }
1828        ;
[b87a5ed]1829
1830type_name_list:                                                                                 // CFA
[4d51835]1831        type_name
1832                { $$ = new TypeValueNode( $1 ); }
1833        | assignment_expression
1834        | type_name_list ',' type_name
[de62360d]1835                { $$ = (ExpressionNode *)( $1->set_link( new TypeValueNode( $3 ))); }
[4d51835]1836        | type_name_list ',' assignment_expression
[de62360d]1837                { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
[4d51835]1838        ;
[b87a5ed]1839
1840type_declaring_list:                                                                    // CFA
[4d51835]1841        TYPE type_declarator
1842                { $$ = $2; }
1843        | storage_class_list TYPE type_declarator
1844                { $$ = $3->addQualifiers( $1 ); }
1845        | type_declaring_list ',' type_declarator
1846                { $$ = $1->appendList( $3->copyStorageClasses( $1 ) ); }
1847        ;
[b87a5ed]1848
1849type_declarator:                                                                                // CFA
[4d51835]1850        type_declarator_name assertion_list_opt
1851                { $$ = $1->addAssertions( $2 ); }
1852        | type_declarator_name assertion_list_opt '=' type_name
1853                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
1854        ;
[b87a5ed]1855
1856type_declarator_name:                                                                   // CFA
[2871210]1857        no_attr_identifier_or_type_name
[4d51835]1858                {
[de62360d]1859                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
[4d51835]1860                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
1861                }
[2871210]1862        | no_01_identifier_or_type_name '(' push type_parameter_list pop ')'
[4d51835]1863                {
[de62360d]1864                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
[4d51835]1865                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
1866                }
1867        ;
[b87a5ed]1868
1869context_specifier:                                                                              // CFA
[2871210]1870        CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
[4d51835]1871                {
[de62360d]1872                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
[4d51835]1873                        $$ = DeclarationNode::newContext( $2, $5, 0 );
1874                }
[2871210]1875        | CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
[4d51835]1876                {
[de62360d]1877                        typedefTable.enterContext( *$2 );
[4d51835]1878                        typedefTable.enterScope();
1879                }
1880          context_declaration_list '}'
1881                {
1882                        typedefTable.leaveContext();
[de62360d]1883                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
[4d51835]1884                        $$ = DeclarationNode::newContext( $2, $5, $10 );
1885                }
1886        ;
[b87a5ed]1887
1888context_declaration_list:                                                               // CFA
[4d51835]1889        context_declaration
1890        | context_declaration_list push context_declaration
1891                { $$ = $1->appendList( $3 ); }
1892        ;
[b87a5ed]1893
1894context_declaration:                                                                    // CFA
[4d51835]1895        new_context_declaring_list pop ';'
1896        | context_declaring_list pop ';'
1897        ;
[b87a5ed]1898
1899new_context_declaring_list:                                                             // CFA
[4d51835]1900        new_variable_specifier
1901                {
1902                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
1903                        $$ = $1;
1904                }
1905        | new_function_specifier
1906                {
1907                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
1908                        $$ = $1;
1909                }
[2871210]1910        | new_context_declaring_list pop ',' push identifier_or_type_name
[4d51835]1911                {
[de62360d]1912                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
[4d51835]1913                        $$ = $1->appendList( $1->cloneType( $5 ) );
1914                }
1915        ;
[b87a5ed]1916
1917context_declaring_list:                                                                 // CFA
[4d51835]1918        type_specifier declarator
1919                {
1920                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
1921                        $$ = $2->addType( $1 );
1922                }
1923        | context_declaring_list pop ',' push declarator
1924                {
1925                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
1926                        $$ = $1->appendList( $1->cloneBaseType( $5 ) );
1927                }
1928        ;
[51b7345]1929
[c11e31c]1930//***************************** EXTERNAL DEFINITIONS *****************************
[51b7345]1931
1932translation_unit:
[4d51835]1933        // empty
1934                {}                                                                                              // empty input file
1935        | external_definition_list
1936                {
1937                        if ( theTree ) {
1938                                theTree->appendList( $1 );
1939                        } else {
1940                                theTree = $1;
1941                        }
1942                }
1943        ;
[51b7345]1944
1945external_definition_list:
[4d51835]1946        external_definition
1947        | external_definition_list push external_definition
[de62360d]1948                { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }
[4d51835]1949        ;
[51b7345]1950
1951external_definition_list_opt:
[4d51835]1952        // empty
1953                { $$ = 0; }
1954        | external_definition_list
1955        ;
[51b7345]1956
1957external_definition:
[4d51835]1958        declaration
1959        | external_function_definition
1960        | asm_statement                                                                         // GCC, global assembler statement
1961                {}
1962        | EXTERN STRINGliteral
1963                {
1964                        linkageStack.push( linkage );
1965                        linkage = LinkageSpec::fromString( *$2 );
1966                }
1967          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
1968                {
1969                        linkage = linkageStack.top();
1970                        linkageStack.pop();
1971                        $$ = $5;
1972                }
1973        | EXTENSION external_definition
1974                { $$ = $2; }
1975        ;
1976
1977external_function_definition:
1978        function_definition
[de62360d]1979                // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
1980                // code with functions missing a type-specifier on the return type.  Parsing is possible because
1981                // function_definition does not appear in the context of an expression (nested functions would preclude this
1982                // concession). A function prototype declaration must still have a type_specifier.  OBSOLESCENT (see 1)
[4d51835]1983        | function_declarator compound_statement
1984                {
1985                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1986                        typedefTable.leaveScope();
1987                        $$ = $1->addFunctionBody( $2 );
1988                }
1989        | old_function_declarator push old_declaration_list_opt compound_statement
1990                {
1991                        typedefTable.addToEnclosingScope( TypedefTable::ID );
1992                        typedefTable.leaveScope();
1993                        $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 );
1994                }
1995        ;
[51b7345]1996
1997function_definition:
[4d51835]1998        new_function_declaration compound_statement                     // CFA
1999                {
2000                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2001                        typedefTable.leaveScope();
2002                        $$ = $1->addFunctionBody( $2 );
2003                }
2004        | declaration_specifier function_declarator compound_statement
2005                {
2006                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2007                        typedefTable.leaveScope();
2008                        $$ = $2->addFunctionBody( $3 )->addType( $1 );
2009                }
2010        | type_qualifier_list function_declarator compound_statement
2011                {
2012                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2013                        typedefTable.leaveScope();
2014                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
2015                }
2016        | declaration_qualifier_list function_declarator compound_statement
2017                {
2018                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2019                        typedefTable.leaveScope();
2020                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
2021                }
2022        | declaration_qualifier_list type_qualifier_list function_declarator compound_statement
2023                {
2024                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2025                        typedefTable.leaveScope();
2026                        $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 );
2027                }
2028
2029                // Old-style K&R function definition, OBSOLESCENT (see 4)
2030        | declaration_specifier old_function_declarator push old_declaration_list_opt compound_statement
2031                {
2032                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2033                        typedefTable.leaveScope();
2034                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
2035                }
2036        | type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
2037                {
2038                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2039                        typedefTable.leaveScope();
2040                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
2041                }
2042
2043                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
2044        | declaration_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
2045                {
2046                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2047                        typedefTable.leaveScope();
2048                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
2049                }
2050        | declaration_qualifier_list type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement
2051                {
2052                        typedefTable.addToEnclosingScope( TypedefTable::ID );
2053                        typedefTable.leaveScope();
2054                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
2055                }
2056        ;
[51b7345]2057
2058declarator:
[4d51835]2059        variable_declarator
2060        | function_declarator
[2871210]2061        | type_redeclarator
[4d51835]2062        ;
[51b7345]2063
2064subrange:
[4d51835]2065        constant_expression '~' constant_expression                     // CFA, integer subrange
[de62360d]2066                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); }
[4d51835]2067        ;
[b87a5ed]2068
2069asm_name_opt:                                                                                   // GCC
[4d51835]2070        // empty
2071        | ASM '(' string_literal_list ')' attribute_list_opt
2072        ;
[b87a5ed]2073
2074attribute_list_opt:                                                                             // GCC
[4d51835]2075        // empty
[1db21619]2076                { $$ = 0; }
[4d51835]2077        | attribute_list
2078        ;
[b87a5ed]2079
2080attribute_list:                                                                                 // GCC
[4d51835]2081        attribute
2082        | attribute_list attribute
[1db21619]2083                { $$ = $2->addQualifiers( $1 ); }
[4d51835]2084        ;
[b87a5ed]2085
2086attribute:                                                                                              // GCC
[4d51835]2087        ATTRIBUTE '(' '(' attribute_parameter_list ')' ')'
[1db21619]2088        //              { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
2089                { $$ = 0; }
[4d51835]2090        ;
[b87a5ed]2091
2092attribute_parameter_list:                                                               // GCC
[4d51835]2093        attrib
2094        | attribute_parameter_list ',' attrib
2095        ;
[b87a5ed]2096
2097attrib:                                                                                                 // GCC
[4d51835]2098        // empty
2099        | any_word
2100        | any_word '(' comma_expression_opt ')'
2101        ;
[b87a5ed]2102
2103any_word:                                                                                               // GCC
[2871210]2104        identifier_or_type_name {}
[4d51835]2105        | storage_class_name {}
2106        | basic_type_name {}
2107        | type_qualifier {}
2108        ;
[51b7345]2109
[c11e31c]2110// ============================================================================
[de62360d]2111// The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary
2112// because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as
2113// in:
[c11e31c]2114//
[b87a5ed]2115//              int (*f())[10] { ... };
2116//              ... (*f())[3] += 1;             // definition mimics usage
[c11e31c]2117//
[de62360d]2118// Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of
2119// the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context.
[c11e31c]2120// ============================================================================
2121
2122// ----------------------------------------------------------------------------
[de62360d]2123// The set of valid declarators before a compound statement for defining a function is less than the set of declarators
2124// to define a variable or function prototype, e.g.:
[c11e31c]2125//
[b87a5ed]2126//              valid declaration               invalid definition
2127//              -----------------               ------------------
[4d51835]2128//              int f;                                  int f {}
2129//              int *f;                                 int *f {}
[b87a5ed]2130//              int f[10];                              int f[10] {}
[4d51835]2131//              int (*f)(int);                  int (*f)(int) {}
[c11e31c]2132//
[de62360d]2133// To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence
2134// variable_declarator and function_declarator.
[c11e31c]2135// ----------------------------------------------------------------------------
2136
[de62360d]2137// This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes
2138// declaring an array of functions versus a pointer to an array of functions.
[51b7345]2139
2140variable_declarator:
[4d51835]2141        paren_identifier attribute_list_opt
[1db21619]2142                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2143        | variable_ptr
2144        | variable_array attribute_list_opt
[1db21619]2145                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2146        | variable_function attribute_list_opt
[1db21619]2147                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2148        ;
[51b7345]2149
2150paren_identifier:
[4d51835]2151        identifier
2152                {
[de62360d]2153                        typedefTable.setNextIdentifier( *$1 );
[4d51835]2154                        $$ = DeclarationNode::newName( $1 );
2155                }
2156        | '(' paren_identifier ')'                                                      // redundant parenthesis
2157                { $$ = $2; }
2158        ;
[51b7345]2159
2160variable_ptr:
[4d51835]2161        '*' variable_declarator
2162                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2163        | '*' type_qualifier_list variable_declarator
2164                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2165        | '(' variable_ptr ')'
2166                { $$ = $2; }
2167        ;
[51b7345]2168
2169variable_array:
[4d51835]2170        paren_identifier array_dimension
2171                { $$ = $1->addArray( $2 ); }
2172        | '(' variable_ptr ')' array_dimension
2173                { $$ = $2->addArray( $4 ); }
2174        | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
2175                { $$ = $2->addArray( $4 ); }
2176        | '(' variable_array ')'                                                        // redundant parenthesis
2177                { $$ = $2; }
2178        ;
[51b7345]2179
2180variable_function:
[4d51835]2181        '(' variable_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2182                { $$ = $2->addParamList( $6 ); }
2183        | '(' variable_function ')'                                                     // redundant parenthesis
2184                { $$ = $2; }
2185        ;
[51b7345]2186
[de62360d]2187// This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested,
2188// there is no context where a function definition can redefine a typedef name. To allow nested functions requires
[2871210]2189// further separation of variable and function declarators in type_redeclarator.  The pattern precludes returning
[de62360d]2190// arrays and functions versus pointers to arrays and functions.
[51b7345]2191
2192function_declarator:
[4d51835]2193        function_no_ptr attribute_list_opt
[1db21619]2194                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2195        | function_ptr
2196        | function_array attribute_list_opt
[1db21619]2197                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2198        ;
[51b7345]2199
2200function_no_ptr:
[4d51835]2201        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2202                { $$ = $1->addParamList( $4 ); }
2203        | '(' function_ptr ')' '(' push parameter_type_list_opt pop ')'
2204                { $$ = $2->addParamList( $6 ); }
2205        | '(' function_no_ptr ')'                                                       // redundant parenthesis
2206                { $$ = $2; }
2207        ;
[51b7345]2208
2209function_ptr:
[4d51835]2210        '*' function_declarator
2211                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2212        | '*' type_qualifier_list function_declarator
2213                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2214        | '(' function_ptr ')'
2215                { $$ = $2; }
2216        ;
[51b7345]2217
2218function_array:
[4d51835]2219        '(' function_ptr ')' array_dimension
2220                { $$ = $2->addArray( $4 ); }
2221        | '(' function_array ')' multi_array_dimension          // redundant parenthesis
2222                { $$ = $2->addArray( $4 ); }
2223        | '(' function_array ')'                                                        // redundant parenthesis
2224                { $$ = $2; }
2225        ;
[51b7345]2226
[de62360d]2227// This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name
2228// (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus
2229// pointers to arrays and functions.
[51b7345]2230
2231old_function_declarator:
[4d51835]2232        old_function_no_ptr
2233        | old_function_ptr
2234        | old_function_array
2235        ;
[51b7345]2236
2237old_function_no_ptr:
[4d51835]2238        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
2239                { $$ = $1->addIdList( $3 ); }
2240        | '(' old_function_ptr ')' '(' identifier_list ')'
2241                { $$ = $2->addIdList( $5 ); }
2242        | '(' old_function_no_ptr ')'                                           // redundant parenthesis
2243                { $$ = $2; }
2244        ;
[51b7345]2245
2246old_function_ptr:
[4d51835]2247        '*' old_function_declarator
2248                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2249        | '*' type_qualifier_list old_function_declarator
2250                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2251        | '(' old_function_ptr ')'
2252                { $$ = $2; }
2253        ;
[51b7345]2254
2255old_function_array:
[4d51835]2256        '(' old_function_ptr ')' array_dimension
2257                { $$ = $2->addArray( $4 ); }
2258        | '(' old_function_array ')' multi_array_dimension      // redundant parenthesis
2259                { $$ = $2->addArray( $4 ); }
2260        | '(' old_function_array ')'                                            // redundant parenthesis
2261                { $$ = $2; }
2262        ;
[51b7345]2263
[2871210]2264// This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
[c11e31c]2265//
[b87a5ed]2266//              typedef int foo;
2267//              {
2268//                 int foo; // redefine typedef name in new scope
2269//              }
[c11e31c]2270//
[de62360d]2271// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2272// and functions versus pointers to arrays and functions.
[51b7345]2273
[2871210]2274type_redeclarator:
2275        paren_type attribute_list_opt
[1db21619]2276                { $$ = $1->addQualifiers( $2 ); }
[2871210]2277        | type_ptr
2278        | type_array attribute_list_opt
[1db21619]2279                { $$ = $1->addQualifiers( $2 ); }
[2871210]2280        | type_function attribute_list_opt
[1db21619]2281                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2282        ;
[51b7345]2283
[2871210]2284paren_type:
2285        typedef
2286        | '(' paren_type ')'
[4d51835]2287                { $$ = $2; }
2288        ;
[51b7345]2289
[2871210]2290type_ptr:
2291        '*' type_redeclarator
[4d51835]2292                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
[2871210]2293        | '*' type_qualifier_list type_redeclarator
[4d51835]2294                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
[2871210]2295        | '(' type_ptr ')'
[4d51835]2296                { $$ = $2; }
2297        ;
[51b7345]2298
[2871210]2299type_array:
2300        paren_type array_dimension
[4d51835]2301                { $$ = $1->addArray( $2 ); }
[2871210]2302        | '(' type_ptr ')' array_dimension
[4d51835]2303                { $$ = $2->addArray( $4 ); }
[2871210]2304        | '(' type_array ')' multi_array_dimension                      // redundant parenthesis
[4d51835]2305                { $$ = $2->addArray( $4 ); }
[2871210]2306        | '(' type_array ')'                                                            // redundant parenthesis
[4d51835]2307                { $$ = $2; }
2308        ;
[51b7345]2309
[2871210]2310type_function:
2311        paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2312                { $$ = $1->addParamList( $4 ); }
[2871210]2313        | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2314                { $$ = $2->addParamList( $6 ); }
[2871210]2315        | '(' type_function ')'                                                         // redundant parenthesis
[4d51835]2316                { $$ = $2; }
2317        ;
[51b7345]2318
[de62360d]2319// This pattern parses a declaration for a parameter variable or function prototype that is not redefining a typedef
2320// name and allows the C99 array options, which can only appear in a parameter list.  The pattern precludes declaring an
2321// array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to
2322// arrays and functions.
[51b7345]2323
2324identifier_parameter_declarator:
[4d51835]2325        paren_identifier attribute_list_opt
[1db21619]2326                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2327        | identifier_parameter_ptr
2328        | identifier_parameter_array attribute_list_opt
[1db21619]2329                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2330        | identifier_parameter_function attribute_list_opt
[1db21619]2331                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2332        ;
[51b7345]2333
2334identifier_parameter_ptr:
[4d51835]2335        '*' identifier_parameter_declarator
2336                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2337        | '*' type_qualifier_list identifier_parameter_declarator
2338                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2339        | '(' identifier_parameter_ptr ')'
2340                { $$ = $2; }
2341        ;
[51b7345]2342
2343identifier_parameter_array:
[4d51835]2344        paren_identifier array_parameter_dimension
2345                { $$ = $1->addArray( $2 ); }
2346        | '(' identifier_parameter_ptr ')' array_dimension
2347                { $$ = $2->addArray( $4 ); }
2348        | '(' identifier_parameter_array ')' multi_array_dimension // redundant parenthesis
2349                { $$ = $2->addArray( $4 ); }
2350        | '(' identifier_parameter_array ')'                            // redundant parenthesis
2351                { $$ = $2; }
2352        ;
[51b7345]2353
2354identifier_parameter_function:
[4d51835]2355        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2356                { $$ = $1->addParamList( $4 ); }
2357        | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2358                { $$ = $2->addParamList( $6 ); }
2359        | '(' identifier_parameter_function ')'                         // redundant parenthesis
2360                { $$ = $2; }
2361        ;
[b87a5ed]2362
[de62360d]2363// This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name,
2364// e.g.:
[c11e31c]2365//
[b87a5ed]2366//              typedef int foo;
2367//              int f( int foo ); // redefine typedef name in new scope
[c11e31c]2368//
[de62360d]2369// and allows the C99 array options, which can only appear in a parameter list.  In addition, the pattern handles the
2370// special meaning of parenthesis around a typedef name:
[c11e31c]2371//
[b87a5ed]2372//              ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
2373//              parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
2374//              not as redundant parentheses around the identifier."
[c11e31c]2375//
2376// which precludes the following cases:
2377//
[b87a5ed]2378//              typedef float T;
[4d51835]2379//              int f( int ( T [5] ) );                                 // see abstract_parameter_declarator
[b87a5ed]2380//              int g( int ( T ( int ) ) );                             // see abstract_parameter_declarator
2381//              int f( int f1( T a[5] ) );                              // see identifier_parameter_declarator
2382//              int g( int g1( T g2( int p ) ) );               // see identifier_parameter_declarator
[c11e31c]2383//
[de62360d]2384// In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
2385// not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
2386// functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
2387// functions.
[51b7345]2388
[2871210]2389type_parameter_redeclarator:
[4d51835]2390        typedef attribute_list_opt
[1db21619]2391                { $$ = $1->addQualifiers( $2 ); }
[2871210]2392        | type_parameter_ptr
2393        | type_parameter_array attribute_list_opt
[1db21619]2394                { $$ = $1->addQualifiers( $2 ); }
[2871210]2395        | type_parameter_function attribute_list_opt
[1db21619]2396                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2397        ;
[51b7345]2398
2399typedef:
[4d51835]2400        TYPEDEFname
2401                {
[de62360d]2402                        typedefTable.setNextIdentifier( *$1 );
[4d51835]2403                        $$ = DeclarationNode::newName( $1 );
2404                }
[2871210]2405        | TYPEGENname
2406                {
2407                        typedefTable.setNextIdentifier( *$1 );
2408                        $$ = DeclarationNode::newName( $1 );
2409                }
[4d51835]2410        ;
[51b7345]2411
[2871210]2412type_parameter_ptr:
2413        '*' type_parameter_redeclarator
[4d51835]2414                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
[2871210]2415        | '*' type_qualifier_list type_parameter_redeclarator
[4d51835]2416                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
[2871210]2417        | '(' type_parameter_ptr ')'
[4d51835]2418                { $$ = $2; }
2419        ;
[51b7345]2420
[2871210]2421type_parameter_array:
[4d51835]2422        typedef array_parameter_dimension
2423                { $$ = $1->addArray( $2 ); }
[2871210]2424        | '(' type_parameter_ptr ')' array_parameter_dimension
[4d51835]2425                { $$ = $2->addArray( $4 ); }
2426        ;
[51b7345]2427
[2871210]2428type_parameter_function:
[4d51835]2429        typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
2430                { $$ = $1->addParamList( $4 ); }
[2871210]2431        | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2432                { $$ = $2->addParamList( $6 ); }
2433        ;
[b87a5ed]2434
[de62360d]2435// This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to
2436// which the type applies, e.g.:
[c11e31c]2437//
[b87a5ed]2438//              sizeof( int );
2439//              sizeof( int [10] );
[c11e31c]2440//
[de62360d]2441// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2442// and functions versus pointers to arrays and functions.
[51b7345]2443
2444abstract_declarator:
[4d51835]2445        abstract_ptr
2446        | abstract_array attribute_list_opt
[1db21619]2447                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2448        | abstract_function attribute_list_opt
[1db21619]2449                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2450        ;
[51b7345]2451
2452abstract_ptr:
[4d51835]2453        '*'
2454                { $$ = DeclarationNode::newPointer( 0 ); }
2455        | '*' type_qualifier_list
2456                { $$ = DeclarationNode::newPointer( $2 ); }
2457        | '*' abstract_declarator
2458                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2459        | '*' type_qualifier_list abstract_declarator
2460                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2461        | '(' abstract_ptr ')'
2462                { $$ = $2; }
2463        ;
[51b7345]2464
2465abstract_array:
[4d51835]2466        array_dimension
2467        | '(' abstract_ptr ')' array_dimension
2468                { $$ = $2->addArray( $4 ); }
2469        | '(' abstract_array ')' multi_array_dimension          // redundant parenthesis
2470                { $$ = $2->addArray( $4 ); }
2471        | '(' abstract_array ')'                                                        // redundant parenthesis
2472                { $$ = $2; }
2473        ;
[51b7345]2474
2475abstract_function:
[4d51835]2476        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
2477                { $$ = DeclarationNode::newFunction( 0, 0, $3, 0 ); }
2478        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2479                { $$ = $2->addParamList( $6 ); }
2480        | '(' abstract_function ')'                                                     // redundant parenthesis
2481                { $$ = $2; }
2482        ;
[51b7345]2483
2484array_dimension:
[4d51835]2485                // Only the first dimension can be empty.
[2871210]2486        '[' ']'
[4d51835]2487                { $$ = DeclarationNode::newArray( 0, 0, false ); }
[2871210]2488        | '[' ']' multi_array_dimension
2489                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
[4d51835]2490        | multi_array_dimension
2491        ;
[51b7345]2492
2493multi_array_dimension:
[4d51835]2494        '[' push assignment_expression pop ']'
2495                { $$ = DeclarationNode::newArray( $3, 0, false ); }
2496        | '[' push '*' pop ']'                                                          // C99
2497                { $$ = DeclarationNode::newVarArray( 0 ); }
2498        | multi_array_dimension '[' push assignment_expression pop ']'
2499                { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
2500        | multi_array_dimension '[' push '*' pop ']'            // C99
2501                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
2502        ;
[51b7345]2503
[c11e31c]2504// This pattern parses a declaration of a parameter abstract variable or function prototype, i.e., there is no
2505// identifier to which the type applies, e.g.:
2506//
[b87a5ed]2507//              int f( int );                   // abstract variable parameter; no parameter name specified
2508//              int f( int (int) );             // abstract function-prototype parameter; no parameter name specified
[c11e31c]2509//
[de62360d]2510// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2511// and functions versus pointers to arrays and functions.
[51b7345]2512
2513abstract_parameter_declarator:
[4d51835]2514        abstract_parameter_ptr
2515        | abstract_parameter_array attribute_list_opt
[1db21619]2516                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2517        | abstract_parameter_function attribute_list_opt
[1db21619]2518                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2519        ;
[51b7345]2520
2521abstract_parameter_ptr:
[4d51835]2522        '*'
2523                { $$ = DeclarationNode::newPointer( 0 ); }
2524        | '*' type_qualifier_list
2525                { $$ = DeclarationNode::newPointer( $2 ); }
2526        | '*' abstract_parameter_declarator
2527                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2528        | '*' type_qualifier_list abstract_parameter_declarator
2529                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2530        | '(' abstract_parameter_ptr ')'
2531                { $$ = $2; }
2532        ;
[51b7345]2533
2534abstract_parameter_array:
[4d51835]2535        array_parameter_dimension
2536        | '(' abstract_parameter_ptr ')' array_parameter_dimension
2537                { $$ = $2->addArray( $4 ); }
2538        | '(' abstract_parameter_array ')' multi_array_dimension // redundant parenthesis
2539                { $$ = $2->addArray( $4 ); }
2540        | '(' abstract_parameter_array ')'                                      // redundant parenthesis
2541                { $$ = $2; }
2542        ;
[51b7345]2543
2544abstract_parameter_function:
[4d51835]2545        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
2546                { $$ = DeclarationNode::newFunction( 0, 0, $3, 0 ); }
2547        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2548                { $$ = $2->addParamList( $6 ); }
2549        | '(' abstract_parameter_function ')'                           // redundant parenthesis
2550                { $$ = $2; }
2551        ;
[51b7345]2552
2553array_parameter_dimension:
[4d51835]2554                // Only the first dimension can be empty or have qualifiers.
2555        array_parameter_1st_dimension
2556        | array_parameter_1st_dimension multi_array_dimension
2557                { $$ = $1->addArray( $2 ); }
2558        | multi_array_dimension
2559        ;
[51b7345]2560
[c11e31c]2561// The declaration of an array parameter has additional syntax over arrays in normal variable declarations:
2562//
[de62360d]2563//              ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in
2564//              a declaration of a function parameter with an array type, and then only in the outermost array type derivation."
[51b7345]2565
2566array_parameter_1st_dimension:
[2871210]2567        '[' ']'
[4d51835]2568                { $$ = DeclarationNode::newArray( 0, 0, false ); }
2569        // multi_array_dimension handles the '[' '*' ']' case
2570        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
2571                { $$ = DeclarationNode::newVarArray( $3 ); }
2572        | '[' push type_qualifier_list pop ']'
2573                { $$ = DeclarationNode::newArray( 0, $3, false ); }
2574        // multi_array_dimension handles the '[' assignment_expression ']' case
2575        | '[' push type_qualifier_list assignment_expression pop ']'
2576                { $$ = DeclarationNode::newArray( $4, $3, false ); }
2577        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
2578                { $$ = DeclarationNode::newArray( $5, $4, true ); }
2579        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
2580                { $$ = DeclarationNode::newArray( $5, $3, true ); }
2581        ;
[b87a5ed]2582
[de62360d]2583// This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies,
2584// e.g.:
[c11e31c]2585//
[b87a5ed]2586//              sizeof( int ); // abstract variable; no identifier name specified
[c11e31c]2587//
[de62360d]2588// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2589// and functions versus pointers to arrays and functions.
[51b7345]2590
2591variable_abstract_declarator:
[4d51835]2592        variable_abstract_ptr
2593        | variable_abstract_array attribute_list_opt
[1db21619]2594                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2595        | variable_abstract_function attribute_list_opt
[1db21619]2596                { $$ = $1->addQualifiers( $2 ); }
[4d51835]2597        ;
[51b7345]2598
2599variable_abstract_ptr:
[4d51835]2600        '*'
2601                { $$ = DeclarationNode::newPointer( 0 ); }
2602        | '*' type_qualifier_list
2603                { $$ = DeclarationNode::newPointer( $2 ); }
2604        | '*' variable_abstract_declarator
2605                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
2606        | '*' type_qualifier_list variable_abstract_declarator
2607                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
2608        | '(' variable_abstract_ptr ')'
2609                { $$ = $2; }
2610        ;
[51b7345]2611
2612variable_abstract_array:
[4d51835]2613        array_dimension
2614        | '(' variable_abstract_ptr ')' array_dimension
2615                { $$ = $2->addArray( $4 ); }
2616        | '(' variable_abstract_array ')' multi_array_dimension // redundant parenthesis
2617                { $$ = $2->addArray( $4 ); }
2618        | '(' variable_abstract_array ')'                                       // redundant parenthesis
2619                { $$ = $2; }
2620        ;
[51b7345]2621
2622variable_abstract_function:
[4d51835]2623        '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2624                { $$ = $2->addParamList( $6 ); }
2625        | '(' variable_abstract_function ')'                            // redundant parenthesis
2626                { $$ = $2; }
2627        ;
[b87a5ed]2628
[de62360d]2629// This pattern parses a new-style declaration for a parameter variable or function prototype that is either an
2630// identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.
[b87a5ed]2631
2632new_identifier_parameter_declarator_tuple:                              // CFA
[4d51835]2633        new_identifier_parameter_declarator_no_tuple
2634        | new_abstract_tuple
2635        | type_qualifier_list new_abstract_tuple
2636                { $$ = $2->addQualifiers( $1 ); }
2637        ;
[b87a5ed]2638
2639new_identifier_parameter_declarator_no_tuple:                   // CFA
[4d51835]2640        new_identifier_parameter_ptr
2641        | new_identifier_parameter_array
2642        ;
[b87a5ed]2643
2644new_identifier_parameter_ptr:                                                   // CFA
[4d51835]2645        '*' type_specifier
2646                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2647        | type_qualifier_list '*' type_specifier
2648                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2649        | '*' new_abstract_function
2650                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2651        | type_qualifier_list '*' new_abstract_function
2652                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2653        | '*' new_identifier_parameter_declarator_tuple
2654                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2655        | type_qualifier_list '*' new_identifier_parameter_declarator_tuple
2656                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2657        ;
[b87a5ed]2658
2659new_identifier_parameter_array:                                                 // CFA
[de62360d]2660                // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
2661                // shift/reduce conflict with new-style empty (void) function return type.
[2871210]2662        '[' ']' type_specifier
2663                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2664        | new_array_parameter_1st_dimension type_specifier
2665                { $$ = $2->addNewArray( $1 ); }
[2871210]2666        | '[' ']' multi_array_dimension type_specifier
2667                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2668        | new_array_parameter_1st_dimension multi_array_dimension type_specifier
2669                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
2670        | multi_array_dimension type_specifier
2671                { $$ = $2->addNewArray( $1 ); }
[2871210]2672        | '[' ']' new_identifier_parameter_ptr
2673                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2674        | new_array_parameter_1st_dimension new_identifier_parameter_ptr
2675                { $$ = $2->addNewArray( $1 ); }
[2871210]2676        | '[' ']' multi_array_dimension new_identifier_parameter_ptr
2677                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2678        | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr
2679                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
2680        | multi_array_dimension new_identifier_parameter_ptr
2681                { $$ = $2->addNewArray( $1 ); }
2682        ;
[51b7345]2683
2684new_array_parameter_1st_dimension:
[4d51835]2685        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
2686                { $$ = DeclarationNode::newVarArray( $3 ); }
2687        | '[' push type_qualifier_list assignment_expression pop ']'
2688                { $$ = DeclarationNode::newArray( $4, $3, false ); }
2689        | '[' push declaration_qualifier_list assignment_expression pop ']'
2690                // declaration_qualifier_list must be used because of shift/reduce conflict with
2691                // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
2692                // appear in this context.
2693                { $$ = DeclarationNode::newArray( $4, $3, true ); }
2694        | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
2695                { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
2696        ;
[b87a5ed]2697
[de62360d]2698// This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no
2699// identifier to which the type applies, e.g.:
[c11e31c]2700//
[b87a5ed]2701//              [int] f( int );                         // abstract variable parameter; no parameter name specified
2702//              [int] f( [int] (int) );         // abstract function-prototype parameter; no parameter name specified
[c11e31c]2703//
2704// These rules need LR(3):
2705//
[2871210]2706//              new_abstract_tuple identifier_or_type_name
2707//              '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'
[c11e31c]2708//
2709// since a function return type can be syntactically identical to a tuple type:
2710//
[b87a5ed]2711//              [int, int] t;
2712//              [int, int] f( int );
[c11e31c]2713//
[2871210]2714// Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
[de62360d]2715// new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
2716// lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are
2717// duplicated when appearing with new_function_specifier.
[b87a5ed]2718
2719new_abstract_declarator_tuple:                                                  // CFA
[4d51835]2720        new_abstract_tuple
2721        | type_qualifier_list new_abstract_tuple
2722                { $$ = $2->addQualifiers( $1 ); }
2723        | new_abstract_declarator_no_tuple
2724        ;
[b87a5ed]2725
2726new_abstract_declarator_no_tuple:                                               // CFA
[4d51835]2727        new_abstract_ptr
2728        | new_abstract_array
2729        ;
[b87a5ed]2730
2731new_abstract_ptr:                                                                               // CFA
[4d51835]2732        '*' type_specifier
2733                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2734        | type_qualifier_list '*' type_specifier
2735                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2736        | '*' new_abstract_function
2737                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2738        | type_qualifier_list '*' new_abstract_function
2739                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2740        | '*' new_abstract_declarator_tuple
2741                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
2742        | type_qualifier_list '*' new_abstract_declarator_tuple
2743                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
2744        ;
[b87a5ed]2745
2746new_abstract_array:                                                                             // CFA
[de62360d]2747                // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
2748                // empty (void) function return type.
[2871210]2749        '[' ']' type_specifier
2750                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
2751        | '[' ']' multi_array_dimension type_specifier
2752                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2753        | multi_array_dimension type_specifier
2754                { $$ = $2->addNewArray( $1 ); }
[2871210]2755        | '[' ']' new_abstract_ptr
2756                { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
2757        | '[' ']' multi_array_dimension new_abstract_ptr
2758                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[4d51835]2759        | multi_array_dimension new_abstract_ptr
2760                { $$ = $2->addNewArray( $1 ); }
2761        ;
[b87a5ed]2762
2763new_abstract_tuple:                                                                             // CFA
[4d51835]2764        '[' push new_abstract_parameter_list pop ']'
2765                { $$ = DeclarationNode::newTuple( $3 ); }
2766        ;
[b87a5ed]2767
2768new_abstract_function:                                                                  // CFA
[2871210]2769        '[' ']' '(' new_parameter_type_list_opt ')'
2770                { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); }
[4d51835]2771        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
2772                { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
2773        | new_function_return '(' push new_parameter_type_list_opt pop ')'
2774                { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
2775        ;
[b87a5ed]2776
[de62360d]2777// 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in
2778//    each declaration, and in the specifier-qualifier list in each structure declaration and type name."
[c11e31c]2779//
[de62360d]2780// 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of
2781//    the declaration specifiers in a declaration is an obsolescent feature."
[c11e31c]2782//
2783// 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not
2784//    prototype-format parameter type declarators) is an obsolescent feature."
2785//
[de62360d]2786// 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and
2787//    declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
[51b7345]2788
[c11e31c]2789//************************* MISCELLANEOUS ********************************
[51b7345]2790
[b87a5ed]2791comma_opt:                                                                                              // redundant comma
[4d51835]2792        // empty
2793        | ','
2794        ;
[51b7345]2795
2796assignment_opt:
[4d51835]2797        // empty
2798                { $$ = 0; }
2799        | '=' assignment_expression
2800                { $$ = $2; }
2801        ;
[51b7345]2802
2803%%
[c11e31c]2804// ----end of grammar----
[51b7345]2805
[5f2f2d7]2806void yyerror( const char * ) {
2807        std::cout << "Error ";
[b87a5ed]2808        if ( yyfilename ) {
[5f2f2d7]2809            std::cout << "in file " << yyfilename << " ";
2810        } // if
[b1d6dd5]2811        std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
[51b7345]2812}
2813
[c11e31c]2814// Local Variables: //
[b87a5ed]2815// mode: c++ //
[de62360d]2816// tab-width: 4 //
[c11e31c]2817// compile-command: "make install" //
2818// End: //
Note: See TracBrowser for help on using the repository browser.