-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc_errors.c
154 lines (124 loc) · 4.29 KB
/
bc_errors.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
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
/*******************************************************************************
* bc_errors.c
* Errors,warnings
*******************************************************************************/
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
#include "bc.h"
#include "errors.h"
extern jmp_buf JB; // comp.c
/*******************************************************************************
* Defs, vars
*******************************************************************************/
typedef struct
{
int ecode;
char *pMsg;
} ERR;
int nErrors;
int nWarnings;
/*******************************************************************************
* void InitErr(void)
*******************************************************************************/
void InitErr(void)
{
nErrors = 0;
nWarnings = 0;
}
/*******************************************************************************
* int GetNrErrors(void)
*******************************************************************************/
int GetNrErrors(void)
{
return nErrors;
}
/*******************************************************************************
* int GetNrWarnings(void)
*******************************************************************************/
int GetNrWarnings(void)
{
return nWarnings;
}
/*******************************************************************************
* Errormessages
*******************************************************************************/
ERR Errors[] = {
{ E_SYNTAX , "Syntax" },
{ E_LINENUM , "Linenum too big" },
{ E_FLTEXP , "Float name expected" },
{ E_EXPECTED , "Expected" },
{ E_NUMFMT , "Number format" },
{ E_FNNOTDEF , "Undefined function" },
{ E_VAREXP , "Var expected" },
{ E_TYPEMISMATCH , "TYpe mismatch" },
{ E_OVERFLOW , "Overflow" },
{ E_FORMTOOCPLX , "Formula too complex" },
{ E_ILLASSIGN , "Illegal assignment" },
{ E_ILLCMD , "Illegal command" },
{ E_UNDEFSTT , "Undef'd statement" },
{ E_FIOVF , "FI table overflow" },
{ E_UNKNOWN , "Unknown BASIC token" },
{ E_MEMFULL , "Program too big" },
{ -1 , NULL },
};
ERR Warnings[] = {
{ W_DIMCHANGED , "array dimensions changed " },
{ W_REDIM , "array redimensioned " },
{ -1 , NULL },
};
/*******************************************************************************
* void SynChk(U8 c)
* GetChr(), Error if not == c
*******************************************************************************/
void SynChk(U8 c)
{
if (GetChr() != c)
{
if (c >= 0x80)
printf("%02x ",c);
else
printf("%c ",c);
Error(E_EXPECTED);
}
}
/*******************************************************************************
* void Error(int e)
* output message to STDOUT and listfile
*******************************************************************************/
void Error(int e)
{
ERR *pErr;
pErr = &Errors[0];
while (pErr->ecode >= 0)
{
if (pErr->ecode == e)
{
printf("%s error in line %5d pos %2d *******\n\r",pErr->pMsg,curLine,GetBufpos());
List ("%s error in line %5d pos %2d *******\n\r",pErr->pMsg,curLine,GetBufpos());
}
pErr++;
}
if (Pass == 2)
nErrors++;
longjmp(JB,2); // Exit to bc_comp.c (skips rest of line, continue with next line)
}
/*******************************************************************************
* void Warn(int w)
*******************************************************************************/
void Warn(int w)
{
ERR *pWarn;
pWarn = &Warnings[0];
while (pWarn->ecode >= 0)
{
if (pWarn->ecode == w)
{
printf("Warning : %s in line %5d pos %2d *******\n\r",pWarn->pMsg,curLine,GetBufpos());
List ("Warning : %s in line %5d pos %2d *******\n\r",pWarn->pMsg,curLine,GetBufpos());
}
pWarn++;
}
if (Pass == 2)
nWarnings++;
}