Summarising, the generator first generates a possible utterance. This utterance is then given as input to the monitor. The monitor calls the parser to find which parts of that utterance are ambiguous. These parts are marked in the derivation tree associated with the utterance. Finally the monitor tries to generate an utterance which uses alternative derivation trees for the marked, i.e. ambiguous, parts.
Generating an utterance given a marked derivation tree proceeds as follows. The generator simply `repeats' the previous generation in a top-down fashion, as long as it encounters unmarked nodes. This part of the generation algorithm thus simply copies previous results. If a marked node is encountered the embedded generation algorithm is called for this partial structure. The result should be a different derivation tree than the given one. Now clearly, this may or may not be possible depending on the grammar. The next paragraph discusses what happens if it is not possible.
The following definition assumes that grammar rules are represented simply as rule(Name, Mother, Ds) where Name is the rule name, Mother is the mother sign and Ds is a list of daughter signs. The predicate mgen is used to generate an utterance, using a marked derivation tree as an extra guide.
mgen(sign(Lf,Str,S,D),t(Name,Ds,y)):- generate(sign(Lf,Str,S,D)), \+ D = t(Name,Ds,_). mgen(sign(Lf,Str,S,D),t(Name,Ds,n)):- rule(Name,sign(Lf,Str,S,D),Kids), mgen_ds(Kids,Ds). mgen_ds(,_). mgen_ds([S|T],[Stree,Ttree]):- mgen(S,Stree), mgen_ds(T,Ttree).