Ignore:
Timestamp:
Aug 16, 2017, 6:31:41 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:
21f0aa8, 6d49ea3
Parents:
fcc88a4
Message:

first attempt, add declarations into "if" conditional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rfcc88a4 r936e9f4  
    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 : Wed Aug  4 13:33:00 2017
    13 // Update Count     : 2475
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Aug 16 18:09:14 2017
     13// Update Count     : 2485
    1414//
    1515
     
    9898        StatementNode * sn;
    9999        ConstantExpr * constant;
     100        IfCtl * ifctl;
    100101        ForCtl * fctl;
    101102        LabelNode * label;
     
    175176%type<en> comma_expression                              comma_expression_opt
    176177%type<en> argument_expression_list              argument_expression                     default_initialize_opt
     178%type<ifctl> if_control_expression
    177179%type<fctl> for_control_expression
    178180%type<en> subrange
     
    794796
    795797selection_statement:
    796         IF '(' comma_expression ')' statement                           %prec THEN
     798        IF '(' if_control_expression ')' statement                              %prec THEN
    797799                // explicitly deal with the shift/reduce conflict on if/else
    798800                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    799         | IF '(' comma_expression ')' statement ELSE statement
     801        | IF '(' if_control_expression ')' statement ELSE statement
    800802                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    801803        | SWITCH '(' comma_expression ')' case_clause           // CFA
     
    819821                }
    820822        ;
     823
     824if_control_expression:
     825        comma_expression
     826                { $$ = new IfCtl( nullptr, $1 ); }
     827        | c_declaration                                                                         // no semi-coln
     828                { $$ = new IfCtl( $1, nullptr ); }
     829        | cfa_declaration                                                                       // no semi-colon
     830                { $$ = new IfCtl( $1, nullptr ); }
     831        | declaration comma_expression
     832                { $$ = new IfCtl( $1, $2 ); }
     833        ;
    821834
    822835// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
     
    10971110
    10981111KR_declaration_list:
    1099         c_declaration
    1100         | KR_declaration_list push c_declaration
     1112        c_declaration ';'
     1113        | KR_declaration_list push c_declaration ';'
    11011114                { $$ = $1->appendList( $3 ); }
    11021115        ;
     
    11171130        ;
    11181131
    1119 declaration:                                                                                    // CFA, new & old style declarations
    1120         cfa_declaration
    1121         | c_declaration
     1132declaration:                                                                                    // old & new style declarations
     1133        c_declaration ';'
     1134        | cfa_declaration ';'                                                           // CFA
    11221135        ;
    11231136
     
    11341147
    11351148cfa_declaration:                                                                                // CFA
    1136         cfa_variable_declaration pop ';'
    1137         | cfa_typedef_declaration pop ';'
    1138         | cfa_function_declaration pop ';'
    1139         | type_declaring_list pop ';'
    1140         | trait_specifier pop ';'
     1149        cfa_variable_declaration pop
     1150        | cfa_typedef_declaration pop
     1151        | cfa_function_declaration pop
     1152        | type_declaring_list pop
     1153        | trait_specifier pop
    11411154        ;
    11421155
     
    13381351
    13391352c_declaration:
    1340         declaration_specifier declaring_list pop ';'
     1353        declaration_specifier declaring_list pop
    13411354                {
    13421355                        $$ = distAttr( $1, $2 );
    13431356                }
    1344         | typedef_declaration pop ';'
    1345         | typedef_expression pop ';'                                            // GCC, naming expression type
    1346         | sue_declaration_specifier pop ';'
     1357        | typedef_declaration pop
     1358        | typedef_expression pop                                                        // GCC, naming expression type
     1359        | sue_declaration_specifier pop
    13471360        ;
    13481361
Note: See TracChangeset for help on using the changeset viewer.