Assignment 2: Slippy 2022
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Assignment 2: Slippy
2022
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.
NOTE:
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 on-line 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 2 3 $ seq 9 10 11 $ seq 10 11 $ seq 500 501 502 503 504 505 $ seq 100 101 |
1 5 | 2041 slippy '3q' |
|
9 20 | 2041 slippy '3q' |
||
10 15 | 2041 slippy '/.1/q' |
||
500 600 | 2041 slippy '/^.+5$/q' |
||
100 1000 | 2041 slippy '/1{3}/q' |
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 |
Subset 0: d - delete command
The Slippy d command deletes the input line, for example:
$ seq 1 5 | 2041 slippy '4d' 1 2 3 5 $ seq 1 100 | 2041 slippy '/.{2}/d' 1 2 3 4 5 6 7 8 9 $ seq 11 20 | 2041 slippy '/[2468]/d' 11 13 15 17 19 |
Subset 0: s - substitute command
The Slippy s command replaces the specified regex on the input line.
$ seq 1 5 | 2041 slippy 's/[15]/zzz/' zzz 2 3 4 zzz $ seq 10 20 | 2041 slippy 's/[15]/zzz/' zzz0 zzz1 zzz2 zzz3 zzz4 zzz5 zzz6 zzz7 zzz8 zzz9 20 $ seq 100 111 | 2041 slippy 's/11/zzz/' 100 101 |
The substitute command can be followed optionally by the modifier character g , for example:
$ echo Hello Andrew | 2041 slippy 's/e//' Hllo Andrew $ echo Hello Andrew | 2041 slippy 's/e//g' Hllo Andrw |
g is the only permitted modifier character.
2022-07-28