-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassAbstractVM.hpp
182 lines (160 loc) · 6.33 KB
/
ClassAbstractVM.hpp
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClassAbstractVM.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgonor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/29 19:48:41 by dgonor #+# #+# */
/* Updated: 2018/11/29 19:48:45 by dgonor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLASSABSTRACTVM_HPP
#define CLASSABSTRACTVM_HPP
#include <algorithm>
#include <exception>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#include <regex>
#include <stack>
#include <map>
#include <list>
#include "ClassIOperand.hpp"
#include "ClassFactory.hpp"
//#include "ClassOperand.hpp"
class AbstractVM {
public:
AbstractVM(void);
AbstractVM(AbstractVM const &vm);
AbstractVM &operator=(AbstractVM const &vm);
~AbstractVM(void);
eOperandType getType(std::string const &type);
bool getExist_error(void) const;
bool getExist_exit(void) const;
bool getEsc(void) const;
void setIterLine(void);
void setExit(void);
void valid_data(std::string const &str);
void data_management(std::string const &str);
void Push(std::string const & str, eOperandType type);
void Assert(std::string const & str, eOperandType type);
void Pop(void);
void Exit(void);
void Add(void);
void Sub(void);
void Mul(void);
void Div(void);
void Mod(void);
void Dump(void);
void Print(void);
void Delim(void);
void Sum(void);
void Max(void);
void Min(void);
void Avrg(void);
void Asort(void);
void Dsort(void);
class LexicalErrorExcept : public std::exception {
public:
LexicalErrorExcept(std::string nline, std::string str)
: _nline(nline), _str(str) {}
const char *what() const throw()
{
std::string error_exept("Error: Lexical - line ");
error_exept = (error_exept + _nline + " --> " + _str);
return (error_exept.c_str());
}
private:
std::string _nline;
std::string _str;
};
class DoubExitExcept : public std::exception{
public:
DoubExitExcept(std::string nline) : _nline(nline) {}
const char *what() const throw()
{
std::string error_exept("Error: Double exit -> line ");
error_exept = (error_exept + _nline);
return (error_exept.c_str());
}
private:
std::string _nline;
};
class EmptyStackExcept : public std::exception{
public:
EmptyStackExcept(std::string nline) : _nline(nline) {}
const char *what() const throw()
{
std::string error_exept("Error: Stack is empty - line " + _nline);
return (error_exept.c_str());
}
private:
std::string _nline;
};
class ErrorAssertExcept : public std::exception{
public:
ErrorAssertExcept(std::string nline, std::string assert_s, std::string stack_s)
: _nline(nline), _assert_s(assert_s), _stack_s(stack_s) {}
const char *what() const throw()
{
std::string error_exept("Error: Assertion is fail --> "
+ _assert_s + " != " + _stack_s);
return (error_exept.c_str());
}
private:
std::string _nline;
std::string _assert_s;
std::string _stack_s;
};
class LessThanTwoArgExcept : public std::exception{
public:
LessThanTwoArgExcept(std::string nline) : _nline(nline) {}
const char *what() const throw()
{
std::string error_exept("Error: Stack has less than 2 arguments - line " + _nline);
return (error_exept.c_str());
}
private:
std::string _nline;
};
class PrintExcept : public std::exception{
public:
PrintExcept(std::string nline, std::string str)
: _nline(nline), _str(str) {}
const char *what() const throw()
{
std::string error_exept("Error: Unprintable character - line "
+ _nline + " --> " + _str);
return (error_exept.c_str());
}
private:
std::string _nline;
std::string _str;
};
class NoExistExitExcept : public std::exception{
public:
const char *what() const throw()
{
std::string error_exept("Error: The command 'exit' no found");
return (error_exept.c_str());
}
};
class ZeroExcept : public std::exception{
public:
const char *what() const throw()
{
return ("Error: Because of the division by '0'. Are you really good at math? ");
}
};
private:
Factory factory;
std::vector<const IOperand *> v;
unsigned long i;
bool exist_error;
bool exist_exit;
bool esc;
};
#endif