用于编译原理作业,已经通过编译,用的是文件的输入输出形式,如果有需要可以自己改成终端输入输出形式。
class WORD(object):
def __init__(self, typenum, word):
self.typenum = typenum
self.word = word
str_input = ""
rwtab = ["begin", "end", "do", "if", "then", "while"]
ch = ""
p_input = 0
p_token = 0
def getchar():
global ch, p_input
# print("input:%d" % p_input)
ch = str_input[p_input]
p_input += 1
return ch
# 去掉空格
def delete_blank():
global ch, p_input
while ch == " " or ch == 10:
ch = str_input[p_input]
p_input += 1
def concat(str1):
global ch
str1 += ch
return str1
def letter():
if ('a' <= ch <= 'z') or ('A' <= ch <= 'Z'):
return True
else:
return False
d