-
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.
- Loading branch information
Showing
7 changed files
with
142 additions
and
7 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,8 @@ | ||
digraph{ | ||
inic[shape=point];inic -> 3; | ||
3 -> 3 [label = "0,1"]; | ||
3 -> 4 [label = "0"]; | ||
4 -> 3 [label = "_"]; | ||
4 -> 5 [label = "1"]; | ||
5[shape=doublecircle]; | ||
} |
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,31 @@ | ||
/** | ||
* En este programa se probará la función de cargar un automata | ||
* por medio de la clase NotDeterministicFiniteAutomata y guardarlo en un archivo. | ||
* El automata de ejemplo y las instrucciones de compilación está descrito en ex1_readme.txt | ||
* El archivo de salida será automata1.dot | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
#include "../automata/ndfa/NotDeterministicFiniteAutomata.h" | ||
#include "../parser/Parser.h" | ||
|
||
int main() { | ||
const int lambda = -1; | ||
string filename = "TP/ejemplos_documentados/automata1.dot"; | ||
|
||
NotDeterministicFiniteAutomata ndfa; | ||
ndfa.setAlphabet({0,1}); //a, b | ||
ndfa.setStates({3,4,5}); | ||
ndfa.setInitialState(3); | ||
ndfa.addPath(3,0,4); | ||
ndfa.addPath(3,0,3); | ||
ndfa.addPath(3,1,3); | ||
ndfa.addPath(4,lambda,3); | ||
ndfa.addPath(4,1,5); | ||
ndfa.addFinalState(5); | ||
|
||
string content = Parser::ndfaToString(ndfa); | ||
Parser::writeToFile(filename, content); | ||
return 0; | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
TP/ejemplos_documentados/ex1_file_read_and_string_validation.cpp
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,60 @@ | ||
/** | ||
* En este programa se probará la función de cargar un automata | ||
* por medio de un archivo de texto y comprobará si algunas cadenas pertenecen al lenguaje. | ||
* El automata de ejemplo está descrito en ex1_readme.txt | ||
* El archivo de entrada será automata1.dot | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
#include "../automata/dfa/DeterministicFiniteAutomata.h" | ||
#include "../automata/ndfa/NotDeterministicFiniteAutomata.h" | ||
#include "../automata/convertion/ConvertionOfAutomatas.h" | ||
#include "../parser/Parser.h" | ||
using namespace std; | ||
|
||
const string filename = "TP/ejemplos_documentados/automata1.dot"; | ||
|
||
int main() { | ||
ifstream file(filename); // Abrir el archivo | ||
Parser parser = *new Parser(); | ||
|
||
if (!file.is_open()) { // Verificar si el archivo se abrió correctamente | ||
cerr << "No se pudo abrir el archivo." << endl; | ||
return -1; | ||
} | ||
|
||
string line; | ||
|
||
if (!getline(file, line)) { // Leer la primera línea | ||
cerr << "No se pudo leer la primera línea." << endl; | ||
return -1; | ||
} | ||
if(!Parser::validateFirstLine(line)){ | ||
cerr << "Formato invalido del archivo." << endl; | ||
return -1; | ||
} | ||
|
||
while (getline(file, line)) { | ||
parser.fileManagement(line); | ||
} | ||
|
||
file.close(); | ||
cout << "Automata leido correcamente"; | ||
|
||
NotDeterministicFiniteAutomata nda = parser.getNDA(); | ||
ConvertionOfAutomatas conversor; | ||
conversor.setNDFA(nda); | ||
DeterministicFiniteAutomata dfa; | ||
conversor.setDFA(dfa); | ||
conversor.convertFromNDFA(); | ||
dfa = conversor.getDFA(); | ||
|
||
vector<string> strings = {"001", "01", "1101101", "0001000"}; | ||
for(string s: strings){ | ||
if(dfa.checkValidString(s)){ | ||
cout << "La cadena " << s << " es aceptada por el automata." << endl; | ||
} else { | ||
cout << "La cadena " << s << " no es aceptada por el automata." << endl; | ||
} | ||
} | ||
} |
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,30 @@ | ||
Se probará la entrada, salida y aceptación de cadenas con el siguiente | ||
automata finito no deterministico (AFND): | ||
|
||
A = < K, E, D, q0, F > | ||
donde: | ||
K = {3, 4, 5} | ||
E = {0, 1} | ||
D = { | ||
d(3,0) = 4 | ||
d(3,0) = 3 | ||
d(3,1) = 3 | ||
d(4,_) = 3 | ||
d(4,1) = 5 | ||
} | ||
q0 = 0 | ||
F = {5} | ||
El automata lee expresiones regulares de la forma ((0|1)*0)+1. | ||
Ejemplos de cadenas que acepta son: | ||
- 001 | ||
- 01 | ||
- 1101101 | ||
|
||
---------------------------------------------- | ||
COMPILACIÓN | ||
--------------------------------------------- | ||
(1) Para compilar ex1_file_creation.cpp, desde la carpeta del repositorio | ||
g++ TP/ejemplos_documentados/ex1_file_creation.cpp TP/automata/dfa/DeterministicFiniteAutomata.cpp TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp TP/parser/Parser.cpp TP/auxiliarmethods/CollectionsOperators.cpp | ||
|
||
(2) Para compilar ex1_file_read_and_string_validation.cpp, desde el mismo directorio | ||
g++ TP/ejemplos_documentados/ex1_file_read_and_string_validation.cpp TP/automata/dfa/DeterministicFiniteAutomata.cpp TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp TP/parser/Parser.cpp TP/auxiliarmethods/CollectionsOperators.cpp TP/automata/convertion/ConvertionOfAutomatas.cpp |
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