home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / icont / trash.icn < prev    next >
Text File  |  1996-03-22  |  1KB  |  36 lines

  1. #
  2. #  This is an ad-hoc program for removing duplicate code in the main switch
  3. #  statement for binary operators (the optimizer should fold these, if
  4. #  the compiler can get that far).
  5. #
  6. #  This program relies on the form of parse.c as presently produced; it is
  7. #  fragile and may need modification for other versions of parse.c.  Look
  8. #  at your parse.c first to see if the template is correct.
  9. #
  10. #  The same thing could be done for N_Unop, but if this works, that will not
  11. #  be necesssary.
  12.  
  13. procedure main()
  14.    template := "{yyval = tree5(N_Binop"
  15.    while line := read () do {
  16.       if not(match(template,line)) then
  17.          write(line)        # copy until "offending member" is found
  18.       else {
  19.          lastline := line    # save it for last case in group
  20.          buffer := []        # push-back buffer
  21.          repeat {
  22.             put(buffer,read())    # "case ..."
  23.             put(buffer,read())    # "# line ...
  24.             line := read()
  25.             if not match(template,line) then {
  26.                write(lastline)    # if not a duplicate, insert the one instance
  27.                while write(get(buffer))    # write out lines pushed back
  28.                write(line)    # write the new line
  29.                break        # break back to the main loop (may be more)
  30.                }
  31.              else while write(get(buffer))  # else write out lines pushed back
  32.              }
  33.           }
  34.        }
  35. end
  36.