A back slash comment line throws a pending block exception

If you have found a bug and would like to report it, it's here...

A back slash comment line throws a pending block exception

Postby bobgillies » 04 Mar 2017 04:31

Code: Select all
// global variables

tvar: board
tvar: laneMask 
tvar: rowMask
tvar: currentLane
tvar: queenCount
tvar: queenRank
tvar: safe
tvar: allThreats
tvar: leftThreats
tvar: rightThreats
tvar: vertThreats

/////////////////////////////////////////////////////////////////////////////
Object Class new: Queens ( numQueens, mutable lane )                       // Declare parameters

Queens method: initialize( numQueens -- )                                  // Initialize  array and
    //  Diagonal downleft, downright, and vertical lanes of threats.       // global variables with 
    ArrayBuffer newWith( 3 , 0 ) := lane                                   // starting values.
    numQueens := numQueens   
    numQueens 1- 1 bitLeft to laneMask
    numQueens 1 bitLeft -1 +  to rowMask
    numQueens to queenCount
            0 to queenRank
            1 to currentLane
     
    ArrayBuffer new to allThreats                                          //<<<<<<<test suite stub <<<<<<<<<<
    ArrayBuffer new to leftThreats                                         // Test suite to buffer each row of
    ArrayBuffer new to rightThreats                                        // lane threats to facilitate hand
    ArrayBuffer new to vertThreats                                         // inspection of their bitpatterns.
;                                                                          //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 Queens method: queenPut  ( n  -- )                                        // Set a board location as
    //   n = bitpattern. 0b0010 queen in the 3rd column of a 4x4 board.    // occupied by a queen.
    //  Calculate the position on the vertical lane bit where the queen       
    //  is placed for that row.         Usage:   0b0010 board queenPut 

                                                                           //<<<<<<<< test suite stub <<<<<<<
    1 @lane at 2 @lane at 3 @lane at bitOr bitOr                           // Test to visually validate all
    dup "\nbitOr'd threats" . .  allThreats add                            // the lane threats for the
    allThreats last rowMask ==                                             // current row.
    if "BackTrack necessary" .  then                                       //
    1 @lane at leftThreats add                                             // Collect the lane's threats.
    2 @lane at rightThreats add                                            //
    3 @lane at vertThreats add                                             //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                                                                         

    1 @lane at n bitOr 1 swap @lane put                                    // Bit mark lanes of threats
    2 @lane at n bitOr 2 swap @lane put
    3 @lane at n bitOr 3 swap @lane put
    queenRank 1+ to queenRank


    //-----------------Shift each lane threat by 1 bit position.
   1 @lane at 2* rowMask bitAnd 1 swap @lane put                           // left diagonal bit mark shift
   2 @lane at 2/ 2 swap @lane put                                          // right diagonal bit mark shift
;


Queens method: nextSpot  \ b1 b2 -- n                                      // Locate a safe position   
    //      b1 = The bitwise combination of each lane of threats.          // for a queen to occupy. 
    //      b2 = The lane's bitmask                               
    //       n = bitpattern result for next safe queen position.             
   
    queenRank @numQueens >=
    if "\nAll " . @numQueens . "queens for this node found" .
        0 to queenRank
    then                   
    1 @lane at  2 @lane at  3 @lane at bitOr bitOr laneMask                // Lane threat bitpattern   
    //---------------- If the bitwise AND operaton results in a zero.      // combination and lane
                                                                           // bit mask on stack.
    while (  dup )
\
        [ 2dup bitAnd   
         
    //-----------------Put a Queen on this row if it's safe from threats.  // The lane check proven                     
            ifZero: [ 2/                                                   // safe from threats.

                       "\nQueen is to be put next at col" . 
                       currentLane .
                       currentLane 1- laneMask bitRight to safe                   
                       currentLane 1+ to currentLane  break
                    ]             
    //----------------Otherwise keep advancing to the next lane.           // Get ready to check
              else: [ 2/ currentLane 1+ to currentLane ]                   // the next lane. 
         ]
    2drop  1 to currentLane             
;

//*******************************test**************************************//
//*                                                                       *//
//*************************************************************************//

: firstTry
4 Queens new to board
0b1000 board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
;

: secondTry
4  Queens new to board
0b0100 board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
;

// Just a repetitive block of code that will be changed to iterate later.
: nQueens \ n q --
Queens new to board
board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
board nextSpot safe board queenPut
;

0b10 7 nQueens


When I try loading this code, the REPL aborts the load with this message:
[queens24:74:-1] Into Queens>>nextSpot Exception : Pending block at end of definition

If I remove the backslash comment on line 74, the code compiles without incident, so I think the branch offset marker is getting misaligned during compilation perhaps?

Cordially,

Bob
bobgillies
 
Posts: 60
Joined: 24 Jan 2017 06:26

Re: A back slash comment line throws a pending block except

Postby Franck » 06 Mar 2017 21:04

This is because the compiler checks if the next word after the second parenthesis of a while is ].
If not, it throws an exception.

You can't any word (even \ ) between the ) and the [

This is the same with other words (ifTrue: check that the next word is ] also for instance).

Franck
Franck
 
Posts: 140
Joined: 29 Oct 2014 19:01

Re: A back slash comment line throws a pending block except

Postby bobgillies » 06 Mar 2017 22:23

You can't any word (even \ ) between the ) and the [


Hello Franck,
I'll keep that in mind for future reference and watch my comment placement.

Cordially,

Bob
bobgillies
 
Posts: 60
Joined: 24 Jan 2017 06:26


Return to Report a bug

Who is online

Users browsing this forum: No registered users and 1 guest

cron