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