-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException.cpp
More file actions
131 lines (109 loc) · 2.44 KB
/
Exception.cpp
File metadata and controls
131 lines (109 loc) · 2.44 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
#pragma once
#include <iostream>
#include "Lex.cpp"
using namespace std;
enum exception_status {
UnknownError,
InvalidLexeme,
UndeclaredIdentifier,
Redefinition,
SyntaxError,
SemanticError,
EndOfFile,
NotEndOfFIle,
EmptyOperation,
TypeError,
Division_by_zero
};
class Exception {
public:
exception_status status;
Lex received;
type_of_lex expected;
static const string TE[];
static const string TL[];
public:
Exception( Lex received,
exception_status status = UnknownError,
type_of_lex expected = LEX_NULL )
{
this->status = status;
this->received = received;
this->expected = expected;
}
friend ostream & operator <<(ostream & out, const Exception & l ) {
out << "!!! Exeption !!!" << " in line : " << l.received.get_line() << endl;
out << "Exception status : " << TE[l.status] << endl;
out << "Recieved : " << l.received ;
if(l.expected != LEX_NULL) out << "Expected : " << TL[l.expected] << endl;
return out;
}
};
const string Exception::TE[] ={
"UnknownError" ,
"InvalidLexeme",
"UndeclaredIdentifier",
"Redefinition",
"SyntaxError",
"SemanticError",
"EOF",
"NotEndOfFile",
"EmptyOperation",
"TypeError",
"Division_by_zero"
};
const string Exception::TL[] ={
"LEX_NULL",
"main",
"int",
"double",
"bool",
"true || false", //LEX_TRUE
"false",
"do",
"while",
"if",
"else",
"for",
"to",
"downto",
"cinout", //LEX_CINOUT
"endl",
";" ,
"," ,
":" ,
"(" ,
")" ,
"{" ,
"}" ,
"=" ,
"<" ,
">" ,
"Wrond operand's type for '+' or '-' operation" , // LEX_PLUS
"-" ,
"Wrond operand's type for '++' or '--' operation", //LEX_IPLUS
"--",
"Wrond operand's type for '*' or '/' or '%' operation" , //LEX_TIMES
"/" ,
"%",
"Wrond operand's type for '^' operation" , // LEX_POW
"<=",
"!=",
">=",
"==",
"!" ,
"'>>' or '<<'", // LEX_IN
"<<",
"Wrond operand's type for '||' operation", // LEX_OR
"Wrond operand's type for '&&' operation", // LEX_AND
"//",
"/*",
"\"",
"string",
"variable name", // LEX_ID
"int || double || bool" // LEX_TYPE
};
// int main() {
// cout << "hello world" << endl;
// return 0;
// }