4.46 Exercise 4.46

Our parsing program relies on operands being evaluated in left-to-right order because our parsing procedure modifies a single global input list. Consider the following function that was given in the chapter:

(define (parse-preopositional-phrase)
  (list 'prep-phrase
        (parse-word prepositions)
        (parse-noun-phrase)))

If the operands were evaluated in, say, right-to-left order, then it would try to parse a noun phrase (thus expecting to remove nouns from the input source) before the preposition itself. This would parse a different set of sentences than we expect.

It would be possible to write this function to behave correctly with right-to-left operand evaluation, but it might be somewhat confusing – at the very least, the operand order corresponds with the actual order that the segments will be found in the sentence. However, if the order of evaluation for operands were implementation-defined, it would not be possible to write this interpreter in a portable fashion.