Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r72457b6 r0fc9756b  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 24 09:01:14 2017
    13 // Update Count     : 2463
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus Jul 11 13:39:00 2017
     13// Update Count     : 2416
    1414//
    1515
     
    118118%token RESTRICT                                                                                 // C99
    119119%token ATOMIC                                                                                   // C11
    120 %token FORALL LVALUE MUTEX VIRTUAL                                              // CFA
    121 %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
     120%token FORALL LVALUE MUTEX                                                              // CFA
     121%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED ZERO_T ONE_T
     122%token VALIST                                                                                   // GCC
    122123%token BOOL COMPLEX IMAGINARY                                                   // C99
    123 %token ZERO_T ONE_T                                                                             // CFA
    124 %token VALIST                                                                                   // GCC
    125124%token TYPEOF LABEL                                                                             // GCC
    126125%token ENUM STRUCT UNION
     
    130129%token ATTRIBUTE EXTENSION                                                              // GCC
    131130%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    132 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH   // CFA
     131%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
    133132%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    134133%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    152151%token ELLIPSIS                                                                                 // ...
    153152
    154 %token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
     153%token MULTassign       DIVassign       MODassign                               // *=   /=      %=/
    155154%token PLUSassign       MINUSassign                                                     // +=   -=
    156155%token LSassign         RSassign                                                        // <<=  >>=
     
    169168%type<op> ptrref_operator                               unary_operator                          assignment_operator
    170169%type<en> primary_expression                    postfix_expression                      unary_expression
    171 %type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
    172 %type<en> shift_expression                              relational_expression           equality_expression
    173 %type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
    174 %type<en> logical_AND_expression                logical_OR_expression
    175 %type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
     170%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
     171%type<en> relational_expression                 equality_expression                     AND_expression                          exclusive_OR_expression
     172%type<en> inclusive_OR_expression               logical_AND_expression          logical_OR_expression           conditional_expression
     173%type<en> constant_expression                   assignment_expression           assignment_expression_opt
    176174%type<en> comma_expression                              comma_expression_opt
    177 %type<en> argument_expression_list              argument_expression                     default_initialize_opt
     175%type<en> argument_expression_list              argument_expression                     assignment_opt
    178176%type<fctl> for_control_expression
    179177%type<en> subrange
     
    186184// statements
    187185%type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    188 %type<sn> iteration_statement                   jump_statement
    189 %type<sn> with_statement                                exception_statement                     asm_statement
     186%type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement
    190187%type<sn> fall_through_opt                              fall_through
    191188%type<sn> statement                                             statement_list
    192189%type<sn> block_item_list                               block_item
    193 %type<sn> with_clause_opt
     190%type<sn> case_clause
    194191%type<en> case_value
    195 %type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
     192%type<sn> case_value_list                               case_label                                      case_label_list
    196193%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    197194%type<sn> /* handler_list */                    handler_clause                          finally_clause
     
    571568        | '(' type_no_function ')' cast_expression
    572569                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    573                 // VIRTUAL cannot be opt because of look ahead issues
    574         | '(' VIRTUAL ')' cast_expression
    575                 { $$ = new ExpressionNode( build_cast( nullptr, $4 ) ); }
    576         | '(' VIRTUAL type_no_function ')' cast_expression
    577                 { $$ = new ExpressionNode( build_cast( $3, $5 ) ); }
    578570//      | '(' type_no_function ')' tuple
    579571//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    580572        ;
    581573
    582 exponential_expression:
     574multiplicative_expression:
    583575        cast_expression
    584         | exponential_expression '\\' cast_expression
    585                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }
    586         ;
    587 
    588 multiplicative_expression:
    589         exponential_expression
    590         | multiplicative_expression '*' exponential_expression
     576        | multiplicative_expression '*' cast_expression
    591577                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
    592         | multiplicative_expression '/' exponential_expression
     578        | multiplicative_expression '/' cast_expression
    593579                { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
    594         | multiplicative_expression '%' exponential_expression
     580        | multiplicative_expression '%' cast_expression
    595581                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
    596582        ;
     
    691677        '='                                                                                     { $$ = OperKinds::Assign; }
    692678        | ATassign                                                                      { $$ = OperKinds::AtAssn; }
    693         | EXPassign                                                                     { $$ = OperKinds::ExpAssn; }
    694679        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    695680        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    744729        | iteration_statement
    745730        | jump_statement
    746         | with_statement
    747731        | exception_statement
    748732        | asm_statement
     
    952936        ;
    953937
    954 with_statement:
    955         WITH '(' tuple_expression_list ')' compound_statement
    956                 { $$ = (StatementNode *)0; }                                    // FIX ME
    957         ;
    958 
    959938exception_statement:
    960939        TRY compound_statement handler_clause
     
    986965                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
    987966
    988         | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    989                 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); }
    990         | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    991                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }
    992         ;
    993 
    994 handler_predicate_opt:
    995         //empty
    996         | ';' conditional_expression
     967        | handler_key '(' push push exception_declaration pop ')' compound_statement pop
     968                { $$ = new StatementNode( build_catch( $1, $5, nullptr, $8 ) ); }
     969        | handler_clause handler_key '(' push push exception_declaration pop ')' compound_statement pop
     970                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $9 ) ) ); }
    997971        ;
    998972
     
    15211495        | IMAGINARY                                                                                     // C99
    15221496                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
     1497        | VALIST                                                                                        // GCC, __builtin_va_list
     1498                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    15231499        | ZERO_T
    15241500                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
    15251501        | ONE_T
    15261502                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
    1527         | VALIST                                                                                        // GCC, __builtin_va_list
    1528                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    15291503        ;
    15301504
     
    16861660        | aggregate_key attribute_list_opt typegen_name         // CFA
    16871661                { $$ = $3->addQualifiers( $2 ); }
    1688 
    1689 // Temp, testing TreeStruct
    1690     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name
    1691         {
    1692             typedefTable.makeTypedef( *$4 );            // create typedef
    1693             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1694             forall = false;                             // reset
    1695         }
    1696       '{' field_declaration_list '}'
    1697         {
    1698             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1699                 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );
    1700         }
    1701     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname
    1702         {
    1703             typedefTable.makeTypedef( *$4 );            // create typedef
    1704             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1705             forall = false;                             // reset
    1706         }
    1707       '{' field_declaration_list '}'
    1708         {
    1709             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1710                 $4, $5, nullptr, $8, true )->addQualifiers( $3 );
    1711         }
    17121662        ;
    17131663
     
    18881838cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    18891839        parameter_declaration
    1890         | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
     1840        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
    18911841                { $$ = $1->addName( $2 ); }
    1892         | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
     1842        | cfa_abstract_tuple identifier_or_type_name assignment_opt
    18931843                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
    18941844                { $$ = $1->addName( $2 ); }
    1895         | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
     1845        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name assignment_opt
    18961846                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    18971847        | cfa_function_specifier
     
    19101860parameter_declaration:
    19111861                // No SUE declaration in parameter list.
    1912         declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
     1862        declaration_specifier_nobody identifier_parameter_declarator assignment_opt
    19131863                {
    19141864                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    19151865                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    19161866                }
    1917         | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
     1867        | declaration_specifier_nobody type_parameter_redeclarator assignment_opt
    19181868                {
    19191869                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    19231873
    19241874abstract_parameter_declaration:
    1925         declaration_specifier_nobody default_initialize_opt
     1875        declaration_specifier_nobody assignment_opt
    19261876                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
    1927         | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
     1877        | declaration_specifier_nobody abstract_parameter_declarator assignment_opt
    19281878                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    19291879        ;
     
    22622212        ;
    22632213
    2264 with_clause_opt:
    2265         // empty
    2266                 { $$ = (StatementNode *)0; }                                    // FIX ME
    2267         | WITH '(' tuple_expression_list ')'
    2268                 { $$ = (StatementNode *)0; }                                    // FIX ME
    2269         ;
    2270 
    22712214function_definition:
    2272         cfa_function_declaration with_clause_opt compound_statement     // CFA
     2215        cfa_function_declaration compound_statement                     // CFA
    22732216                {
    22742217                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22752218                        typedefTable.leaveScope();
    2276                         $$ = $1->addFunctionBody( $3 );
    2277                 }
    2278         | declaration_specifier function_declarator with_clause_opt compound_statement
     2219                        $$ = $1->addFunctionBody( $2 );
     2220                }
     2221        | declaration_specifier function_declarator compound_statement
    22792222                {
    22802223                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22812224                        typedefTable.leaveScope();
    2282                         $$ = $2->addFunctionBody( $4 )->addType( $1 );
    2283                 }
    2284         | type_qualifier_list function_declarator with_clause_opt compound_statement
     2225                        $$ = $2->addFunctionBody( $3 )->addType( $1 );
     2226                }
     2227        | type_qualifier_list function_declarator compound_statement
    22852228                {
    22862229                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22872230                        typedefTable.leaveScope();
    2288                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
    2289                 }
    2290         | declaration_qualifier_list function_declarator with_clause_opt compound_statement
     2231                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
     2232                }
     2233        | declaration_qualifier_list function_declarator compound_statement
    22912234                {
    22922235                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22932236                        typedefTable.leaveScope();
    2294                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
    2295                 }
    2296         | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
     2237                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
     2238                }
     2239        | declaration_qualifier_list type_qualifier_list function_declarator compound_statement
    22972240                {
    22982241                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22992242                        typedefTable.leaveScope();
    2300                         $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     2243                        $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    23012244                }
    23022245
    23032246                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2304         | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2247        | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement
    23052248                {
    23062249                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23072250                        typedefTable.leaveScope();
    2308                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addType( $1 );
    2309                 }
    2310         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2251                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
     2252                }
     2253        | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23112254                {
    23122255                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23132256                        typedefTable.leaveScope();
    2314                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
     2257                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
    23152258                }
    23162259
    23172260                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2318         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2261        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23192262                {
    23202263                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23212264                        typedefTable.leaveScope();
    2322                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    2323                 }
    2324         | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2265                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2266                }
     2267        | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23252268                {
    23262269                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23272270                        typedefTable.leaveScope();
    2328                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
     2271                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
    23292272                }
    23302273        ;
     
    30883031        ;
    30893032
    3090 default_initialize_opt:
     3033assignment_opt:
    30913034        // empty
    30923035                { $$ = nullptr; }
Note: See TracChangeset for help on using the changeset viewer.