PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] strwrs -Rn example in spec
Date: Tuesday, 18 Feb 2020, 20:59:50


    > Message Posted By: Unknown
    >
    > Hello!
    > In the HW3 spec, you write:
    >
    >   strwrs -Sn  aa a  abb aab   "aaabbb"   "aabbb", "abbb" ...
    >
    > The second iteration begins by looking at the first character of the
    > replacement string, which is not what the -n flag is supposed to be doing.
    > I'm a bit confused about how this works out. You assumed the -n flag
    > begins looking at the character immediately preceding the replacement
    > string.

The easiest way to see what is happening is to run
Hwk3/strwrs with the -v flag:

  % echo aaabbb | strwrs -v -Sn aa a abb aab
  F=aa      T=a       POS=0   OLD=aaabbb      NEW=aabbb
  F=aa      T=a       POS=0   OLD=aabbb       NEW=abbb
  F=abb     T=aab     POS=0   OLD=abbb        NEW=aabb
  F=aa      T=a       POS=0   OLD=aabb        NEW=abb
  F=abb     T=aab     POS=0   OLD=abb         NEW=aab
  F=aa      T=a       POS=0   OLD=aab         NEW=ab
  ab

This shows that the first transition is the first rule
(aa => a) being applied to the start of the string
(aaabbb => aabbb).  There are no further substitutions
when the search continues with the second character of
the new string.  (Had there been any, they would have
been shown without repeating the rule.)  Since the
application was successful, the -S flag causes the first
rule to be applied again, again to the start of the
string, giving the second transition.

--Stan-
PREV INDEX NEXT