Skip to content

ookcoder/ook-brainfuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Ook Brainfuck

Ook encoder written in Brainfuck.

A majority of the logic is duplicated so the final Brainfuck is generated by the encode-gen.rb script. There is a sample Brainfuck script in encode.bf.

Generator

ruby ./brainfuck-gen.rb "text to encode"

Draft Notes

# Reserves 5 registers at the start
>>>>>

# Input text
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Move to the first character
[<]>

[
  # start MATCHING_LOGIC

  # Set the logic registers
  < [-]  # Copy temp
  < [-]  # Copy working value
  < [-]  # Logic A set to 0 intiially and is set to one if partial match
  < [-]+ # Logic B set to 1 initially and is set to zero if no match
  < [-]+ # Unmatched set to 1 initially
  >>>>>

  # Moves value to the previous two registers
  [-<+<+>>]
  # Move value from behind to original cursor
  <[->+<]<

  # Detect the letter m
  ------------------------------------------------------------------------------------------------------------
  [
    <+
    >-
    [
      <<->>
      [-]
    ]
    <
    [
      <
      # If true, we found the character m
      [
        # Clear the registers for printing
        >[-]<[-]
        # Print the same character for now but OOKs should be printed here
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
        # Clear the unmatched register
        <
        [-]
        >
        # Break
        [-]
      ]
      >
      # Break
      [-]
    ]
    >
  ]
  # end MATCHING_LOGIC

  # start CONTINUATION_LOGIC
  <<<
  [
    # Unmatched if we enter here
    >>>>>

    # Repeat MATCHING_LOGIC here for remaining characters

    <<<
  ]
  >>>
  # end CONTINUATION_LOGIC

  # Move to next character
  >>>
]

# Print trailing k here

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published