Changes in src/Parser/parser.yy [c6b1105:45161b4d]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rc6b1105 r45161b4d 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 : Mon Jun 27 17:47:56201613 // Update Count : 1 62714 // 12 // Last Modified On : Wed Apr 13 16:58:43 2016 13 // Update Count : 1519 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. designation with and without '=' (use ':' instead) 34 // 2. attributes not allowed in parenthesis of declarator 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 35 37 // 36 38 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall … … 77 79 %token TYPEOF LABEL // GCC 78 80 %token ENUM STRUCT UNION 79 %token OTYPE FTYPE DTYPE TRAIT // CFA81 %token OTYPE FTYPE DTYPE TRAIT // CFA 80 82 %token SIZEOF OFFSETOF 81 83 %token ATTRIBUTE EXTENSION // GCC … … 129 131 %type<constant> constant 130 132 %type<en> tuple tuple_expression_list 131 %type<en> ptrref_operatorunary_operator assignment_operator133 %type<en> unary_operator assignment_operator 132 134 %type<en> primary_expression postfix_expression unary_expression 133 135 %type<en> cast_expression multiplicative_expression additive_expression shift_expression … … 224 226 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression 225 227 %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr 226 %type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier228 %type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier 227 229 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name 228 230 … … 350 352 primary_expression 351 353 | postfix_expression '[' push assignment_expression pop ']' 352 // CFA, comma_expression disallowed in th is context because it results in a commonuser error: subscripting a354 // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a 353 355 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 354 356 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is … … 421 423 unary_expression: 422 424 postfix_expression 423 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires424 //semantics checks, e.g., ++3, 3--, *3, &&3425 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" 426 // still requires semantics checks, e.g., ++3, 3--, *3, &&3 425 427 | constant 426 428 { $$ = $1; } 427 429 | string_literal_list 428 430 { $$ = $1; } 429 | EXTENSION cast_expression // GCC430 { $$ = $2->set_extension( true ); }431 | ptrref_operator cast_expression // CFA432 { $$ = new CompositeExprNode( $1, $2 ); }433 // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:434 // { * X; } // dereference X435 // { * int X; } // CFA declaration of pointer to int436 | unary_operator cast_expression437 { $$ = new CompositeExprNode( $1, $2 ); }438 431 | ICR unary_expression 439 432 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } 440 433 | DECR unary_expression 441 434 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); } 435 | EXTENSION cast_expression // GCC 436 { $$ = $2; } 437 | unary_operator cast_expression 438 { $$ = new CompositeExprNode( $1, $2 ); } 439 | '!' cast_expression 440 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2 ); } 441 | '*' cast_expression // CFA 442 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2 ); } 443 // '*' is is separated from unary_operator because of shift/reduce conflict in: 444 // { * X; } // dereference X 445 // { * int X; } // CFA declaration of pointer to int 446 // '&' must be moved here if C++ reference variables are supported. 442 447 | SIZEOF unary_expression 443 448 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); } … … 456 461 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 457 462 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); } 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 ); } 463 | ANDAND no_attr_identifier // GCC, address of label 464 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); } 467 465 ; 468 466 469 467 unary_operator: 470 '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 468 '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); } 469 | '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 471 470 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); } 472 | '!' { $$ = new OperatorNode( OperatorNode::Neg ); }473 471 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); } 474 472 ; … … 648 646 Token fn; fn.str = new std::string( "^?{}" ); // location undefined 649 647 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ), 650 (ExpressionNode *)( $2)->set_link( $4 ) ), 0 );648 (ExpressionNode *)(new CompositeExprNode( new OperatorNode( OperatorNode::AddressOf ), $2 ))->set_link( $4 ) ), 0 ); 651 649 } 652 650 ; 653 651 654 652 labeled_statement: 655 // labels cannot be identifiers 0 or 1 656 IDENTIFIER ':' attribute_list_opt statement 653 no_attr_identifier ':' attribute_list_opt statement 657 654 { 658 655 $$ = $4->add_label( $1 ); … … 682 679 { $$ = new StatementNode( $1 ); } 683 680 | EXTENSION declaration // GCC 684 { $$ = new StatementNode( $2 ) /*->set_extension( true )*/; }681 { $$ = new StatementNode( $2 ); } 685 682 | function_definition 686 683 { $$ = new StatementNode( $1 ); } … … 807 804 808 805 jump_statement: 809 GOTO IDENTIFIER';'806 GOTO no_attr_identifier ';' 810 807 { $$ = new StatementNode( StatementNode::Goto, $2 ); } 811 808 | GOTO '*' comma_expression ';' // GCC, computed goto … … 816 813 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 817 814 { $$ = new StatementNode( StatementNode::Continue ); } 818 | CONTINUE IDENTIFIER';' // CFA, multi-level continue815 | CONTINUE no_attr_identifier ';' // CFA, multi-level continue 819 816 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 820 817 // the target of the transfer appears only at the start of an iteration statement. … … 823 820 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 824 821 { $$ = new StatementNode( StatementNode::Break ); } 825 | BREAK IDENTIFIER';' // CFA, multi-level exit822 | BREAK no_attr_identifier ';' // CFA, multi-level exit 826 823 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 827 824 // the target of the transfer appears only at the start of an iteration statement. … … 1472 1469 new_field_declaring_list ';' // CFA, new style field declaration 1473 1470 | EXTENSION new_field_declaring_list ';' // GCC 1474 { $$ = $2 /*->set_extension( true )*/; }1471 { $$ = $2; } 1475 1472 | field_declaring_list ';' 1476 1473 | EXTENSION field_declaring_list ';' // GCC 1477 { $$ = $2 /*->set_extension( true )*/; }1474 { $$ = $2; } 1478 1475 ; 1479 1476 … … 1503 1500 // A semantic check is required to ensure bit_subrange only appears on base type int. 1504 1501 { $$ = $1->addBitfield( $2 ); } 1505 | variable_type_redeclarator bit_subrange_size_opt1502 | type_redeclarator bit_subrange_size_opt 1506 1503 // A semantic check is required to ensure bit_subrange only appears on base type int. 1507 1504 { $$ = $1->addBitfield( $2 ); } … … 1705 1702 { $$ = $2; } 1706 1703 | ATassign initializer 1707 { $$ = $2 ->set_maybeConstructed( false ); }1704 { $$ = $2; } 1708 1705 ; 1709 1706 … … 1747 1744 1748 1745 designator: 1749 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1"1750 //allowed => semantic check1746 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 1747 // only ".0" and ".1" allowed => semantic check 1751 1748 FLOATINGconstant 1752 1749 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); } … … 1991 1988 } 1992 1989 | EXTENSION external_definition 1993 { $$ = $2 /*->set_extension( true )*/; }1990 { $$ = $2; } 1994 1991 ; 1995 1992 … … 1997 1994 function_definition 1998 1995 // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of 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) 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) 2003 1999 | function_declarator compound_statement 2004 2000 { … … 2078 2074 declarator: 2079 2075 variable_declarator 2080 | variable_type_redeclarator2081 2076 | function_declarator 2077 | type_redeclarator 2082 2078 ; 2083 2079 … … 2179 2175 2180 2176 variable_ptr: 2181 ptrref_operatorvariable_declarator2177 '*' variable_declarator 2182 2178 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2183 | ptrref_operatortype_qualifier_list variable_declarator2179 | '*' type_qualifier_list variable_declarator 2184 2180 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2185 2181 | '(' variable_ptr ')' … … 2205 2201 ; 2206 2202 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. 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. 2210 2207 2211 2208 function_declarator: … … 2227 2224 2228 2225 function_ptr: 2229 ptrref_operatorfunction_declarator2226 '*' function_declarator 2230 2227 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2231 | ptrref_operatortype_qualifier_list function_declarator2228 | '*' type_qualifier_list function_declarator 2232 2229 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2233 2230 | '(' function_ptr ')' … … 2264 2261 2265 2262 old_function_ptr: 2266 ptrref_operatorold_function_declarator2263 '*' old_function_declarator 2267 2264 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2268 | ptrref_operatortype_qualifier_list old_function_declarator2265 | '*' type_qualifier_list old_function_declarator 2269 2266 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2270 2267 | '(' old_function_ptr ')' … … 2291 2288 // and functions versus pointers to arrays and functions. 2292 2289 2293 variable_type_redeclarator:2290 type_redeclarator: 2294 2291 paren_type attribute_list_opt 2295 2292 { $$ = $1->addQualifiers( $2 ); } … … 2308 2305 2309 2306 type_ptr: 2310 ptrref_operator variable_type_redeclarator2307 '*' type_redeclarator 2311 2308 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2312 | ptrref_operator type_qualifier_list variable_type_redeclarator2309 | '*' type_qualifier_list type_redeclarator 2313 2310 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2314 2311 | '(' type_ptr ')' … … 2352 2349 2353 2350 identifier_parameter_ptr: 2354 ptrref_operatoridentifier_parameter_declarator2351 '*' identifier_parameter_declarator 2355 2352 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2356 | ptrref_operatortype_qualifier_list identifier_parameter_declarator2353 | '*' type_qualifier_list identifier_parameter_declarator 2357 2354 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2358 2355 | '(' identifier_parameter_ptr ')' … … 2393 2390 // not as redundant parentheses around the identifier." 2394 2391 // 2395 // For example:2392 // which precludes the following cases: 2396 2393 // 2397 2394 // typedef float T; … … 2430 2427 2431 2428 type_parameter_ptr: 2432 ptrref_operatortype_parameter_redeclarator2429 '*' type_parameter_redeclarator 2433 2430 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2434 | ptrref_operatortype_qualifier_list type_parameter_redeclarator2431 | '*' type_qualifier_list type_parameter_redeclarator 2435 2432 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2436 2433 | '(' type_parameter_ptr ')' … … 2470 2467 2471 2468 abstract_ptr: 2472 ptrref_operator2469 '*' 2473 2470 { $$ = DeclarationNode::newPointer( 0 ); } 2474 | ptrref_operatortype_qualifier_list2471 | '*' type_qualifier_list 2475 2472 { $$ = DeclarationNode::newPointer( $2 ); } 2476 | ptrref_operatorabstract_declarator2473 | '*' abstract_declarator 2477 2474 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2478 | ptrref_operatortype_qualifier_list abstract_declarator2475 | '*' type_qualifier_list abstract_declarator 2479 2476 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2480 2477 | '(' abstract_ptr ')' … … 2539 2536 2540 2537 abstract_parameter_ptr: 2541 ptrref_operator2538 '*' 2542 2539 { $$ = DeclarationNode::newPointer( 0 ); } 2543 | ptrref_operatortype_qualifier_list2540 | '*' type_qualifier_list 2544 2541 { $$ = DeclarationNode::newPointer( $2 ); } 2545 | ptrref_operatorabstract_parameter_declarator2542 | '*' abstract_parameter_declarator 2546 2543 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2547 | ptrref_operatortype_qualifier_list abstract_parameter_declarator2544 | '*' type_qualifier_list abstract_parameter_declarator 2548 2545 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2549 2546 | '(' abstract_parameter_ptr ')' … … 2617 2614 2618 2615 variable_abstract_ptr: 2619 ptrref_operator2616 '*' 2620 2617 { $$ = DeclarationNode::newPointer( 0 ); } 2621 | ptrref_operatortype_qualifier_list2618 | '*' type_qualifier_list 2622 2619 { $$ = DeclarationNode::newPointer( $2 ); } 2623 | ptrref_operatorvariable_abstract_declarator2620 | '*' variable_abstract_declarator 2624 2621 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2625 | ptrref_operatortype_qualifier_list variable_abstract_declarator2622 | '*' type_qualifier_list variable_abstract_declarator 2626 2623 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2627 2624 | '(' variable_abstract_ptr ')' … … 2662 2659 2663 2660 new_identifier_parameter_ptr: // CFA 2664 ptrref_operatortype_specifier2661 '*' type_specifier 2665 2662 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2666 | type_qualifier_list ptrref_operatortype_specifier2663 | type_qualifier_list '*' type_specifier 2667 2664 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2668 | ptrref_operatornew_abstract_function2665 | '*' new_abstract_function 2669 2666 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2670 | type_qualifier_list ptrref_operatornew_abstract_function2667 | type_qualifier_list '*' new_abstract_function 2671 2668 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2672 | ptrref_operatornew_identifier_parameter_declarator_tuple2669 | '*' new_identifier_parameter_declarator_tuple 2673 2670 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2674 | type_qualifier_list ptrref_operatornew_identifier_parameter_declarator_tuple2671 | type_qualifier_list '*' new_identifier_parameter_declarator_tuple 2675 2672 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2676 2673 ; … … 2749 2746 2750 2747 new_abstract_ptr: // CFA 2751 ptrref_operatortype_specifier2748 '*' type_specifier 2752 2749 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2753 | type_qualifier_list ptrref_operatortype_specifier2750 | type_qualifier_list '*' type_specifier 2754 2751 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2755 | ptrref_operatornew_abstract_function2752 | '*' new_abstract_function 2756 2753 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2757 | type_qualifier_list ptrref_operatornew_abstract_function2754 | type_qualifier_list '*' new_abstract_function 2758 2755 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2759 | ptrref_operatornew_abstract_declarator_tuple2756 | '*' new_abstract_declarator_tuple 2760 2757 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2761 | type_qualifier_list ptrref_operatornew_abstract_declarator_tuple2758 | type_qualifier_list '*' new_abstract_declarator_tuple 2762 2759 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2763 2760 ;
Note:
See TracChangeset
for help on using the changeset viewer.