Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r1b29996 r9059213  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct 26 17:35:53 2016
    13 // Update Count     : 2066
     12// Last Modified On : Wed Oct 19 22:19:33 2016
     13// Update Count     : 2003
    1414//
    1515
     
    9494%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
    9595%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    96 %token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
    97 // Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
    98 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
    99 // converted into the tuple index (.)(1). e.g., 3.x
    100 %token<tok>     REALDECIMALconstant     REALFRACTIONconstant    FLOATINGconstant
     96%token<tok> INTEGERconstant             FLOATINGconstant                CHARACTERconstant               STRINGliteral
    10197%token<tok> ZERO                                ONE                                             // CFA
    10298
     
    316312                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    317313        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    318         | REALDECIMALconstant                                           { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    319         | REALFRACTIONconstant                                          { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    320314        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    321315        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     
    364358        | zero_one
    365359                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    366         | tuple
    367360        | '(' comma_expression ')'
    368361                { $$ = $2; }
     
    381374        | postfix_expression '(' argument_expression_list ')'
    382375                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
     376                // ambiguity with .0 so space required after field-selection, e.g.
     377                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    383378        | postfix_expression '.' no_attr_identifier
    384379                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    385380        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    386         | postfix_expression REALFRACTIONconstant                       // CFA, tuple index
     381        | postfix_expression '.' INTEGERconstant
    387382        | postfix_expression ARROW no_attr_identifier
    388383                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    421416field:                                                                                                  // CFA, tuple field selector
    422417        field_name
     418                // ambiguity with .0 so space required after field-selection, e.g.
     419                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    423420                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    424         | REALDECIMALconstant field
    425                 { $$ = new ExpressionNode( build_fieldSel( $2, build_varref( $1 ) ) ); }
    426         | REALDECIMALconstant '[' push field_list pop ']'
    427                 { $$ = new ExpressionNode( build_fieldSel( $4, build_varref( $1 ) ) ); }
    428421        | field_name '.' field
    429422                { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); }
     
    437430
    438431field_name:
    439         INTEGERconstant fraction_constants
    440                 { $$ = $1; }
    441         | FLOATINGconstant fraction_constants
    442                 { $$ = $1; }
    443         | no_attr_identifier fraction_constants
    444                 { $$ = $1; }
    445         ;
    446 
    447 fraction_constants:
    448         // empty
    449         | fraction_constants REALFRACTIONconstant
     432        no_attr_identifier
     433                // x.1, x.[0, 0.0]
     434        | INTEGERconstant
    450435        ;
    451436
     
    520505        | '(' type_name_no_function ')' cast_expression
    521506                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    522 //      | '(' type_name_no_function ')' tuple
    523 //              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     507        | '(' type_name_no_function ')' tuple
     508                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    524509        ;
    525510
     
    607592        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    608593                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
    609 //      | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
    610 //              { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
     594        | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
     595                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    611596        ;
    612597
     
    620605        | unary_expression assignment_operator assignment_expression
    621606                { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); }
    622 //      | tuple assignment_opt                                                          // CFA, tuple expression
    623 //              { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }
     607        | tuple assignment_opt                                                          // CFA, tuple expression
     608                { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }
    624609        ;
    625610
     
    648633                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
    649634                // comma_expression in new_identifier_parameter_array and new_abstract_array
    650 //      '[' ']'
    651 //              { $$ = new ExpressionNode( build_tuple() ); }
    652 //      '[' push assignment_expression pop ']'
    653 //              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    654         '[' push ',' tuple_expression_list pop ']'
     635        '[' ']'
     636                { $$ = new ExpressionNode( build_tuple() ); }
     637        | '[' push assignment_expression pop ']'
     638                { $$ = new ExpressionNode( build_tuple( $3 ) ); }
     639        | '[' push ',' tuple_expression_list pop ']'
    655640                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    656641        | '[' push assignment_expression ',' tuple_expression_list pop ']'
     
    11511136
    11521137new_function_specifier:                                                                 // CFA
    1153 //      '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict
    1154 //              {
    1155 //                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    1156 //              }
     1138        '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict
     1139                {
     1140                        $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
     1141                }
    11571142//      '[' ']' identifier '(' push new_parameter_type_list_opt pop ')'
    11581143//              {
     
    11731158                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    11741159                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1175         new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
     1160        | new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'
    11761161                // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator).
    11771162                {
     
    28372822
    28382823new_abstract_function:                                                                  // CFA
    2839 //      '[' ']' '(' new_parameter_type_list_opt ')'
    2840 //              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    2841         new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
     2824        '[' ']' '(' new_parameter_type_list_opt ')'
     2825                { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
     2826        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    28422827                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28432828        | new_function_return '(' push new_parameter_type_list_opt pop ')'
Note: See TracChangeset for help on using the changeset viewer.