Ignore:
Timestamp:
Mar 29, 2023, 5:34:51 PM (15 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
ac235a8
Parents:
afdb74b
Message:

formatting, add new waituntil grammar, rewrite waitfor grammar, simplify waitfor build-routines to match new grammar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rafdb74b r9fd9d015  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 22 21:26:01 2023
    13 // Update Count     : 6002
     12// Last Modified On : Wed Mar 29 11:21:38 2023
     13// Update Count     : 6321
    1414//
    1515
     
    360360
    361361// names and constants: lexer differentiates between identifier and typedef names
    362 %token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDIMname             TYPEDEFname             TYPEGENname
    363 %token<tok> TIMEOUT                     WOR                                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
     362%token<tok> IDENTIFIER          TYPEDIMname             TYPEDEFname             TYPEGENname
     363%token<tok> TIMEOUT                     WAND    WOR                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
    364364%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
    365365%token<tok> DIRECTIVE
     
    430430%type<catch_kind> handler_key
    431431%type<sn> mutex_statement
    432 %type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
    433 %type<sn> waitfor_statement
    434 %type<wfs> waitfor_clause
     432%type<en> when_clause                                   when_clause_opt                         waitfor         waituntil               timeout
     433%type<sn> waitfor_statement                             waituntil_statement
     434%type<wfs> wor_waitfor_clause                   waituntil_clause                        wand_waituntil_clause   wor_waituntil_clause
    435435
    436436// declarations
     
    536536// Similar issues exit with the waitfor statement.
    537537
    538 // Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
    539 // associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
     538// Order of these lines matters (low-to-high precedence). THEN is left associative over WAND/WOR/TIMEOUT/ELSE, WAND/WOR
     539// is left associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
    540540%precedence THEN                // rule precedence for IF/WAITFOR statement
     541%precedence ANDAND              // token precedence for start of WAND in WAITFOR statement
     542%precedence WAND                // token precedence for start of WAND in WAITFOR statement
     543%precedence OROR                // token precedence for start of WOR in WAITFOR statement
    541544%precedence WOR                 // token precedence for start of WOR in WAITFOR statement
    542545%precedence TIMEOUT             // token precedence for start of TIMEOUT in WAITFOR statement
     
    625628quasi_keyword:                                                                                  // CFA
    626629        TIMEOUT
     630        | WAND
    627631        | WOR
    628632        | CATCH
     
    775779                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    776780        | postfix_expression ICR
    777                 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
     781                { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
    778782        | postfix_expression DECR
    779                 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
     783                { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
    780784        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    781785                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
     
    805809        '@'                                                                                                     // CFA, default parameter
    806810                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    807                 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     811                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    808812        | assignment_expression
    809813        ;
     
    880884                }
    881885        | unary_operator cast_expression
    882                 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
     886                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
    883887        | ICR unary_expression
    884                 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
     888                { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
    885889        | DECR unary_expression
    886                 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
     890                { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
    887891        | SIZEOF unary_expression
    888892                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); }
     
    11371141        | mutex_statement
    11381142        | waitfor_statement
     1143        | waituntil_statement
    11391144        | exception_statement
    11401145        | enable_disable_statement
     
    12461251        | declaration comma_expression                                          // semi-colon separated
    12471252                { $$ = new CondCtl( $1, $2 ); }
    1248         ;
     1253        ;
    12491254
    12501255// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
     
    13291334                }
    13301335        | FOR '(' for_control_expression_list ')' statement     %prec THEN
    1331                 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
     1336                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
    13321337        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
    13331338                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); }
     
    15211526                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    15221527                }
    1523         ;
     1528        ;
    15241529
    15251530downupdowneq:
     
    15301535        | ErangeDownEq
    15311536                { $$ = OperKinds::GEThan; }
    1532         ;
     1537        ;
    15331538
    15341539updown:
     
    15371542        | ErangeDown
    15381543                { $$ = OperKinds::GThan; }
    1539         ;
     1544        ;
    15401545
    15411546updowneq:
     
    15451550        | ErangeDownEq
    15461551                { $$ = OperKinds::GEThan; }
    1547         ;
     1552        ;
    15481553
    15491554jump_statement:
     
    16281633        ;
    16291634
    1630 waitfor:
    1631         WAITFOR '(' cast_expression ')'
    1632                 { $$ = $3; }
    1633 //      | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'
    1634 //              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1635         | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
    1636                 { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    1637         ;
    1638 
    16391635cast_expression_list:
    16401636        cast_expression
     
    16451641
    16461642timeout:
    1647         TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
    1648         ;
    1649 
    1650 waitfor_clause:
     1643        TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
     1644        ;
     1645
     1646wor:
     1647        OROR
     1648        | WOR
     1649
     1650waitfor:
     1651        WAITFOR '(' cast_expression ')'
     1652                { $$ = $3; }
     1653        | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
     1654                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
     1655        ;
     1656
     1657wor_waitfor_clause:
    16511658        when_clause_opt waitfor statement                                       %prec THEN
    1652                 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); }
    1653         | when_clause_opt waitfor statement WOR waitfor_clause
    1654                 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); }
    1655         | when_clause_opt timeout statement                                     %prec THEN
    1656                 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); }
    1657         | when_clause_opt ELSE statement
    1658                 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
     1659                // Called first: create header for WaitForStmt.
     1660                { $$ = build_waitfor( new WaitForStmt(), $1, $2, maybe_build_compound( $3 ) ); }
     1661        | wor_waitfor_clause wor when_clause_opt waitfor statement      %prec THEN
     1662                { $$ = build_waitfor( $1, $3, $4, maybe_build_compound( $5 ) ); }
     1663        | wor_waitfor_clause wor when_clause_opt ELSE statement
     1664                { $$ = build_waitfor_else( $1, $3, maybe_build_compound( $5 ) ); }
     1665        | wor_waitfor_clause wor when_clause_opt timeout statement      %prec THEN
     1666                { $$ = build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ); }
    16591667        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1660         | when_clause_opt timeout statement WOR ELSE statement // syntax error
     1668        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    16611669                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    1662         | when_clause_opt timeout statement WOR when_clause ELSE statement
    1663                 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); }
    1664         ;
     1670        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
     1671                { $$ = build_waitfor_else( build_waitfor_timeout( $1, $3, $4, maybe_build_compound( $5 ) ), $7, maybe_build_compound( $9 ) ); }
    16651672
    16661673waitfor_statement:
    1667         when_clause_opt waitfor statement                                       %prec THEN
    1668                 { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
    1669         | when_clause_opt waitfor statement WOR waitfor_clause
    1670                 { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
     1674        wor_waitfor_clause                                                                      %prec THEN
     1675                { $$ = new StatementNode( $1 ); }
     1676        ;
     1677
     1678wand:
     1679        ANDAND
     1680        | WAND
     1681        ;
     1682
     1683waituntil:
     1684        WAITUNTIL '(' cast_expression ')'
     1685                { $$ = $3; }
     1686        ;
     1687
     1688waituntil_clause:
     1689        when_clause_opt waituntil statement
     1690                { printf( "waituntil_clause 1\n" ); $$ = nullptr; }
     1691        | '(' wor_waituntil_clause ')'
     1692                { printf( "waituntil_clause 2\n" ); $$ = nullptr; }
     1693        ;
     1694
     1695wand_waituntil_clause:
     1696        waituntil_clause                                                                        %prec THEN
     1697                { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; }
     1698        | waituntil_clause wand wand_waituntil_clause
     1699                { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; }
     1700        ;
     1701
     1702wor_waituntil_clause:
     1703        wand_waituntil_clause
     1704                { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; }
     1705        | wor_waituntil_clause wor wor_waituntil_clause         %prec THEN
     1706                { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; }
     1707        | wor_waituntil_clause wor when_clause_opt ELSE statement
     1708                { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; }
     1709        | wor_waituntil_clause wor when_clause_opt timeout statement    %prec THEN
     1710                { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; }
     1711        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1712        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
     1713                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1714        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
     1715                { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; }
     1716        ;
     1717
     1718waituntil_statement:
     1719        wor_waituntil_clause                                                            %prec THEN
     1720                // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement.
     1721                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    16711722        ;
    16721723
    16731724exception_statement:
    1674         TRY compound_statement handler_clause                                   %prec THEN
     1725        TRY compound_statement handler_clause                           %prec THEN
    16751726                { $$ = new StatementNode( build_try( $2, $3, nullptr ) ); }
    16761727        | TRY compound_statement finally_clause
     
    18321883                {
    18331884                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
    1834                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1885                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    18351886                        //   printf( "\tattr %s\n", attr->name.c_str() );
    18361887                        // } // for
     
    23022353                {
    23032354                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2304                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2355                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    23052356                        //   printf( "\tattr %s\n", attr->name.c_str() );
    23062357                        // } // for
     
    23182369                {
    23192370                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2320                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2371                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    23212372                        //   printf( "\tattr %s\n", attr->name.c_str() );
    23222373                        // } // for
     
    23962447                {
    23972448                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2398                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2449                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    23992450                        //   printf( "\tattr %s\n", attr->name.c_str() );
    24002451                        // } // for
     
    25232574                        $$ = fieldDecl( $1, $2 );
    25242575                        // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2525                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2576                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    25262577                        //   printf( "\tattr %s\n", attr->name.c_str() );
    25272578                        // } // for
     
    25302581                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
    25312582        | STATIC type_specifier field_declaring_list_opt ';' // CFA
    2532                 { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
     2583                { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
    25332584        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
    25342585                {
     
    25412592                }
    25422593        | INLINE aggregate_control ';'                                          // CFA
    2543                 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
     2594                { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    25442595        | typedef_declaration ';'                                                       // CFA
    25452596        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    26242675                { $$ = DeclarationNode::newEnum( $3->name, $6, true, false, nullptr, $4 )->addQualifiers( $2 ); }
    26252676        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    2626                 {
     2677                {
    26272678                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
    26282679                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    31583209                {
    31593210                        distQual( $5, $1 );
    3160                         forall = false;
     3211                        forall = false;
    31613212                        $$ = $5;
    31623213                }
     
    31693220                {
    31703221                        distQual( $5, $1 );
    3171                         forall = false;
     3222                        forall = false;
    31723223                        $$ = $5;
    31733224                }
     
    31803231                {
    31813232                        distQual( $6, $1->addQualifiers( $2 ) );
    3182                         forall = false;
     3233                        forall = false;
    31833234                        $$ = $6;
    31843235                }
     
    33873438        | '(' attribute_list variable_ptr ')' array_dimension
    33883439                { $$ = $3->addQualifiers( $2 )->addArray( $5 ); }
    3389         | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
     3440        | '(' variable_array ')' multi_array_dimension          // redundant parenthesis
    33903441                { $$ = $2->addArray( $4 ); }
    33913442        | '(' attribute_list variable_array ')' multi_array_dimension // redundant parenthesis
     
    38103861        | ErangeUpEq
    38113862                { $$ = OperKinds::LEThan; }
    3812         ;
     3863        ;
    38133864
    38143865multi_array_dimension:
Note: See TracChangeset for help on using the changeset viewer.