Steps to adding ELSIF to your grammar:
- Implement if/else using matched/unmatched. Test.
- Incorporate while in the matched/unmatched productions. This means creating both a
matched and an unmatched version of while. Test.
- Incorporate loop in the matched/unmatched productions. This means creating both a
matched and an unmatched version of loop. Test.
-
Now link in the elsif stuff by adding to the list of possible matched statements:
| IF simpleExp THEN matched matchedelsifs
and to the unmatched statements something like:
IF simpleExp THEN matched unmatchedelsifs
This will connect to two new nonterminals matchedelsifs and unmatchedelsifs.
-
For matchedelsifs create productions that add one or more ELSIFs. They need
things that look like:
ELSIF simpleExp THEN matched ELSIF simpleExp THEN matched ELSIF simpleExp THEN matched ...
This list of elsifs must end in an: ELSE matched to match the elsif.
- Similarly add productions for unmatchedelsifs which is again a list of ELSIFs like above but can end in one of two ways that are unmatched. See what were unmatched things in the unmatched code you already wrote for a hint.