import sys

def interpreter(args:list):
    #print(args)
    if len(args) <= 1:
        return 1
    if not args[1].endswith('.bf'):
        return 2

    try:
        file = open(args[1], 'r')
    except FileNotFoundError:
        return 3
    
    cells = [0]
    loop = []
    output = []
    characters = []
    print(len(cells))
    currentCell = 1
    #print(file.readlines())

    for line in file.readlines():
        for character in line:
            characters.append(character)
    for i in range(len(characters)):
        #print(character)
        if characters[i] == '+':
            if(cells[currentCell-1] == 255):    
                cells[currentCell-1] = 0
            else:
                cells[currentCell-1] += 1
        if characters[i] == '-':
            if(cells[currentCell-1] == 0):    
                cells[currentCell-1] = 255
            else:
                cells[currentCell-1] -= 1
        if characters[i] == '<':
            currentCell -= 1
        if characters[i] == '>':
            currentCell += 1
            if currentCell > len(cells):
                cells.append(0)
                #print(len(cells))
        if characters[i] == '[':
            if(currentCell == 0):
                i = loop[len(loop)-1][1]
                currentCell = loop[len(loop)-1][1]
            else:
                loop.append([currentCell,0])
        if characters[i] == ']':
            if(currentCell != 0):
                loop[len(loop)-1][1] = currentCell
                cells[currentCell-1] -= 1
                i = loop[len(loop)-1][0] + 1
                currentCell = loop[len(loop)-1][0] + 1
            else:
                loop.pop()
            print("LOOPS")
            print(loop)
        if characters[i] == '.':
            output.append(chr(cells[currentCell-1] + 65))
        #print(character)
        #print(cells)
    print(cells, end='\n')
    print(output)
                
    return 0

if __name__=='__main__':
    case = interpreter(sys.argv)
    if case  == 0:
        print('Success')
    elif case == 1:
        print('No file given.')
    elif case == 2:
        print('Wrong file type.')
    elif case == 3:
        print('Given file not found.')
    
import sys

def interpreter(args:list):
    #print(args)
    if len(args) <= 1:
        return 1
    if not args[1].endswith('.bf'):
        return 2

    try:
        file = open(args[1], 'r')
    except FileNotFoundError:
        return 3
    
    cells = [0]
    loop = []
    output = []
    characters = []
    print(len(cells))
    currentCell = 1
    #print(file.readlines())

    for line in file.readlines():
        for character in line:
            characters.append(character)
    for i in range(len(characters)):
        #print(character)
        if characters[i] == '+':
            if(cells[currentCell-1] == 255):    
                cells[currentCell-1] = 0
            else:
                cells[currentCell-1] += 1
        if characters[i] == '-':
            if(cells[currentCell-1] == 0):    
                cells[currentCell-1] = 255
            else:
                cells[currentCell-1] -= 1
        if characters[i] == '<':
            currentCell -= 1
        if characters[i] == '>':
            currentCell += 1
            if currentCell > len(cells):
                cells.append(0)
                #print(len(cells))
        if characters[i] == '[':
            if(currentCell == 0):
                i = loop[len(loop)-1][1]
                currentCell = loop[len(loop)-1][1]
            else:
                loop.append([currentCell,0])
        if characters[i] == ']':
            if(currentCell != 0):
                loop[len(loop)-1][1] = currentCell
                cells[currentCell-1] -= 1
                i = loop[len(loop)-1][0] + 1
                currentCell = loop[len(loop)-1][0] + 1
            else:
                loop.pop()
            print("LOOPS")
            print(loop)
        if characters[i] == '.':
            output.append(chr(cells[currentCell-1] + 65))
        #print(character)
        #print(cells)
    print(cells, end='\n')
    print(output)
                
    return 0

if __name__=='__main__':
    case = interpreter(sys.argv)
    if case  == 0:
        print('Success')
    elif case == 1:
        print('No file given.')
    elif case == 2:
        print('Wrong file type.')
    elif case == 3:
        print('Given file not found.')
    
#print(args) #print(file.readlines()) #print(character) #print(len(cells)) #print(character) #print(cells)