import abstract_types tokens_enum = ['global_res_word','context_res_word', 'res_symbol', 'identifier', 'string_type', 'int_type', 'float_type'] tokens = abstract_types.enum(tokens_enum) global_res_words_enum = ['var', 'if', 'while', 'for', 'print'] glob_res = abstract_types.enum(global_res_words_enum) context_res_words_enum = ['break', 'next', 'loop', 'else'] cont_res = abstract_types.enum(context_res_words_enum) global_res_symbols_enum = ['+', '-', '*', '/', '(', ')', '^', '%', 'EOF'] symb_res = abstract_types.enum(global_res_symbols_enum) token_type = abstract_types.record() token_type.infile = file('d:/source.bpl', 'r') token_type.cur_str = "" token_type.cur_str_len = 0 token_type.cur_line = 0 token_type.cur_pos = 0 token_type.type_of_token = tokens token_type.read_str = "" token_type.cap_str = "" token_type.int_val = 0 token_type.float_val = 0.0 token_type.glob_res_word = glob_res token_type.cont_res_word = cont_res token_type.res_sym = symb_res def is_delim(char): if ' ,;'.find(char) <> -1: return 1 return 0 def advance_token(token): token.cur_str = "" token.read_str = "" token.cap_str = "" while (token.cur_str[token.cur_pos] = " "): if token.cur_pos > token.cur_str_len: token.cur_str = token.infile.readline() token.cur_str_len = len(token.cur_str) token.cur_pos = 0 if not token.cur_str: token.type_of_token = 'RESERVED_SYMBOL' token.res_sym = 'EOF' read_str_idx = 0