Changeset 3b0bc16 for src/Parser


Ignore:
Timestamp:
Feb 1, 2022, 8:22:12 PM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
fde0a58
Parents:
729c991
Message:

change class name WhileStmt? to WhileDoStmt?, add else clause to WhileDoStmt? and ForStmt?, change names thenPart/ElsePart to then/else_

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r729c991 r3b0bc16  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan 29 09:45:56 2022
    13 // Update Count     : 901
     12// Last Modified On : Tue Feb  1 11:06:18 2022
     13// Update Count     : 903
    1414//
    1515
     
    414414Statement * build_case( ExpressionNode * ctl );
    415415Statement * build_default();
    416 Statement * build_while( CondCtl * ctl, StatementNode * stmt );
    417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt );
     416Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * els = nullptr );
     417Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * els = nullptr );
     418Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * els = nullptr );
    419419Statement * build_branch( BranchStmt::Type kind );
    420420Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
  • src/Parser/StatementNode.cc

    r729c991 r3b0bc16  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan 29 09:45:51 2022
    13 // Update Count     : 384
     12// Last Modified On : Tue Feb  1 18:39:00 2022
     13// Update Count     : 395
    1414//
    1515
     
    145145} // build_default
    146146
    147 Statement * build_while( CondCtl * ctl, StatementNode * stmt ) {
    148         std::list< Statement * > branches;
    149         buildMoveList< Statement, StatementNode >( stmt, branches );
    150         assert( branches.size() == 1 );
    151 
     147Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ ) {
    152148        std::list< Statement * > init;
    153149        Expression * cond = build_if_control( ctl, init );
    154         return new WhileStmt( cond, branches.front(), init, false );
     150
     151        std::list< Statement * > aststmt;
     152        buildMoveList< Statement, StatementNode >( stmt, aststmt );
     153        assert( aststmt.size() == 1 );
     154
     155        std::list< Statement * > astelse;
     156        buildMoveList< Statement, StatementNode >( else_, astelse );
     157
     158        return new WhileDoStmt( cond, aststmt.front(), astelse.front(), init, false );
    155159} // build_while
    156160
    157 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) {
    158         std::list< Statement * > branches;
    159         buildMoveList< Statement, StatementNode >( stmt, branches );
    160         assert( branches.size() == 1 );
     161Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ ) {
     162        std::list< Statement * > aststmt;
     163        buildMoveList< Statement, StatementNode >( stmt, aststmt );
     164        assert( aststmt.size() == 1 );
     165
     166        std::list< Statement * > astelse;
     167        buildMoveList< Statement, StatementNode >( else_, astelse );
    161168
    162169        std::list< Statement * > init;
    163         return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true );
     170        return new WhileDoStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), aststmt.front(), astelse.front(), init, true );
    164171} // build_do_while
    165172
    166 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ) {
    167         std::list< Statement * > branches;
    168         buildMoveList< Statement, StatementNode >( stmt, branches );
    169         assert( branches.size() == 1 );
    170 
     173Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ ) {
    171174        std::list< Statement * > init;
    172         if ( forctl->init != 0 ) {
     175        if ( forctl->init != nullptr ) {
    173176                buildMoveList( forctl->init, init );
    174177        } // if
    175178
    176         Expression * cond = 0;
    177         if ( forctl->condition != 0 )
     179        Expression * cond = nullptr;
     180        if ( forctl->condition != nullptr )
    178181                cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) );
    179182
    180         Expression * incr = 0;
    181         if ( forctl->change != 0 )
     183        Expression * incr = nullptr;
     184        if ( forctl->change != nullptr )
    182185                incr = maybeMoveBuild< Expression >(forctl->change);
    183186
     187        std::list< Statement * > aststmt;
     188        buildMoveList< Statement, StatementNode >( stmt, aststmt );
     189        assert( aststmt.size() == 1 );
     190
     191        std::list< Statement * > astelse;
     192        buildMoveList< Statement, StatementNode >( else_, astelse );
     193
    184194        delete forctl;
    185         return new ForStmt( init, cond, incr, branches.front() );
     195        return new ForStmt( init, cond, incr, aststmt.front(), astelse.front() );
    186196} // build_for
    187197
  • src/Parser/parser.yy

    r729c991 r3b0bc16  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 30 09:41:13 2022
    13 // Update Count     : 5165
     12// Last Modified On : Tue Feb  1 11:06:13 2022
     13// Update Count     : 5167
    1414//
    1515
     
    11971197                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
    11981198        | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA
    1199                 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1199                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1200                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); }
    12001201        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    12011202                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
     
    12031204                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
    12041205        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
    1205                 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1206                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1207                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); }
    12061208        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
    12071209                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     
    12091211                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
    12101212        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
    1211                 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1213                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
     1214                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); }
    12121215        ;
    12131216
Note: See TracChangeset for help on using the changeset viewer.