-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removendo busca de codigo fonte na pasta 'code'
- Loading branch information
1 parent
05c8c69
commit 21a272b
Showing
3 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from tkinter import * | ||
from analizador_lexico import AnalizadorLexico | ||
|
||
class Application: | ||
|
||
analizador_lexico = None | ||
root = None | ||
container_esquerdo = None | ||
|
||
btn_analise = None | ||
txt = None | ||
|
||
items_result = [] | ||
|
||
def __init__(self, analizador_lexico: AnalizadorLexico): | ||
self.analizador_lexico = analizador_lexico | ||
|
||
def start(self): | ||
|
||
self.root = Tk() | ||
w, h = self.root.winfo_screenwidth(), self.root.winfo_screenheight() | ||
self.root.geometry("%dx%d+0+0" % (w, h)) | ||
|
||
self.root.update_idletasks() | ||
self.root.update() | ||
|
||
container_principal = Frame(self.root) | ||
container_principal["padx"] = 50 | ||
container_principal.pack() | ||
|
||
titulo = Label(container_principal, text="Analisador Léxico") | ||
titulo["font"] = ("Arial", "15", "bold") | ||
titulo.pack() | ||
|
||
container_direito = Frame(container_principal) | ||
container_direito["pady"] = 10 | ||
container_direito.pack(side=LEFT) | ||
|
||
container_meio = Frame(container_principal) | ||
container_meio["padx"] = 20 | ||
container_meio.pack(side=LEFT) | ||
|
||
container_esquerdo = Frame(container_principal) | ||
container_esquerdo["padx"] = 20 | ||
container_esquerdo.pack(side=LEFT) | ||
|
||
self.container_esquerdo = container_esquerdo | ||
|
||
self.txt = self.create_textarea(container_direito) | ||
|
||
self.btn_analise = Button(container_meio, text="Analisar >>>", fg="black", command=self.click_analisar) | ||
self.btn_analise.pack() | ||
|
||
self.create_grid(container_esquerdo, []) | ||
|
||
self.refresh() | ||
|
||
def refresh(self): | ||
self.root.update_idletasks() | ||
self.root.update() | ||
|
||
def create_textarea(self, container): | ||
scroll = Scrollbar(container) | ||
textarea = Text(container, height=50, width=80) | ||
|
||
scroll.pack(side=RIGHT, fill=Y) | ||
textarea.pack(side=LEFT, fill=Y) | ||
scroll.config(command=textarea.yview) | ||
textarea.config(yscrollcommand=scroll.set) | ||
|
||
return textarea | ||
|
||
def create_grid(self, container, tokens:list): | ||
# {'codigo': 19, 'token': 'dsadas', 'descricao': 'Identificador'} | ||
# {'codigo': 2, 'token': '=', 'descricao': 'Sinal de Igualdade'} | ||
# {'codigo': 19, 'token': 'dasdas', 'descricao': 'Identificador'} | ||
self.rows = [] | ||
|
||
for widget in self.items_result: | ||
widget.destroy() | ||
|
||
items = [] | ||
label = Label(container, text="Código") | ||
label["font"] = ("Arial", "11") | ||
label.grid(row=0, column=0) | ||
|
||
items.append(label) | ||
|
||
label = Label(container, text="Token") | ||
label["font"] = ("Arial", "11") | ||
label.grid(row=0, column=1) | ||
|
||
items.append(label) | ||
|
||
label = Label(container, text="Descrição") | ||
label["font"] = ("Arial", "11") | ||
label.grid(row=0, column=2) | ||
|
||
items.append(label) | ||
|
||
for i, token in enumerate(tokens): | ||
|
||
r = i + 1 | ||
|
||
for j, valor in enumerate(token): # Columns | ||
b = Entry(container) | ||
b.insert(0, token[valor]) | ||
items.append(b) | ||
b.grid(row=r, column=j) | ||
|
||
self.items_result = items | ||
|
||
def create_grid_erro(self, container, erro): | ||
|
||
self.rows = [] | ||
|
||
for widget in self.items_result: | ||
widget.destroy() | ||
|
||
items = [] | ||
label = Label(container, text=erro, fg="red") | ||
label["font"] = ("Arial", "11") | ||
label.grid(row=0, column=0) | ||
|
||
items.append(label) | ||
|
||
self.items_result = items | ||
|
||
|
||
def click_analisar(self): | ||
|
||
self.analizador_lexico.clear() | ||
|
||
code = self.txt.get("1.0", "end-1c") | ||
self.analizador_lexico.add_codigo('', code) | ||
|
||
try: | ||
tokens = self.analizador_lexico.analize() | ||
print(tokens) | ||
print('---------------------') | ||
self.create_grid(self.container_esquerdo, tokens) | ||
except Exception as e: | ||
self.create_grid_erro(self.container_esquerdo, e) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
from analizador_lexico import AnalizadorLexico | ||
import glob | ||
import time | ||
from interface import Application | ||
|
||
|
||
al = AnalizadorLexico() | ||
|
||
app = Application(al) | ||
|
||
for path_file in glob.glob("code/*.pas"): | ||
file = open(path_file, 'r') | ||
al.add_codigo(path_file, file.read()) | ||
# Abrindo diretamente o arquivos | ||
# for path_file in glob.glob("code/*.pas"): | ||
# file = open(path_file, 'r') | ||
# al.add_codigo(path_file, file.read()) | ||
|
||
al.analize() | ||
# al.analize() | ||
|
||
|
||
app.start() | ||
|
||
|
||
|
||
app.root.mainloop() | ||
|
||
time.sleep(3) | ||
|
||
|