-
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.
Cleaning code
- Loading branch information
Showing
7 changed files
with
231 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
#define RED_CONSOLE_COLOR 4 | ||
#define GREEN_CONSOLE_COLOR 2 | ||
#define WHITE_CONSOLE_COLOR 15 | ||
|
||
#define IS_ON_WINDOWS defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | ||
|
||
#if IS_ON_WINDOWS | ||
#include <windows.h> // Used to change color of text | ||
void SetConsoleColor_Windows(int color) | ||
{ | ||
|
||
HANDLE console_color = GetStdHandle(STD_OUTPUT_HANDLE); | ||
SetConsoleTextAttribute(console_color, color); | ||
} | ||
#endif | ||
|
||
void SetConsoleColor(int color) | ||
{ | ||
#if IS_ON_WINDOWS | ||
SetConsoleColor_Windows(color); | ||
#endif | ||
} | ||
|
||
void ResetConsoleColor() | ||
{ | ||
SetConsoleColor(WHITE_CONSOLE_COLOR); | ||
} | ||
|
||
// Driver Code | ||
int main() | ||
{ | ||
SetConsoleColor(RED_CONSOLE_COLOR); | ||
cout << " Hello Geeks, " << "good night!!!"; | ||
|
||
SetConsoleColor(WHITE_CONSOLE_COLOR); | ||
cout << " Hello Geeks, " << "good night!!!"; | ||
|
||
SetConsoleColor(GREEN_CONSOLE_COLOR); | ||
cout << " Hello Geeks, " << "good night!!!"; | ||
|
||
ResetConsoleColor(); | ||
|
||
return 0; | ||
} |
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
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,52 @@ | ||
#include "NFA_Printer.hpp" | ||
|
||
void NFA_Printer::PrintProcessmentTree(NaryTree<Transition*>* processmentTree) | ||
{ | ||
// Get all crashed chains and all chain at the deepest level (bigger height value) | ||
MyList<NaryTree_Node<Transition*>*> crashedsChains, finishedsChains; | ||
crashedsChains = processmentTree->GetWithHeight(NFA_Machine::CRASH_STATE_HEIGHT); | ||
finishedsChains = processmentTree->GetWithHeight(processmentTree->GetMaxHeight()); | ||
|
||
PrintProcessmentList(crashedsChains); | ||
PrintProcessmentList(finishedsChains); | ||
} | ||
|
||
void NFA_Printer::PrintProcessmentList(MyList<NaryTree_Node<Transition*>*> node) | ||
{ | ||
AlphabetSymbol* symbol; | ||
|
||
for(int i = 0; i < node.Length(); i++) | ||
{ | ||
NaryTree_Node<Transition*>* s = node.At(i); | ||
MyList<Transition*> chainList = MyList<Transition*>(); | ||
|
||
while(s != nullptr) | ||
{ | ||
chainList.Push(s->GetContent()); | ||
s = s->GetParent(); | ||
} | ||
|
||
Transition* _transition = chainList.GetLast(); | ||
std::cout << _transition->GetDestinationState()->GetName(); | ||
|
||
for(int j = chainList.Length()-2; j >= 0; j--) | ||
{ | ||
Transition* _transition = chainList.At(j); | ||
|
||
symbol = _transition->GetTransitionSymbol(); | ||
|
||
if(symbol != nullptr) | ||
std::cout << " -> " << symbol->GetValue() << " -> " ; | ||
|
||
std::cout << _transition->GetDestinationState()->GetName(); | ||
} | ||
|
||
// Print the status of the last state in the chain | ||
if(chainList.At(0)->GetDestinationState()->IsAFinalState()) | ||
std::cout << " " << NFA_Printer::CHAIN_IS_ACCEPTED_SYMBOL; | ||
else | ||
std::cout << " " << NFA_Printer::CHAIN_IS_NOT_ACCEPTED_SYMBOL; | ||
|
||
std::cout << "\n"; | ||
} | ||
} |
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,17 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include "Transition.hpp" | ||
#include "Utils/NaryTree.hpp" | ||
#include "NFA_Machine.hpp" | ||
|
||
namespace NFA_Printer | ||
{ | ||
const char CHAIN_IS_ACCEPTED_SYMBOL = 'V'; | ||
const char CHAIN_IS_NOT_ACCEPTED_SYMBOL = 'X'; | ||
const std::string CHAIN_IS_ACCEPTED_MSG = "A cadeia processada eh aceita. \n"; | ||
const std::string CHAIN_IS_NOT_ACCEPTED_MSG = "A cadeia processada nao eh aceita. \n"; | ||
|
||
void PrintProcessmentTree(NaryTree<Transition*>* processmentTree); | ||
void PrintProcessmentList(MyList<NaryTree_Node<Transition*>*> node); | ||
} |
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
Oops, something went wrong.