Assignment 2: Slippy
Aims
This assignment aims to give you:
practice in Python programming generally.
a clear and concrete understanding of sed's
core semantics.
Introduction
Your task in this assignment is to implement Slippy
.
Slippy stands for **[S]**ed **[L]**anguage **[I]**nterpreter in **[P]**ure **[PY]**thon.
A subset of the important Unix/Linux tool Sed.
You will do this in Python
.
Sed is a very complex program that has many commands.
You will implement only a few of the most important commands.
You will also be given a number of simplifying assumptions, which make your task easier.
Slippy
is a POSIX-compatible subset of sed with extended regular expressions (EREs).
On CSE systems you would run sed -E
You must implement Slippy
in Python only.
See the Permitted Languages
section below for more information.
the material in the lecture notes will not be sufficient by itself to allow you to complete this assignment.
You may need to search the command-line and online documentation for Python, Sed, and Regex
Being able to search documentation efficiently for the information you need is a very useful skill for any kind of computing work.
Reference implementation
Many aspects of this assignment are not fully specified in this document; instead, you must match the behaviour of the reference implementation: 2041 slippy
Provision of a reference implementation is a common method to provide or define an operational specification, and it's something you will likely need to do after you leave UNSW.
Discovering and matching the reference implementation's behaviour is deliberately part of the assignment, and will take some thought.
If you discover what you believe to be a bug in the reference implementation, report it in the class forum.
Andrew and Dylan may fix the bug, or indicate that you do not need to match the reference implementation's behaviour in this case.
Slippy Commands
Subset 0
In subset 0 slippy will always be given a single Slippy command as a command-line argument.
The Slippy command will be one of 'q', 'p', 'd', or 's' (see below).
The only other command-line argument possible in subset 0 is the -n option.
Input files will not be specified in subset 0.
For subset 0 slippy need only read from standard input.
Subset 0: q - quit command
The Slippy q command causes slippy.py to exit, for example:
$ seq 1 5 | 2041 slippy '3q'
1
2
3
$ seq 9 20 | 2041 slippy '3q'
9
10
11
$ seq 10 15 | 2041 slippy '/.1/q'
10
11
$ seq 500 600 | 2041 slippy '/^.+5$/q'
500
501
502
503
504
505
$ seq 100 1000 | 2041 slippy '/1{3}/q'
100
101
102
103
104
105
106
107
108
109
110
111
slippy commands are applied to input lines as they are read.
The q command means slippy may not read all input.
For example, the command prints an "infinite" number of lines containing (by default) "yes".
$ yes | 2041 slippy '3q'
y
y
y
This means slippy can not read all input first, e.g. into a list, before applying commands.
Subset 0: p - print command
The Slippy p commands prints the input line, for example:
$ seq 1 5 | 2041 slippy '2p'
1
2
2
3
4
5
seq 7 11 | 2041 slippy '4p'
7
8
9
10
10
11
$ seq 65 85 | 2041 slippy '/^7/p'
65
66
67
68
69
70
70
71
71
72
72
73
73
74
74
75
75
76
76
77
77
78
78
79
79
80
81
82
83
84
85
$ seq 1 5 | 2041 slippy 'p'
1
1
2
2
3
3
4
4
5
5