Changeset 6d01d89 for src/Parser
- Timestamp:
- Feb 14, 2019, 10:21:41 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 85d44c6
- Parents:
- 65a7050
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r65a7050 r6d01d89 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 8 18:08:23 201813 // Update Count : 4 05212 // Last Modified On : Thu Feb 14 18:02:44 2019 13 // Update Count : 4216 14 14 // 15 15 … … 99 99 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__. 100 100 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier ); 101 //cur->addType( specifier ); 102 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 101 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 103 102 cl->cloneBaseType( cur ); 104 103 } // for 105 104 declList->addType( cl ); 106 // delete cl;107 105 return declList; 108 106 } // distAttr … … 201 199 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->get_expr()) ) { 202 200 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 201 } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->get_expr()) ) { 202 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1 ) ) { 203 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 204 } else { 205 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; 206 } // if 203 207 } else { 204 208 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; … … 324 328 %type<en> argument_expression_list argument_expression default_initialize_opt 325 329 %type<ifctl> if_control_expression 326 %type<fctl> for_control_expression 330 %type<fctl> for_control_expression for_control_expression_list 327 331 %type<compop> inclexcl 328 332 %type<en> subrange … … 984 988 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER 985 989 identifier_or_type_name ':' attribute_list_opt statement 986 { 987 $$ = $4->add_label( $1, $3 ); 988 } 990 { $$ = $4->add_label( $1, $3 ); } 989 991 ; 990 992 … … 1002 1004 statement_decl 1003 1005 | statement_decl_list statement_decl 1004 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1006 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1005 1007 ; 1006 1008 … … 1009 1011 { $$ = new StatementNode( $1 ); } 1010 1012 | EXTENSION declaration // GCC 1011 { 1012 distExt( $2 ); 1013 $$ = new StatementNode( $2 ); 1014 } 1013 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1015 1014 | function_definition 1016 1015 { $$ = new StatementNode( $1 ); } 1017 1016 | EXTENSION function_definition // GCC 1018 { 1019 distExt( $2 ); 1020 $$ = new StatementNode( $2 ); 1021 } 1017 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1022 1018 | statement 1023 1019 ; … … 1026 1022 statement 1027 1023 | statement_list_nodecl statement 1028 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1024 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1029 1025 ; 1030 1026 … … 1138 1134 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1139 1135 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1140 | FOR '(' push for_control_expression ')' statement pop1136 | FOR '(' push for_control_expression_list ')' statement pop 1141 1137 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1142 1138 | FOR '(' ')' statement // CFA => for ( ;; ) … … 1144 1140 ; 1145 1141 1142 for_control_expression_list: 1143 for_control_expression 1144 | for_control_expression_list ':' for_control_expression 1145 { $$ = $3; } 1146 ; 1147 1146 1148 for_control_expression: 1147 comma_expression // CFA 1149 ';' comma_expression_opt ';' comma_expression_opt 1150 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); } 1151 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1152 { $$ = new ForCtrl( $1, $3, $5 ); } 1153 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1154 { $$ = new ForCtrl( $1, $2, $4 ); } 1155 | comma_expression // CFA 1148 1156 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1149 1157 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1150 | co nstant_expression inclexcl constant_expression// CFA1158 | comma_expression inclexcl comma_expression // CFA 1151 1159 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1152 | co nstant_expression inclexcl constant_expression '~' constant_expression // CFA1160 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1153 1161 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1154 1162 | comma_expression ';' comma_expression // CFA 1155 1163 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1156 1164 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1157 | comma_expression ';' co nstant_expression inclexcl constant_expression // CFA1165 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1158 1166 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1159 | comma_expression ';' co nstant_expression inclexcl constant_expression '~' constant_expression // CFA1167 | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA 1160 1168 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); } 1161 | comma_expression ';' comma_expression_opt ';' comma_expression_opt1162 { $$ = new ForCtrl( $1, $3, $5 ); }1163 | ';' comma_expression_opt ';' comma_expression_opt1164 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }1165 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'1166 { $$ = new ForCtrl( $1, $2, $4 ); }1167 1169 ; 1168 1170
Note: See TracChangeset
for help on using the changeset viewer.