-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd_trace_to_tabc.pl
50 lines (36 loc) · 1.27 KB
/
add_trace_to_tabc.pl
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
#!/usr/bin/env perl
# $Header$
# Script to take the x.tab.c output from Bison, and insert extra function calls
# into it to support the following :
# - detection of possible elidable terminators
# - backtracing on syntax errors
# Hopefully, this changes things that are not *too* specific to particular
# versions of bison. It was originally developed against output from bison
# version 1.27.
# COPYRIGHT
print <<EOF;
extern elide_trace_reduce(int, int);
extern elide_trace_shift(int,int);
extern report_trace_shift(int);
extern report_trace_reduce(int, int);
extern report_trace_error(short *yyss, short *yyssp);
EOF
while (<>) {
# Force type of yytranslate, otherwise we won't have a fixed type to
# declare it as in the elide code.
s/static const char yytranslate/static const short yytranslate/o;
if (m{/\* Shift the lookahead}o) {
print;
print "elide_trace_shift(yystate,yychar);\n";
print "report_trace_shift(yychar);\n";
} elsif (m{^\s*yyreduce\:}o) {
print;
print "elide_trace_reduce(yystate, yyn);\n";
print "report_trace_reduce(yystate, yyn);\n";
} elsif (m{^\s*yyerrlab\:}o) {
print;
print "report_trace_error(yyss, yyssp);";
} else {
print;
}
}