-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.c
156 lines (131 loc) · 3.76 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
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
155
/******************************************************************************
* CVS version:
* $Id: error.c,v 1.2 2004/05/05 22:00:08 nickie Exp $
******************************************************************************
*
* C code file : error.c
* Project : PCL Compiler
* Version : 1.0 alpha
* Written by : Nikolaos S. Papaspyrou ([email protected])
* Date : May 14, 2003
* Description : Generic symbol table in C, simple error handler
*
* Comments: (in Greek iso-8859-7)
* ---------
* Εθνικό Μετσόβιο Πολυτεχνείο.
* Σχολή Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών.
* Τομέας Τεχνολογίας Πληροφορικής και Υπολογιστών.
* Εργαστήριο Τεχνολογίας Λογισμικού
*/
/* ---------------------------------------------------------------------
---------------------------- Header files ---------------------------
--------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "general.h"
#include "error.h"
extern char lastWhitespace;
extern char * yytext;
/* ---------------------------------------------------------------------
--------- Υλοποίηση των συναρτήσεων του χειριστή σφαλμάτων ----------
--------------------------------------------------------------------- */
void internal (const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else
fprintf(stderr, "%s:%d: ", filename, linecount);
fprintf(stderr, "Internal error, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
//FIXME: here fremove("filename") to delete .imm and .asm files if a syntax error is spotted
exit(INTERNAL_ERRNUM);
}
void fatal (const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else
fprintf(stderr, "%s:%d: ", filename, linecount);
fprintf(stderr, "Fatal error, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(FATAL_ERRNUM);
}
void error (const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else
fprintf(stderr, "%s:%d: ", filename, linecount);
fprintf(stderr, "Error, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
}
void warning (const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else
fprintf(stderr, "%s:%d: ", filename, linecount);
fprintf(stderr, "Warning, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
}
/* Our additions */
/* ************* */
void sserror(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else{
int errLine = linecount;
if(lastWhitespace=='\n')
errLine--;
fprintf(stderr, "%s:%d: ", filename, errLine);
}
fprintf(stderr, "semantic error, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(SEMANTIC_ERRNUM);
}
/* Semantic error traced in the middle of a rule
* (before the rule is parsed completely) */
void ssmerror(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt[0] == '\r')
fmt++;
else{
fprintf(stderr, "%s:%d: ", filename, linecount);
}
fprintf(stderr, "semantic error, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(SEMANTIC_ERRNUM);
}
/* For syntax errors: called implicitly by parser */
int yyerror(const char *msg)
{
fprintf(stderr, "%s:%d: ", filename, linecount);
fprintf(stderr,"syntax error: %s\n",msg);
exit(SYNTAX_ERRNUM);
}