Hints for the Challenge:

Below, you can find another hint for the Challenge.

You should only get here after reading, digesting, and applying the .

Hint

The problem with the current approach using markers is that in order to recognize markers we need to put them in the program somehwere. And we did that literally. Remember that in our previous program we had the statement:

containing '|'. Therefore, the string S will have to contain something that produces these three characters. The quotes cannot be put literally in S (we introduced the quote marker for that reason), and if we put the vertical bar literally inside S, then this occurrence of the vertical bar should not be translated into a newline, but should be written literally. The problem with our previous program is that these occurrences also got translated, giving rise to a spurious newline and a quoted quote.

So, the options are

  1. Avoid literal occurences of the markers in the program (outside the string literal).
  2. Avoid translating the markers inside the string literal whenever they occur as recognizers.

The second approach could be made to work, but is more involved than you might believe at first sight. The first is easier, especially when one can also avoid the additional quotes in the program.

There are various ways in which one can avoid the literal occurence of the marker(s) in the program (but outside the string literal S).

  1. The sneaky way is to use a known occurrence of the marker(s) inside the string literal instead.
  2. Alternatively, each marker can be encoded using more than one character, so that recognizing such character sequences need not involve that sequence literally but split. This approach is more generic, because it has the advantage that we need not look for unused characters as markers. (Or, to put it differently, once a one-character marker has been chosen, we must avoid that character in the remainder of the program for other purposes. For instance, it could be awkard to choose the plus symbol + as newline marker.) We will get back to the generic approach later.

The sneaky idea of approach 1a is to express the translation of newline markers by a statement of the form:

where the three dots are replaced by an appropriate index value.

Can you develop this into a solution?

Try your program in the machine, and see if you can extend it to a complete solution.

Apply the Hint

It is your turn ...

Need Another Hint?

If you tried this hint, or do not see how it helps, then you are ready for the .


Valid HTML 4.01 Transitional

Copyright ©2009, Tom Verhoeff, T.Verhoeff@TUE.NL