本文整理汇总了Python中grammar.Grammar.convertGtoAF方法的典型用法代码示例。如果您正苦于以下问题:Python Grammar.convertGtoAF方法的具体用法?Python Grammar.convertGtoAF怎么用?Python Grammar.convertGtoAF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grammar.Grammar
的用法示例。
在下文中一共展示了Grammar.convertGtoAF方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inicia
# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import convertGtoAF [as 别名]
def inicia(self):
case = 0
lex = Lex()
# # 1 ER PALAVRAS RESERVADAS
a1 = lex.lexer('reservado', case)
dict = a1.getDictAutomato()
case += len(dict)
# # 2 ER IDENTIFICADORES
a2 = lex.lexer('identificadores', case)
# # 3 GRAMATICA DE SESPECIAL
terminais = ['+', '-', '=', '/', '*', '>', '<', '!']
nTerminais = ['S']
producoes = {'S': ['+', '-', '=', '/', '*', '>', '<', '!']}
inicial = 'S'
g = Grammar(producoes,terminais, nTerminais, inicial)
s, i, f = g.convertGtoAF()
a3 = Automato(s, i, f)
a3.determina()
a3.printAtomato()
print("\n")
dict = a2.getDictAutomato()
case += len(dict)
a3 = lex.renameState(a3, case)
# # 4 GRAMATICA SEPARADORES
terminais2 = [':',';', ' ', '(', ')', '[', ']', ',', '\n']
nTerminais2 = ['S']
producoes2 = {'S': [':',';', ' ', '(', ')', '[', ']', ',', '\n']}
inicial2 = 'S'
g = Grammar(producoes2,terminais2, nTerminais2, inicial2)
s2, i2, f2 = g.convertGtoAF()
a4 = Automato(s2, i2, f2)
a4.determina()
a4.printAtomato()
print("\n")
dict = a3.getDictAutomato()
case += len(dict)
a4 = lex.renameState(a4, case)
# ER CONSTANTES
dict = a4.getDictAutomato()
case += len(dict)
a5 = lex.lexer('constantes', case)
r = a5
r = a1.oU([a2, a3, a4, a5])
print ("\n")
r.determina()
r.printAtomato()
with open('automato.pkl', 'wb') as output:
pickle.dump(r, output, pickle.HIGHEST_PROTOCOL)
示例2: gramaticaAutomato
# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import convertGtoAF [as 别名]
def gramaticaAutomato(input):
input = entrytext.get()
l = LeitorG(input)
dict, termi,nonter,ini = l.ler()
g = Grammar(dict,termi,nonter,ini)
s, inicial, final = g.convertGtoAF()
a = Automato(s,inicial,final)
a.printAtomato()
a.writeAutomataToFile(input)
input = input.replace('.in', '')
data_file = open('../testes/'+input+'.out')
data = data_file.read()
data_file.close()
test = Tk.Tk()
Results = Tk.Label(test, text = data)
Results.grid(row = 20, column = 3, sticky= Tk.W)