def main(): # コマンドライン引数を取得 args = sys.argv # 関数定義 funcs = args[1] # 定数定義 defines = args[2] # 入力ファイル infile = args[3] # 出力ファイル outfile = args[4] # 字句解析する parser = MyParser(Lexer(LexerReader(infile)), funcs, defines) # 構文解析する parser.parse(outfile)
while (True): # prompt user for input file name input_file = input( 'Input file name [Press \'Enter\' to user default - input.txt]: ') # check if blank, change to default if (input_file == ''): input_file = 'input.txt' if (os.path.isfile(input_file)): break else: print('ImportError: could not find file', input_file) print('Found file', input_file) # open file and read all lines (removing any '\n' chars) with open(input_file, 'r') as open_file: lines = open_file.readlines() # parse the text to generate stack code parser = MyParser(print_tree, time_parse) output = parser.parse(lines) if (output != None): print('Finished parsing with no errors.') # print output print('\nPrinting generated output:') for node in output: print(node)