blob: a94594b288666241dcb7ccb78d34a98473ce9870 (
plain)
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
|
#
# This is an ad-hoc program for removing duplicate code in the main switch
# statement for binary operators (the optimizer should fold these, if
# the compiler can get that far).
#
# This program relies on the form of parse.c as presently produced; it is
# fragile and may need modification for other versions of parse.c. Look
# at your parse.c first to see if the template is correct.
#
# The same thing could be done for N_Unop, but if this works, that will not
# be necesssary.
procedure main()
template := "{yyval = tree5(N_Binop"
while line := read () do {
if not(match(template,line)) then
write(line) # copy until "offending member" is found
else {
lastline := line # save it for last case in group
buffer := [] # push-back buffer
repeat {
put(buffer,read()) # "case ..."
put(buffer,read()) # "# line ...
line := read()
if not match(template,line) then {
write(lastline) # if not a duplicate, insert the one instance
while write(get(buffer)) # write out lines pushed back
write(line) # write the new line
break # break back to the main loop (may be more)
}
else while write(get(buffer)) # else write out lines pushed back
}
}
}
end
|