def main(): if (len(sys.argv) < 2): print("ERRO - Por Favor Informe Um Arquivo .tpp") else: file = open(sys.argv[1], 'r', encoding='utf-8') sin = Sintatica(file.read(), Lexica().tokens) dot = Digraph(comment='TREE') Tree().printTree(sin.ast, dot) #dot.render('out/sintatica/normal.gv', view=True) Tree().poda(sin.ast) dot = Digraph(comment='TREE') Tree().printTreeCut(sin.ast, dot) #dot.render('out/semantica/poda.gv', view=True) sema = Semantica() sema.percorrerTree(sin.ast) sema.verificacoes() #sema.printTabSymbols() llvm.initialize() llvm.initialize_all_targets() llvm.initialize_native_target() llvm.initialize_native_asmparser() modulo = ir.Module(sys.argv[1]) modulo.triple = llvm.get_process_triple() target = llvm.Target.from_triple(modulo.triple) targetMachine = target.create_target_machine() modulo.data_layout = targetMachine.target_data Geracao().percorrer(sin.ast, modulo) arquivo = open('teste.ll', 'w') arquivo.write(str(modulo)) arquivo.close() print(modulo)
def __init__(self, code): lex = Lexica() self.tokens = lex.tokens self.precedence = ((('left', 'IGUALDADE', 'NEGACAO', 'MENOR_IGUAL', 'MAIOR', 'MAIOR_IGUAL', 'MENOR'), ('left', 'SOMA', 'SUBTRACAO'), ('left', 'MULTIPLICACAO', 'DIVISAO'))) parser = yacc.yacc(debug=True, module=self, optimize=False) self.ast = parser.parse(code)
def __init__(self, code): lexer = Lexica() self.tokens = lexer.tokens self.precedence = ( ('left', 'IGUAL', 'MAIOR_IGUAL', 'MAIOR', 'MENOR_IGUAL', 'MENOR'), ('left', 'MAIS', 'MENOS'), ('left', 'MULTIPLICACAO', 'DIVISAO'), ) parser = yacc.yacc(debug=False, module=self, optimize=False) self.ast = parser.parse(code)
def main(): if (len(sys.argv) < 2): print("ERRO - Por Favor Informe Um Arquivo .tpp") else: try: lexer = Lexica() lexer.readFile(sys.argv[1]) lexer.printTokens() except: print( "ERRO - Nao Foi Possivel Executar a Função, Por Favor Tente Novamente" )
def main(): if (len(sys.argv) < 2): print("ERRO - Por Favor Informe Um Arquivo .tpp") else: try: file = open(sys.argv[1], 'r', encoding='utf-8') arvore = Sintatica(file.read(), Lexica().tokens) w = Digraph('G', filename='out/teste.gv') Tree().printTree(arvore.ast, '', '', w, i=0) w.view() except Exception as e: print(e) print( "ERRO - Nao Foi Possivel Executar a Funcao, Por Favor Tente Novamente" )
def main(): if(len(sys.argv) < 2): print("ERRO - Por Favor Informe Um Arquivo .tpp") else: file = open(sys.argv[1], 'r', encoding='utf-8') sin = Sintatica(file.read(), Lexica().tokens) #dot = Digraph(comment='TREE') #Tree().printTree(sin.ast, dot) #dot.render('out/sintatica/normal.gv', view=True) Tree().poda(sin.ast) #dot = Digraph(comment='TREE') #Tree().printTreeCut(sin.ast, dot) #dot.render('out/semantica/poda.gv', view=True) sema = Semantica() sema.percorrerTree(sin.ast) sema.verificacoes()
# Yacc example import ply.yacc as yacc import sys # Get the token map from the lexer. This is required. from lexica import Lexica lexica = Lexica() tokens = lexica.tokens def p_expression_plus(p): 'expression : expression MAIS term' p[0] = p[1] + p[3] def p_expression_minus(p): 'expression : expression MENOS term' p[0] = p[1] - p[3] def p_expression_term(p): 'expression : term' p[0] = p[1] def p_term_times(p): 'term : term MULTIPLICACAO factor' p[0] = p[1] * p[3] def p_term_div(p): 'term : term DIVISAO factor' p[0] = p[1] / p[3]