-
Notifications
You must be signed in to change notification settings - Fork 1
/
ERROR.PAS
120 lines (79 loc) · 2.42 KB
/
ERROR.PAS
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
{ ERROR.PAS
Description:
Writes out all kinds of compile-time errors. Does not perform
a halt; expects the program itself to "unravel" the process.
}
unit error;
interface
uses misc, keywords, token;
{ Functions and Procedures }
procedure hit_eof(var f: progfile; expecting: acl_type; specific:integer);
procedure expected(var f: progfile;
expect_ttype: acl_type; expect_specific: integer);
procedure expect_general(var f: progfile;
general_desc: string);
procedure error_message(var f: progfile; message: string);
function insist_on(var f: progfile;
some_type: acl_type; some_number: integer): boolean;
implementation
procedure hit_eof(var f: progfile; expecting: acl_type; specific: integer);
begin
if KeepLooking then begin
KeepLooking := FALSE;
write('Found end of file; expected ');
write_token(expecting, specific);
writeln
end
end;
procedure expected(var f: progfile;
expect_ttype: acl_type; expect_specific: integer);
begin
if KeepLooking then begin
source_pos(f);
write('Expected ');
write_token(expect_ttype, expect_specific);
write('; found ');
write_token(f.ttype, f.tnum);
writeln
end
end; { expected }
procedure expect_general(var f: progfile;
general_desc: string);
begin
if KeepLooking then begin
source_pos(f);
write('Expected ');
write(general_desc, '; found ');
write_token(f.ttype, f.tnum);
writeln
end
end; { expected }
procedure error_message(var f: progfile; message: string);
begin
if KeepLooking then begin
source_pos(f);
writeln(message)
end
end;
{ insist_on
Description:
Used when a particular token is insisted upon by the syntax, usually
for readability. It will be an error for the token not to exist.
}
function insist_on(var f: progfile;
some_type: acl_type; some_number: integer): boolean;
begin
if not get_token(f) then begin
hit_eof(f, some_type, some_number);
insist_on := FALSE
end
else if (f.ttype <> some_type) and (f.tnum <> some_number) then begin
expected(f, some_type, some_number);
KeepLooking := FALSE;
insist_on := FALSE
end
else
insist_on := TRUE
end; { insist_on }
end. { unit error }