Ignore:
Timestamp:
Jul 26, 2017, 12:19:41 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
b947fb2
Parents:
e0a653d (diff), ea91c42 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    re0a653d r33218c6  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 11 13:39:00 2017
    13 // Update Count     : 2416
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jul 24 09:01:14 2017
     13// Update Count     : 2463
    1414//
    1515
     
    118118%token RESTRICT                                                                                 // C99
    119119%token ATOMIC                                                                                   // C11
    120 %token FORALL LVALUE MUTEX                                                              // CFA
    121 %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED ZERO_T ONE_T
     120%token FORALL LVALUE MUTEX VIRTUAL                                              // CFA
     121%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
     122%token BOOL COMPLEX IMAGINARY                                                   // C99
     123%token ZERO_T ONE_T                                                                             // CFA
    122124%token VALIST                                                                                   // GCC
    123 %token BOOL COMPLEX IMAGINARY                                                   // C99
    124125%token TYPEOF LABEL                                                                             // GCC
    125126%token ENUM STRUCT UNION
     
    129130%token ATTRIBUTE EXTENSION                                                              // GCC
    130131%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    131 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
     132%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH   // CFA
    132133%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    133134%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    151152%token ELLIPSIS                                                                                 // ...
    152153
    153 %token MULTassign       DIVassign       MODassign                               // *=   /=      %=/
     154%token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
    154155%token PLUSassign       MINUSassign                                                     // +=   -=
    155156%token LSassign         RSassign                                                        // <<=  >>=
     
    168169%type<op> ptrref_operator                               unary_operator                          assignment_operator
    169170%type<en> primary_expression                    postfix_expression                      unary_expression
    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
     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
    174176%type<en> comma_expression                              comma_expression_opt
    175 %type<en> argument_expression_list              argument_expression                     assignment_opt
     177%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    176178%type<fctl> for_control_expression
    177179%type<en> subrange
     
    184186// statements
    185187%type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    186 %type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement
     188%type<sn> iteration_statement                   jump_statement
     189%type<sn> with_statement                                exception_statement                     asm_statement
    187190%type<sn> fall_through_opt                              fall_through
    188191%type<sn> statement                                             statement_list
    189192%type<sn> block_item_list                               block_item
    190 %type<sn> case_clause
     193%type<sn> with_clause_opt
    191194%type<en> case_value
    192 %type<sn> case_value_list                               case_label                                      case_label_list
     195%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    193196%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    194197%type<sn> /* handler_list */                    handler_clause                          finally_clause
     
    568571        | '(' type_no_function ')' cast_expression
    569572                { $$ = 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 ) ); }
    570578//      | '(' type_no_function ')' tuple
    571579//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    572580        ;
    573581
     582exponential_expression:
     583        cast_expression
     584        | exponential_expression '\\' cast_expression
     585                { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }
     586        ;
     587
    574588multiplicative_expression:
    575         cast_expression
    576         | multiplicative_expression '*' cast_expression
     589        exponential_expression
     590        | multiplicative_expression '*' exponential_expression
    577591                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
    578         | multiplicative_expression '/' cast_expression
     592        | multiplicative_expression '/' exponential_expression
    579593                { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
    580         | multiplicative_expression '%' cast_expression
     594        | multiplicative_expression '%' exponential_expression
    581595                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
    582596        ;
     
    677691        '='                                                                                     { $$ = OperKinds::Assign; }
    678692        | ATassign                                                                      { $$ = OperKinds::AtAssn; }
     693        | EXPassign                                                                     { $$ = OperKinds::ExpAssn; }
    679694        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    680695        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    729744        | iteration_statement
    730745        | jump_statement
     746        | with_statement
    731747        | exception_statement
    732748        | asm_statement
     
    936952        ;
    937953
     954with_statement:
     955        WITH '(' tuple_expression_list ')' compound_statement
     956                { $$ = (StatementNode *)0; }                                    // FIX ME
     957        ;
     958
    938959exception_statement:
    939960        TRY compound_statement handler_clause
     
    965986                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
    966987
    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 ) ) ); }
     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
     994handler_predicate_opt:
     995        //empty
     996        | ';' conditional_expression
    971997        ;
    972998
     
    14951521        | IMAGINARY                                                                                     // C99
    14961522                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    1497         | VALIST                                                                                        // GCC, __builtin_va_list
    1498                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    14991523        | ZERO_T
    15001524                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
    15011525        | ONE_T
    15021526                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
     1527        | VALIST                                                                                        // GCC, __builtin_va_list
     1528                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    15031529        ;
    15041530
     
    16601686        | aggregate_key attribute_list_opt typegen_name         // CFA
    16611687                { $$ = $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        }
    16621712        ;
    16631713
     
    18381888cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    18391889        parameter_declaration
    1840         | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
     1890        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
    18411891                { $$ = $1->addName( $2 ); }
    1842         | cfa_abstract_tuple identifier_or_type_name assignment_opt
     1892        | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
    18431893                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
    18441894                { $$ = $1->addName( $2 ); }
    1845         | type_qualifier_list cfa_abstract_tuple identifier_or_type_name assignment_opt
     1895        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
    18461896                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    18471897        | cfa_function_specifier
     
    18601910parameter_declaration:
    18611911                // No SUE declaration in parameter list.
    1862         declaration_specifier_nobody identifier_parameter_declarator assignment_opt
     1912        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    18631913                {
    18641914                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    18651915                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    18661916                }
    1867         | declaration_specifier_nobody type_parameter_redeclarator assignment_opt
     1917        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    18681918                {
    18691919                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    18731923
    18741924abstract_parameter_declaration:
    1875         declaration_specifier_nobody assignment_opt
     1925        declaration_specifier_nobody default_initialize_opt
    18761926                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
    1877         | declaration_specifier_nobody abstract_parameter_declarator assignment_opt
     1927        | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
    18781928                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    18791929        ;
     
    22122262        ;
    22132263
     2264with_clause_opt:
     2265        // empty
     2266                { $$ = (StatementNode *)0; }                                    // FIX ME
     2267        | WITH '(' tuple_expression_list ')'
     2268                { $$ = (StatementNode *)0; }                                    // FIX ME
     2269        ;
     2270
    22142271function_definition:
    2215         cfa_function_declaration compound_statement                     // CFA
     2272        cfa_function_declaration with_clause_opt compound_statement     // CFA
    22162273                {
    22172274                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22182275                        typedefTable.leaveScope();
    2219                         $$ = $1->addFunctionBody( $2 );
    2220                 }
    2221         | declaration_specifier function_declarator compound_statement
     2276                        $$ = $1->addFunctionBody( $3 );
     2277                }
     2278        | declaration_specifier function_declarator with_clause_opt compound_statement
    22222279                {
    22232280                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22242281                        typedefTable.leaveScope();
    2225                         $$ = $2->addFunctionBody( $3 )->addType( $1 );
    2226                 }
    2227         | type_qualifier_list function_declarator compound_statement
     2282                        $$ = $2->addFunctionBody( $4 )->addType( $1 );
     2283                }
     2284        | type_qualifier_list function_declarator with_clause_opt compound_statement
    22282285                {
    22292286                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22302287                        typedefTable.leaveScope();
    2231                         $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
    2232                 }
    2233         | declaration_qualifier_list function_declarator compound_statement
     2288                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2289                }
     2290        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    22342291                {
    22352292                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22362293                        typedefTable.leaveScope();
    2237                         $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
    2238                 }
    2239         | declaration_qualifier_list type_qualifier_list function_declarator compound_statement
     2294                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2295                }
     2296        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    22402297                {
    22412298                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22422299                        typedefTable.leaveScope();
    2243                         $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 );
     2300                        $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    22442301                }
    22452302
    22462303                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2247         | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement
     2304        | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22482305                {
    22492306                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22502307                        typedefTable.leaveScope();
    2251                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
    2252                 }
    2253         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
     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
    22542311                {
    22552312                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22562313                        typedefTable.leaveScope();
    2257                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2314                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    22582315                }
    22592316
    22602317                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2261         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
     2318        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22622319                {
    22632320                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22642321                        typedefTable.leaveScope();
    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
     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
    22682325                {
    22692326                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22702327                        typedefTable.leaveScope();
    2271                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
     2328                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
    22722329                }
    22732330        ;
     
    30313088        ;
    30323089
    3033 assignment_opt:
     3090default_initialize_opt:
    30343091        // empty
    30353092                { $$ = nullptr; }
Note: See TracChangeset for help on using the changeset viewer.