On Thursday, February 14, 2002, at 08:12 PM, Michael Fowler wrote:

> On Thu, Feb 14, 2002 at 04:14:39PM -0500, Ian P. Thomas wrote:
>>
>> # The array, unchecked_dfa_states, is going to be an array of arrays 
>> ( 2-D ).
>> # dfa_state_creation is a subroutine that returns an array, and takes 
>> an array
>> # or single number, and a scalar, as parameters.
>
>> push @unchecked_dfa_states, [ dfa_state_creation( $nfa_start_state, 
>> $epsilon ) ];
>> # I want it to loop until this array is empty.
>> while ( $#unchecked_dfa_states > 0 )
>
> The typical idiom is:
>
>   while (@unchecked_dfa_states)
>
>> {
>>      # I remove the first array and add it to another 2-D array.  Syntax
>> may be wrong.
>>      @checked_dfa_state = shift(  [ $unchecked_dfa_state[ 0 ]  );
>
> shift expects an array, not an array reference.  This won't even parse
> correctly, for that reason and because you have an unmatched bracket.  
> Did
> you copy and paste your code, or type it in?
>
> What I believe you want is:
>
>         @checked_dfa_states = @{ shift(@unchecked_dfa_states) };
>
> That pulls off the first element of @unchecked_dfa_states and 
> dereferences
> it.
>
>
>>      # alphabet is an array of symbols( letters or numbers )
>>      foreach $symbol ( @alphabet )
>>      {
>>      # I'm having trouble here passing the array, as a whole, to the
>> subroutine.  I don't         # think that I'm getting the syntax right.
>> The subroutine will eventually return an array that will be
>>      # pushed on to the 2-D array unchecked_dfa_states.
>>              push(@unchecked_dfa_states, dfa_state_creation(
>> [ unchecked_dfa_states[ 0 ]  ], $symbol  ) );
>>      } # End foreach.
>
> I believe you want:
>
>                 push(
>                     @unchecked_dfa_states,
>                     dfa_state_creation($unchecked_dfa_states[0], 
> $symbol)
>                 );
>
> It's very hard to determine what it is you're trying to accomplish from 
> your
> code and description.  I'm not sure what's a typo and what's
> misunderstanding.  If the above doesn't help you should send another 
> message
> to the list describing more of what you want to happen, with at least
> parseable code.
>
>
> Michael
> --
> Administrator                      www.shoebox.net
> Programmer, System Administrator   www.gallanttech.com
> --
>

        I typed some of it in so there may have been some typos.

What I believe you want is:

         @checked_dfa_states = @{ shift(@unchecked_dfa_states) };

        If I read this correctly, I takes the first array from 
unchecked_dfa_states and passes it out, but not before dereferencing 
it.  I needed something that could take the first array as a whole 
object and pass it to checked_dfa_states, another array of arrays.  
After pouring through my Perl books, I think what I needed to do was to 
give each stored array in unchecked_dfa_states a scalar reference.  This 
way I could pass the reference to the whole array.  Does that sound 
right?
        The alternative that I used was keeping two arrays. One just held 
information about  the size of the arrays in unchecked_dfa_states.  I 
called it  unchecked_dfa_states_sizes.  I did a for loop using a value 
from the unchecked_dfa_states_sizes array as the ceiling  to put each 
element into a temporary array.  I then pushed this temporary array onto 
checked_dfa_states.  The reason I was able to do this is because I kept 
the two arrays,

unchecked_dfa_states
unchecked_dfa_states_sizes

in sync.  That meant that every subscript for unchecked_dfa_states_sizes 
matched a corresponding subscript for an array in unchecked_dfa_states.  
A reference to an array, and a separate reference to its size.  The 
other part...

I believe you want:

push(
                     @unchecked_dfa_states,
                     dfa_state_creation($unchecked_dfa_states[0], $symbol)
                 );

        I can't remember exactly, but I believe when I tried to do it this 
way, it passed an actual numeric value, the memory address to the array 
referenced by $unchecked_dfa_states[0].  As above, I stored the array 
referenced by $unchecked_dfa_states[0] into a temporary array and passed 
that in like this

dfa_state_creation( @temp, $symbol)

        This worked.  Thanks for the help.  I think I need to spend some 
more time with the animal books and reading this list.  I ended up 
having some problems using global variables later in the program.  Next 
time I'll cut and paste the code. :)


Ian P. Thomas


Of course it runs NetBSD
www.netbsd.org

Reply via email to