The LOLCODE forum

Discussions in support of the LOLCODE.com wiki

You are not logged in.

Announcement

New registrations are disabled. Please see this announcement.
  • Index
  •  » MEWzings
  •  » Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

#1 2007-06-04 05:38:39

Arachnid
Member
Registered: 2007-06-02
Posts: 271

Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

Here's a BF interpreter written entirely in standard LOLCode. Since we don't have any way to convert characters to their ASCII values and vice-versa, output doesn't work as expected, and input doesn't work at all, but it still proves turing completeness!

Note that if you're using lolcode.net to compile it, you'll need to update to Revision 19, as it fixes some bugs I came across when writing this!

Code:

HAI
BTW This is a BrainFuck interpreter written in LOLCode
BTW It accepts as input a BF program, followed by a "!", followed  by any input to the BF program.
BTW Since BrainFuck is turing-complete, this proves that LOLCode is too

I HAS A INSTRUCTIONS    BTW Array for BF instructions
I HAS A IPTR            BTW Pointer to first empty element in INSTRUCTIONS
LOL IPTR R 0
I HAS A LOOPZ            BTW Array of loop start/end addresses
I HAS A LOOPSTACKZ        BTW Loop stack for building the above two
I HAS A LSPTR            BTW Pointer to first empty element of LOOPSTACKZ
LOL LSPTR R 0

BTW Read in BF instructions, terminated with "!"
IM IN YR CODE
  GIMMEH LETTAR IPTR IN MAH INSTRUCTIONS
  
  IZ IPTR IN MAH INSTRUCTIONS LIEK "["?
    LOL LSPTR IN MAH LOOPSTACKZ R IPTR
    UPZ LSPTR!!
  KTHX
  
  IZ IPTR IN MAH INSTRUCTIONS LIEK "]"?
    I HAS A STARTPTR
    NERFZ LSPTR!!
    LOL STARTPTR R LSPTR IN MAH LOOPSTACKZ
    LOL STARTPTR IN MAH LOOPZ R IPTR
    LOL IPTR IN MAH LOOPZ R STARTPTR
  KTHX

  IZ IPTR IN MAH INSTRUCTIONS LIEK "!"?
    GTFO
  NOWAI
    UPZ IPTR!!
  KTHX    
KTHX

BTW Variables for BF's tape
I HAS A LTAPE
I HAS A RTAPE
I HAS A LPTR
LOL LPTR R 0
I HAS A RPTR
LOL RPTR R 0
I HAS A CELL
LOL CELL R 0

BTW Reset instruction pointer to start
LOL IPTR R 0

BTW Start interpreting
IM IN YR LOOP
  I HAS A THING
  LOL THING R IPTR IN MAH INSTRUCTIONS
  
  BTW Move tape head right
  IZ THING LIEK ">"?
    LOL LPTR IN MAH LTAPE R CELL
    UPZ LPTR!!
    IZ RPTR LIEK 0?
      LOL CELL R 0
    NOWAI
      NERFZ RPTR!!
      LOL CELL R RPTR IN MAH RTAPE
    KTHX
  KTHX
  
  BTW Move tape head left
  IZ THING LIEK "<"?
    LOL RPTR IN MAH RTAPE R CELL
    UPZ RPTR!!
    IZ LPTR LIEK 0?
      LOL CELL R 0
    NOWAI
      NERFZ LPTR!!
      LOL CELL R LPTR IN MAH LTAPE
    KTHX
  KTHX
  
  BTW Increment
  IZ THING LIEK "+"?
    UPZ CELL!!
  KTHX
  
  BTW Decrement
  IZ THING LIEK "-"?
    NERFZ CELL!!
  KTHX
  
  BTW Output produces numbers instead of ASCII characters
  IZ THING LIEK "."?
    VISIBLE CELL!
    VISIBLE " "!
  KTHX
  
  BTW Input doesn't work because we can't convert characters to integers
  BTW Oh well, it doesn't stop it being turing complete
  
  BTW Start of loop
  IZ THING LIEK "[" AND CELL LIEK 0?
    LOL IPTR R IPTR IN MAH LOOPZ
  KTHX
  
  BTW End of loop
  IZ THING LIEK "]" AND CELL NOT LIEK 0?
    LOL IPTR R IPTR IN MAH LOOPZ
  KTHX
  
  BTW End of program!
  IZ THING LIEK "!"?
    GTFO
  KTHX
  
  UPZ IPTR!!
KTHX
KTHXBYE

lolcode.net - .NET LOLCode compiler.

Offline

 

#2 2007-06-04 07:40:29

atl
BDFL
From: lolcode.com
Registered: 2007-05-31
Posts: 324
Website

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

Arachnid wrote:

Here's a BF interpreter written entirely in standard LOLCode. Since we don't have any way to convert characters to their ASCII values and vice-versa, output doesn't work as expected, and input doesn't work at all, but it still proves turing completeness!

Whoa.
If anyone else can verify this on an independent implementation, this is going straight to the front page and into the examples section.

Offline

 

#3 2007-06-04 09:07:53

antimatter
New member
Registered: 2007-06-02
Posts: 3

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

Wow.  I'm currently working on an interpreter, and this is a really awesome features test that helps me pinpoint what stuff I'm still missing.  Thanks a lot!

Offline

 

#4 2007-06-08 00:21:48

lolruby2
New member
Registered: 2007-06-07
Posts: 9

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

whoa... never saw that long of lolcode yet

is it working?

Offline

 

#5 2007-06-08 00:56:57

Arachnid
Member
Registered: 2007-06-02
Posts: 271

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

