Ron Rivest writes:
 > (*) A Post tag system has a number of rewrite rules of the form
 >      L_i --> R_i
 >     where L_i and R_i are strings over some alphabet (e.g. binary).
 >     As long as the prefix of the input matches some L_i, that
 >     L_i is removed from the beginning of the input, and the
 >     replacement R_i is added to the end of the input.  

You mean like:

#!/usr/bin/perl
# usage: post-tag '01-->02' '002-->3'
# tests: 01 002 010 00201

while($_=shift) {
  die unless m/(.*)-->(.*)/;
  push(@L, $1);
  push(@R, $2);
}
while(<>) {
  chomp;
  do {
    for($i=0; $i < @L; $i++) {
      $l=$L[$i];
      $r=$R[$i];
      print "$_ trying $l-->$r\n";
      last if s/^$l(.*)/$1$r/;
    }
  print "$_ restarting\n" if ($i < @L);
  } while ($i < @L);
  print "$_\n";
}

-- 
-russ nelson <[EMAIL PROTECTED]>  http://russnelson.com
Crynwr sells support for free software  | PGPok | Government schools are so
521 Pleasant Valley Rd. | +1 315 268 1925 voice | bad that any rank amateur
Potsdam, NY 13676-3213  | +1 315 268 9201 FAX   | can outdo them. Homeschool!

Reply via email to