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