|
Revision 425, 1.0 kB
(checked in by hodgestar, 3 years ago)
|
|
Playing around with Whitespace.
|
| Line | |
|---|
| 1 | === Embedded Programming == |
|---|
| 2 | |
|---|
| 3 | I have written a tabs to spaces converter in Whitespace [1] and embedded [2] it |
|---|
| 4 | into this comment. You'll need the Python interpreter from [3] because the |
|---|
| 5 | Haskell one doesn't report EOFs nicely. |
|---|
| 6 | |
|---|
| 7 | Usage: |
|---|
| 8 | python main.py file-containing-this-comment < file-with-tabs > file-with-spaces |
|---|
| 9 | |
|---|
| 10 | I have included the dissambled [4] code below for your convenience. Hopefully the |
|---|
| 11 | blog software doesn't discard the (extremely meaningful) whitespace in this |
|---|
| 12 | comment! |
|---|
| 13 | |
|---|
| 14 | [1] http://compsoc.dur.ac.uk/whitespace/ |
|---|
| 15 | [2] http://compsoc.dur.ac.uk/whitespace/tools.php |
|---|
| 16 | [3] http://www.mrphlip.com/pywhitespace.tar.bz2 |
|---|
| 17 | [4] http://yagni.com/whitespace/index.html |
|---|
| 18 | |
|---|
| 19 | === Source Code === |
|---|
| 20 | |
|---|
| 21 | label 1 |
|---|
| 22 | |
|---|
| 23 | #read a char and put copies on the stack |
|---|
| 24 | push 0 |
|---|
| 25 | readchar |
|---|
| 26 | push 0 |
|---|
| 27 | retrieve |
|---|
| 28 | |
|---|
| 29 | #compare to EOF and jump to end if it matches |
|---|
| 30 | dup |
|---|
| 31 | push -1 |
|---|
| 32 | sub |
|---|
| 33 | jz 5 |
|---|
| 34 | |
|---|
| 35 | #compare to \t and jump to 3 if it matches |
|---|
| 36 | dup |
|---|
| 37 | push 9 |
|---|
| 38 | sub |
|---|
| 39 | jz 3 |
|---|
| 40 | jump 2 |
|---|
| 41 | |
|---|
| 42 | #non-tab |
|---|
| 43 | label 2 |
|---|
| 44 | outchar |
|---|
| 45 | jump 4 |
|---|
| 46 | |
|---|
| 47 | #tab |
|---|
| 48 | label 3 |
|---|
| 49 | discard |
|---|
| 50 | push 32 |
|---|
| 51 | dup |
|---|
| 52 | dup |
|---|
| 53 | dup |
|---|
| 54 | outchar |
|---|
| 55 | outchar |
|---|
| 56 | outchar |
|---|
| 57 | outchar |
|---|
| 58 | jump 4 |
|---|
| 59 | |
|---|
| 60 | #goto start |
|---|
| 61 | label 4 |
|---|
| 62 | jump 1 |
|---|
| 63 | |
|---|
| 64 | #end |
|---|
| 65 | label 5 |
|---|
| 66 | exit |
|---|