Changeset 52be5948


Ignore:
Timestamp:
Aug 9, 2022, 5:38:16 PM (22 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
c48b61c
Parents:
091ccdb
Message:

update for-control with more error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r091ccdb r52be5948  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  8 15:45:04 2022
    13 // Update Count     : 5574
     12// Last Modified On : Tue Aug  9 17:21:46 2022
     13// Update Count     : 5629
    1414//
    1515
     
    199199#define NEW_ZERO new ExpressionNode( build_constantInteger( *new string( "0" ) ) )
    200200#define NEW_ONE  new ExpressionNode( build_constantInteger( *new string( "1" ) ) )
     201#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    201202
    202203ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     
    13241325                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); }
    13251326        | downupdowneq comma_expression                                         // CFA
    1326                 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), $1 == OperKinds::GThan || $1 == OperKinds::GEThan ? $2->clone() : NEW_ZERO, $1, $2->clone(), NEW_ONE ); }
     1327                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); }
     1328
    13271329        | comma_expression updowneq comma_expression            // CFA
    1328                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, NEW_ONE ); }
    1329         | '@' updowneq comma_expression                                         // CFA
    1330                 { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ),
    1331                                                 $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3->clone(), NEW_ONE ); }
    1332         | comma_expression updown '@'                                           // CFA
    1333                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, NEW_ONE ); }
     1330                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); }
     1331        | '@' updowneq comma_expression                                         // CFA, error
     1332                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1333        | comma_expression updowneq '@'                                         // CFA
     1334                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
    13341335
    13351336        | comma_expression updowneq comma_expression '~' comma_expression // CFA
    1336                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    1337         | '@' updowneq comma_expression '~' comma_expression // CFA
    1338                 { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ),
    1339                                                 $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO,     $2, $3->clone(), $5 ); }
    1340         | comma_expression updown '@' '~' comma_expression      // CFA
    1341                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, $5 ); }
    1342         | comma_expression updown '@' '~' '@'                           // CFA
    1343                 {
    1344                         if ( $2 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
    1345                         else $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, nullptr );
    1346                 }
    1347         | comma_expression ';'                                                          // CFA
    1348                 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); }
     1337                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); }
     1338        | '@' updowneq comma_expression '~' comma_expression // CFA, error
     1339                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1340        | comma_expression updowneq '@' '~' comma_expression // CFA, error
     1341                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1342        | comma_expression updowneq comma_expression '~' '@' // CFA, error
     1343                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1344        | '@' updowneq comma_expression '~' '@'                         // CFA, error
     1345                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1346        | comma_expression updowneq '@' '~' '@'                         // CFA, error
     1347                { SemanticError( yylloc, "Missing loop fields ('@') with an anonymous loop index is not useful." ); $$ = nullptr; }
     1348
    13491349        | comma_expression ';' comma_expression                         // CFA
    13501350                { $$ = forCtrl( $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }
    13511351        | comma_expression ';' downupdowneq comma_expression // CFA
    1352                 { $$ = forCtrl( $4, $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4->clone(), NEW_ONE ); }
     1352                { $$ = forCtrl( $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); }
     1353
    13531354        | comma_expression ';' comma_expression updowneq comma_expression // CFA
    1354                 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, NEW_ONE ); }
    1355         | comma_expression ';' '@' updowneq comma_expression // CFA
    1356                 { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), NEW_ONE ); }
    1357         | comma_expression ';' comma_expression updown '@'      // CFA
    1358                 { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); }
     1355                { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); }
     1356        | comma_expression ';' '@' updowneq comma_expression // CFA, error
     1357                { SemanticError( yylloc, "Missing start value so cannot compare." ); $$ = nullptr; }
     1358        | comma_expression ';' comma_expression updowneq '@' // CFA
     1359                {
     1360                        if ( $4 == OperKinds::LEThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, "Decrement with missing comparison is meaningless. Use \"~\"." ); $$ = nullptr; }
     1361                        else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
     1362                }
    13591363
    13601364        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
    1361                 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
    1362         | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA
    1363                 { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), $7 ); }
    1364         | comma_expression ';' comma_expression updown '@' '~' comma_expression // CFA
    1365                 { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 ); }
    1366         | comma_expression ';' comma_expression updown '@' '~' '@' // CFA
     1365                { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }
     1366        | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error
     1367                { SemanticError( yylloc, "Missing start declaration so cannot compare." ); $$ = nullptr; }
     1368        | comma_expression ';' comma_expression updowneq '@' '~' comma_expression // CFA
     1369                {
     1370                        if ( $4 == OperKinds::LEThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, "Equal for comparison is meaningless with missing comparison. Use \"~\"." ); $$ = nullptr; }
     1371                        else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 );
     1372                }
     1373        | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA
     1374                { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }
     1375        | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error
     1376                { SemanticError( yylloc, "Missing start declaration so cannot compare." ); $$ = nullptr; }
     1377        | comma_expression ';' comma_expression updowneq '@' '~' '@' // CFA
    13671378                {
    13681379                        if ( $4 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
     1380                        else if ( $4 == OperKinds::LEThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, "Equal for comparison is meaningless with missing comparison. Use \"~\"." ); $$ = nullptr; }
    13691381                        else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, nullptr );
    13701382                }
     
    13731385                { $$ = forCtrl( $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); }
    13741386        | declaration downupdowneq comma_expression                     // CFA
    1375                 { $$ = forCtrl( $1, $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3, NEW_ONE ); }
     1387                { $$ = forCtrl( $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); }
     1388
    13761389        | declaration comma_expression updowneq comma_expression // CFA
    1377                 { $$ = forCtrl( $1, $2, $3, $4, NEW_ONE ); }
    1378         | declaration '@' updowneq comma_expression                     // CFA
    1379                 { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, NEW_ONE ); }
    1380         | declaration comma_expression updown '@'                       // CFA
    1381                 { $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE ); }
     1390                { $$ = forCtrl( $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); }
     1391        | declaration '@' updowneq comma_expression                     // CFA, error
     1392                { SemanticError( yylloc, "Missing start value so cannot compare." ); $$ = nullptr; }
     1393        | declaration comma_expression updowneq '@'                     // CFA
     1394                {
     1395                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "Decrement with missing comparison is meaningless. Use \"~\"." ); $$ = nullptr; }
     1396                        else $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE );
     1397                }
    13821398
    13831399        | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA
    1384                 { $$ = forCtrl( $1, $2, $3, $4, $6 ); }
    1385         | declaration '@' updowneq comma_expression '~' comma_expression // CFA
    1386                 { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, $6 ); }
    1387         | declaration comma_expression updown '@' '~' comma_expression // CFA
    1388                 { $$ = forCtrl( $1, $2, $3, nullptr, $6 ); }
    1389         | declaration comma_expression updown '@' '~' '@'       // CFA
     1400                { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); }
     1401        | declaration '@' updowneq comma_expression '~' comma_expression // CFA, error
     1402                { SemanticError( yylloc, "Missing start declaration so cannot compare." ); $$ = nullptr; }
     1403        | declaration comma_expression updowneq '@' '~' comma_expression // CFA
     1404                {
     1405                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "Equal for comparison is meaningless with missing comparison. Use \"~\"." ); $$ = nullptr; }
     1406                        else $$ = forCtrl( $1, $2, $3, nullptr, $6 );
     1407                }
     1408        | declaration comma_expression updowneq comma_expression '~' '@' // CFA
     1409                { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); }
     1410        | declaration '@' updowneq comma_expression '~' '@' // CFA, error
     1411                { SemanticError( yylloc, "Missing start declaration so cannot compare." ); $$ = nullptr; }
     1412        | declaration comma_expression updowneq '@' '~' '@'     // CFA
    13901413                {
    13911414                        if ( $3 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
     1415                        else if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "Equal for comparison is meaningless with missing comparison. Use \"~\"." ); $$ = nullptr; }
    13921416                        else $$ = forCtrl( $1, $2, $3, nullptr, nullptr );
    13931417                }
     
    14001424        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
    14011425                {
     1426                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; }
    14021427                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    14031428                }
Note: See TracChangeset for help on using the changeset viewer.