diff --git a/labs/01/example_graph.png b/labs/01/example_graph.png new file mode 100644 index 0000000..36abdd9 Binary files /dev/null and b/labs/01/example_graph.png differ diff --git a/labs/01/practica1.py b/labs/01/practica1.py new file mode 100644 index 0000000..73908db --- /dev/null +++ b/labs/01/practica1.py @@ -0,0 +1,74 @@ +#José Guerrero A01285612 +#8 de enero del 2024 + +from graphviz import Digraph + +# Creamos el objeto de Graphviz +dot = Digraph() + +#Funcion para verificar si el set es reflexivo +def is_reflexive(set): + for element in set: + #Por elemento(secuencia) en el set, creamos una secuencia con el elemento 0 y el elemento 0 para buscar los pares + #en el set ej.- (0,0) (1,1) (2,2) (3,3) + if (element[0], element[0]) not in set: #Si no se encuentra el par, regresa False + return False + else: + pass + #Si sale del loop, regresa True + return True + + +#Funcion para verificar si el set es simetrico +def is_symmetric(set): + for element in set: #Por cada secuencia en el set + #Creamos una secuencia para buscar el opuesto del elemento + if (element[1], element[0]) not in set: + #Si no se encuentra el opuesto, regresa False + return False + else: + #Si se encuentra, pasa al siguiente elemento + pass + #Si sale del loop, regresa True + return True + + +#Funcion para verificar si el set es transitivo +def is_transitive(set): + #Por cada secuencia en el set + for element in set: + #Agarramos una segunda secuencia para buscar el opuesto del elemento + for element2 in set: + #Si el segundo elemento de la primera secuencia es igual al primer elemento de la segunda secuencia + if element[1] == element2[0]: + #Creamos secuencia de elemento[0] y elemento2[1] para buscar si esta en el set + if (element[0], element2[1]) not in set: + return False + return True + +# Set a verificar +set = {(0,0), (0,1), (0,3), (1,0), (1,1), (2,2), (3,0), (3,3)} + +# Llamamos a las funciones y las imprimimos +print("Reflexive:", is_reflexive(set)) +print("Symmetric:", is_symmetric(set)) +print("Transitive:", is_transitive(set)) + +#-------------------------GRAPHVIZ-------------------------# + +# Metodos para usar Graphviz +dot.attr(rankdir='LR') +dot.attr('node', shape='circle') + +#Creamos los nodos +dot.edge('0', '0') +dot.edge('0', '1') +dot.edge('0', '3') +dot.edge('1', '0') +dot.edge('1', '1') +dot.edge('2', '2') +dot.edge('3', '0') +dot.edge('3', '3') + +#Renderizamos la imagen +dot.render('example_graph', format='png', cleanup=True) diff --git a/labs/03/act3.l b/labs/03/act3.l new file mode 100644 index 0000000..561f586 --- /dev/null +++ b/labs/03/act3.l @@ -0,0 +1,23 @@ +%{ +#include "y.tab.h" +#include +#include +#include +%} + + + +%% + +a|the {return ARTICLE;} +boy|girl|flower {return NOUN;} +touches|likes|sees {return VERB;} +with {return PREP;} + +[ \t]+ +<> { return 0; } +\n + +. + +%% \ No newline at end of file diff --git a/labs/03/act3.y b/labs/03/act3.y new file mode 100644 index 0000000..c8b89ee --- /dev/null +++ b/labs/03/act3.y @@ -0,0 +1,63 @@ +%{ +#include +#include +#include +#include "y.tab.h" + +extern int wwlex(); /* Use wwlex instead of yylex */ +extern void yyerror(const char* s); + +int line_number = 1; + +%} + +%token ARTICLE NOUN VERB PREP + +%% +sentence : noun_phrase verb_phrase { printf("PASS\n"); } + ; + +noun_phrase : cmplx_noun { } + | cmplx_noun prep_phrase { } + ; + +verb_phrase : cmplx_verb { } + | cmplx_verb prep_phrase { } + ; + +prep_phrase : PREP cmplx_noun { } + ; + +cmplx_noun : ARTICLE NOUN { } + ; + +cmplx_verb : VERB { } + | VERB noun_phrase { } + ; + + + +%% + +void yyerror(const char* s) { + fprintf(stderr, "Error at line %d: %s\n", line_number, s); +} + +int main(int argc, char **argv) { + if (argc == 2) { + FILE *yyin = fopen(argv[1], "r"); + if (!yyin) { + fprintf(stderr, "Error opening file: %s\n", strerror(errno)); // File opening error + return 1; // Return non-zero, indicates an error + } + + yyparse(); // Parse the input file + fclose(yyin); // Closes the file + + } else { + fprintf(stderr, "Usage: %s filename\n", argv[0]); // Display usage information for incorrect command-line arguments + return 1; // Return non-zero, indicates an error + } + + return 0; // Return 0, successful execution +} \ No newline at end of file diff --git a/labs/03/test.txt b/labs/03/test.txt new file mode 100644 index 0000000..eaa9082 --- /dev/null +++ b/labs/03/test.txt @@ -0,0 +1,4 @@ +a boy sees +the boy sees a flower +a girl with a flower likes the boy +a flower sees a flower \ No newline at end of file