def repl(input_: str = ''): print(""" ______ _ __ _ | ___ \ (_) / _| | | | |_/ /_ __ __ _ _ _ __ | |_ _ _ ___| | __ _ __ _ _ | ___ \ '__/ _` | | '_ \| _| | | |/ __| |/ / | '_ \| | | | | |_/ / | | (_| | | | | | | | |_| | (__| < _| |_) | |_| | \____/|_| \__,_|_|_| |_|_| \__,_|\___|_|\_(_) .__/ \__, | | | __/ | |_| |___/ Welcome to the Brainfuck interpreter :) Written in Python 3 by @franciscocid (on Github!) Repo: https://github.com/franciscocid/brainfuckpy """) while True: try: repl_code = input('Input: ') brain = Brainfuck() result = brain.run(repl_code, input_) print('Output:', result) except (EOFError, KeyboardInterrupt): print("...Exiting...") exit(0) except Exception as e: print(e) raise e
def __init__(self, mutationRate, crossoverRate, generationCnt, basePop, baseLen): self.mutationRate = mutationRate self.crossoverRate = crossoverRate self.generations = generationCnt self.bf = Brainfuck() self.symbols = ['+', '-', '>', '<', '.', '[', ']'] self.desiredOutput = "Hello Me!" self.sampleInput = [] self.basePop = basePop self.baseLen = baseLen
def setUp(self): self.bf = Brainfuck()
if args.log: if args.log == LOG_TO_STDOUT: logging.basicConfig(stream=sys.stdout, format='%(asctime)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) else: logging.basicConfig(filename='{}'.format(args.log), filemode='w', format='%(asctime)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) if not args.file: brainfuck = Brainfuck() while True: instructions = input('> ') brainfuck.interpret(instructions) print(brainfuck.memory) if args.file: brainfuck = Brainfuck( "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>123+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." ) try: brainfuck.run() except KeyboardInterrupt: pass
from brainfuck import Brainfuck from util.logger import setup_logs from repl import repl import argparse, logging arg_parser = argparse.ArgumentParser(prog='bf', description='Brainfuck VM') arg_parser.add_argument('source', nargs='?', help='Source file') arg_parser.add_argument('--input', nargs='*', help='Input text') arg_parser.add_argument('--log', action='store_true', help='Display logs on stdout') args = arg_parser.parse_args() if args.log: setup_logs() input_: str = ' '.join(args.input) if args.input else '' if args.source: logging.info('Loading from source: ' + args.source) brain = Brainfuck() with open(args.source, 'r') as f: result = brain.run(f.read(), input_=input_) print(result) else: logging.info('Setting up REPL...') repl(input_=input_)
from brainfuck import Brainfuck t1_code = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." print('-' * 125) print("Test 1: Hello World Program") print("Code:", t1_code) print("Result: ", end='') Brainfuck(t1_code) print('-' * 125)