-
Notifications
You must be signed in to change notification settings - Fork 7
Primera entrega: Implementación de analizador de fórmulas tipo Excel #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SantiagoAvila21
wants to merge
5
commits into
ACMUD:master
Choose a base branch
from
JuanMosqueraUD:feature/analisis-lexico
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a8f422
Clases Base para analisis léxico de expresiones regulares
JuanMosqueraUD 88f81f9
base de clases para analisis léxico
JuanMosqueraUD de8f8cf
feat: corregido constructor y funciones de parsing
felipeabril520 0aa0823
Doc: README.md logic.py
SantiagoAvila21 173df7b
docs: docstrings de la primera funcionalidad
JuanMosqueraUD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| # 🧮 Archivo: `logic.py` | ||
|
|
||
| Este archivo implementa una clase llamada `Logic` en Python, la cual sirve como un **intérprete básico de expresiones tipo Excel**. Su propósito es descomponer una fórmula dada en sus partes fundamentales: funciones, constantes, referencias a celdas y rangos. | ||
|
|
||
| --- | ||
|
|
||
| ## ✨ Funcionalidad del archivo | ||
|
|
||
| Al ejecutar el script, el usuario puede ingresar una fórmula por consola (por ejemplo: `=SUMA(1,A1,B2:B5)`), y el programa identificará automáticamente: | ||
|
|
||
| - Funciones utilizadas (`SUMA`) | ||
| - Números constantes (`1`) | ||
| - Referencias a celdas individuales (`A1`) | ||
| - Rangos de celdas (`B2:B5`) | ||
|
|
||
| --- | ||
|
|
||
| ## 📌 Estructura del código | ||
|
|
||
| El archivo contiene: | ||
|
|
||
| ### Clase: `Logic` | ||
|
|
||
| | Método | Función | | ||
| |---------------------|-------------------------------------------------------------------------| | ||
| | `__init__` | Inicializa la expresión y prepara los contenedores | | ||
| | `funcionesFun()` | Extrae los nombres de funciones usando expresiones regulares | | ||
| | `constantesFun()` | Detecta constantes numéricas en la expresión | | ||
| | `referenciasFun()` | Identifica celdas individuales y rangos, evitando duplicación | | ||
| | `imprimirCadenaFun()`| Muestra los resultados si la fórmula es válida | | ||
| | `clasificacionFun()` | Ejecuta el análisis completo si la cadena inicia con `=` | | ||
|
|
||
| ### Interfaz por consola | ||
|
|
||
| Un bucle `while` al final del archivo permite al usuario probar expresiones hasta ingresar una válida (que comience con `=`). | ||
|
|
||
| --- | ||
|
|
||
| ## ▶️ Cómo ejecutar | ||
|
|
||
| ```bash | ||
| python logic_interpreter.py |
This file contains hidden or 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,79 @@ | ||
| import re | ||
|
|
||
| # El interprete de las expresiones brindadas | ||
| class Logic: | ||
| def __init__(self, texto): | ||
| self.texto = texto.strip() | ||
| self.division = "" | ||
| self.constantes = [] | ||
| self.funciones = [] | ||
| self.referencias = [] | ||
| self.rangos = [] | ||
| self.value = False | ||
|
|
||
| def funcionesFun(self): | ||
| try: | ||
| formula = self.division[1].upper() # Normalizar a mayúsculas | ||
| pattern = r"\b([A-Z]+)\s*\(" | ||
| self.funciones = re.findall(pattern, formula) | ||
| except IndexError: | ||
| print("No se encontró ninguna función") | ||
| except Exception as e: | ||
| print(f"Error en funciones: {e}") | ||
|
|
||
| def constantesFun(self): | ||
| try: | ||
| formula = self.division[1] | ||
| pattern = r'[-+]?\b\d+(?:\.\d+)?\b' | ||
| self.constantes = re.findall(pattern, formula) | ||
| except IndexError: | ||
| print("No se encontró ninguna constante") | ||
| except Exception as e: | ||
| print(f"Error en constantes: {e}") | ||
|
|
||
| def referenciasFun(self): | ||
| try: | ||
| formula = self.division[1].upper() | ||
| # Detectar rangos como A1:B34 | ||
| self.rangos = re.findall(r'\b[A-Z]{1,3}[1-9][0-9]{0,4}:[A-Z]{1,3}[1-9][0-9]{0,4}\b', formula) | ||
| # Detectar referencias simples (excluyendo las que ya están en rangos) | ||
| todas = re.findall(r'\b[A-Z]{1,3}[1-9][0-9]{0,4}\b', formula) | ||
| partes_de_rangos = [celda for r in self.rangos for celda in r.split(":")] | ||
| self.referencias = [ref for ref in todas if ref not in partes_de_rangos] | ||
| except Exception as e: | ||
| print(f"Error en referencias: {e}") | ||
|
|
||
| def imprimirCadenaFun(self): | ||
| if self.value: | ||
| print("\n--- Resultado ---") | ||
| print(f"Funciones encontradas: {self.funciones}") | ||
| print(f"Constantes encontradas: {self.constantes}") | ||
| print(f"Referencias individuales: {self.referencias}") | ||
| print(f"Rangos detectados: {self.rangos}") | ||
| print("------------------\n") | ||
| else: | ||
| print("No puedes imprimir nada. La fórmula no empieza con '='.") | ||
|
|
||
| def clasificacionFun(self): | ||
| if "=" in self.texto: | ||
| self.value = True | ||
| else: | ||
| print("❌ La fórmula no contiene '='.") | ||
| return | ||
|
|
||
| try: | ||
| self.division = self.texto.split("=", maxsplit=1) | ||
| self.funcionesFun() | ||
| self.constantesFun() | ||
| self.referenciasFun() | ||
| self.imprimirCadenaFun() | ||
| except Exception as e: | ||
| print(f"Ocurrió un error general: {e}") | ||
|
|
||
| # Parte para hacer el test | ||
| while True: | ||
| test = input("Ingrese su expresión a valorar (ej: =SUMA(1,A1,B2:B5)): ") | ||
| prueba = Logic(test) | ||
| prueba.clasificacionFun() | ||
| if prueba.value: | ||
| break | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si esto es un test, debe ir en tests, no en src, porque cuando sea importado el modulo se ejecutará este código, que adicionalmente es bloqueante.
Usa pytest para poder acceder facilmente a src.
y luego en terminal