Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioDias committed Apr 15, 2024
1 parent bafd384 commit f5fd448
Show file tree
Hide file tree
Showing 76 changed files with 12,709 additions and 331 deletions.
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ set(CMAKE_CXX_STANDARD 14)
add_executable(tpOb1
TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp
TP/automata/dfa/DeterministicFiniteAutomata.cpp
TP/automata/AutomataInterface.h
TP/automata/dfa/DeterministicFiniteAutomata.h
TP/automata/ndfa/NotDeterministicFiniteAutomata.h
TP/auxiliarmethods/CollectionsOperators.h
TP/auxiliarmethods/CollectionsOperators.cpp
TP/Main.cpp
TP/parser/Parser.h
TP/parser/Parser.cpp
TP/automata/convertion/ConvertionOfAutomatas.h
TP/automata/convertion/ConvertionOfAutomatas.cpp)
TP/automata/convertion/ConvertionOfAutomatas.cpp
TP/testing/fileToNdfa.cpp
TP/testing/fileToNdfa.cpp
TP/testing/fileToNdfa.cpp
TP/testing/ndfaToFile.cpp
TP/testing/testClausuraLambda.cpp
TP/testing/testMover.cpp
TP/testing/testParserFunctions.cpp
TP/parser/automata-to-string/ndfa/NDFAToString.h
TP/parser/automata-to-string/ndfa/NDFAToString.cpp
TP/ejemplos_documentados/ex1_file_creation.cpp
TP/ejemplos_documentados/ex1_file_read_and_string_validation.cpp
TP/ejemplos_documentados/ex2_file_creation.cpp
TP/ejemplos_documentados/ex2_file_read_and_string_validation.cpp
TP/ejemplos_documentados/ex2_file_creation.cpp
TP/parser/automata-to-string/dfa/DFAToString.h
TP/parser/automata-to-string/dfa/DFAToString.cpp
)
4 changes: 2 additions & 2 deletions TP/ejemplos_documentados/ex2_readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Ejemplos de cadenas que acepta son:
COMPILACIÓN
---------------------------------------------
(1) Para compilar ex1_file_creation.cpp, desde la carpeta del repositorio
g++ TP/ejemplos_documentados/ex2_file_creation.cpp TP/automata/dfa/DeterministicFiniteAutomata.cpp TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp TP/parser/Parser.cpp TP/auxiliarmethods/CollectionsOperators.cpp
g++ TP/ejemplos_documentados/ex2_file_creation.cpp TP/automata/dfa/DeterministicFiniteAutomata.cpp TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp TP/parser/Parser.cpp TP/auxiliarmethods/CollectionsOperators.cpp TP/parser/automata-to-string/dfa/DFAToString.cpp TP/parser/automata-to-string/ndfa/NDFAToString.cpp

(2) Para compilar ex2_file_read_and_string_validation.cpp, desde el mismo directorio
g++ TP/ejemplos_documentados/ex2_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
g++ TP/ejemplos_documentados/ex2_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 TP/parser/automata-to-string/dfa/DFAToString.cpp TP/parser/automata-to-string/ndfa/NDFAToString.cpp
63 changes: 6 additions & 57 deletions TP/parser/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "Parser.h"
#include <regex>
#include <utility>
#include <bits/stdc++.h>
#include "../automata/dfa/DeterministicFiniteAutomata.h"
#include "../automata/ndfa/NotDeterministicFiniteAutomata.h"
#include "automata-to-string/ndfa/NDFAToString.h"
#include "automata-to-string/dfa/DFAToString.h"

using namespace std;

