1 # Clarify the flex debug trace by substituting first line of each rule.
2 # Francois Pinard <pinard@iro.umontreal.ca>, July 1990.
4 # Rewritten to process correctly \n's in scanner input.
5 # BEGIN section modified to correct a collection of rules.
6 # Michal Jaegermann <michal@phys.ualberta.ca>, December 1993
10 # gcc -o PROGRAM PROGRAM.c -lfl
11 # PROGRAM 2>&1 | gawk -f debflex.awk PROGRAM.l
13 # (VP's note: this script presently does not work with either "old" or
14 # "new" awk; fixes so it does will be welcome)
17 # Insure proper usage.
20 print "usage: gawk -f debflex.awk FLEX_SOURCE <DEBUG_OUTPUT";
24 # Remove and save the name of flex source.
29 # Swallow the flex source file.
33 while (getline <source
) {
39 # Count the sections. When encountering section 3,
40 # break out of the awk BEGIN block.
42 if (match ($
0, /^
%%/)) {
49 # Only the lines in section 2 which do not begin in a
50 # tab or space might be referred to by the flex debug
51 # trace. Save only those lines.
53 if (section ==
2 && match ($
0, /^
[^
\t]/)) {
58 dashes =
"-----------------------------------------------------------";
63 # collect complete rule output from a scanner
65 collect = collect
"\n" $
0;
68 # otherwise we have a new rule - process what we got so far
72 # and the same thing if we hit EOF
79 # splitting this way we loose some double dashes and
80 # left parentheses from echoed input - a small price to pay
81 n =
split(collect
, field
, "\n--|[(]");
83 # this loop kicks in only when we already collected something
84 for (i =
1; i
<= n
; i
++) {
86 # we do not care for traces of newlines.
87 if (0 ==
match(field
[i
], /\"\n+\"[)]/)) {
93 printf("%s:%d: %-8s -- %s\n",
94 source
, line
, text
, rules
[line
]);
98 printf "%s:%d: *** No such rule.\n", source
, line
;
104 if ("" != field
[i
]) {
105 if ("end of buffer or a NUL)" == field
[i
]) {
106 print dashes
; # Simplify trace of buffer reloads
109 if (match(field
[i
], /accepting rule at line
/)) {
110 # force interpretation of line as a number
111 line =
0 + substr(field
[i
], RLENGTH);
114 # echo everything else
115 printf("--%s\n", field
[i
]);
118 collect =
"\n" $
0; # ... and start next trace