perl recursive function

;&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));

From the above string,I have a Hash which looks like this

Hash(psmi_1,THREAD) = 0
Hash(psmi_1,TRIGGER) = retire_1
Hash(psmi_1,event)=psmi
Hash(retire_1,LIP)=0x203f
Hash(retire_1,TRIGGER)=smi_1
Hash(smi_1,THREAD)=1
Hash(smi_1,TRIGGER)=eom_1
Hash(eom_1,LIP)=0x203f
Hash(eom_1,THREAD)=0
Hash(eom_1,trigger)=eom
Hash(smi_1,event)=smi
Hash(retire_1,trigger)=retire

This string can be varying quite a bit

;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

Above is another sample string

So, basically for every event, there can be one trigger like the 2nd string example or a chain of triggers like the 1st string.

Now I want to be able to Iterate thru the entire Hash and find out what all events should happen when LIP = 0x203f, There can be multiple events and also we need to check that we are satisfying the other triggering conditions

Here is my algorithm for the 2nd string, This piece of code is in system verilog, so, please read it for my algorithm.

;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

This a simple case where there is 1 trigger for a event, But I want to know how to handle it when the trigger is a chain of events.
   
               
       
#ass_Array is the Hash
#s is the key to the Hash
 
   
do
  begin
     if (`vmm_str_match(s, "/TRIGGER/")) begin 
           
             s = `vmm_str_backref(s, 0);
             $display(" entry1 is %s : %s\n",s,ass_array[s]);
      end
      if (`vmm_str_match(s, ",LIP")) begin
            
             $display(" entry2 is%s:%s:pre%s:post%send \n",s,ass_array[s],  `vmm_str_prematch(s),`vmm_str_postmatch(s));
             if (ass_array[s] == "0x203f") begin
                itrigger = `vmm_str_prematch(s);
                $display ("trigger name is %s ",  itrigger);
                do
                  begin
                     if(s3 == {itrigger,",trigger"})begin
                        itrigger_value = ass_array[s3];
                        if ( itrigger_value == "eom" || itrigger_value == "retire" || itrigger_value == "bom")
                          $display ("trigger value is %s", itrigger_value);
                        else begin
                           
                        end
                     end
                     $display ("printing s3 loop %s : %s:%s", s3, ass_array[s3],{itrigger,",trigger"} );
                  end 
                while (ass_array.next( s3 ));
                do
                  begin
                    if (`vmm_str_match(s1, ",TRIGGER")) begin
                       if (ass_array[s1] == itrigger)begin
                          ievent = `vmm_str_prematch(s1);
                          
                          $display ("event name is %s", ievent);
                          do
                            begin
                              if(s2 == {ievent,",event"})begin
                                 ievent_value = ass_array[s2];
                                 $display ("event value is %s", ievent_value );
                              end
         
                            end 
                          while (ass_array.next( s2 ));
                       end
                    end
                  end 
                 while (ass_array.next( s1 ));
             end//if (ass_array[s] == "0x202d") begin
         
      end
    
     
     lvl_counter = lvl_counter + 1 ;
     $display("Anu here%s:%send\n",s,  ass_array[s]);        
end 
while (ass_array.next( s ));

Open in new window

Anu2117Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
> what all events should happen when LIP = 0x203f,
based on the above string, what would those be?
0
Anu2117Author Commented:
Event can be smi, nmi,psmi,....
;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

Let me explain the meaning of above string...
Event nmi should happen on thread = 0 when that thread hits eom and LIP on the thread is 0x2020. Ignore self_check for now.
My other string can be explained as....  
;&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));
 
 #{
    my $a = &TRIGGER('eom',THREAD=>0);
    my $b = &EVENT(smi,TRIGGER=>$a,THREAD=>1);
    my $c = &TRIGGER('retire',TRIGGER=>$b);
    my $d = &EVENT(psmi,THREAD=>0,TRIGGER=>$c);
   # return $d;
}#
 
0
Anu2117Author Commented:
Oh I probably should mention that the events and triggers and threads and LIP .... basically all the elements can have various various values.
0
ozoCommented:
#Do you mean something like this?

my %f=(
       EVENT=>sub{ return bless shift,'EVENT'},
       TRIGGER=>sub{ return bless shift,'TRIGGER'},
       );
use Data::Dumper;
print Dumper event('&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));');
sub event{
    my($s,$re)=@_;
    if( !$re ){
      ($re=$s)=~s/((\()|(\))|[^()]+)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs;  
      $re=qr{(?:(\w+)\s*=>\s*)?(\w+|'[^'']*'|&(\w+)\[.*?\]\((@{[join'|',map quotemeta,$s=~/$re/]})\))};

    }
    my @a;    
while( $s=~/$re/g ){
    my $k=$1||'';
    my $f=$f{$3};
    push @a,{$k => ($f?&{$f}(event($4,$re)):$2)};
}
   return \@a;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.