-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNfunc.cpp
More file actions
295 lines (253 loc) · 4.5 KB
/
Nfunc.cpp
File metadata and controls
295 lines (253 loc) · 4.5 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include <iostream>
#include <string>
#include <vector>
#include <stack>
using namespace std ;
vector<string> datatypes;
vector<string> functions;
vector<string> keywords;
stack<string> parenthesis;
vector<string> variables;
bool isdatatype(string);
void abort(string s )
{
cout<<s;
}
void write(string s )
{
cout<<s;
}
//void log(string data){
// ofstream outfile;
// outfile.open("log.txt", ios_base::app);
// outfile <<data<<endl;
// outfile.close();
//}
//
//void balanced(string s)
//{
// if(parenthesis.empty())
// {
// abort("No Opening Bracket found, but closing bracket encounter");
// }
// char x=s[0];
// string par;
// switch(x)
// {
// case '}':
// par=parenthesis.top();
// if(par[0] != '{')
// {
// abort("Unbalanced Bracket, '}' encountered");
// }
// parenthesis.pop();
// break;
// case ')':
// par=parenthesis.top();
// if(par[0] != '(')
// {
// abort("Unbalanced Bracket, ')' encountered");
// }
// parenthesis.pop();
// break;
// case ']':
// par=parenthesis.top();
// if(par[0] != '[')
// {
// abort("Unbalanced Bracket, ']' encountered");
// }
// parenthesis.pop();
// break;
// default :
// if(parenthesis.empty())
// {
// abort("No Opening Bracket found, but closing bracket encounter");
// }
// break;
// }
//}
//
//void push(string s)
//{
// parenthesis.push(s);
//}
//
//
//void check_paren(vector<string> vec)
//{
// for(int i=0;i<vec.size();i++)
// {
// if(vec[i].compare("{")==0 || vec[i].compare("(")==0 || vec[i].compare("[")==0)
// {
// push(vec[i]);
// }
// if(vec[i].compare("}")==0 || vec[i].compare(")")==0 || vec[i].compare("]")==0)
// {
// balanced(vec[i]);
// }
// }
// if(!parenthesis.empty())
// {
// abort("Parenthesis not balanced");
// }
//}
void clrscreen(vector<string>);
int main()
{
cout<<"Hello World\n";
cout<<"Hello World2\n";
system("CLS");
cout<<"Hello World3\n";
string s = "clear";
vector<string> vec;
vec.push_back(s);
vec.push_back(" 5 ");
clrscreen(vec);
return 0;
}
//
//vector<string> datatypes;
//vector<string> functions;
//vector<string> keywords;
void isvalid_func(vector<string> vec)
{
if(vec[0]!="def")
{
return;
}
if(!isdatatype(vec[1]))
{
abort("Invalid Return Type");
}
string name = vec[2];
int size = name.size()-name.find_first_of("(");
name =name.substr(0,size);
for(int i=0;i<keywords.size();i++)
{
if(keywords[i].compare(name)==0)
{
abort("Function name cannot be a Keyword");
}
}
for(int i=0;i<functions.size();i++)
{
if(functions[i]==vec[2])
{
abort("Function Name Repeated");
}
}
functions.push_back(vec[2]);
if(vec[3]!="{")
{
abort("{ expected ");
}
string str = vec[1]+" "+vec[2]+" "+vec[3] + " ;";
write(str);
}
bool isvariable(string str)
{
for(int i=0;i<variables.size();i++)
{
if(str.compare(variables[i])==0)
{
return true;
}
}
return false;
}
bool isdatatype(string str)
{
for(int i=0;i<datatypes.size();i++)
{
if(str.compare(datatypes[i])==0)
{
return true;
}
}
return false;
}
void clrscreen(vector<string> vec)
{
if(vec[0].compare("clear")==0 && vec.size()==1)
{
string clr = "system(\"CLS\");";
write(clr);
}
else
{
abort("Invalid Clear Command");
}
}
void isvalid_return(vector<string> vec)
{
if(isvalid_number(vec[1]))
{
string str = vec[0] + " " + vec[1] + " ;";
write(str);
}
else
{
abort("Invalid return");
}
}
bool isvalid_function(vector<string> vec)
{
for(int index=0;index<vec.size());index++)
{
for(int i=0;i<functions.size());i++)
{
if(functions[i].compare(vec[index]))
{
func_call(vec,index);
return true;
}
}
}
return false;
}
void func_call(vector<string> vec,int index)
{
if(index==0)
{
string str = vec[0] + " ;";
write(str);
}
if(index == 2)
{
string str = vec[0] + " " + vec[1] + " " + vec[2] + " ;";
write(str);
}
else
{
abort("Invalid Function Call");
}
}
void isvalid_expression(vector<string> tokens)
{
int flag, i = 0, index = 0;
string str;
if(!isvalid_function(tokens))
{
while (index < tokens.size())
{
flag = 0;
if (i % 2 == 0)
{
if (isvalid_variable(tokens[index]) || isvalid_number(tokens[index] ))
flag = 1;
}
else
{
if (isvalid_operator(tokens[index]))
flag = 2;
}
if (flag == 0)
abort("error in expression");
str = str + " " + tokens[index];
i++;
index++;
}
str = str + ";";
write(str);
}
}