Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > error message Deep recursion on subroutine

Reply
Thread Tools

error message Deep recursion on subroutine

 
 
NamSa
Guest
Posts: n/a
 
      05-04-2009
my code printing error message this <data> 6 line it's TIME function.
TIME function is recursive computations .
Deep recursion on subroutine "main::Value" at toy.pl line 104, <DATA>
line 6.
Deep recursion on subroutine "main::Fun" at toy.pl line 40, <DATA>
line 6.
Deep recursion on subroutine "main::Fun" at toy.pl line 40, <DATA>
line 6.
Deep recursion on subroutine "main::Subst" at toy.pl line 62, <DATA>
line 6.



my code Lisp-Like TOY Language
base function 2 function it's MINUS and IF. another function make is
base IF or MINUS

use strict;

use warnings;



my @fun_list = ("MINUS","IF");

my %fun_hash = (

MINUS => 'Minus',

IF=> 'If',

AA=> '(x y)(IF x y)',

BB=> '(x y)(MINUS x y)',

ADD=> '(x y)(MINUS x (MINUS 0 y))',

EQUAL=> '(v2 v3)(MINUS (MINUS 1 (IF ( MINUS v2 v3) 1)) (IF (MINUS
v3 v2) 1))',

"IF/THEN/ELSE"=> '(v7 v8 v9)(ADD (IF v7 v (IF (MINUS 1 v7) v9))'

);



#main

while (<DATA>){

print Value($_) ;



}



sub Value{

my $exp=$_[0];

my $result;

while($exp !~ /^-?\d+/){

if (my @array = $exp =~ /\(\s*((??!\s+\))[^()])+)\s*\)/xg){

for (@array){

$result = Fun($_);

$exp =~ s/\(\s*$_\s*\)/$result/;

}

}

}

return $exp;

}





sub Fun{

my $exp = $_[0];

my @arg = split / /,$exp;

for my $key (keys %fun_hash){

if( $exp =~ /^$key/){

if($key eq "MINUS"){

return Minus($arg[1],$arg[2]);

}elsif($key eq "IF"){

return If($arg[1],$arg[2]);

}else{

return Subst($key,$exp);

}

}

}

}



sub Minus{

my $x = $_[0];

my $y = $_[1];

return $x-$y;

}





sub If{

my $x = $_[0];

my $y = $_[1];

if($x <= 0){

return 0;

}else{

return $y;

}

}



sub Subst{

my $key = $_[0];

my $exp = $_[1];

my $i=0;

my @arg = split / /,$exp;

my $fun = $fun_hash{$key};

my @ar = $fun=~ /\(\s*((??!\s+\))[^()])+)\s*\)/xg;

my @arg2 = split / /,$ar[0];

my $arg_size = @arg2;

$fun =~ s/\(\s*$ar[0]\s*\)//g;

for (@arg2){

$fun =~ s/$_/$arg[$i+1]/g;

$i++;

}

return Value($fun);

}



__DATA__

(AA 0 5 )

(BB 0 5 )

(ADD 5 5 )

(EQUAL 6 5 )

(IF/THEN/ELSE 1 2 5)
 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      05-04-2009
On 2009-05-04 03:18, NamSa <> wrote:
> my code printing error message this <data> 6 line it's TIME function.
> TIME function is recursive computations .
> Deep recursion on subroutine "main::Value" at toy.pl line 104, <DATA>
> line 6.


This is not an error message, just a warning. You can turn it off with
"no warnings 'recursion';". See perldoc warn, perldoc perllexwarn and
perldoc perldiag for details.

hp
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TIEHANDLE and deep recursion Tim Watts Perl Misc 11 05-10-2012 02:53 PM
efficiency of recursion (stack level too deep) Chet Nichols III Ruby 3 11-14-2007 08:41 PM
Deep Freeze In Deep Trouble johntangelo@gmail.com Computer Security 4 09-19-2007 03:16 AM
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Returning value from deep recursion Arun Java 1 01-26-2005 03:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57