Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    re7aed49 rc6b1105  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 22 21:20:17 2016
    13 // Update Count     : 1584
     12// Last Modified On : Mon Jun 27 17:47:56 2016
     13// Update Count     : 1627
    1414//
    1515
     
    224224%type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression
    225225%type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr
    226 %type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier
     226%type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier
    227227%type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
    228228
     
    350350        primary_expression
    351351        | postfix_expression '[' push assignment_expression pop ']'
    352                 // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a
     352                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    353353                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    354354                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
     
    421421unary_expression:
    422422        postfix_expression
    423         // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires semantics
    424         // checks, e.g., ++3, 3--, *3, &&3
     423                // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires
     424                // semantics checks, e.g., ++3, 3--, *3, &&3
    425425        | constant
    426426                { $$ = $1; }
     
    431431        | ptrref_operator cast_expression                                       // CFA
    432432                { $$ = 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
     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
    436436        | unary_operator cast_expression
    437437                { $$ = new CompositeExprNode( $1, $2 ); }
     
    456456        | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
    457457                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); }
    458         | ANDAND no_attr_identifier                                                     // GCC, address of label
    459                 { $$ = 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 ) ); }
    460460        ;
    461461
     
    463463        '*'                                                                                     { $$ = new OperatorNode( OperatorNode::PointTo ); }
    464464        | '&'                                                                           { $$ = 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 ); }
    465467        ;
    466468
     
    651653
    652654labeled_statement:
    653         no_attr_identifier ':' attribute_list_opt statement
     655                // labels cannot be identifiers 0 or 1
     656        IDENTIFIER ':' attribute_list_opt statement
    654657                {
    655658                        $$ = $4->add_label( $1 );
     
    804807
    805808jump_statement:
    806         GOTO no_attr_identifier ';'
     809        GOTO IDENTIFIER ';'
    807810                { $$ = new StatementNode( StatementNode::Goto, $2 ); }
    808811        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
     
    813816                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    814817                { $$ = new StatementNode( StatementNode::Continue ); }
    815         | CONTINUE no_attr_identifier ';'                                       // CFA, multi-level continue
     818        | CONTINUE IDENTIFIER ';'                                       // CFA, multi-level continue
    816819                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    817820                // the target of the transfer appears only at the start of an iteration statement.
     
    820823                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    821824                { $$ = new StatementNode( StatementNode::Break ); }
    822         | BREAK no_attr_identifier ';'                                          // CFA, multi-level exit
     825        | BREAK IDENTIFIER ';'                                          // CFA, multi-level exit
    823826                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    824827                // the target of the transfer appears only at the start of an iteration statement.
     
    15001503                // A semantic check is required to ensure bit_subrange only appears on base type int.
    15011504                { $$ = $1->addBitfield( $2 ); }
    1502         | type_redeclarator bit_subrange_size_opt
     1505        | variable_type_redeclarator bit_subrange_size_opt
    15031506                // A semantic check is required to ensure bit_subrange only appears on base type int.
    15041507                { $$ = $1->addBitfield( $2 ); }
     
    17441747
    17451748designator:
    1746         // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0
    1747         // only ".0" and ".1" allowed => semantic check
     1749                // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1"
     1750                // allowed => semantic check
    17481751        FLOATINGconstant
    17491752                { $$ = new DesignatorNode( new VarRefNode( $1 ) ); }
     
    19941997        function_definition
    19951998                // 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)
    19992003        | function_declarator compound_statement
    20002004                {
     
    20742078declarator:
    20752079        variable_declarator
     2080        | variable_type_redeclarator
    20762081        | function_declarator
    2077         | type_redeclarator
    20782082        ;
    20792083
     
    22012205        ;
    22022206
    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.
    22072210
    22082211function_declarator:
     
    22882291// and functions versus pointers to arrays and functions.
    22892292
    2290 type_redeclarator:
     2293variable_type_redeclarator:
    22912294        paren_type attribute_list_opt
    22922295                { $$ = $1->addQualifiers( $2 ); }
     
    23052308
    23062309type_ptr:
    2307         ptrref_operator type_redeclarator
     2310        ptrref_operator variable_type_redeclarator
    23082311                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2309         | ptrref_operator type_qualifier_list type_redeclarator
     2312        | ptrref_operator type_qualifier_list variable_type_redeclarator
    23102313                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    23112314        | '(' type_ptr ')'
     
    23902393//              not as redundant parentheses around the identifier."
    23912394//
    2392 // which precludes the following cases:
     2395// For example:
    23932396//
    23942397//              typedef float T;
Note: See TracChangeset for help on using the changeset viewer.