Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rdc2b4d6 rca78437  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // parser.yy --
     7// cfa.y --
    88//
    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 : Mon Jul 17 12:17:00 2017
    13 // Update Count     : 2455
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jun 12 12:59:00 2017
     13// Update Count     : 2402
    1414//
    1515
     
    4848#include <cstdio>
    4949#include <stack>
     50#include "lex.h"
     51#include "parser.h"
    5052#include "ParseNode.h"
    5153#include "TypedefTable.h"
     
    8688bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    8789%}
    88 
    89 // Types declaration
    90 %union
    91 {
    92         Token tok;
    93         ParseNode * pn;
    94         ExpressionNode * en;
    95         DeclarationNode * decl;
    96         DeclarationNode::Aggregate aggKey;
    97         DeclarationNode::TypeClass tclass;
    98         StatementNode * sn;
    99         ConstantExpr * constant;
    100         ForCtl * fctl;
    101         LabelNode * label;
    102         InitializerNode * in;
    103         OperKinds op;
    104         std::string * str;
    105         bool flag;
    106         CatchStmt::Kind catch_kind;
    107 }
    10890
    10991//************************* TERMINAL TOKENS ********************************
     
    129111%token ATTRIBUTE EXTENSION                                                              // GCC
    130112%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 WITH   // CFA
     113%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
    132114%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    133115%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    151133%token ELLIPSIS                                                                                 // ...
    152134
    153 %token EXPassign        MULTassign      DIVassign       MODassign       // \=   *=      /=      %=
     135%token MULTassign       DIVassign       MODassign                               // *=   /=      %=/
    154136%token PLUSassign       MINUSassign                                                     // +=   -=
    155137%token LSassign         RSassign                                                        // <<=  >>=
     
    157139
    158140%token ATassign                                                                                 // @=
     141
     142// Types declaration
     143%union
     144{
     145        Token tok;
     146        ParseNode * pn;
     147        ExpressionNode * en;
     148        DeclarationNode * decl;
     149        DeclarationNode::Aggregate aggKey;
     150        DeclarationNode::TypeClass tclass;
     151        StatementNode * sn;
     152        ConstantExpr * constant;
     153        ForCtl * fctl;
     154        LabelNode * label;
     155        InitializerNode * in;
     156        OperKinds op;
     157        std::string * str;
     158        bool flag;
     159}
    159160
    160161%type<tok> identifier  no_attr_identifier  zero_one
     
    168169%type<op> ptrref_operator                               unary_operator                          assignment_operator
    169170%type<en> primary_expression                    postfix_expression                      unary_expression
    170 %type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
    171 %type<en> shift_expression                              relational_expression           equality_expression
    172 %type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
    173 %type<en> logical_AND_expression                logical_OR_expression
    174 %type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
     171%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
     172%type<en> relational_expression                 equality_expression                     AND_expression                          exclusive_OR_expression
     173%type<en> inclusive_OR_expression               logical_AND_expression          logical_OR_expression           conditional_expression
     174%type<en> constant_expression                   assignment_expression           assignment_expression_opt
    175175%type<en> comma_expression                              comma_expression_opt
    176 %type<en> argument_expression_list              argument_expression                     default_initialize_opt
     176%type<en> argument_expression_list              argument_expression                     assignment_opt
    177177%type<fctl> for_control_expression
    178178%type<en> subrange
     
    185185// statements
    186186%type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    187 %type<sn> iteration_statement                   jump_statement
    188 %type<sn> with_statement                                exception_statement                     asm_statement
     187%type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement
    189188%type<sn> fall_through_opt                              fall_through
    190189%type<sn> statement                                             statement_list
    191190%type<sn> block_item_list                               block_item
    192 %type<sn> with_clause_opt
     191%type<sn> case_clause
    193192%type<en> case_value
    194 %type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
     193%type<sn> case_value_list                               case_label                                      case_label_list
    195194%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    196195%type<sn> /* handler_list */                    handler_clause                          finally_clause
    197 %type<catch_kind> handler_key
    198196
    199197// declarations
     
    574572        ;
    575573
    576 exponential_expression:
     574multiplicative_expression:
    577575        cast_expression
    578         | exponential_expression '\\' cast_expression
    579                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }
    580         ;
    581 
    582 multiplicative_expression:
    583         exponential_expression
    584         | multiplicative_expression '*' exponential_expression
     576        | multiplicative_expression '*' cast_expression
    585577                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
    586         | multiplicative_expression '/' exponential_expression
     578        | multiplicative_expression '/' cast_expression
    587579                { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
    588         | multiplicative_expression '%' exponential_expression
     580        | multiplicative_expression '%' cast_expression
    589581                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
    590582        ;
     
    685677        '='                                                                                     { $$ = OperKinds::Assign; }
    686678        | ATassign                                                                      { $$ = OperKinds::AtAssn; }
    687         | EXPassign                                                                     { $$ = OperKinds::ExpAssn; }
    688679        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    689680        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    738729        | iteration_statement
    739730        | jump_statement
    740         | with_statement
    741731        | exception_statement
    742732        | asm_statement
     
    946936        ;
    947937
    948 with_statement:
    949         WITH '(' tuple_expression_list ')' compound_statement
    950                 { $$ = (StatementNode *)0; }                                    // FIX ME
    951         ;
    952 
    953938exception_statement:
    954939        TRY compound_statement handler_clause
     
    974959
    975960handler_clause:
    976         // TEMPORARY, TEST EXCEPTIONS
    977         handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    978                 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); }
    979         | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    980                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
    981 
    982         | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    983                 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); }
    984         | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    985                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }
    986         ;
    987 
    988 handler_predicate_opt:
    989         //empty
    990         | ';' conditional_expression
    991         ;
    992 
    993 handler_key:
    994         CATCH
    995                 { $$ = CatchStmt::Terminate; }
    996         | CATCHRESUME
    997                 { $$ = CatchStmt::Resume; }
     961        CATCH '(' push push exception_declaration pop ')' compound_statement pop
     962                { $$ = new StatementNode( build_catch( CatchStmt::Terminate, $5, nullptr, $8 ) ); }
     963        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
     964                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, $6, nullptr, $9 ) ) ); }
     965        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
     966                { $$ = new StatementNode( build_catch( CatchStmt::Resume, $5, nullptr, $8 ) ); }
     967        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
     968                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Resume, $6, nullptr, $9 ) ) ); }
    998969        ;
    999970
     
    16801651        | aggregate_key attribute_list_opt typegen_name         // CFA
    16811652                { $$ = $3->addQualifiers( $2 ); }
    1682 
    1683 // Temp, testing TreeStruct
    1684     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name
    1685         {
    1686             typedefTable.makeTypedef( *$4 );            // create typedef
    1687             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1688             forall = false;                             // reset
    1689         }
    1690       '{' field_declaration_list '}'
    1691         {
    1692             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1693                 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );
    1694         }
    1695     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname
    1696         {
    1697             typedefTable.makeTypedef( *$4 );            // create typedef
    1698             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1699             forall = false;                             // reset
    1700         }
    1701       '{' field_declaration_list '}'
    1702         {
    1703             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1704                 $4, $5, nullptr, $8, true )->addQualifiers( $3 );
    1705         }
    17061653        ;
    17071654
     
    18821829cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    18831830        parameter_declaration
    1884         | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
     1831        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt
    18851832                { $$ = $1->addName( $2 ); }
    1886         | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
     1833        | cfa_abstract_tuple identifier_or_type_name assignment_opt
    18871834                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
    18881835                { $$ = $1->addName( $2 ); }
    1889         | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
     1836        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name assignment_opt
    18901837                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    18911838        | cfa_function_specifier
     
    19041851parameter_declaration:
    19051852                // No SUE declaration in parameter list.
    1906         declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
     1853        declaration_specifier_nobody identifier_parameter_declarator assignment_opt
    19071854                {
    19081855                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    19091856                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
    19101857                }
    1911         | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
     1858        | declaration_specifier_nobody type_parameter_redeclarator assignment_opt
    19121859                {
    19131860                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     
    19171864
    19181865abstract_parameter_declaration:
    1919         declaration_specifier_nobody default_initialize_opt
     1866        declaration_specifier_nobody assignment_opt
    19201867                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
    1921         | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
     1868        | declaration_specifier_nobody abstract_parameter_declarator assignment_opt
    19221869                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    19231870        ;
     
    22202167                {
    22212168                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2222                         linkage = LinkageSpec::linkageUpdate( linkage, $2 );
     2169                        linkage = LinkageSpec::linkageCheck( $2 );
    22232170                }
    22242171          '{' external_definition_list_opt '}'
     
    22562203        ;
    22572204
    2258 with_clause_opt:
    2259         // empty
    2260                 { $$ = (StatementNode *)0; }                                    // FIX ME
    2261         | WITH '(' tuple_expression_list ')'
    2262                 { $$ = (StatementNode *)0; }                                    // FIX ME
    2263         ;
    2264 
    22652205function_definition:
    2266         cfa_function_declaration with_clause_opt compound_statement     // CFA
     2206        cfa_function_declaration compound_statement                     // CFA
    22672207                {
    22682208                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22692209                        typedefTable.leaveScope();
    2270                         $$ = $1->addFunctionBody( $3 );
    2271                 }
    2272         | declaration_specifier function_declarator with_clause_opt compound_statement
     2210                        $$ = $1->addFunctionBody( $2 );
     2211                }
     2212        | declaration_specifier function_declarator compound_statement
    22732213                {
    22742214                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22752215                        typedefTable.leaveScope();
    2276                         $$ = $2->addFunctionBody( $4 )->addType( $1 );
    2277                 }
    2278         | type_qualifier_list function_declarator with_clause_opt compound_statement
     2216                        $$ = $2->addFunctionBody( $3 )->addType( $1 );
     2217                }
     2218        | type_qualifier_list function_declarator compound_statement
    22792219                {
    22802220                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22812221                        typedefTable.leaveScope();
    2282                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
    2283                 }
    2284         | declaration_qualifier_list function_declarator with_clause_opt compound_statement
     2222                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
     2223                }
     2224        | declaration_qualifier_list function_declarator compound_statement
    22852225                {
    22862226                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22872227                        typedefTable.leaveScope();
    2288                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
    2289                 }
    2290         | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
     2228                        $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
     2229                }
     2230        | declaration_qualifier_list type_qualifier_list function_declarator compound_statement
    22912231                {
    22922232                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22932233                        typedefTable.leaveScope();
    2294                         $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     2234                        $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    22952235                }
    22962236
    22972237                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2298         | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2238        | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement
    22992239                {
    23002240                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23012241                        typedefTable.leaveScope();
    2302                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addType( $1 );
    2303                 }
    2304         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2242                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
     2243                }
     2244        | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23052245                {
    23062246                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23072247                        typedefTable.leaveScope();
    2308                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
     2248                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
    23092249                }
    23102250
    23112251                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2312         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2252        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23132253                {
    23142254                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23152255                        typedefTable.leaveScope();
    2316                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    2317                 }
    2318         | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2256                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2257                }
     2258        | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
    23192259                {
    23202260                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23212261                        typedefTable.leaveScope();
    2322                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
     2262                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
    23232263                }
    23242264        ;
     
    23832323        | TYPEGENname
    23842324        | CONST
    2385                 { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
     2325                { $$ = Token{ new string( "__const__" ) }; }
    23862326        ;
    23872327
     
    30823022        ;
    30833023
    3084 default_initialize_opt:
     3024assignment_opt:
    30853025        // empty
    30863026                { $$ = nullptr; }
Note: See TracChangeset for help on using the changeset viewer.