Changeset f80e0218 for src/Parser/parser.yy
- Timestamp:
- Jun 30, 2016, 4:32:56 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r1b5c81ed rf80e0218 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // cfa.y -- 8 // 7 // cfa.y -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:58:43201613 // Update Count : 1 51914 // 12 // Last Modified On : Mon Jun 27 17:47:56 2016 13 // Update Count : 1627 14 // 15 15 16 16 // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C … … 31 31 // two levels of extensions. The first extensions cover most of the GCC C extensions, except for: 32 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 33 // 1. designation with and without '=' (use ':' instead) 34 // 2. attributes not allowed in parenthesis of declarator 37 35 // 38 36 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall … … 79 77 %token TYPEOF LABEL // GCC 80 78 %token ENUM STRUCT UNION 81 %token OTYPE FTYPE DTYPE TRAIT // CFA79 %token OTYPE FTYPE DTYPE TRAIT // CFA 82 80 %token SIZEOF OFFSETOF 83 81 %token ATTRIBUTE EXTENSION // GCC … … 131 129 %type<constant> constant 132 130 %type<en> tuple tuple_expression_list 133 %type<en> unary_operator assignment_operator131 %type<en> ptrref_operator unary_operator assignment_operator 134 132 %type<en> primary_expression postfix_expression unary_expression 135 133 %type<en> cast_expression multiplicative_expression additive_expression shift_expression … … 226 224 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression 227 225 %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_specifier226 %type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier 229 227 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name 230 228 … … 352 350 primary_expression 353 351 | postfix_expression '[' push assignment_expression pop ']' 354 // CFA, comma_expression disallowed in th e context because it results in a commomuser error: subscripting a352 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 355 353 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 356 354 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is … … 423 421 unary_expression: 424 422 postfix_expression 425 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc"426 // still requiressemantics checks, e.g., ++3, 3--, *3, &&3423 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires 424 // semantics checks, e.g., ++3, 3--, *3, &&3 427 425 | constant 428 426 { $$ = $1; } 429 427 | string_literal_list 430 428 { $$ = $1; } 429 | EXTENSION cast_expression // GCC 430 { $$ = $2->set_extension( true ); } 431 | ptrref_operator cast_expression // CFA 432 { $$ = new CompositeExprNode( $1, $2 ); } 433 // '*' ('&') is separated from unary_operator because of shift/reduce conflict in: 434 // { * X; } // dereference X 435 // { * int X; } // CFA declaration of pointer to int 436 | unary_operator cast_expression 437 { $$ = new CompositeExprNode( $1, $2 ); } 431 438 | ICR unary_expression 432 439 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } 433 440 | DECR unary_expression 434 441 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); } 435 | EXTENSION cast_expression // GCC436 { $$ = $2; }437 | unary_operator cast_expression438 { $$ = new CompositeExprNode( $1, $2 ); }439 | '!' cast_expression440 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2 ); }441 | '*' cast_expression // CFA442 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2 ); }443 // '*' is is separated from unary_operator because of shift/reduce conflict in:444 // { * X; } // dereference X445 // { * int X; } // CFA declaration of pointer to int446 // '&' must be moved here if C++ reference variables are supported.447 442 | SIZEOF unary_expression 448 443 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); } … … 461 456 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 462 457 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); } 463 | ANDAND no_attr_identifier // GCC, address of label 464 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); } 458 // | ANDAND IDENTIFIER // GCC, address of label 459 // { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); } 460 ; 461 462 ptrref_operator: 463 '*' { $$ = new OperatorNode( OperatorNode::PointTo ); } 464 | '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); } 465 // GCC, address of label must be handled by semantic check for ref,ref,label 466 | ANDAND { $$ = new OperatorNode( OperatorNode::And ); } 465 467 ; 466 468 467 469 unary_operator: 468 '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); } 469 | '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 470 '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 470 471 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); } 472 | '!' { $$ = new OperatorNode( OperatorNode::Neg ); } 471 473 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); } 472 474 ; … … 646 648 Token fn; fn.str = new std::string( "^?{}" ); // location undefined 647 649 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ), 648 (ExpressionNode *)( new CompositeExprNode( new OperatorNode( OperatorNode::AddressOf ), $2 ))->set_link( $4 ) ), 0 );650 (ExpressionNode *)( $2 )->set_link( $4 ) ), 0 ); 649 651 } 650 652 ; 651 653 652 654 labeled_statement: 653 no_attr_identifier ':' attribute_list_opt statement 655 // labels cannot be identifiers 0 or 1 656 IDENTIFIER ':' attribute_list_opt statement 654 657 { 655 658 $$ = $4->add_label( $1 ); … … 679 682 { $$ = new StatementNode( $1 ); } 680 683 | EXTENSION declaration // GCC 681 { $$ = new StatementNode( $2 ) ; }684 { $$ = new StatementNode( $2 )/*->set_extension( true )*/; } 682 685 | function_definition 683 686 { $$ = new StatementNode( $1 ); } … … 804 807 805 808 jump_statement: 806 GOTO no_attr_identifier';'809 GOTO IDENTIFIER ';' 807 810 { $$ = new StatementNode( StatementNode::Goto, $2 ); } 808 811 | GOTO '*' comma_expression ';' // GCC, computed goto … … 813 816 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 814 817 { $$ = new StatementNode( StatementNode::Continue ); } 815 | CONTINUE no_attr_identifier';' // CFA, multi-level continue818 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 816 819 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 817 820 // the target of the transfer appears only at the start of an iteration statement. … … 820 823 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 821 824 { $$ = new StatementNode( StatementNode::Break ); } 822 | BREAK no_attr_identifier';' // CFA, multi-level exit825 | BREAK IDENTIFIER ';' // CFA, multi-level exit 823 826 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 824 827 // the target of the transfer appears only at the start of an iteration statement. … … 1469 1472 new_field_declaring_list ';' // CFA, new style field declaration 1470 1473 | EXTENSION new_field_declaring_list ';' // GCC 1471 { $$ = $2 ; }1474 { $$ = $2/*->set_extension( true )*/; } 1472 1475 | field_declaring_list ';' 1473 1476 | EXTENSION field_declaring_list ';' // GCC 1474 { $$ = $2 ; }1477 { $$ = $2/*->set_extension( true )*/; } 1475 1478 ; 1476 1479 … … 1500 1503 // A semantic check is required to ensure bit_subrange only appears on base type int. 1501 1504 { $$ = $1->addBitfield( $2 ); } 1502 | type_redeclarator bit_subrange_size_opt1505 | variable_type_redeclarator bit_subrange_size_opt 1503 1506 // A semantic check is required to ensure bit_subrange only appears on base type int. 1504 1507 { $$ = $1->addBitfield( $2 ); } … … 1702 1705 { $$ = $2; } 1703 1706 | ATassign initializer 1704 { $$ = $2 ; }1707 { $$ = $2->set_maybeConstructed( false ); } 1705 1708 ; 1706 1709 … … 1744 1747 1745 1748 designator: 1746 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 01747 // only ".0" and ".1"allowed => semantic check1749 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1" 1750 // allowed => semantic check 1748 1751 FLOATINGconstant 1749 1752 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); } … … 1988 1991 } 1989 1992 | EXTENSION external_definition 1990 { $$ = $2 ; }1993 { $$ = $2/*->set_extension( true )*/; } 1991 1994 ; 1992 1995 … … 1994 1997 function_definition 1995 1998 // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of 1996 // code with functions missing a type-specifier on the return type. Parsing is possible because 1997 // function_definition does not appear in the context of an expression (nested functions would preclude this 1998 // concession). A function prototype declaration must still have a type_specifier. OBSOLESCENT (see 1) 1999 // legacy code with global functions missing the type-specifier for the return type, and assuming "int". 2000 // Parsing is possible because function_definition does not appear in the context of an expression (nested 2001 // functions preclude this concession, i.e., all nested function must have a return type). A function prototype 2002 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 1999 2003 | function_declarator compound_statement 2000 2004 { … … 2074 2078 declarator: 2075 2079 variable_declarator 2080 | variable_type_redeclarator 2076 2081 | function_declarator 2077 | type_redeclarator2078 2082 ; 2079 2083 … … 2175 2179 2176 2180 variable_ptr: 2177 '*'variable_declarator2181 ptrref_operator variable_declarator 2178 2182 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2179 | '*'type_qualifier_list variable_declarator2183 | ptrref_operator type_qualifier_list variable_declarator 2180 2184 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2181 2185 | '(' variable_ptr ')' … … 2201 2205 ; 2202 2206 2203 // This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested, 2204 // there is no context where a function definition can redefine a typedef name. To allow nested functions requires 2205 // further separation of variable and function declarators in type_redeclarator. The pattern precludes returning 2206 // arrays and functions versus pointers to arrays and functions. 2207 // This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is 2208 // no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist 2209 // is the same scope. The pattern precludes returning arrays and functions versus pointers to arrays and functions. 2207 2210 2208 2211 function_declarator: … … 2224 2227 2225 2228 function_ptr: 2226 '*'function_declarator2229 ptrref_operator function_declarator 2227 2230 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2228 | '*'type_qualifier_list function_declarator2231 | ptrref_operator type_qualifier_list function_declarator 2229 2232 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2230 2233 | '(' function_ptr ')' … … 2261 2264 2262 2265 old_function_ptr: 2263 '*'old_function_declarator2266 ptrref_operator old_function_declarator 2264 2267 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2265 | '*'type_qualifier_list old_function_declarator2268 | ptrref_operator type_qualifier_list old_function_declarator 2266 2269 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2267 2270 | '(' old_function_ptr ')' … … 2288 2291 // and functions versus pointers to arrays and functions. 2289 2292 2290 type_redeclarator:2293 variable_type_redeclarator: 2291 2294 paren_type attribute_list_opt 2292 2295 { $$ = $1->addQualifiers( $2 ); } … … 2305 2308 2306 2309 type_ptr: 2307 '*'type_redeclarator2310 ptrref_operator variable_type_redeclarator 2308 2311 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2309 | '*' type_qualifier_listtype_redeclarator2312 | ptrref_operator type_qualifier_list variable_type_redeclarator 2310 2313 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2311 2314 | '(' type_ptr ')' … … 2349 2352 2350 2353 identifier_parameter_ptr: 2351 '*'identifier_parameter_declarator2354 ptrref_operator identifier_parameter_declarator 2352 2355 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2353 | '*'type_qualifier_list identifier_parameter_declarator2356 | ptrref_operator type_qualifier_list identifier_parameter_declarator 2354 2357 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2355 2358 | '(' identifier_parameter_ptr ')' … … 2390 2393 // not as redundant parentheses around the identifier." 2391 2394 // 2392 // which precludes the following cases:2395 // For example: 2393 2396 // 2394 2397 // typedef float T; … … 2427 2430 2428 2431 type_parameter_ptr: 2429 '*'type_parameter_redeclarator2432 ptrref_operator type_parameter_redeclarator 2430 2433 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2431 | '*'type_qualifier_list type_parameter_redeclarator2434 | ptrref_operator type_qualifier_list type_parameter_redeclarator 2432 2435 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2433 2436 | '(' type_parameter_ptr ')' … … 2467 2470 2468 2471 abstract_ptr: 2469 '*'2472 ptrref_operator 2470 2473 { $$ = DeclarationNode::newPointer( 0 ); } 2471 | '*'type_qualifier_list2474 | ptrref_operator type_qualifier_list 2472 2475 { $$ = DeclarationNode::newPointer( $2 ); } 2473 | '*'abstract_declarator2476 | ptrref_operator abstract_declarator 2474 2477 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2475 | '*'type_qualifier_list abstract_declarator2478 | ptrref_operator type_qualifier_list abstract_declarator 2476 2479 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2477 2480 | '(' abstract_ptr ')' … … 2536 2539 2537 2540 abstract_parameter_ptr: 2538 '*'2541 ptrref_operator 2539 2542 { $$ = DeclarationNode::newPointer( 0 ); } 2540 | '*'type_qualifier_list2543 | ptrref_operator type_qualifier_list 2541 2544 { $$ = DeclarationNode::newPointer( $2 ); } 2542 | '*'abstract_parameter_declarator2545 | ptrref_operator abstract_parameter_declarator 2543 2546 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2544 | '*'type_qualifier_list abstract_parameter_declarator2547 | ptrref_operator type_qualifier_list abstract_parameter_declarator 2545 2548 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2546 2549 | '(' abstract_parameter_ptr ')' … … 2614 2617 2615 2618 variable_abstract_ptr: 2616 '*'2619 ptrref_operator 2617 2620 { $$ = DeclarationNode::newPointer( 0 ); } 2618 | '*'type_qualifier_list2621 | ptrref_operator type_qualifier_list 2619 2622 { $$ = DeclarationNode::newPointer( $2 ); } 2620 | '*'variable_abstract_declarator2623 | ptrref_operator variable_abstract_declarator 2621 2624 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2622 | '*'type_qualifier_list variable_abstract_declarator2625 | ptrref_operator type_qualifier_list variable_abstract_declarator 2623 2626 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2624 2627 | '(' variable_abstract_ptr ')' … … 2659 2662 2660 2663 new_identifier_parameter_ptr: // CFA 2661 '*'type_specifier2664 ptrref_operator type_specifier 2662 2665 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2663 | type_qualifier_list '*'type_specifier2666 | type_qualifier_list ptrref_operator type_specifier 2664 2667 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2665 | '*'new_abstract_function2668 | ptrref_operator new_abstract_function 2666 2669 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2667 | type_qualifier_list '*'new_abstract_function2670 | type_qualifier_list ptrref_operator new_abstract_function 2668 2671 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2669 | '*'new_identifier_parameter_declarator_tuple2672 | ptrref_operator new_identifier_parameter_declarator_tuple 2670 2673 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2671 | type_qualifier_list '*'new_identifier_parameter_declarator_tuple2674 | type_qualifier_list ptrref_operator new_identifier_parameter_declarator_tuple 2672 2675 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2673 2676 ; … … 2746 2749 2747 2750 new_abstract_ptr: // CFA 2748 '*'type_specifier2751 ptrref_operator type_specifier 2749 2752 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2750 | type_qualifier_list '*'type_specifier2753 | type_qualifier_list ptrref_operator type_specifier 2751 2754 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2752 | '*'new_abstract_function2755 | ptrref_operator new_abstract_function 2753 2756 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2754 | type_qualifier_list '*'new_abstract_function2757 | type_qualifier_list ptrref_operator new_abstract_function 2755 2758 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2756 | '*'new_abstract_declarator_tuple2759 | ptrref_operator new_abstract_declarator_tuple 2757 2760 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2758 | type_qualifier_list '*'new_abstract_declarator_tuple2761 | type_qualifier_list ptrref_operator new_abstract_declarator_tuple 2759 2762 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2760 2763 ;
Note:
See TracChangeset
for help on using the changeset viewer.