Expand Down Expand Up @@ -98,65 +101,11 @@ void Parser::fileManagement(const string& line) {
else if(!isRankdirLine(line)) throw runtime_error("Linea no reconocida: " + line);
}
string Parser::dfaToString(DeterministicFiniteAutomata dfa) {
string ret = "digraph{\ninic[shape=point];\ninic->";
ret += "{\"" + CollectionsOperators::to_string_set(dfa.getInitialState()) + "\"};\n";
toStringStatesDFA(dfa, ret);
toStringFinalStateDFA(dfa, ret);
ret += "\n}";
return ret;
}
void Parser::toStringStatesDFA(DeterministicFiniteAutomata dfa, string &ret) {
for(const auto& set1 : dfa.getStates()) {
if(set1.empty())
continue;
for(const auto& set2 : dfa.getStates()) {
if(set2.empty())
continue;
set<int> label = dfa.calculateWaysToGo(set1, set2);
if(!label.empty()) {
ret += "\"" + CollectionsOperators::to_string_set(set1) + "\" -> \"" + CollectionsOperators::to_string_set(set2) + "\" [label = \"";
for(auto elem : label)
ret += to_string(elem) + ",";
ret.pop_back();
ret += "\"];\n";
}
}
}
}
void Parser :: toStringFinalStateDFA(DeterministicFiniteAutomata dfa, string& ret) {
ret += "\"" + CollectionsOperators::to_string_set_of_sets(dfa.getFinalStates()) + "\" [shape=doublecircle];\n";
ret.pop_back();
return DFAToString::dfaToString(std::move(dfa));
}

string Parser::ndfaToString(NotDeterministicFiniteAutomata ndfa) {
string ret = "digraph{\ninic[shape=point];inic -> ";
ret += to_string(ndfa.getInitialState()) + ";\n";
NDFATransitionsToString(ndfa, ret);
toStringFinalStateNDFA(ndfa, ret);
ret += "\n}";
return ret;
}
void Parser::NDFATransitionsToString(NotDeterministicFiniteAutomata ndfa, string& ret) {
const int LAMBDA = -1;
for(int number : ndfa.getSates()) {
for(int number2 : ndfa.getSates()) {
set<int> label = ndfa.calculateWaysToGo(number,number2);
if(!label.empty()) {
ret += to_string(number) + " -> " + to_string(number2) + " [label = \"";
for(int elem : label){
if(elem == LAMBDA){
ret += ("_,");
} else ret += to_string(elem) + ",";
}
ret.pop_back();
ret += "\"];\n";
}
}
}
}
void Parser :: toStringFinalStateNDFA(NotDeterministicFiniteAutomata ndfa, string& ret) {
for(int finalState : ndfa.getFinalSates())
ret += to_string(finalState) + "[shape=doublecircle];\n";
ret.pop_back();
return NDFAToString::ndfaToString(std::move(ndfa));
}

