-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.cc
More file actions
49 lines (44 loc) · 1.3 KB
/
errors.cc
File metadata and controls
49 lines (44 loc) · 1.3 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
#include "header.h"
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
extern int yylineno;
void yyerror(char const *s){
if(s == "syntax error"){
s = "Unrecognizable text";
}
cerr << "\nLine " << yylineno << ": " << s << endl;
exit(-1);
}
/**
* Throw error message, based on error type.
*
* @param e type fo error from errors enum.
* @param var name of variable, which caused error.
*/
void err(errors e, string var){
string err = "";
switch(e){
case errors::BadArrayScope:
err = "Wrong scope of variable '" + (string)var + "'";
break;
case errors::AlreadyDeclaredVar:
err = "Multiple declarations of variable '" + (string)var + "'";
break;
case errors::UndeclaredVar:
err = "Undeclared variable '" + (string)var + "'";
break;
case errors::UninitializedVar:
err = "Uninitialized variable '" + (string)var + "'";
break;
case errors::BadVarType:
err = "Wrong usage of variable '" + (string)var + "' according to its type";
break;
case errors::UnrecognizedText:
default:
err = "Couldn't recognize text '" + (string)var + "'";
break;
}
yyerror(err.c_str());
}