Often it is desirable to include items in your rule that are not modified by the rule but are simply used for matching. These items are specified in the rule context. The syntax for the rule then becomes:
left-hand-side > right-hand-side / context;
Each item from the left- and right-hand sides is represented by an underscore in the context. (Note that this is a somewhat different meaning of an underscore than we saw in the previous unit for insertions and deletions.)
gA gB gC > gX gY gZ / gP _ gQ _ _ gR;
The above rule replaces A with X, B with Y, and C with Z. But it only is fired in the situation where gP, gQ, and gR occur as specified in the context, i.e., ‘P A Q B C R’. Notice that there is a one-to-one correspondence between the items in the left-hand side, the items in the right-hand side, and the underscores in the context.
Write a program to replace every instance of the letter c. Replace soft c’s with s and hard c’s with k. (Use the rule that soft c’s preceed e, i, and y, and hard c’s preceed a, o, u, and consonants.) Make sure that the case of the substituted letter matches that of the original “c”.
Extend your Greek program from Exercise 5b to always insert a lowercase u unless both the “Q” and the following letter are uppercase, in which case an uppercase “U” is inserted.
Extend your Greek program from Exercise 4c or 5a to replace a sigma with the word-final form (not word-final., U+03C2) where appropriate. Hint: use two rules, the first recognizing the situation where the sigma is