Talk:ThaM

From Esolang
(Redirected from Talk:Tham)
Jump to navigation Jump to search

Commented BF Interpreter

1
|Get input, null terminated|
[I^B]
[
  |If the commands ascii value minus 43 doesn't equal 0(so the number isn't 43), add 43 back and check the next chr the same way|
  43-(43+
  44-(44+
  45-(45+
  46-(46+
  60-(60+
  91-(91+
  |If its not a BF operator pop it, if it is chr 33, pop it still and end the loop|
  93-(B!B)
  |If it is one of the chrs matched above, put it onto the source stack "s" as a num from 1-7|
  (7^s))
  (6^s))
  (5^s))
  (4^s))
  (3^s))
  (2^s))
  (1^s)
]
|Take the first command off of the source stack "s"|
s^B
[
  |Check which command it is|
  1-(1+
  2-(2+
  3-(3+
  4-(4+
  5-(5+
  6-(6+
  |If it isn't ']', there was a bug in the interpreter, so output "wtf?" and end the loop by putting 0 on the source stack "s"| 
  7-(0,063,102,116,119[B^O]0B^s)(
    |If it is ] and the current bf cell is not 0 then...|
    c^B1+B^cr^B^B(
      |Get the last executed command from the stack e|
      e^B
      [
        |If the last executed command isn't a '[', just push it back on the source stack "s"|
        6-(6+B^s)(
          |If it is a [, check if its the matching one to our open bracket, if it is end this loop, else continue looking|
          o^B1-B^B^oc^B^BB^c-(6B^e0)(6B^s)
        )
      ]
    )))
  |If the command is a '[', increase the [ count|
  (o^B1+B^o6^e))
  |If the command is '>', move the data from the left data stack "l" to the right data stack "r", making the top of the right data stack the current BF cell|
  (l^r5^e))
  |If the command is '.', output the chr on the top of right data stack "r"|
  (r^BO4^e))
  |If the command is '-', decrease the top of right data stack "r"|
  (r^B1-B^r3^e))
  |If the command is ',', get a chr from input and replace the top of right data stack "r"|
  (I^Br^B!B^r2^e))
  |If the command is '+', increase the top of the right data stack "r"|
  (r^B1+B^r1^e)
  |Get the next command from source stack "s"|
  s^B
]=

poiuy_qwert 19:22, 9 Sep 2006 (UTC)

Modified to match updated spec. --MizardX 02:14, 29 November 2008 (UTC)