-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_handling.c
123 lines (114 loc) · 4.3 KB
/
error_handling.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
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
/*
Error handling of errors occurred during introspection of .as file
*/
#include <stdio.h>
#include "error_handling.h"
void print_error(error_code err, int line_number) {
switch (err) {
case SYNTAX_ERROR:
printf("line %d: Syntax error. \n", line_number);
break;
case LABEL_WITH_NO_DATA_ERROR:
printf("Line %d: line should contain more than a label.\n", line_number);
break;
case LABEL_ALREADY_EXISTS_ERROR:
printf("line %d: Previously defined label. \n", line_number);
break;
case LABEL_TOO_LONG_ERROR:
printf("line %d: label contains more than 30 characters.\n", line_number);
break;
case LABEL_CONTAINS_INVALID_CHARACTER_ERROR:
printf("line %d: label contains invalid characters.\n", line_number);
break;
case LABEL_FIRST_CHAR_IS_NOT_ALPHA_ERROR:
printf("line %d: First character of the label must be a letter.\n", line_number);
break;
case LABEL_IS_KEYWORD_ERROR:
printf("line %d: Label cannot be a keyword.\n", line_number);
case NOT_EXISTS_DIRECTIVE_ERROR:
printf("line %d: Unrecognized directive. \n", line_number);
break;
case LABEL_IS_ALREADY_EXTERN:
printf("Line %d: label already defined as external \n", line_number);
break;
case LABEL_IS_ALREADY_ENTRY:
printf("Line %d: label already defined as entry \n", line_number);
break;
case LABEL_IS_ALREADY_MACRO:
printf("Line %d: label already defined as macro \n", line_number);
break;
case BAD_COMMAND_ARGUMENT:
printf("line %d: bad argument[s]\n", line_number);
break;
case INSTRUCTION_NOT_FOUND:
printf("line %d: unrecognized insruction. \n", line_number);
break;
case LABEL_NOT_FOUND:
printf("Line %d: label was not defined in the file \n", line_number);
break;
case ENTRY_NOT_EXIST:
printf("Line %d: entry was not defined in the file \n", line_number);
break;
case EMPTY_ERROR:
printf("line %d: unknown error with this line. \n", line_number);
break;
/*
case 50:
printf("line %d: To many characters for one line. The number of characters per line must be less than 80.\n",
line_number);
break;
case 111:
printf("line %d: label cannot be an instruction.\n", line_number);
break;
case 112:
printf("Line %d: Illegal addressing, check operands. \n", line_number);
break;
case 131:
printf("Line %d: label cannot be a register \n", line_number);
break;
case 114:
printf("Line %d:no character[s] between the quotation marks ", line_number);
break;
case 116:
case 117:
printf("Line %d: cannot define label as external. ", line_number);
printf("label already defined as internal.\n");
break;
case 118:
printf("Line %d: Error: expecting argument...\n", line_number);
break;*/
}
}
/*---------------- write_error2 ------------------------
write_error2: This function uses the global variable
"error" to determine whether an error
should be written to the screen.
--------------------------------------------------------
*/
/*
int write_error2(int line_number, char *line) {
switch (error) {
case 1:
printf("Line %d: unrecognized label \n", line_number);
break;
case 2:
printf("Line %d: Error: expecting argument... \n", line_number);
break;
case 3:
printf("Line %d: To few actual argument[s] \n", line_number);
break;
case 4:
printf("Line %d: misseing quotation[s] character on .string directive", line_number);
break;
case 5:
line = skipspace(line);
line = nextfield(line);
if (line == NULL)
return 0;
printf("Line %d: file has no internal label name \"%s\" ", line_number, line);
break;
}
return -13; */
/* late *//*
}
*/