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