Changeset 6d49ea3 for src/Parser


Ignore:
Timestamp:
Aug 17, 2017, 5:37:20 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
274ce8c
Parents:
936e9f4
Message:

second attempt, add declarations into if conditional

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r936e9f4 r6d49ea3  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 16:39:43 2017
    13 // Update Count     : 340
     12// Last Modified On : Thu Aug 17 16:01:31 2017
     13// Update Count     : 345
    1414//
    1515
     
    2424#include "SynTree/Expression.h"    // for Expression, ConstantExpr
    2525#include "SynTree/Label.h"         // for Label, noLabels
     26#include "SynTree/Declaration.h"
    2627#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
    2728#include "parserutility.h"         // for notZeroExpr
     
    9899        } // if
    99100
    100         return new IfStmt( noLabels, notZeroExpr(
    101                                                            /*ctl->condition
    102                                                                  ?*/ maybeMoveBuild< Expression >(ctl->condition)
    103                                                                  /*: new VariableExpr( init.end() )*/ )
    104                                                    , thenb, elseb );
    105         // ret->initialization = init;
    106         // delete ctl;
    107         // assert( ret );
    108         // return ret;
     101        Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     102        delete ctl;
     103        return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
    109104}
    110105
  • src/Parser/parser.yy

    r936e9f4 r6d49ea3  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 18:09:14 2017
    13 // Update Count     : 2485
     12// Last Modified On : Thu Aug 17 15:52:12 2017
     13// Update Count     : 2489
    1414//
    1515
     
    796796
    797797selection_statement:
    798         IF '(' if_control_expression ')' statement                              %prec THEN
     798        IF '(' push if_control_expression ')' statement                         %prec THEN
    799799                // explicitly deal with the shift/reduce conflict on if/else
    800                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    801         | IF '(' if_control_expression ')' statement ELSE statement
    802                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
     800                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     801        | IF '(' push if_control_expression ')' statement ELSE statement
     802                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    803803        | SWITCH '(' comma_expression ')' case_clause           // CFA
    804804                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
     
    823823
    824824if_control_expression:
    825         comma_expression
     825        comma_expression pop
    826826                { $$ = new IfCtl( nullptr, $1 ); }
    827         | c_declaration                                                                         // no semi-coln
     827        | c_declaration                                                                         // no semi-colon
    828828                { $$ = new IfCtl( $1, nullptr ); }
    829829        | cfa_declaration                                                                       // no semi-colon
    830830                { $$ = new IfCtl( $1, nullptr ); }
    831         | declaration comma_expression
     831        | declaration comma_expression                                          // semi-colon separated
    832832                { $$ = new IfCtl( $1, $2 ); }
    833833        ;
Note: See TracChangeset for help on using the changeset viewer.