forked from Khaliddxx/CMOS_SpiceGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize.h
159 lines (136 loc) · 3.29 KB
/
initialize.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <stack>
#include <sstream>
using namespace std;
//function to get the output character
vector <char> extract_output(string& input_exp)
{
int found;
vector <char> output_chars;
found = input_exp.find("=");
while (found != string::npos)
{
output_chars.push_back(input_exp[found - 1]);
input_exp.erase(found - 1, 2);
found = input_exp.find("=");
}
return output_chars;
}
//Function to check priority of labels
bool check_priority(char& operator1, char& operator2)
{
bool priority_bool = false;
if ((operator1 == '`' && operator2 == '&') ||
(operator1 == '`' && operator2 == '|') ||
(operator1 == '&' && operator2 == '|'))
priority_bool = true;
return priority_bool;
}
//function to push the characters in a vector according to thier priority
vector <string> calculate_Priority(string& input_exp)
{
vector <string> string_vec;
vector <string> last_vect;
string current_str, expression;
char top_char;
stack<char> stack;
stringstream ss(input_exp);
while (ss.good())
{
string substr;
getline(ss, substr, ';');
string_vec.push_back(substr);
}
for (int i = 0; i < string_vec.size(); i++)
{
current_str = string_vec[i];
for (int i = 0; i < current_str.length(); i++)
{
if (current_str[i] == '`' || current_str[i] == '&' || current_str[i] == '|')
{
if (!stack.empty())
top_char = stack.top();
while (!stack.empty() && check_priority(top_char, current_str[i]))
{
top_char = stack.top();
stack.pop();
expression += top_char;
if (!stack.empty())
top_char = stack.top();
}
stack.push(current_str[i]);
}
else if (current_str[i] == '(')
stack.push(current_str[i]);
else if (current_str[i] == ')' && !stack.empty())
{
top_char = stack.top();
stack.pop();
while (!stack.empty() && top_char != '(')
{
expression += top_char;
top_char = stack.top();
stack.pop();
}
}
else
expression += current_str[i];
}
while (!stack.empty())
{
top_char = stack.top();
stack.pop();
expression += top_char;
}
last_vect.push_back(expression);
expression = "";
}
return last_vect;
}
//Function that does the same thing as de Morgan Law
vector<char>negate_exp(string input) {
vector<char>temp;
vector<char>new_temp;
vector<char>final_temp;
bool flag = true;
for (int i = input.length(); i >= 0; i--) {
temp.push_back(input[i]);
}
if (input.back() == '`') {
input.pop_back();
for (int i = 0; i < input.length(); i++)
final_temp.push_back(input[i]);
}
else {
for (int i = 0; i < temp.size(); i++) {
if ((temp[i] == '`' && temp[i + 1] == '&') || (temp[i] == '`' && temp[i + 1] == '|')) {
flag = false;
continue;
}
else if (flag == true) {
if (temp[i] == '`' && (temp[i + 1] != '&' || '|')) {
continue;
}
else if (temp[i] == '|') {
new_temp.push_back('&');
}
else if (temp[i] == '&') {
new_temp.push_back('|');
}
else {
if (i != 0 && temp[i - 1] != '`' && temp[i] != ('|' || '&'))
new_temp.push_back('`');
new_temp.push_back(temp[i]);
}
}
if (!flag)
new_temp.push_back(temp[i]);
}
for (int j = new_temp.size() - 1; j > 0; j--)
final_temp.push_back(new_temp[j]);
}
return final_temp;
}