sicp-ex-4.47



<< Previous exercise (4.46) | Index | Next exercise (4.48) >>


woofy

1. If the input does not start with a verb the process will try to read and trackback on the first word repeatedly forever

2. The procedure will call itself indefinitely when evalutating the argment value and won't even start to read input

In the domain of compiler, the technique in the book maybe corresponds to the left recursion elimination. That is to transform the production (that generate 1 'r' followed by 0 or multiple 'x') :

A => Ax | r
(Louis' approach)

to:

B=> ε | xB
A=> rB
(Textbook's approach)

so that there is no production on the right starts with the symbol on the left (left recursion). The effect is that if we follow the rules directly we won't stuck in infinite recursion (we have choices to stop or to go deeper).


meteorgan

  
  
 This doesn't work. Because the second branch of amb expression will call (parse-verb-phrase) again, this will lead to infinite loop. If we change the order in amb, it still will lead to infinite loop.