-
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.
adding console colors
- Loading branch information
Showing
10 changed files
with
125 additions
and
109 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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
alfabeto=0,1 | ||
estados=q0,q1,q2,q3 | ||
alfabeto=a,b | ||
estados=q0,q1,q2,q3,q4 | ||
inicial=q0 | ||
final=q3 | ||
final=q1,q4 | ||
transicoes | ||
q0,q0,0 | ||
q0,q0,1 | ||
q0,q1,1 | ||
q1,q2,1 | ||
q2,q3,0 | ||
q3,q3,1 | ||
q3,q3,0 | ||
q0,q1,epsilon | ||
q0,q3,epsilon | ||
q1,q1,b | ||
q1,q2,a | ||
q2,q1,a | ||
q2,q2,b | ||
q3,q3,a | ||
q3,q4,b | ||
q4,q4,a | ||
q4,q3,b |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
alfabeto=0,1 | ||
estados=q0,q1,q2,q3 | ||
alfabeto=a,b | ||
estados=q0,q1,q2,q3,q4,q5,q6,q7 | ||
inicial=q0 | ||
final=q3 | ||
final=q0,q7 | ||
transicoes | ||
q0,q0,0 | ||
q0,q0,1 | ||
q0,q1,1 | ||
q1,q2,1 | ||
q2,q3,0 | ||
q3,q3,1 | ||
q3,q3,0 | ||
q0,q1,epsilon | ||
q1,q2,epsilon | ||
q1,q6,epsilon | ||
q2,q3,a | ||
q3,q4,epsilon | ||
q4,q5,b | ||
q5,q1,epsilon | ||
q6,q7,a | ||
q7,q1,epsilon |
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 |
---|---|---|
@@ -1,52 +1,71 @@ | ||
#include "NFA_Printer.hpp" | ||
|
||
using namespace ConsoleFormatter; | ||
|
||
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()); | ||
|
||
std::cout << "-----Processment-----"; | ||
PrintProcessmentList(crashedsChains); | ||
PrintProcessmentList(finishedsChains); | ||
} | ||
|
||
void NFA_Printer::PrintProcessmentList(MyList<NaryTree_Node<Transition*>*> node) | ||
{ | ||
AlphabetSymbol* symbol; | ||
AlphabetSymbol* symbol; | ||
|
||
for(int i = 0; i < node.Length(); i++) | ||
{ | ||
NaryTree_Node<Transition*>* s = node.At(i); | ||
MyList<Transition*> chainList = MyList<Transition*>(); | ||
|
||
for(int i = 0; i < node.Length(); i++) | ||
// Getting all processing chain of the last state | ||
// Iterate from bottom to top | ||
while(s != nullptr) | ||
{ | ||
NaryTree_Node<Transition*>* s = node.At(i); | ||
MyList<Transition*> chainList = MyList<Transition*>(); | ||
chainList.Push(s->GetContent()); | ||
s = s->GetParent(); | ||
} | ||
|
||
while(s != nullptr) | ||
{ | ||
chainList.Push(s->GetContent()); | ||
s = s->GetParent(); | ||
} | ||
bool chainIsAccepted = chainList.At(0)->GetDestinationState()->IsAFinalState(); | ||
|
||
Transition* _transition = chainList.GetLast(); | ||
std::cout << _transition->GetDestinationState()->GetName(); | ||
// Make text green case chain is accepted, red otherwise | ||
UpdateConsoleColor(chainIsAccepted); | ||
|
||
for(int j = chainList.Length()-2; j >= 0; j--) | ||
{ | ||
Transition* _transition = chainList.At(j); | ||
Transition* _transition = chainList.GetLast(); | ||
|
||
symbol = _transition->GetTransitionSymbol(); | ||
// Print initial state | ||
std::cout << std::endl << _transition->GetDestinationState()->GetName(); | ||
|
||
if(symbol != nullptr) | ||
std::cout << " -> " << symbol->GetValue() << " -> " ; | ||
for(int j = chainList.Length()-2; j >= 0; j--) | ||
{ | ||
Transition* _transition = chainList.At(j); | ||
|
||
std::cout << _transition->GetDestinationState()->GetName(); | ||
} | ||
symbol = _transition->GetTransitionSymbol(); | ||
|
||
// 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; | ||
if(symbol != nullptr) | ||
std::cout << " -> " << symbol->GetValue() << " -> " ; | ||
|
||
std::cout << "\n"; | ||
std::cout << _transition->GetDestinationState()->GetName(); | ||
} | ||
|
||
if(chainIsAccepted) | ||
std::cout << " " << NFA_Printer::CHAIN_IS_ACCEPTED_SYMBOL; | ||
else | ||
std::cout << " " << NFA_Printer::CHAIN_IS_NOT_ACCEPTED_SYMBOL; | ||
|
||
ConsoleFormatter::ResetConsoleColor(); | ||
} | ||
} | ||
|
||
void NFA_Printer::UpdateConsoleColor(bool chainIsAccepted) | ||
{ | ||
int consoleColor = chainIsAccepted ? ConsoleFormatter::GREEN_CONSOLE_COLOR | ||
: ConsoleFormatter::RED_CONSOLE_COLOR; | ||
|
||
ConsoleFormatter::SetConsoleColor(consoleColor); | ||
} |
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,29 @@ | ||
#include "ConsoleFormatter.hpp" | ||
|
||
#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 | ||
#endif | ||
|
||
void ConsoleFormatter::SetConsoleColor(int color) | ||
{ | ||
#if IS_ON_WINDOWS | ||
HANDLE console_color = GetStdHandle(STD_OUTPUT_HANDLE); | ||
SetConsoleTextAttribute(console_color, color); | ||
//SetConsoleColor_Windows(color); | ||
#endif | ||
} | ||
|
||
void ConsoleFormatter::ResetConsoleColor() | ||
{ | ||
SetConsoleColor(WHITE_CONSOLE_COLOR); | ||
} | ||
|
||
// void ConsoleFormatter::SetConsoleColor_Windows(int color) | ||
// { | ||
// #if IS_ON_WINDOWS | ||
// HANDLE console_color = GetStdHandle(STD_OUTPUT_HANDLE); | ||
// SetConsoleTextAttribute(console_color, color); | ||
// #endif | ||
// } |
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,11 @@ | ||
#pragma once | ||
|
||
namespace ConsoleFormatter | ||
{ | ||
const int RED_CONSOLE_COLOR = 12; | ||
const int GREEN_CONSOLE_COLOR = 10; | ||
const int WHITE_CONSOLE_COLOR = 15; | ||
|
||
void SetConsoleColor(int color); | ||
void ResetConsoleColor(); | ||
} |
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