void Parser::writeToFile(const string& filename, const string& content){
Expand Down
6 changes: 1 addition & 5 deletions TP/parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ class Parser {
static bool validateTransitionLine(const string& line);
static bool validateFinalStateLine(const string& line);
bool isRankdirLine(const string& line);
static string ndfaToString(NotDeterministicFiniteAutomata ndfa);
static string dfaToString(DeterministicFiniteAutomata dfa);
static string ndfaToString(NotDeterministicFiniteAutomata ndfa);
static void writeToFile(const string& filename, const string& content);

private:
static bool checkDelta(const string& line);
NotDeterministicFiniteAutomata nda;
bool readLastLine;
static void NDFATransitionsToString(NotDeterministicFiniteAutomata ndfa, string& ret);
static void toStringFinalStateNDFA(NotDeterministicFiniteAutomata ndfa, string& ret);
static void toStringStatesDFA(DeterministicFiniteAutomata dfa, string& ret);
static void toStringFinalStateDFA(DeterministicFiniteAutomata dfa, string& ret);
static string toStringSet(const set<int>& set);
};

Expand Down
37 changes: 37 additions & 0 deletions TP/parser/automata-to-string/dfa/DFAToString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Created by ignaciodias on 15/04/24.
//

#include "DFAToString.h"
#include "../../../auxiliarmethods/CollectionsOperators.h"

string DFAToString::dfaToString(DeterministicFiniteAutomata dfa) {
string ret = "digraph{\ninic[shape=point];\ninic->";
ret += "\"" + CollectionsOperators::to_string_set(dfa.getInitialState()) + "\";\n";
toStringStatesDFA(dfa, ret);
toStringFinalStateDFA(dfa, ret);
ret += "\n}";
return ret;
}
void DFAToString::toStringStatesDFA(DeterministicFiniteAutomata dfa, string &ret) {
for(const auto& set1 : dfa.getStates()) {
if(set1.empty())
continue;
for(const auto& set2 : dfa.getStates()) {
if(set2.empty())
continue;
set<int> label = dfa.calculateWaysToGo(set1, set2);
if(!label.empty()) {
ret += "\"" + CollectionsOperators::to_string_set(set1) + "\" -> \"" + CollectionsOperators::to_string_set(set2) + "\" [label = \"";
for(auto elem : label)
ret += to_string(elem) + ",";
ret.pop_back();
ret += "\"];\n";
}
}
}
}
void DFAToString::toStringFinalStateDFA(DeterministicFiniteAutomata dfa, string& ret) {
ret += "\"" + CollectionsOperators::to_string_set_of_sets(dfa.getFinalStates()) + "\" [shape=doublecircle];\n";
ret.pop_back();
}
18 changes: 18 additions & 0 deletions TP/parser/automata-to-string/dfa/DFAToString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by ignaciodias on 15/04/24.
//

#ifndef TPOB1_DFATOSTRING_H
#define TPOB1_DFATOSTRING_H
#include "../../../automata/dfa/DeterministicFiniteAutomata.h"

class DFAToString {
public:
static string dfaToString(DeterministicFiniteAutomata dfa);
private:
static void toStringStatesDFA(DeterministicFiniteAutomata dfa, string& ret);
static void toStringFinalStateDFA(DeterministicFiniteAutomata dfa, string& ret);
};


#endif //TPOB1_DFATOSTRING_H
Binary file not shown.
33 changes: 33 additions & 0 deletions TP/parser/automata-to-string/ndfa/NDFAToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,36 @@
//

#include "NDFAToString.h"

string NDFAToString::ndfaToString(NotDeterministicFiniteAutomata ndfa) {
string ret = "digraph{\ninic[shape=point];inic -> ";
ret += to_string(ndfa.getInitialState()) + ";\n";
NDFATransitionsToString(ndfa, ret);
toStringFinalStateNDFA(ndfa, ret);
ret += "\n}";
return ret;
}
void NDFAToString::NDFATransitionsToString(NotDeterministicFiniteAutomata ndfa, string& ret) {
const int LAMBDA = -1;
for(int number : ndfa.getSates()) {
for(int number2 : ndfa.getSates()) {
set<int> label = ndfa.calculateWaysToGo(number,number2);
if(!label.empty()) {
ret += to_string(number) + " -> " + to_string(number2) + " [label = \"";
for(int elem : label){
if(elem == LAMBDA){
ret += ("_,");
} else ret += to_string(elem) + ",";
}
ret.pop_back();
ret += "\"];\n";
}
}
}
}
void NDFAToString::toStringFinalStateNDFA(NotDeterministicFiniteAutomata ndfa, string& ret) {
for(int finalState : ndfa.getFinalSates())
ret += to_string(finalState) + "[shape=doublecircle];\n";
ret.pop_back();
}

9 changes: 6 additions & 3 deletions TP/parser/automata-to-string/ndfa/NDFAToString.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

#ifndef TPOB1_NDFATOSTRING_H
#define TPOB1_NDFATOSTRING_H


#include "../../../automata/ndfa/NotDeterministicFiniteAutomata.h"

class NDFAToString {
public:
static string ndfaToString(NotDeterministicFiniteAutomata ndfa);
private:
static void NDFATransitionsToString(NotDeterministicFiniteAutomata ndfa, string& ret);
static void toStringFinalStateNDFA(NotDeterministicFiniteAutomata ndfa, string& ret);

};



#endif //TPOB1_NDFATOSTRING_H
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"directoryIndex" : 0,
"id" : "tpOb1::@6890427a1f51a3e7e1df",
"jsonFile" : "target-tpOb1-Debug-1186c934158f18653ad3.json",
"jsonFile" : "target-tpOb1-Debug-e24e8dc0fb1dd0e35cd5.json",
"name" : "tpOb1",
"projectIndex" : 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"objects" :
[
{
"jsonFile" : "codemodel-v2-0d0c7409ff5211f23f51.json",
"jsonFile" : "codemodel-v2-0f0acc5aec9ca6a2f244.json",
"kind" : "codemodel",
"version" :
{
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"codemodel-v2" :
{
"jsonFile" : "codemodel-v2-0d0c7409ff5211f23f51.json",
"jsonFile" : "codemodel-v2-0f0acc5aec9ca6a2f244.json",
"kind" : "codemodel",
"version" :
{
Expand Down
Loading

0 comments on commit f5fd448

Please sign in to comment.