Re: Forth
Mark Jason Dominus <[email protected]>
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Andrew Dalke <dalke-DxsMES/F/[email protected]>: > I just waste^H^H^H^H^Hspent the last 5 hours or so implementing > a stack interpreter for the Turing Machine Instruction Set. It > uses unary numbers, so > 0 == > 1 == 1 > 2 == 11 > 5 == 11111 > etc. > It does not understand negative numbers. I wasted a bunch of time writing a macro assembler for Turing machines. I wanted to write a binary multiplication program, but the binary addition program was so painful that I wrote the macro assembler instead to help me. You get to write things like !alphabet _ 01 !macro scan right to $sym then $newstate start $sym backup $sym R start ^$sym start * R backup * $newstate * L !endmacro argA scan right to _ then argB argB scan right to X then continue continue ... which would assemble to argA _ G0001 _ R argA 0 argA 0 R argA 1 argA 1 R G0001 _ argB _ L G0001 0 argB 0 L G0001 1 argB 1 L argB _ G0002 _ R argB 0 argB 0 R argB 1 argB 1 R G0002 _ continue _ L G0002 0 continue 0 L G0002 1 continue 1 L continue... The label 'backup' has been replaced by 'G0001' in the first macro expansion, and by 'G0002' in the second expansion. There are a couple of missing features, but as I was falling asleep a coupld of nights ago I realized that the next step would be to implement a compiler that compiles forth to macro assembler. > Next, a swap, and a rotate 3, and support for negative numbers, > and ... why soon I'll have a Forth interpreter! The next step seems to me to be a PostScript interpreter. :)