The following description is based on the rather conservative pronunciation of Portuguese in Porto Alegre, Rio Grande do Sul, Brazil. Because the orthography is even more conservative, the rules will roughly characterize the phonological changes that have occured in one dialect since the orthography fossilized. We will limit the input to lowercase words in this exercise. Because we have limited our input words to lowercase letters, the six special characters will appear only in surface strings, never at the lexical level. These zeros will not appear in the final output.
All lexical symbols map to themselves on the surface level by default.
You can use the lexical side or the surface side or some combination thereof to restrict the context but there is no rule ordering. Use the command lex-test to test individual words. Because of the accented characters, it is best to run test in an Emacs buffer. To create one, use the command M-x shell . The command will prompt you to enter the name of the input and the output file.