Please answer this question directly on the computer. Max 20
This test is intended to check your ability to write attributed Cocol grammars. It should only take you about 45 minutes at the most. Textbooks may be used.
1. You thought you had heard the last of SAFM, didn't you? Wrong again! Here is a version of a grammar for the SAFM 104-107 schedules like the one you saw a few weeks ago.
COMPILER Radio $CN /* The delights of SAFM 104 to 107 P.D. Terry, Rhodes University, 2016 Nearly LL(1) version */ CHARACTERS letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" . digit = "0123456789" . control = CHR(0) .. CHR(31) . TOKENS word = letter { letter | digit } [ ',' ] . number = [ "-" ] digit { digit } . COMMENTS FROM "{" TO "}" NESTED IGNORE control PRODUCTIONS Radio = { TalkShow | "music" | "advert" [ NewsBulletin ] } EOF . NewsBulletin = NewsItem { NewsItem } [ Weather ] Filler . NewsItem = "Zuma" [ "Gordhan" ] | "Gordhan" "Zuma" | "Mugabe" | "corruption" | Story . Story = word { [ number ] word | "Gordhan" | "Mugabe" | "Zuma" } ( "." | "?" | "..." | ":" ) . TalkShow = Host { Listener Host } . Host = "host" Opinion . Listener = "listener" Caller Opinion . Opinion = { Story } . Filler = "music" | "advert" . Weather = "maxmin" "temperatures" OneTemp { "," OneTemp } . OneTemp = Town number number . Town = word . /* a single word suffices for testing */ Caller = word . END Radio.
Show how this grammar could be attributed so that it could report (using methods from the IO library) :
(a) the length of the longest story that was used in any News Bulletin during the whole day. (b) a list of the callers to the Talk Shows, and the number of times each caller offered an opinion.
Hint: This is a non-recursive grammar, so that you will be able to use global/static variables to handle some of those aspects if you wish. But you must please parameterize the Story production.
md test6
cd test6
copy i:\csc301\trans\test6.zip
unzip test6.zip
RADIO.ATG RADIO.TXT *.BAT *.FRAME
Do not edit the data file, simply edit the ATG file.
cmake radio
radio radio.txt
To save you time in predicting the output by hand, the system should give you output something like
Mike 1 Klarity 2 Amandla 3 Minister 1 Longest story had 24 words