Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r01afd8d r253d0b4  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 27 14:45:57 2024
    13 // Update Count     : 6705
     12// Last Modified On : Mon Jun 24 22:45:20 2024
     13// Update Count     : 6684
    1414//
    1515
     
    224224#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    225225#define MISSING_ANON_FIELD "illegal syntax, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
    226 #define MISSING_LOW "illegal syntax, missing low value for ascanding range so index is uninitialized."
    227 #define MISSING_HIGH "illegal syntax, missing high value for descending range so index is uninitialized."
    228 
    229 static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     226#define MISSING_LOW "illegal syntax, missing low value for up-to range so index is uninitialized."
     227#define MISSING_HIGH "illegal syntax, missing high value for down-to range so index is uninitialized."
     228
     229static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, enum OperKinds compop,
     230                                                          ExpressionNode * comp, ExpressionNode * inc ) {
    230231        // Wrap both comp/inc if they are non-null.
    231232        if ( comp ) comp = new ExpressionNode( build_binary_val( location,
     
    242243}
    243244
    244 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     245ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    245246        if ( index->initializer ) {
    246247                SemanticError( yylloc, "illegal syntax, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     
    253254} // forCtrl
    254255
    255 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     256ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    256257        ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get());
    257258        if ( constant && (constant->rep == "0" || constant->rep == "1") ) {
     
    267268#define MISSING_LOOP_INDEX "illegal syntax, only a single identifier or declaration allowed in initialization, e.g., for ( i; ... ) or for ( int i; ... ). Expression disallowed."
    268269
    269 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     270ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    270271        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) {
    271272                return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
     273        // } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) {
     274        //      if ( auto identifier = commaExpr->arg2.as<ast::NameExpr>() ) {
     275        //              return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
     276        //      } else {
     277        //              SemanticError( yylloc, "illegal syntax, loop-index name missing. Expression disallowed." ); return nullptr;
     278        //      } // if
    272279        } else {
    273280                SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     
    275282} // forCtrl
    276283
    277 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, __attribute__((unused)) OperKinds compop, ExpressionNode * range_over_expr ) {
     284ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) {
    278285        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) {
    279286                DeclarationNode * indexDecl = DeclarationNode::newName( new std::string(identifier->name) );
    280287                assert( range_over_expr );
    281288                return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
     289        // } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) {
     290        //      if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
     291        //              assert( range_over_expr );
     292        //              DeclarationNode * indexDecl = distAttr(
     293        //                      DeclarationNode::newTypeof( range_over_expr, true ),
     294        //                      DeclarationNode::newName( new std::string( identifier->name) ) );
     295        //              return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
     296        //      } else {
     297        //              SemanticError( yylloc, "illegal syntax, loop-index name missing. Comma expression disallowed." ); return nullptr;
     298        //      } // if
    282299        } else {
    283300                SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     
    409426%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    410427
    411 %token ErangeUp         ErangeUpEq      ErangeDown      ErangeDownEq // +~      +~=/~=  -~      -~=
     428%token ErangeUpEq       ErangeDown      ErangeDownEq                    // ~=   -~      -~=
    412429%token ATassign                                                                                 // @=
    413430
     
    15051522                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    15061523
    1507                 // These rules accept a comma_expression for the initialization, when only an identifier is correct. Being
    1508                 // permissive allows for a better error message from forCtrl.
    15091524        | comma_expression ';' comma_expression                         // CFA
    15101525                { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }
     
    15261541                }
    15271542        | comma_expression ';' '@' updowneq '@'                         // CFA, invalid syntax rule
    1528                 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; }
     1543                { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15291544
    15301545        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
     
    15551570                }
    15561571        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
    1557                 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; }
     1572                { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15581573
    15591574        | declaration comma_expression                                          // CFA
     
    16031618                }
    16041619        | declaration '@' updowneq '@' '~' '@'                          // CFA, invalid syntax rule
    1605                 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; }
     1620                { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    16061621
    16071622        | comma_expression ';' enum_key                                         // CFA, enum type
    16081623                {
    1609                         $$ = enumRangeCtrl( $1, OperKinds::LEThan, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) );
     1624                        $$ = enumRangeCtrl( $1, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) );
    16101625                }
    16111626        | comma_expression ';' downupdowneq enum_key            // CFA, enum type, reverse direction
    16121627                {
    1613                         if ( $3 == OperKinds::GThan ) {
    1614                                 SemanticError( yylloc, "all enumeration ranges are equal (all values). Add an equal, e.g., ~=, -~=." ); $$ = nullptr;
    1615                                 $3 = OperKinds::GEThan;
    1616                         } // if
    1617                         $$ = enumRangeCtrl( $1, $3, new ExpressionNode( new ast::TypeExpr( yylloc, $4->buildType() ) ) );
     1628                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
     1629                                SemanticError( yylloc, "illegal syntax, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
     1630                        }
     1631                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    16181632                }
    16191633        ;
     
    16281642        ;
    16291643
    1630 // This rule exists to handle the ambiguity with unary operator '~'. The rule is the same as updowneq minus the '~'.
    1631 // Specifically, "for ( ~5 )" means the complement of 5, not loop 0..4. Hence, in this case "for ( ~= 5 )", i.e., 0..5,
    1632 // it is not possible to just remove the '='. The entire '~=' must be removed.
    16331644downupdowneq:
    1634         ErangeUp
    1635                 { $$ = OperKinds::LThan; }
    1636         | ErangeDown
     1645        ErangeDown
    16371646                { $$ = OperKinds::GThan; }
    16381647        | ErangeUpEq
     
    16431652
    16441653updown:
    1645         '~'                                                                                                     // shorthand 0 ~ 10 => 0 +~ 10
    1646                 { $$ = OperKinds::LThan; }
    1647         | ErangeUp
     1654        '~'
    16481655                { $$ = OperKinds::LThan; }
    16491656        | ErangeDown
Note: See TracChangeset for help on using the changeset viewer.