Better than nothing...
#!perl -l
@s=@o=();%p=split//,'-1+1/2*2_3';($_=<>)=~s/\s//g;s/(^|[-+\/*(])-(\d+)/$1_$2/g;@l=split/([-+\/*()])/;for(@l){s/_/-/g;/\d/&&push@o,$_;/\(/&&push@s,$_;if(/\)/){while(defined($x=pop@s)and'('ne$x){push@o,$x}}if(/^[-+\/*]$/){while($p{$s[$#s]}>=$p{$_}){$x=pop@s;push@o,$x}push@s,$_}}while($x=pop@s){push@o,$x}print join' ',@o
|