Computer Science 301 - 2016 - Test on Week 6

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.


You are to solve this problem on the computer

  • Immediately after logging on, get to the command line level in the usual way.

  • Copy the prac kit into a newly created directory/folder in your file space

    md test6
    cd test6
    copy i:\csc301\trans\test6.zip
    unzip test6.zip

  • You will find the executable version of Coco/R and the familiar batch files for running it, the frame files, and the above grammar spread out to make for easier addition of the actions and attributes and with some hints as to where you might add other methods into the parser, as well as a data file for test purposes.

    RADIO.ATG RADIO.TXT *.BAT *.FRAME

    Do not edit the data file, simply edit the ATG file.

  • Add the actions into the RADIO.ATG file, and compile and run the sytem with the supplied data 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
    

  • Please make sure that your modified ATG file contains your name and student number.

  • Remember Einstein's advice Keep it as simple as possible, but no simpler.

  • It is suggested that you solve the problem in two stages - first handle part (a) and then, when that is working, add the rest of the code to solve the slightly more involved part (b).

  • When you have solved the problem, print a copy of the final ATG file (and any others you might have created) using LPRINT as usual, and hand it in. If you don't have any printer balance, mail it to me at p.terry@ru.ac.za as an attachment


    Home  © P.D. Terry