-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
37 lines (33 loc) · 1.18 KB
/
error.c
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
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file exp.c
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Error handling
*/
#include "error.h"
#include <stdio.h>
#include <stdlib.h>
// Error messages for all return codes
const char* error_msgs[] = {
[RET_OK] = "",
[ERR_LEX] = "Lexical error",
[ERR_SYN] = "Syntax error",
[ERR_SEM_FUN] = "Semantic error - function (undeclared, redefinition, ...)",
[ERR_SEM_CALL] = "Semantic error - function call (wrong number of parameters, ...)",
[ERR_SEM_VAR] = "Semantic error - undefined variable",
[ERR_SEM_RET] = "Semantic error - return statement",
[ERR_SEM_COMP] = "Semantic error - incompatible types",
[ERR_SEM] = "Other semantic error",
[ERR_INTERNAL] = "Internal error (e.g. memory allocation error)"};
void error_exit(enum return_code code) {
fprintf(stderr, "%s\n", error_msgs[code]);
exit(code);
}
void error_not_implemented() {
fprintf(stderr, "Not implemented!\n");
exit(ERR_INTERNAL);
}