Project 2 — Programming in snail

CS-364: Programming Languages

Spring 2022

In this programming project, you will gain faimiliarity with snail, the programming language we will be implementing this semester. You will implement a nontrivial algorithm in the language.

Project 2 allows you to familiarize yourself with the snail programming language and practice implementing foundational algorithms. Having a non-trivial understanding of the langauge will help you to properly implement its semantics in future projects.

You may work in teams of two for this project.

Danger! You can expect this project to take you significantly longer than Project 1. Give yourself plenty of time to work through inevitable confusion before the deadline.

Requirements

Working in teams of two (or individually), create and submit the following five (5) artifacts:

  • A snail source file, p2.sl, that contains your implementation of the program specified below.
  • A valid novel task list test input for your program, named test-1.txt.
  • A plain UTF-8 text file called readme.txt that describes your implementation and design decisions.
  • A plain UTF-8 text file called references.txt providing a citation for each resource you used (excluding class notes, and assigned readings) to complete the assignment. For example, if you found a Stack Overflow answer helpful, provide a link to it. Additionally, provide a brief description of how the resource helped you.
  • A plain UTF-8 text file called team.txt containing the SLU email IDs of the students who worked on the artifacts.

Specification

Create a snail program, p2.sl. Your program must take in a list of dependent tasks and either output a valid order in which to perform them or the single word cycle. This problem is just topological sort not-so-cleverly disguised. Feel free to look up how to do toposort on the internet and cite your references (but remember that you must turn in your own work; you may not copy someone else's code and claim it as your own).

Your program will accept a number of lines of textual input (via standard input). There are no command-line arguments — you must always read from standard input.

That text input will contain a non-zero but even number of lines. Every two lines represent a pair of tasks. The first line gives the name of a task, the second line gives the name of a task that it depends on. This text input is also called the task list.

The task list will contain only standard ASCII characters (no UTF/8 Unicode or special accents). The goal is to test programming and program language concepts, not your internationalization abilities.

Each task name starts at the beginning of the line and extends all the way up to (but not including) the end of that line. So the newline or carriage return characters \r or \n are not part of the task name.

Example task list:
learn C
read the C tutorial
do P1
learn C

The interpretation is that in order to learn C one must first read the C tutorial and that in order to do P1 one must first learn C.

Desired output:
read the C tutorial
learn C
do P1

Cycles

If the task list contains a cycle of any size, your program should output exactly and only the word cycle.

Example cyclic input:
get a job
have experience
have experience
work on a job
work on a job
get a job

Even if the task list contains a few non-cyclic parts, any single cycle forces you to output only the word cycle.

Always output to standard output only. In snail, this is the only form of output supported.

There is no fixed limit on the number of lines in the task list (although it is not zero and it is even).

Two tasks with the same name are really just the same task. Use standard string equality.

Duplicated pairs of tasks are not allowed and will not be tested.

Example duplicated pairs:
learn C
read the C tutorial
do P1
learn C
learn C
read the C tutorial

The above task list is not valid input because the pair learn C/read the C tutorial appears twice. Program behavior if the task list contains a duplicate pair is undefined. You will not be tested on it.

Choosing Among Unconstrained Tasks

If there are multiple outstanding unconstrained tasks, your program should output them in ascending ASCII alphabetical order. That is, if you ever have two or more tasks, each of which has no remaining dependencies, output the one that comes first ASCII-alphabetically. (This constraint makes your program deterministic; for any given input there is only one correct output.)

Example:
learn C
understand C pointers
learn C
read the C tutorial
do P1
learn C

Because r comes before u, your output should be:

Correct output:
read the C tutorial
understand C pointers
learn C
do P1

To put it another way, consider this task list:

Example task list:
B
A
C
D
C
E

Which yields a dependency graph like this:

              
                A  D E
                |  \ /
                B   C
               
            

The proper ordering for this set of tasks is A B D E C. Note that B comes before D and E, even though B depends on A. This is because, once A is finished, B is free to go and it comes first alphabetically. You may want to consider this requirement when you pick your sorting algorithm. Given this requirement the answer A D E B C is incorrect and will receive no credit.

Resources

For this programming assignment, three coding resources are provided to you:

  • revsort.sl — provides concrete implementation of "task list reversal" (a similar, but simpler, problem). The program reads lines from standard input and outputs them in reverse sorted order using the built-in array type. This is somewhat similar to what you are asked to do for P2. Notably, it shows you how snail handles string input, arrays, and sorting. You may reuse this code in your solution.
  • revsort-list.sl — provides another implementation of "task list reversal" (a similar, but simpler, problem), this time using a linked list data structure. You may reuse this code in your solution.
  • p2-testcases-nix.zip — includes a number of test inputs and expected outputs so that you can test your programs before submitting

Commentary

Documentation is your friend! here are some external resources you might find helpful:

Take a look at both revsort.sl and revsort-list.sl. You could do worse than using one or both of these as a starting point. It might also be helpful to review the repositiory of example snail programs.

There are different kinds of graph structures you could use to represent the tasks read in from standard input. An adjacency list (a list of lists) is likely sufficient here.

Because you receive extra credit for a working Python or Reason implementation (see the Grading Rubric below), I recommend that you attempt the task in one of these languages first. That way you can be sure that you understand the toposort algorithm in a familiar language before you try it in an unfamiliar one. Once you have it working, you can translate that into snail.

It is possible to use a text file as input to snail. This is known as input redirection. You can also redirect output to a file. The syntax for this is shown below.

              
                # redirect input for program
                snail p2.sl < /path/to/input/file

                # redirect output for program 
                snail p2.sl > /path/to/output/file

                # these can be combined 
                snail p2.sl < input > output
              
            

If you are still stuck, you can post on Piazza or approch the professor.

Video Guides

Video guides are provided to help you get started with various aspects of this project. Note that there may be errors and mistakes in these videos. You should not blindly follow the steps taken in these videos!

Graph Data Structure in snail

BFS in snail

What to Submit

You must turn in a tar.gz file containing these files:

  • readme.txt: your README file
  • references.txt: your file of citations
  • test-1.txt: a valid novel task list (it may or may not contain a cycle — your choice)
  • source_files: including
    • p2.sl (contains your program for P2)
    • You may also submit p2.py or p2.re for extra credit.
    • These source files must include a comment with the project identifier: 38a1108d19f54a1fab115779487fbbcea3ae1843
  • team.txt: a file listing only the SLU email IDs of both team members (see below). If you are working alone, you should turn in a file with just your email ID.

The readme.txt file should be a plain UTF-8 text file (not a Word file, not an RTF file, not an HTML file) describing your design decisions. What library functions did you use? How did you store the (implicit) graph in P2? What was the biggest challenge of using snail? One or two English paragraphs should suffice. Spelling, grammar, capitalization and punctuation all count.

Generating the compressed file for SLUGS

Note, you can use the CS-364 Makefile to generate a submission archive:

                
                make fullsubmit
                
              

The Makefile is available here. Be sure to update the IDENTIFIER and EXECUTABLE variables appropriately.

Working in Pairs

You may complete this assignment in a team of two. Teamwork imposes burdens of communication and coordination, but has the benefits of more thoughtful designs and cleaner programs. Team programming is also the norm in the professional world.

Students on a team are expected to participate equally in the effort and to be thoroughly familiar with all aspects of the joint work. Both members bear full responsibility for the completion of assignments. Partners turn in one solution for each programming assignment; each member receives the same grade for the assignment. If a partnership is not going well, the instructor will help to negotiate new partnerships. Teams may not be dissolved in the middle of an assignment.

If you are working in a team, both team members should submit to SLUGS. All submissions should include the file team.txt, a two-line, two-word flat UTF-8 text file that contains the email ID of both teammates. Don't include the @stlawu.edu bit. Example: If sjtime10 and kaangs10 are working together, both kaangs10 and sjtime10 should submit fullsubmit.tar.gz with a team.txt file that contains:

                
                kaangs10
                sjtime10
                
              

Then, sjtime10 and kaangs10 will both receive the same grade for that submission.

Grading Rubric

P2 Grading (out of 50 points):

  • 40 points: autograder tests
  • 4 points: clear description in your README and References
    • 4 — thorough discussion of design decisions and choice of test cases; a few paragraphs of coherent English sentences should be fine. Citations provided are properly formatted.
    • 2 — vague or hard to understand; omits important details. Citations provided are properly formatted.
    • 0 — little to no effort. Citations do not provide correct information.
  • 2 points: valid and novel test-1.txt file
  • 4 points: code cleanliness
    • 4 — code is mostly clean and well-commented
    • 2 — code is sloppy and/or poorly commented in places
    • 0 — little to no effort to organize and document code
  • 5 points extra credit: correct implementation in Python or Reason