# error message Deep recursion on subroutine

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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 v8) (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;

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)

## Re: error message Deep recursion on subroutine

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