2
TP Yacc message and error handling module 2-5-91 AG
3
Note: this module should be USEd by any module using the heap during
4
initialization, since it installs a heap error handler (which
5
terminates the program with fatal error `memory overflow').
8
Copyright (c) 1990-92 Albert Graef <ag@muwiinfa.geschichte.uni-mainz.de>
9
Copyright (C) 1996 Berend de Boer <berend@pobox.com>
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
$Modtime: 96-07-31 14:50 $
29
$History: YACCMSGS.PAS $
31
* ***************** Version 2 *****************
32
* User: Berend Date: 96-10-10 Time: 21:16
33
* Updated in $/Lex and Yacc/tply
34
* Updated for protected mode, windows and Delphi 1.X and 2.X.
44
var errors, warnings : Integer;
45
(* - current error and warning count *)
46
procedure error(msg : String);
47
(* - print current input line and error message (pos denotes position to
48
mark in source file line) *)
49
procedure warning(msg : String);
50
(* - print warning message *)
51
procedure fatal(msg : String);
52
(* - writes a fatal error message, erases Yacc output file and terminates
53
the program with errorlevel 1 *)
57
(* sign-on and usage message: *)
59
sign_on = 'TP Yacc Version 4.1a [April 2000], Copyright (c) 1990-2000 Albert Graef';
61
usage = 'Usage: pyacc [options] yacc-file[.y] [output-file[.pas]]';
63
usage = 'Usage: yacc [options] yacc-file[.y] [output-file[.pas]]';
65
options = 'Options: -v verbose, -d debug';
67
(* command line error messages: *)
69
invalid_option = 'invalid option ';
70
illegal_no_args = 'illegal number of parameters';
74
open_comment_at_eof = '101: open comment at end of file';
75
missing_string_terminator = '102: missing string terminator';
76
rcurl_expected = '103: %} expected';
77
rbrace_expected = '104: } expected';
78
rangle_expected = '105: > expected';
79
ident_expected = '106: identifier expected';
80
error_in_def = '110: error in definition';
81
error_in_rule = '111: error in rule';
82
syntax_error = '112: syntax error';
83
unexpected_eof = '113: unexpected end of file';
85
(* semantic errors: *)
87
nonterm_expected = '201: nonterminal expected';
88
literal_expected = '202: literal expected';
89
double_tokennum_def = '203: literal already defined';
90
unknown_identifier = '204: unknown identifier';
91
type_error = '205: type error';
92
range_error = '206: range error';
93
empty_grammar = '207: empty grammar?';
97
cannot_open_file = 'FATAL: cannot open file ';
98
write_error = 'FATAL: write error';
99
mem_overflow = 'FATAL: memory overflow';
100
intset_overflow = 'FATAL: integer set overflow';
101
sym_table_overflow = 'FATAL: symbol table overflow';
102
nt_table_overflow = 'FATAL: nonterminal table overflow';
103
lit_table_overflow = 'FATAL: literal table overflow';
104
type_table_overflow = 'FATAL: type table overflow';
105
prec_table_overflow = 'FATAL: precedence table overflow';
106
rule_table_overflow = 'FATAL: rule table overflow';
107
state_table_overflow = 'FATAL: state table overflow';
108
item_table_overflow = 'FATAL: item table overflow';
109
trans_table_overflow = 'FATAL: transition table overflow';
110
redn_table_overflow = 'FATAL: reduction table overflow';
116
procedure position(var f : Text;
120
(* writes a position mark of the form
123
on f with the caret ^ positioned at pos in line
124
a subsequent write starts at the next line, indented with tab *)
126
line1, line2 : String;
128
(* this hack handles tab characters in line: *)
129
line1 := intStr(lineNo)+': '+line;
130
line2 := blankStr(intStr(lineNo)+': '+copy(line, 1, pos-1));
132
writeln(f, line2, '^');
136
procedure error(msg : String);
140
position(output, lno, line, cno-tokleng);
143
position(yylst, lno, line, cno-tokleng);
145
if ioresult<>0 then ;
148
procedure warning(msg : String);
152
position(output, lno, line, cno-tokleng);
155
position(yylst, lno, line, cno-tokleng);
157
if ioresult<>0 then ;
160
procedure fatal(msg : String);
164
close(yyin); close(yyout); close(yylst); erase(yyout);
170
function heapErrorHandler ( size : Word ) : Integer; far;
173
fatal(mem_overflow) (* never returns *)
175
heapErrorHandler := 1
176
end(*heapErrorHandler*);
181
errors := 0; warnings := 0;
184
(* install heap error handler: *)
185
heapError := @heapErrorHandler;