Computer Science 301 - 2017 - Test on Week 6

This week's test is being conducted in a way that will give you a feeling for how the "24 hour exam" will be staged in November. In this handout you are presented with a problem to study (and to make a start on a solution). You are at liberty to discuss the problem and/or solution with your friends, consult the textbook and generally do anything that will calm your nerves. This afternoon you will each have to develop a solution on your own, no further group discussions allowed.

This afternoon you will be presented with an exam kit containing the material you are now reading (with the grammar below spread out for ease of editing), as well as a source kit that you will be free to get from the web site if you feel confident enough to complete the solution electronically in the 45 minutes allotted to the test.

The grammar below attempts to describe a week of frenetic activity in the life of CSC 301, 2017.

    COMPILER CSC301 $CN
    /* That was the week that was (famous satrical BBC TV series of many years ago) */

    CHARACTERS
      letter  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .

    TOKENS
      name = letter { letter } .

    IGNORE CHR(0) .. CHR(31)

    PRODUCTIONS
      CSC301       = { Student } EOF .
      Student      = name Prac "PracTest" .
      Prac         = Handouts { Task } "Submit" Marker .
      Handouts     = "PracKit" [ "TaskSheet" ] [ "CoverSheet" ] .
      Task         = "Attempt" { ConsultTutor "Attempt" }  .
      ConsultTutor = name .
      Marker       = name .

    END CSC301.

As you may know, we sometimes have trouble finding tutors and markers. As you may not know, we are going to have a problem paying them, because they have recently told me that they want to be paid a fee for each occasion they are consulted, as well as a fee for each submission they mark. So what I need now are two lists : a list of all students, with their marks (and a value for the top mark in the class) and a list of tutors, with a report of those claimed numbers for each service rendered.

The markers have hit on a scheme to automate the marking without really doing any work. They will simply look at the number of tasks attempted, and the number of attempts made to solve them, and then award a mark computed as the greater of 30 and

Mark = 20 * Tasks - 2 * Attempts

You are to add to the grammar so that a Coco/R generated system can produce and display me this information.

Hint: Although this is a problem that might be solved in many ways, I want to see that you know how to make use of a simple auxiliary table structure, and that you know how to add actions to a grammar and parameterize the methods in it. You will be given some suggestions for fields and methods for a table handler in the test kit later today.

Typical output might be as follows:

    MacHine              30
    Nerde                96
    Veepoor              32
    Khandoo              56
    Tweedum              36
    Tweedee              36
    Tride                30
    Looza                30

    Top mark was 96

    Damon                  9 consultations   1  marked
    Pat                   20 consultations   2  marked
    Marq                  13 consultations   3  marked
    Kefentse               9 consultations   2  marked
For your convenience the grammar you saw in the initial handout has been spread out on the following pages.

You can download it in the kit TEST6.ZIP in the familiar way. If you want to solve this test electronically, you will be asked to LPRINT your solutions - grammar and table handler) to hand in. If you prefer, you can simply complete the code by writing it in the spaces provided on the printout.

Your solution should introduce suitable parameters into the methods associated with Student, Prac and Task and not make use of static variables in the Parser class.

The skeleton table handler will be found (after unpacking TEST6.ZIP in the file CSC301\Table.cs. You can make the system and execute it with the commands

                 CMAKE   CSc301
                 CSc301  CSc301.txt

    using Library;

    COMPILER CSC301 $CN
    /* Describe progress of an extended compiler practical */

    IGNORECASE

    CHARACTERS
      letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .

    TOKENS
      name   = letter { letter } .

    IGNORE CHR(0) .. CHR(31)

    PRODUCTIONS
      CSC301                             (. int topMark = 0; .)
      = { Student


        } EOF


      .
_________________________________________

      Student


      = name



        Prac



        "PracTest"

      .
_________________________________________

      Prac


      = Handouts


        { Task


        } "Submit"


        Marker
      .
_________________________________________

      Handouts
      = "PracKit"
        [ "TaskSheet"  ]
        [ "CoverSheet" ]
      .
_________________________________________

      Task
      = "Attempt"

        { ConsultTutor


          "Attempt"


        }
      .
_________________________________________

      ConsultTutor

      = name


      .
_________________________________________

      Marker

      = name


      .

    END CSC301.
    // Table handler for Prac checker

      using Library;
      using System.Collections.Generic;

      class Tutor {
      // Feel free to add other fields and methods, but keep it simple

        public string name;



        public Tutor(string name) {
          this.name  = name;



        } // constructor

      } // Tutor

      class Table {

        static List<Tutor> tutors = new List<Tutor>();

        public static void Update(string name) {
        // Update the claims of a tutor with a known name
          int i = 0;
          while (i < tutors.Count &&     // short-circuit helps
                 !name.ToUpper().Equals(tutors[i].name.ToUpper()))
            i++;

          if (i == tutors.Count)
            tutors.Add(new Tutor(name)); // new entry









        } // Table.Update

        public static void TutorReport() {
          IO.WriteLine();
          foreach (Tutor t in tutors) {







          }
        } // TutorReport

      } // Table


Home  © P.D. Terry