200 lines
3.3 KiB
C++
200 lines
3.3 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
||
#include <iostream>
|
||
#include <vector>
|
||
#include <algorithm>
|
||
#include <cstring>
|
||
#include <cctype>
|
||
#include <string>
|
||
#include <cmath>
|
||
#include <set>
|
||
#include <map>
|
||
#include <ctime>
|
||
#include <chrono>
|
||
#include <fstream>
|
||
#include <iomanip>
|
||
#include <queue>
|
||
using namespace std;
|
||
#define endl '\n'
|
||
#define endll cout << endl
|
||
#define LL_MAX 2223372036854775807
|
||
typedef long long ll;
|
||
|
||
template <typename T>
|
||
|
||
class Stack {
|
||
private:
|
||
struct Node
|
||
{
|
||
Node* back;
|
||
T value;
|
||
};
|
||
Node* Head;
|
||
public:
|
||
Stack()
|
||
{
|
||
Head = nullptr;
|
||
}
|
||
|
||
void Add(T component)
|
||
{
|
||
Node* bk = Head;
|
||
Head = new Node;
|
||
Head->back = bk;
|
||
Head->value = component;
|
||
}
|
||
|
||
T Pop()
|
||
{
|
||
if (Head != nullptr)
|
||
{
|
||
Node* v = Head;
|
||
Head = Head->back;
|
||
T value = v->value;
|
||
delete(v);
|
||
return value;
|
||
}
|
||
}
|
||
|
||
bool isEmpty()
|
||
{
|
||
if (Head == nullptr)
|
||
return true;
|
||
return false;
|
||
}
|
||
};
|
||
|
||
|
||
struct Arg {
|
||
public:
|
||
string Name;
|
||
string Type;
|
||
string Value;
|
||
|
||
Arg() {}
|
||
|
||
Arg(string n, string t, string v) : Name(n), Type(t), Value(v) {}
|
||
|
||
Arg(string n, string t) : Name(n), Type(t), Value("None") {}
|
||
};
|
||
|
||
class SysCall
|
||
{
|
||
public:
|
||
int ID;
|
||
string Name;
|
||
vector<Arg> Args;
|
||
|
||
SysCall(int id, string name, vector<Arg> args) : ID(id), Name(name), Args(args) {}
|
||
|
||
string toString()
|
||
{
|
||
string otv = "ID: " + to_string(ID) + "\t Name: " + Name + "\n";
|
||
for (Arg a : Args)
|
||
{
|
||
otv += "name: " + a.Name + "\t type: " + a.Type + "\t value: " + a.Value + "\n";
|
||
}
|
||
return otv;
|
||
}
|
||
};
|
||
|
||
class Kernel
|
||
{
|
||
private:
|
||
vector<SysCall> Calls;
|
||
public:
|
||
Kernel()
|
||
{
|
||
Calls = vector<SysCall>({
|
||
SysCall(1, "A", vector<Arg>({
|
||
Arg("AB", "int")
|
||
})),
|
||
SysCall(2, "B", vector<Arg>({
|
||
Arg("AB", "int", "163"),
|
||
Arg("BA", "string", "145")})),
|
||
SysCall(3, "V", vector<Arg>({
|
||
Arg("BA", "string", "145"),
|
||
Arg("OT", "bool", "731"),
|
||
Arg("QA", "float", "921")
|
||
})),
|
||
SysCall(4, "ST", vector<Arg>({
|
||
Arg("A", "string", "45"),
|
||
Arg("O", "string", "71"),
|
||
Arg("Q", "double", "21")
|
||
})),
|
||
SysCall(5, "OP", vector<Arg>({
|
||
Arg("B", "string", "15"),
|
||
Arg("OGT", "bool", "731"),
|
||
Arg("QFA", "float", "921")
|
||
}))
|
||
});
|
||
}
|
||
|
||
void ShowAll()
|
||
{
|
||
for (SysCall c : Calls)
|
||
{
|
||
cout << c.toString() << "\n";
|
||
}
|
||
}
|
||
|
||
void Call(int id, Stack<Arg> stack)
|
||
{
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
|
||
for (auto it : Calls)
|
||
{
|
||
if (it.ID == id)
|
||
{
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " << it.Name << endl;
|
||
for (auto arg : it.Args)
|
||
{
|
||
if (stack.isEmpty())
|
||
{
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ERROR" << endl;
|
||
return;
|
||
}
|
||
Arg a = stack.Pop();
|
||
if (arg.Type != a.Type)
|
||
{
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Error \t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << it.Name << endl; return;
|
||
}
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << a.Type << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << a.Value << endl;
|
||
}
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl; return;
|
||
}
|
||
}
|
||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID Error" << endl;
|
||
return;
|
||
}
|
||
};
|
||
|
||
int main1()
|
||
{
|
||
setlocale(LC_ALL, "Russian");
|
||
|
||
Kernel k;
|
||
|
||
endll;
|
||
Stack<Arg> S1;
|
||
S1.Add(Arg("AB", "int"));
|
||
k.Call(1, S1);
|
||
endll;
|
||
Stack<Arg> S3;
|
||
S3.Add(Arg("QA", "float", "921"));
|
||
S3.Add(Arg("OT", "bool", "731"));
|
||
S3.Add(Arg("BA", "string", "145"));
|
||
k.Call(3, S3);
|
||
endll;
|
||
Stack<Arg> S2;
|
||
S2.Add(Arg("QA", "float", "921"));
|
||
S2.Add(Arg("OT", "bool", "731"));
|
||
S2.Add(Arg("BA", "string", "145"));
|
||
k.Call(2, S2);
|
||
endll;
|
||
Stack<Arg> S4;
|
||
k.Call(4, S4);
|
||
endll;
|
||
Stack<Arg> S5;
|
||
k.Call(8, S5);
|
||
|
||
return 0;
|
||
} |