猫史档案馆


【Python作品分享】Python编译器【作品秀】

用户:PlumStevenPlumSteven查看:0 回复:0 评论:0 创建时间:2021-09-05T13:03:09


【作品展示】

center_image

 

【作品介绍】

一个小小的编译器,暂时更新至input()函数

 

【作品源代码】

print('Python编译器')

program = []
variables = []
var_values = []

def input_code():
    print('输入代码,运行输入start')
    while True:
        line_program = input()        
        if line_program == 'start':
            break

        program.append(line_program)
def code():
    input_code()
    global i
    print('程序开始运行')
    for i in program:
        check_code()
def check_code():
    if 'print' in i:
        if '(' in i:
            if ')' in i:
                if i.count("'") == 2 or i.count('"') == 2:
                    print_content = i[7: len(i) - 2]
                    print(print_content)
                else:
                    if not i[6: len(i)].isdigit():
                        if i.count('.') == 1:
                            pass
                        else:
                            print("NameError: name '", i[6: len(i) - 1], "' is not defined")
            else:
                print('SyntaxError: unexpected EOF while parsing')
        else:
            if '(' not in i and ')' not in i:   
                if i.count("'") == 2:
                    print("SyntaxError: Missing parentheses in call to 'print'.Did you mean print (",  i[i.find("'"): len(i)], ')?')
                elif i.count('"') == 2:
                    print("SyntaxError: Missing parentheses in call to 'print'.Did you mean print (",  i[i.find('"'): len(i)], ')?')
                else:
                    print("SyntaxError: Missing parentheses in call to 'print'.Did you mean print (",  i[6: len(i)], ')?')
            else:
                print('SyntaxError: unexpected EOF while parsing')
    elif 'input' in i:
        if '(' in i:
            if ')' in i:
                input()
            else:
                print('SyntaxError: unexpected EOF while parsing')
        else:
            if ')' in i:
                print('SyntaxError: unexpected EOF while parsing')
    else:
        print("NameError: name '", i, "'is not defined")
code()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页