PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: Hwk3
Date: Tuesday, 20 Oct 2020, 13:55:06


    > My code passes all the public tests but I am currently trying to fix the
    > issue of repeated expansions, sort of like in your post "Amusing Test Case"
    > Example:
    > ./mcBash \$PWD
    > (1)$ ${a=${b=$1}}
    >
    > My code outputs the expansion of $PWD instead of "$PWD" because in its
    > current form, it is finding the innermost bracket and recursively expanding
    > it. So after the first step it turns into ${a=$1} -> expands $1.  Is this
    > the wrong direction and I should somehow try to use regex to find the
    > outermost brackets to begin with? Sorry if this is unclear.

The example above shows why your current approach will
not work in all cases---the scanning must take place
from left to right, not inside out.

As I posted Sunday,

  What this suggests is that you may want to continually
  remove a prefix of the input and append its replacement
  to another, initially empty string.  The regexes for this
  process are fairly simple.

In terms of Python, it suggets that you may want to use
re.match(), not re.search() or another matching
function.

--Stan-
PREV INDEX NEXT