Colab(Python) Korean Interpreter Language
翻译'%20fill-opacity='.8'%20d='M3.256%203.913a3.083%203.083%200%200%200-.003%204.397L8%2012.998l4.743-4.684a3.085%203.085%200%200%200%20.001-4.4c-.6-.593-1.4-.914-2.233-.914a3.17%203.17%200%200%200-1.91.635L8%204.087l-.601-.452A3.17%203.17%200%200%200%205.489%203c-.834%200-1.634.321-2.233.913m10.19%205.111-4.748%204.69a.996.996%200%200%201-1.397%200L2.549%209.02a4.083%204.083%200%200%201%20.004-5.82A4.17%204.17%200%200%201%205.488%202c.907%200%201.787.29%202.512.835A4.17%204.17%200%200%201%2010.51%202c1.093%200%202.146.422%202.936%201.202a4.085%204.085%200%200%201%200%205.822'%20/%3e%3c/svg%3e)

| # https://gist.github.com/Name-hw/19e735823ae892d22f513e34ee38f49c | |
| code = """ | |
| # 변수는 최대 10개까지 사용 가능 | |
| 변수1 = 1 | |
| 변수2 = 22 | |
| 변수3 = 333 | |
| 변수7 = 7777 | |
| 변수불러오기도함 = 변수7 | |
| 덧셈도하는변수 = 1 + 7 + 54 + 100 | |
| 변수끼리덧셈도함 = 변수7 + 변수1 + 변수2 + 10000 | |
| 뺄셈도하는변수 = 100 - 23 | |
| 변수끼리뺄셈도함 = 변수7 - 변수1 - 변수2 - 1 | |
| 덧셈뺄셈둘다가능 = 10000 - 변수2 + 변수1 + 1000 | |
| # 주석도 구현됨 | |
| 출력(1, 234, 321, 4444) | |
| 출력() | |
| 출력(변수1, 변수2, 변수3, 변수7) | |
| 출력(변수불러오기도함) | |
| 출력() | |
| 출력(덧셈도하는변수, 변수끼리덧셈도함) | |
| 출력(뺄셈도하는변수, 변수끼리뺄셈도함) | |
| 출력() | |
| 출력(덧셈뺄셈둘다가능) | |
| 출력() | |
| 출력(1, 변수1, 2, 변수2, 3, 변수3) # 숫자와 변수 동시 출력 가능 | |
| 출력() | |
| 변수1 = 100 # 변수 다시 선언 가능 | |
| 변수2 = 200 | |
| 변수3 = 300 | |
| 변수7 = 700 | |
| 출력(1, 변수1, 2, 변수2, 3, 변수3) # 숫자와 변수 동시 출력 가능 | |
| """ | |
| changedCode = "" | |
| isAppendable = False # changedCode 만들 때 변수 이름 변경 확인 | |
| rawVariableNames = [] | |
| isAssignment = False # 대입 확인 ('=' 존재 확인) | |
| isAdd = False # +기호 확인 | |
| isSub = False # -기호 확인 | |
| isFunction = False # 함수 확인 | |
| isComment = False # 주석 확인 | |
| isVarSearching = False # 변수 탐색 확인 | |
| tempStr = "" | |
| ################################################################################ | |
| for i in range(len(code)): # changedCode는 띄어쓰기 삭제, 변수 이름 변경, 주석 삭제함 | |
| char = code[i] | |
| if char == "\n": | |
| if isVarSearching: | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx != -1: | |
| tempStr = "V" + str(varIdx) | |
| isVarSearching = False | |
| else: | |
| tempStr = "" | |
| isAppendable = True | |
| isAssignment = False | |
| isAdd = False | |
| isSub = False | |
| isFunction = False | |
| isComment = False | |
| else: | |
| if char == " " or isComment: | |
| continue | |
| if char == "=": # 변수 이름 생성 | |
| if isVarSearching: | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx != -1: | |
| tempStr = "V" + str(varIdx) | |
| else: | |
| rawVariableNames.append(tempStr) | |
| tempStr = "V" + str(len(rawVariableNames) - 1) | |
| isAppendable = True | |
| isAssignment = True | |
| isVarSearching = False | |
| elif char == "+": | |
| if isVarSearching: | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx != -1: | |
| tempStr = "V" + str(varIdx) | |
| isAdd = True | |
| isAppendable = True | |
| isVarSearching = False | |
| elif char == "-": | |
| if isVarSearching: | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx != -1: | |
| tempStr = "V" + str(varIdx) | |
| isSub = True | |
| isAppendable = True | |
| isVarSearching = False | |
| elif char == "(": | |
| isFunction = True | |
| isAppendable = True | |
| isVarSearching = False | |
| elif char == ")": | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx == -1: | |
| isVarSearching = True | |
| else: | |
| tempStr = "V" + str(varIdx) | |
| isAppendable = True | |
| isVarSearching = False | |
| isFunction = False | |
| isAppendable = True | |
| isVarSearching = False | |
| elif char == ',': | |
| if isVarSearching: | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx != -1: | |
| tempStr = "V" + str(varIdx) | |
| isAppendable = True | |
| isVarSearching = False | |
| elif char == "#": | |
| isComment = True | |
| continue | |
| else: | |
| if not isAssignment: | |
| isVarValue = False | |
| isVarSearching = False | |
| varIdx = -1 | |
| for idx in range(len(rawVariableNames)): | |
| if rawVariableNames[idx] == tempStr: | |
| varIdx = idx | |
| if varIdx == -1: | |
| isVarSearching = True | |
| else: | |
| tempStr = "V" + str(varIdx) | |
| isAppendable = True | |
| isVarSearching = False | |
| tempStr += char | |
| if isAppendable and not isVarSearching: | |
| isAppendable = False | |
| isVarSearching = False | |
| changedCode += tempStr | |
| tempStr = "" | |
| # print(changedCode) | |
| ################################################################################ | |
| variableValues = [] | |
| while len(variableValues) < len(rawVariableNames): # variableValues가 알맞게 채워지지 않는 것은 AI 도움받음 (미리 0으로 설정) | |
| variableValues.append(0) | |
| isEntered = False # 딱히 사용 안함 | |
| # 변수 관련 상태 | |
| isVariable = False # 변수 확인 ('V' 확인) | |
| isVarSearching = False # 변수 찾기 ('V' 뒤 변수 인덱스 확인) | |
| # 연산 관련 상태 | |
| isOperation = False | |
| isAssignment = False # 대입 확인 ('=' 존재 확인) | |
| isAdd = False # +기호 확인 | |
| isSub = False # -기호 확인 | |
| isFunction = False # 함수 확인 | |
| isComment = False # 주석 확인 | |
| tempStr = "" | |
| tempVarIdx1 = 0 # 사칙연산(대입) 시 변수 인덱스 (주로 씀) | |
| tempVarIdx2 = 0 # 사칙연산(대입) 시 변수 인덱스 (필요할 때만) | |
| tempVarValue = "" | |
| temp1 = "0" # 사칙연산 시 왼쪽 값 | |
| temp2 = "0" # 사칙연산 시 오른쪽 값 | |
| tempArgs = [] | |
| tempArg = "" | |
| for i in range(len(changedCode)): | |
| char = changedCode[i] | |
| # print(i, char) | |
| if char == "\n": | |
| if isAssignment: | |
| variableValues[tempVarIdx1] = tempVarValue | |
| isEntered = True | |
| isVariable = False | |
| isVarSearching = False | |
| isOperation = False | |
| isAssignment = False | |
| isAdd = False | |
| isSub = False | |
| isFunction = False | |
| isComment = False | |
| tempStr = "" | |
| tempVarIdx1 = 0 | |
| tempVarIdx2 = 0 | |
| tempVarValue = "" | |
| temp1 = "0" | |
| temp2 = "0" | |
| tempArgs = [] | |
| tempArg = "" | |
| continue | |
| else: | |
| isEntered = False | |
| if char == " " or isComment: | |
| continue | |
| # 조건문으로 특수 기호 판별하고, 현재 행의 상태 변경 | |
| if char == "=": # 변수 이름 생성 | |
| isVariable = False | |
| isOperation = True | |
| isAssignment = True | |
| elif char == "+": | |
| temp1 = tempVarValue | |
| temp2 = "0" | |
| tempVarValue = "" | |
| isVariable = False | |
| isOperation = True | |
| isAdd = True | |
| isSub = False | |
| elif char == "-": | |
| temp1 = tempVarValue | |
| temp2 = "0" | |
| tempVarValue = "" | |
| isVariable = False | |
| isOperation = True | |
| isAdd = False | |
| isSub = True | |
| elif char == "(": | |
| isFunction = True | |
| elif char == ")": | |
| if isFunction: | |
| tempArgs.append(tempArg) | |
| if tempStr == "출력": # 반복문을 사용하여 변수 이름으로 변수의 값을 찾는 부분은 AI 도움받음 | |
| for i in range(len(tempArgs)): | |
| tempArg = tempArgs[i] | |
| if i == len(tempArgs)-1: | |
| print(tempArg) | |
| else: | |
| print(tempArg, end=" ") | |
| isFunction = False | |
| elif char == "#": | |
| isComment = True | |
| elif char == "V": | |
| isVarSearching = True | |
| else: | |
| if isVarSearching: # char은 'V' 뒤 숫자 | |
| if not isOperation and not isFunction: | |
| tempVarIdx1 = int(char) | |
| else: | |
| tempVarIdx2 = int(char) | |
| isVariable = True | |
| isVarSearching = False | |
| if isFunction: | |
| if char == ",": | |
| tempArgs.append(tempArg) | |
| tempArg = "" | |
| isVariable = False # tempArg가 값, 변수 둘 다 되도록 구현할 때 상태 버그는 AI 도움받음 | |
| else: | |
| if isVariable: | |
| tempArg += str(variableValues[tempVarIdx2]) | |
| else: | |
| tempArg += char | |
| elif isComment: | |
| continue | |
| else: | |
| tempStr += char | |
| if isOperation: | |
| if isAssignment: | |
| if isVariable: | |
| tempVarValue = variableValues[tempVarIdx2] | |
| if isAdd: | |
| if isVariable: | |
| tempVarValue = str(int(temp1) + int(variableValues[tempVarIdx2])) | |
| isVariable = False | |
| else: | |
| temp2 += char | |
| tempVarValue = str(int(temp1) + int(temp2)) | |
| isVariable = False | |
| elif isSub: | |
| if isVariable: | |
| tempVarValue = str(int(temp1) - int(variableValues[tempVarIdx2])) | |
| isVariable = False | |
| else: | |
| temp2 += char | |
| tempVarValue = str(int(temp1) - int(temp2)) | |
| isVariable = False | |
| elif not isVariable: | |
| tempVarValue += char | |
| # for i in range(len(variableNames)): | |
| # varName = variableNames[i] | |
| # varValue = variableValues[i] | |
| # print(varName, varValue) |
参与讨论