I've tested it on 'hello world'. It works that far, at least, and the language is so simple it ought to work on anything else. Just bear in mind that input doesn't do anything, and output prints ASCII codes instead of actual characters.


lolcode.net - .NET LOLCode compiler.

Offline

 

#6 2007-06-15 04:15:55

Ultra-Loser
Member
Registered: 2007-06-12
Posts: 16

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

It's official: After several hours of work, Arachnid's BF interpreter works in LMAO. This means that both the BF interpreter *and* LMAO are turing complete! Woot! Celebration time!

Offline

 

#7 2007-10-11 02:20:54

viraptor
Moderator
From: Bath / UK
Registered: 2007-08-15
Posts: 20
Website

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

LOLCODE v1.2 (+ BUKKIT) compatible BF interpreter
Takes one BF symbol per line of input. Erlol can run "hello world" from wikipedia and properly prints out numbers with this version!

Code:

HAI
BTW This is a BrainFuck interpreter written in LOLCode
BTW It accepts as input a BF program, followed by a "!", followed  by any input to the BF program.
BTW Since BrainFuck is turing-complete, this proves that LOLCode is too

I HAS A INSTRUCTIONS    BTW Array for BF instructions
I HAS A IPTR            BTW Pointer to first empty element in INSTRUCTIONS
IPTR R 0
I HAS A LOOPZ            BTW Array of loop start/end addresses
I HAS A LOOPSTACKZ        BTW Loop stack for building the above two
I HAS A LSPTR            BTW Pointer to first empty element of LOOPSTACKZ
LSPTR R 0

BTW Read in BF instructions, terminated with "!"
IM IN YR CODE
  GIMMEH IPTR IN MAH INSTRUCTIONS

  BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "[", O RLY?
    YA RLY
      LSPTR IN MAH LOOPSTACKZ R IPTR
      LSPTR R SUM OF LSPTR AN 1
  OIC

  BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "]", O RLY?
    YA RLY
      I HAS A STARTPTR
      LSPTR R DIFF OF LSPTR AN 1
      STARTPTR R LSPTR IN MAH LOOPSTACKZ
      STARTPTR IN MAH LOOPZ R IPTR
      IPTR IN MAH LOOPZ R STARTPTR
  OIC

  BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "!", O RLY?
    YA RLY
      GTFO
    NO WAI
      IPTR R SUM OF IPTR AN 1
  OIC
IM OUTTA YR CODE

BTW Variables for BF's tape
I HAS A LTAPE
I HAS A RTAPE
I HAS A LPTR
LPTR R 0
I HAS A RPTR
RPTR R 0
I HAS A CELL
CELL R 0

BTW Reset instruction pointer to start
IPTR R 0

BTW Start interpreting
IM IN YR LOOP
  I HAS A THING
  THING R IPTR IN MAH INSTRUCTIONS

  BTW Move tape head right
  BOTH SAEM THING AN ">", O RLY?
    YA RLY
      LPTR IN MAH LTAPE R CELL
      LPTR R SUM OF LPTR AN 1
      BOTH SAEM RPTR AN 0, O RLY?
        YA RLY
          CELL R 0
        NO WAI
          RPTR R DIFF OF RPTR AN 1
          CELL R RPTR IN MAH RTAPE
      OIC
  OIC

  BTW Move tape head left
  BOTH SAEM THING AN "<", O RLY?
    YA RLY
      RPTR IN MAH RTAPE R CELL
      RPTR R SUM OF RPTR AN 1
      BOTH SAEM LPTR AN 0, O RLY?
        YA RLY
          CELL R 0
        NO WAI
          LPTR R DIFF OF LPTR AN 1
          CELL R LPTR IN MAH LTAPE
      OIC
  OIC

  BTW Increment
  BOTH SAEM THING AN "+", O RLY?
    YA RLY
      CELL R SUM OF CELL AN 1
  OIC

  BTW Decrement
  BOTH SAEM THING AN "-", O RLY?
    YA RLY
      CELL R DIFF OF CELL AN 1
  OIC

  BTW Output produces numbers instead of ASCII characters
  BOTH SAEM THING AN ".", O RLY?
    YA RLY
      VISIBLE CELL!
      VISIBLE " "!
  OIC

  BTW Input doesn't work because we can't convert characters to integers
  BTW Oh well, it doesn't stop it being turing complete

  BTW Start of loop
  BOTH OF BOTH SAEM THING AN "[" AN BOTH SAEM CELL AN 0, O RLY?
    YA RLY
      IPTR R IPTR IN MAH LOOPZ
  OIC

  BTW End of loop
  BOTH OF BOTH SAEM THING AN "]" AN DIFFRINT CELL AN 0, O RLY?
    YA RLY
      IPTR R IPTR IN MAH LOOPZ
  OIC

  BTW End of program!
  BOTH SAEM THING AN "!", O RLY?
    YA RLY
      GTFO
  OIC

  IPTR R SUM OF IPTR AN 1
IM OUTTA YR LOOP
KTHXBYE

Offline

 

#8 2008-07-02 20:12:46

atl
BDFL
From: lolcode.com
Registered: 2007-05-31
Posts: 324
Website

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

O HAI, REDDIT!

This is pretty old news, but glad it raised the LOLs today.

Be sure to check the Main Site for more up-to-date news. This older blog entry gives an idea of what's happened in the past year.

Offline

 

#9 2008-07-08 21:22:58

zoransa
New member
Registered: 2008-07-08
Posts: 1
Website

Re: Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

you guys are simply AWESOME!

Offline

 
  • Index
  •  » MEWzings
  •  » Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson