# Copyright (c) 2023, 2025 Dennis J. Darland - All Rights Reserved # the relative strength of operations are given by the following # the lower the number, the greater the strength # negation $define NEXTRA 1 # binary truth functions other than conjunction $define LEXTRA 1 # conjunction $define AEXTRA 2 # will be for quantifiers $define QEXTRA 1 $define NO_PRECEDENCE 0 $define CONJUNCTION_LOW_PRECEDENCE 2 $define CONJUNCTION_HIGH_PRECEDENCE 1 $define MAX_LOOP 50000000000 $define PM 0 $define LUK 1 $define POLISH_INCLUDED 1 $define BEGIN "%begin" global dot, dott, dottt, dotttt, dottttt, dotttttt, and, andd, anddd, andddd, anddddd, anddddd, andddddd, dot_flag, qexist, qall, qdsc, qneg, lineno, sno_s, val_s, echo, sno_tmp, val_tmp, last_sep, qor, qimp, qiff, lextra, qextra, max_exe, delim_q2, delim_l2, max_iter, stk, reverse_polish, head, qiddf, dbg, dbg2, stack, nextra, aextra, active, partA1, partA2, found_paren, front1 procedure main() # next 2 lines used to get debugging from unicon &trace := 100000 # how many function calls to trace &dump := 1 # nonzero turns on termination dump init() process() finish() end procedure init() if not (dbg := open("dbg.txt","w")) then stop("cannot open dbg.txt") if not (dbg2 := open("dbg2.txt","w")) then stop("cannot open dbg2.txt") write(dbg, "Started Debugging") write(dbg2, "Started Debugging") max_iter := MAX_LOOP max_exe := 10000000 nextra := NEXTRA lextra := LEXTRA aextra := AEXTRA qextra := QEXTRA active := 1 delim_l2 := ' abcdefghijklmnopqrstuvwxyz$\\' delim_q2 := ' abcdefghijklmnopqrstuvwxyz$\\' delim_n2 := ' abcdefghijklmnopqrstuvwxyz$\\' # initialize globals echo := 1 # show original line with dots next to one with parens lineno := 0 # global as may be useful if error messages etc. # The following are used to identify strings used in latex - mostly principia dot := "\\pmdot" dott := "\\pmdott" dottt := "\\pmdottt" dotttt := "\\pmdotttt" dottttt := "\\pmdottttt" dotttttt := "\\pmdotttttt" and := "\\pmand" andd := "\\pmandd" anddd := "\\pmanddd" andddd := "\\pmandddd" anddddd := "\\pmanddddd" andddddd := "\\pmandddddd" qexist := "\\pmsome{" qneg := "\\pmnot" qall := "\\pmall{" qdsc := "\\dsc{" qor := "\\pmor" qiddf := "\\pmiddf" qimp := "\\pmimp" qiff := "\\pmiff" sno_s := table(0) val_s := table(0) val_s[1] := "." sno_s[1] := "@SNO.@" # Not expected in linein - may be changed if conflict val_s[2] := "^" sno_s[2] := "@SNO^@" # Not expected in linein - may be changed if conflict val_s[3] := "!" sno_s[3] := "@SNO!@" # Not expected in linein - may be changed if conflict val_s[4] := "%" sno_s[4] := "@SNO%@" # Not expected in linein - may be changed if conflict val_s[5] := ";" sno_s[5] := "@SNO;@" # Not expected in linein - may be changed if conflict val_s[6] := ":" sno_s[6] := "@SNO:@" # Not expected in linein - may be changed if conflict sno_s[7] := "@SNOpsi@" val_s[7] := "\\psi" sno_s[8] := "@SNOalpha@" val_s[8] := "\\alpha" sno_s[9] := "@SNObeta@" val_s[9] := "\\beta" sno_s[10] := "@SNOgamma@" val_s[10] := "\\gamma" sno_s[11] := "@SNOphi@" val_s[11] := "\\phi" sno_s[12] := "@SNOphi@" val_s[12] := "\\phi" sno_s[13] := "@SNOchi@" val_s[13] := "\\chi" sno_tmp := "@SNOTEMP@" # Not expected in linein - may be changed if conflict val_tmp := "TEMP" while line := read() do { write(line) if line == BEGIN then break } end procedure finish() write("\\end{document}") write(dbg,"Stopping debugging") close(dbg) write(dbg2,"Stopping debugging") close(dbg2) end procedure process() while linein := read() do { # read from standard in lineno +:= 1 # # write("% lineno ", lineno, " = ", linein) # dont change comment lines if linein ? find("%ACTIVEON") then { active := 1 next } if linein ? find("%ACTIVEOFF") then { active := 0 next } if (linein ? match("%") || tab(0)) & (active = 1) then { write(linein) next } # only change lines with dots if find("\\pmand", linein) then a := 1 else a := 0 if find("\\pmdot", linein) then b := 1 else b := 0 if ((a + b) > 0) & (active = 1) then { if echo = 1 then { write(dbg2, "ECHO1 = ", linein) write(linein) write(" ") partA1 := "" partA2 := "" write(dbg2, "before process2 linein = ", linein) process2(linein) } } else { if (echo = 1) & (active = 1) then { write(dbg2, "ECHO2 = ", linein) write(linein) write(" ") next } } } end procedure process2(linein) found_paren := 0 a := find(dot, linein) # b := find(and, linein) linein ? ((front := tab(a)) & (linein := tab(0))) # avoid any conflicts av := 1 while av <= *sno_s do { linein := avoid(linein,sno_s[av],val_s[av]) av +:= 1 } # write("%% HERE linein = ", linein) ## Next change possible leading dots if lineout := sub_dot_leading(linein, dotttttt, " ^^^^^^ ") then linein := lineout else if lineout := sub_dot_leading(linein, dottttt, " ^^^^^") then linein := lineout else if lineout := sub_dot_leading(linein, dotttt, " ^^^^ ") then linein := lineout else if lineout := sub_dot_leading(linein, dottt, " ^^^ ") then linein := lineout else if lineout := sub_dot_leading(linein, dott, " ^^ ") then linein := lineout else if lineout := sub_dot_leading(linein, dot, " ^ ") then linein := lineout # first change dots associated with quantifiers with to "!" # quantifiers must come first # if not first they would already be changed to wrong value # also changes quantifier symbol to "TEMP" - to avoid getting stuck # would be better to find someting other than "TEMP" # longer number of dots done first # this is Group II on page 9 of to *56 # ! before quantifier % after linein := fix_op_dot(linein) linein := sub_dot_two_leading(linein, qor, dotttttt, (" " || repl(".", 6 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, dottttt, (" " || repl(".", 5 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, dotttt, (" " || repl(".", 4 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, dottt, (" " || repl(".", 3 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, dott, (" " || repl(".", 2 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, dot, (" " || repl(".", 1 + lextra) || " ")) linein := sub_dot_two_leading(linein, qor, " ", (" " || repl(".", lextra) || " ")) # Next change "TEMP" back to or symbol # # write("% POST03 linein = after or", linein) # linein := sub_temp(linein, qor) linein := sub_dot_two_leading(linein, qimp, dotttttt, (" " || repl(".", 6 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, dottttt, (" " || repl(".", 5 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, dotttt, (" " || repl(".", 4 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, dottt, (" " || repl(".", 3 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, dott, (" " || repl(".", 2 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, dot, (" " || repl(".", 1 + lextra) || " ")) linein := sub_dot_two_leading(linein, qimp, " ", (" " || repl(".", lextra) || " ")) # Next change "TEMP" back to imp symbol # linein := sub_temp(linein, qimp) # # write("% POST04 linein after imp = ", linein) linein := sub_dot_two_leading(linein, qiff, dotttttt, (" " || repl(".", 6 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, dottttt, (" " || repl(".", 5 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, dotttt, (" " || repl(".", 4 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, dottt, (" " || repl(".", 3 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, dott, (" " || repl(".", 2 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, dot, (" " || repl(".", 1 + lextra) || " ")) linein := sub_dot_two_leading(linein, qiff, " ", (" " || repl(".", lextra) || " ")) # Next change "TEMP" back to quantifier symbol # linein := sub_temp(linein, qiff) # # write("% POST05 linein after iff = ", linein) linein := sub_dot_two_trailing(linein, qor, dotttttt, (" " || repl("^", 6 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, dottttt, (" " || repl("^", 5 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, dotttt, (" " || repl("^", 4 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, dottt, (" " || repl("^", 3 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, dott, (" " || repl("^", 2 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, dot, (" " || repl("^", 1 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qor, " ", (" " || repl("^", lextra) || " ")) # Next change "TEMP" back to or symbol # # write("% POST03 linein = after or", linein) # linein := sub_temp(linein, qor) linein := sub_dot_two_trailing(linein, qimp, dotttttt, (" " || repl("^", 6 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, dottttt, (" " || repl("^", 5 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, dotttt, (" " || repl("^", 4 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, dottt, (" " || repl("^", 3 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, dott, (" " || repl("^", 2 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, dot, (" " || repl("^", 1 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qimp, " ", (" " || repl("^", lextra) || " ")) # Next change "TEMP" back to imp symbol # linein := sub_temp(linein, qimp) # # write("% POST04 linein after imp = ", linein) linein := sub_dot_two_trailing(linein, qiff, dotttttt, (" " || repl("^", 6 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, dottttt, (" " || repl("^", 5 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, dotttt, (" " || repl("^", 4 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, dottt, (" " || repl("^", 3 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, dott, (" " || repl("^", 2 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, dot, (" " || repl("^", 1 + lextra) || " ")) linein := sub_dot_two_trailing(linein, qiff, " ", (" " || repl("^", lextra) || " ")) # Next change "TEMP" back to quantifier symbol # linein := sub_temp(linein, qiff) # # write("% POST05 linein after iff = ", linein) # Next change dots associated with conjunction to ";" # Group III on page 9 to *56 ax1 := repl(";", aextra) ax2 := repl(":", aextra) linein := sub_dot(linein, andddddd, (ax1 || ";;;;; \\land :::::" || ax2) ) linein := sub_dot(linein, anddddd, (ax1 || ";;;; \\land ::::" || ax2) ) linein := sub_dot(linein, andddd, (ax1 || ";;; \\land :::" || ax2) ) linein := sub_dot(linein, anddd, (ax1 || ";; \\land ::" || ax2) ) linein := sub_dot(linein, andd, (ax1 || "; \\land :" || ax2) ) linein := sub_dot(linein, and, (ax1 || " \\land " || ax2) ) # # write("% POST06 linein after and = ", linein) linein := sub_dot_not(linein, dotttttt, (" " || repl("!",6 + nextra) || " ")) linein := sub_dot_not(linein, dottttt, (" " || repl("!",5 + nextra) || " ")) linein := sub_dot_not(linein, dotttt, (" " || repl("!",4 + nextra) || " ")) linein := sub_dot_not(linein, dottt, (" " || repl("!",3 + nextra) || " ")) linein := sub_dot_not(linein, dott, (" " || repl("!",2 + nextra) || " ")) linein := sub_dot_not(linein, dot, (" " || repl("!",1 + nextra) || " ")) # Next change "TEMP" back to quantifier symbol # next compute number of left parens to start with # total number of "!" or "." # ";" is neutral - produces same number of right or left paren # Later as analyze keep track of open and close paren # and add enough close paren to balance # first_dots := scan1(linein) # write("% before analyze linein = ", linein) # see comments within analyze linein := front || linein linein := sub_dot(linein, dotttttt, "!!!!!!") linein := sub_dot(linein, dottttt, "!!!!!") linein := sub_dot(linein, dotttt, "!!!!") linein := sub_dot(linein, dottt, "!!!") linein := sub_dot(linein, dott, "!!") linein := sub_dot(linein, dot, "!") write(dbg, "HERE BA li = ", linein) linein := sub_temp(linein, qneg) linein := analyze0(linein) lineout2 := analyze1(linein) lineout := analyze2(lineout2) write(dbg, "HERE AA li = ", lineout) # finally remove as many paren from left and right as possibe # we will have started with more opening paren than needed # lineout := trim_excess(lineout) av := 1 while av <= *sno_s do { restore_avoided(linein,sno_s[av],val_s[av]) # avoid should not occur in line av +:= 1 } while (lineout ? ((p1 := tab(find("["))) & (p1a := tab(find(")"))) & (tab(many(") "))) & (r1 := tab(0)))) do { write(dbg2, "p1 = ",p1) write(dbg2, "p1a = ",p1a) write(dbg2, "r1 = ",r1) lineout := p1 || fix_paren_str2(p1a) || r1 } lineout := reverse(lineout) while (lineout ? ((p2 := tab(find("]"))) & (p2a := tab(find("("))) & (tab(many("( "))) & (r2 := tab(0)))) do { write(dbg2, "p2a = ",p2a) write(dbg2, "p2 = ",p2) write(dbg2, "r2 = ",r2) lineout := p2 || fix_paren_str2(p2a) || r2 } lineout := reverse(lineout) write(dbg2, "LINEOUT [ fix = ", lineout) # lineout_sav := lineout lineout := fix_paren_str(lineout) write(dbg2, "LINEOUT [ fix2 = ", lineout) lineout_sav := lineout # lineout := trim_excess_trailing(lineout) lineout_sav := lineout # original parentheses version before Polish # if active == 1 then { # write(lineout) # } write("") if (POLISH_INCLUDED = 1) then { to_Polish(lineout_sav) } # else { # linein_sav := linein # write(linein) # if (POLISH_INCLUDED = 1) then { # to_Polish(linein) # } # } end procedure avoid(linein,sno,val) # avoid should not occur in line if linein ? find(sno) then { write("Error line = ",lineno, sno, " conflicts with internal value. (unlikely)") write(&errout, "Error line = ",lineno, sno, " conflicts with internal value. (unlikely)") write("May change in dot_to_paren.icn") write(&errout, "May change in dot_to_paren.icn") exit(1) } else { while linein ? (part1 := tab(find(val)) & tab(match(".")) & part2 := tab(0)) do { linein := part1 || sno || part2 } } return linein end procedure restore_avoided(linein,sno,val) # avoid should not occur in line while linein ? (part1 := tab(find(sno)) & tab(match(sno)) & part2 := tab(0)) do { linein := part1 || val || part2 } return linein end # for groups I and III procedure sub_dot(linein, dot_str, dots_out) write(dbg, "HEREHERE linein = ", linein) write(dbg, "HEREHERE dot_str = ", dot_str) write(dbg, "HEREHERE dots_out = ", dots_out) lineout := linein while \lineout ? ((part1 := tab(find(dot_str))) & tab(match(dot_str)) & (part2 := tab(0))) do { write(dbg,"HEREAGAIN part1 = ",part1) write(dbg,"HEREAGAIN part2 = ",part2) linein := part1 || dots_out || part2 if \linein then lineout := linein } write(dbg, "HEREHEREHERE ", lineout) return lineout end # for group II procedure sub_dot_leading(linein, dot_str, dots_out) write(dbg2, "% LEADING in ", linein) if linein ? ((pos(1) & (tab(match(dot_str))) & (part2 := tab(0)))) then { linein := dots_out || part2 lineout := linein write(dbg2, "% LEADING out ", lineout) return lineout } else { # write("% FAILED LEADING out ", lineout) fail } end # for group II procedure sub_dot_two_trailing(linein, symbol , dot_str, dots_out) write(dbg2, "SUB_DOT_TWO_TRAILING") write(dbg2, "linein = ",linein) write(dbg2, "symbol = ", symbol) write(dbg2, "dot_str = ", dot_str) write(dbg2, "dots_out = ", dots_out) if (symbol == "\\pmimp") & (dot_str == "\\pmdot") then write(dbg2, "ALERT") # immediately after operator while linein ? ( (part0 := tab(find(symbol))) & write(dbg2, "trailing PART0 = ", part0) & (part1 := tab(match(symbol))) & write(dbg2, "trailing PART1 (SYMBOL) = ", part1) & (part2 := (tab(many(' ')) | tab(match("")))) & (part3 := tab(match(dot_str))) & (part3b := (tab(many(' ')) | tab(match("")))) & (part4 := tab(0)) & (write(dbg2, "part4 = ", part4))) do { linein := part0 || "TEMP" || dots_out || part4 write(dbg2, "AFTER linein = ",linein) } linein := sub_temp(linein, symbol) return linein end # for group II procedure sub_dot_two_leading(linein, symbol , dot_str, dots_out) write(dbg2, "SUB_DOT_TWO_LEADING") write(dbg2, "linein = ",linein) write(dbg2, "symbol = ", symbol) write(dbg2, "dot_str = ", dot_str) write(dbg2, "dots_out = ", dots_out) # immediately before operator if (symbol == "\\pmimp") & (dot_str == "\\pmdot") then write(dbg2, "ALERT2") linein := reverse(linein) symbol := reverse(symbol) dot_str := reverse(dot_str) lineout := reverse(sub_dot_two_trailing(linein, symbol , dot_str, dots_out)) write(dbg2, "leading lineout = ",lineout) return lineout end # for not procedure sub_dot_not(linein, dot_str, dots_out) write(dbg2, "SUB_DOT_TWO_LEADING") write(dbg2, "linein = ",linein) write(dbg2, "symbol = ", symbol) write(dbg2, "dot_str = ", dot_str) write(dbg2, "dots_out = ", dots_out) # immediately before operator # if (symbol == "\\pmimp") & (dot_str == "\\pmdot") then write(dbg2, "ALERT2") # linein := reverse(linein) # symbol := reverse(symbol) # dot_str := reverse(dot_str) lineout := sub_dot_two_trailing(linein, "\pmnot" , dot_str, dots_out) write(dbg2, "NOT lineout = ",lineout) return lineout end $ifdef FUTURE procedure sub_qdot(linein, quant , dot_str, dots_out) write(&errout, "SUB_QDOT") write(&errout, "linein = ",linein) write(&errout, "symbol = ", quant) write(&errout, "dot_str = ", dot_str) write(&errout, "dots_out = ", dots_out) # immediately before quantifier while linein ? ( # (part0 := tab(many(' ')) | tab(match(""))) & part0 := tab(find(quant)) & write(&errout, "PART0 blank = ", part0) & part1 := tab(match(quant)) & write(&errout, "PART1 (QUANT) = ", part1) & part2 := (tab(many(' ')) | tab(match(""))) & part3 := tab(many('abcdefghijklmnopqrstuvwxyzABCDERGHIJKLMNOPQRSTUVWXYZ\\')) & write(&errout, "part3 (quantified) = ", part3) & part4 := tab(match("}")) & write(&errout, "part4 } = ", part4) & (tab(many(' ')) | tab(match(""))) & part5 := tab(0) & write(&errout, "part5 = ", part5)) do { write(&errout, "PART5 = ", part5) max_exe -:= 1 if max_exe <= 0 then exit() if part6 := sub_qdot2(part5, dotttttt, (" " || repl("%", 6 + qextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, dottttt, (" " || repl("%", 5 + qextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, dotttt, (" " || repl("%", 4 + qextra) || " ")) then linein := "part0 || part2 || TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, dottt, (" " || repl("%", 3 + qextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, dott, (" " || repl("%",2 + qextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, dot, (" " || repl("%", 1 + qextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_qdot2(part5, " ", (" " || repl("%", qextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 write(&errout, "BOTTOM linein = ", linein) } write(&errout, "linein = ", lineout) return linein end procedure sub_qdot2(part, dot_str, dots_out) write(&errout, "SUB_QDOT2") write(&errout, "SUB_QDOT2 part = ", part) write(&errout, "SUB_QDOT2 dot_str = ", dot_str) write(&errout, "SUB_QDOT2 dots_out = ", dots_out) if dot_str ~== " " then { if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & (part1 := tab(match(dot_str))) & (part2 := tab(0)))) then { part := part0 || dots_out || part2 return part } else if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(any(delim_q2)) & part2 := tab(0))) then { part := part0 || part1 || part2 return part } } fail end $endif $ifdef PAST # for group II procedure sub_ldot_OLD_OLD(linein, log_conn , dot_str, dots_out) write(&errout, " SUB_LDOT") write(&errout, " linein = ",linein) write(&errout, " symbol = ", log_conn) write(&errout, " dot_str = ", dot_str) write(&errout, " dots_out = ", dots_out) # immediately before connective while linein ? ( (if dot_str ~== " " then { part0 := tab(find(dot_str)) & part1 := tab(match(dot_str)) & (tab(many(' '))| tab(match(""))) & part2 := tab(match(log_conn)) } else { (part0 := tab(many(' ')) | tab(match(""))) part1 := "" & part2 := tab(match(log_conn)) }) & write(&errout, "% part1 (dot_str) = ", part1) & write(&errout, "% part2 (dot_str) = ", part2) & bad := (tab(many(' ')) | tab(match(""))) & write(&errout,"% BAD = |", bad, "|") & # bad2 := tab(0) & # # write("% BAD2 = ", bad2) & # part2 := tab(match(log_conn)) & # write("% part2 (log_conn) = ", part2, "part2 = ", part2) & part5 := tab(0)) do { max_exe -:= 1 if max_exe <= 0 then exit() write(&errout, "part5 = ", part5) # write("% part5 = ", part5)) do { if part6 := sub_ldot2(part5, dotttttt, (" " || repl("^", 6 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dottttt, (" " || repl("^", 5 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dotttt, (" " || repl("^", 4 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dottt, (" " || repl("^", 3 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dott, (" " || repl("^", 2 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dot, (" " || repl("^", 1 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, " ", (" " || repl("^", lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 write(&errout, "% BOTTOM linein = ", linein) } # write("% FAILED lineout = ", lineout) return linein end procedure sub_ldot2_OLD_OLD(part, dot_str, dots_out) write(&errout, "SUB_LDOT2") write(&errout, "SUB_LDOT2 part = ", part) write(&errout, "SUB_LDOT2 dot_str = ", dot_str) write(&errout, "SUB_LDOT2 dots_out = ", dots_out) if (dot_str ~== " ") then { if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(match(dot_str)) & part2 := tab(0))) then { part := part0 || dots_out || part2 # write("% SUB_LDOT2 return part = ", part) return part } } else if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(any(delim_l2)) & part2 := tab(0))) then { part := part0 || dots_out || part2 # write("% SUB_LDOT2 return part = ", part) return part } fail end $endif # to put quantifier symbol for "TEMP" value procedure sub_temp(linein, temp) while linein ? (part1 := tab(find("TEMP")) & tab(match("TEMP")) & part2 := tab(0)) do { linein := part1 || temp || part2 } return linein end procedure trim_excess(line) line := trim(line) line ? (part1 := tab(find("(")) & # part 1 is string up to 1st paren part2 := tab(find("$")) & # part 2 is rest through the end part3 := tab(match("$"))) i := 2 it := part2 j := *part2 sav := part2 while ((part2[i] == "(") & (part2[j] == ")")) do { it := part2[i:j] part2 := it i := 2 j := *part2 if check(it) == 1 then { sav := it next } else break } return part1 || sav || "$" end procedure check(line) # make sure not too many paren removed leftp := 0 rightp := 0 i := 1 while i <= *line do { if line[i] == "(" then leftp +:= 1 if line[i] == ")" then rightp +:= 1 if rightp > leftp then fail i +:= 1 } return 1 end $ifdef FUTURE procedure quantifier_next(linein, i) temp := linein[i:0] if temp ? (tab(many('.') & (tab(match(qexist)) | tab(match(qall)) | tab(match(qneg)) | tab(match(qdsc))))) then { write(&errout, QUANTIFIER_NEXT = 1) return 1 } else fail end $endif procedure next_paren(charin) it := charin if it == "." then return ")" if it == "+" then return "(" if it == "^" then return "(" if it == "!" then return "(" if it == "%" then return ")" if it == ";" then return ")" if it == ":" then return "(" if it == "(" then return "(" if it == ")" then return ")" # if it == "[" then return "(" # if it == "]" then return ")" return it end procedure fix_paren(charin) it := charin if it == "{" then return "(" if it == "}" then return ")" return it end procedure fix_paren2(charin) it := charin if it == "[" then return "{" if it == "]" then return "}" return it end procedure trim_excess_trailing(in) paren_cnt := 0 out := "" in_sz := *in i := 1 while i <= in_sz do { if in[i] == "(" then paren_cnt +:= 1 if in[i] == ")" then paren_cnt -:= 1 if (paren_cnt >= 0) then out ||:= in[i] } return out end procedure append_lineout(lineout, str) return (lineout || str) end procedure to_Polish(infix) write(dbg, "Enter to_Polish infix below") write(dbg, infix) if (infix ? find("(")) then { if (infix ? find("$")) then { infix ? (head1 := tab(find("pmthm")) & head2 := tab(match("pmthm")) & stmt := tab(0)) write(dbg, "A0001 head1 = ", head1) write(dbg, "A0002 head2 = ", head2) head := head1 || head2 write(dbg, "A0003 head = ", head) write(dbg, "A0004 stmt = ", stmt) stmt := reverse(stmt) write(dbg, "A0005 reverse stmt = ", stmt) stmt ? (tail1 := tab(find("$")) & tail2 := tab(match("$")) & rest := tab(0)) write(dbg, "A0006 tail1 = ", tail1) write(dbg, "A0007 tail2 = ", tail2) write(dbg, "A0008 rest = ", rest) stmt := reverse(rest) # write_note("Polish No Precedence") # polish := infixToPolish(stmt, NO_PRECEDENCE, PM) # write(head || polish || reverse(tail2 || tail1)) # write_note("Polish Conjunction Low Precedence") # polish := infixToPolish(stmt, CONJUNCTION_LOW_PRECEDENCE, PM) # write(head || polish || reverse(tail2 || tail1)) # write_note("Polish Notation") polish := infixToPolish(stmt, CONJUNCTION_LOW_PRECEDENCE, LUK) polish2 := (head || polish || reverse(tail2 || tail1)) write(" ") fixed_par := (head || preToInfix(polish) || reverse(tail2 || tail1)) write(dbg, "Dennis1", polish) write(dbg, "Dennis2", fixed_par) if (active = 1) then { write(fixed_par) write(" ") write(polish2) } # write_note("Polish Conjunction High Precedence") # polish := infixToPolish(stmt, CONJUNCTION_HIGH_PRECEDENCE, PM) # write(head || polish || reverse(tail2 || tail1)) # write_note("Polish No Precedence Lukasiewicz notation") # polish := infixToPolish(stmt, NO_PRECEDENCE, LUK) # write(head || polish || reverse(tail2 || tail1)) # write_note("Polish Conjunction High Precedence Lukasiewicz notation") # write_note("Polish Lukasiewicz notation") # polish := infixToPolish(stmt, CONJUNCTION_HIGH_PRECEDENCE, LUK) # write(head || polish || reverse(tail2 || tail1)) write("") } } write(dbg, "Exit to_Polish stmt below") write(dbg, stmt) end procedure infixToPolish(infix, precedence_flag, pm_or_luk) write(dbg, "infixToPolish B0001") write(dbg, "B002 infix = ",infix) infix := reverse(infix) write(dbg, "B003 reverse infix = ",infix) polish := "" iii := 1 while iii <= *infix do { write(dbg, "B004 iii = ", iii, " *infix = ", *infix) max_iter -:= 1 if max_iter < 0 then exit() if (infix[iii] == ")") then infix[iii] := "(" else if(infix[iii] == "(") then infix[iii] := ")" write(dbg, "B005 infix = ",infix) iii +:= 1 } write(dbg, "before infixToReverse_Polish") polish := infixToReverse_Polish(infix, precedence_flag, pm_or_luk) polish := reverse(polish) return polish end procedure op_symbol(symbol, pm_or_luk) case pm_or_luk of { LUK: case stripped(symbol) of { "pmimp\\" : return " C " "dnal\\" : return " K " "ffimp\\" : return " E " "romp\\" : return " A " "fddimp\\" : return " = " "tonmp\\" : return " N " default: return symbol } PM: return symbol } end procedure precedence(operator, precedence_flag) case precedence_flag of { NO_PRECEDENCE: return 1 CONJUNCTION_HIGH_PRECEDENCE: case operator of { "dnal\\": return 5 default: return 1 } CONJUNCTION_LOW_PRECEDENCE: case operator of { "dnal\\": return 0 default: return 1 } } end procedure infixToReverse_Polish(infix, precedence_flag, pm_or_luk) write(dbg, "Enter infixToReverse_Polish") write(dbg, "C0001 infix = ", infix) stk := [] reverse_polish := "" while (*infix > 0) & (infix ~== " ") & (infix ~== " ") do { write(dbg,"C0002 *infix = ", *infix) max_iter -:= 1 if max_iter < 0 then exit() nxt := get_next(infix) write(dbg,"C0003 nxt = ", nxt) if is_operand(stripped(nxt)) then { # step 2 write(dbg,"C0004 is operand") append_reverse_polish(nxt, pm_or_luk) } else if (stripped(nxt) == "(") then { write(dbg,"C0005 is (") # step 3 push_stack("(") } else if (stripped(nxt) == ")") then { write(dbg,"C0006 is )") # step 4 while ((*stk > 0) & (top_stack() ~== "(" )) do { write(dbg,"C0007 *stk = ", *stk) max_iter -:= 1 if max_iter < 0 then exit() write(dbg,"C0007 top_stack = ", top_stack()) append_reverse_polish(top_stack(), pm_or_luk) pop_stack() } pop_stack() } else { # step 5 write(dbg, "C0008 *stk = ", *stk) write(dbg, "C0009 top_stack() = ", top_stack()) write(dbg, "C0010 precedence(top_stack()) = ", precedence(top_stack())) write(dbg, "C0011 precedence(top_stack()) = ", precedence(nxt)) write(dbg, "C0012 nxt = ", nxt) while (*stk > 0 & (top_stack() ~== "(") & precedence(top_stack() >= precedence(nxt))) do { max_iter -:= 1 if max_iter < 0 then exit() append_reverse_polish(top_stack(), pm_or_luk) pop_stack() } write(dbg, "C0013 nxt = ", nxt) push_stack(stripped(nxt)) max_iter -:= 1 if max_iter < 0 then exit() } write(dbg, "C0014 infix = ", infix) infix := infix[*nxt + 1 : 0] write(dbg, "C0015 infix = ", infix) } while (*stk > 0) do { write(dbg, "C0016 *stk = ", *stk) max_iter -:= 1 if max_iter < 0 then exit() write(dbg, "C0017 top_stack() = ", top_stack()) append_reverse_polish(top_stack(), pm_or_luk) pop_stack() } return reverse_polish end procedure push_stack(x) push(stk, stripped(x)) end procedure pop_stack() if x := pop(stk) then return x else return null end procedure top_stack() if x := pop(stk) then { push(stk, x) return x } else return null end procedure append_reverse_polish(x, pm_or_luk) reverse_polish ||:= " " || op_symbol(x, pm_or_luk) || " " end procedure is_quantifier(infix) if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("emosmp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("llamp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("csdmp\\")))) then return it1 || it2 else fail end procedure get_operand(infix) if not is_quantifier(infix) then if not is_operator(infix) then if infix ? (it := (tab(many(' ')) | "") & (operand := tab(many('\\abcdefghijklmnopqrstuvwxyzBDFGHIJLMOPQRSTUVWXYZ}{][,')))) then return it || operand else fail end procedure get_operator(infix) if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("pmimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("fddimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("romp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("ffimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("dnal\\")))) then return it1 || it2 else fail end procedure get_next(infix) if infix ? (it1 := (tab(many(' ')) | "") & it2 := tab(match(")"))) then return it1 || it2 else if infix ? (it1 := (tab(many(' ')) | "") & it2 := tab(match("("))) then return it1 || it2 else if it := get_operator(infix) then return it if it := get_operand(infix) then return it else fail end procedure is_operand(infix) if not is_quantifier(infix) then if not is_operator(infix) then if infix ? (it := (tab(many(' ')) | "") & (operand := tab(many('\\abcdefghijklmnopqrstuvwxyzBDFGHIJLMOPQRSTUVWXYZ}{][,')))) then return it || operand else fail end procedure is_operator(infix) if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("pmimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("ffdimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("romp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("ffimp\\")))) then return it1 || it2 if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("dnal\\")))) then return it1 || it2 else fail end procedure is_unary_op(infix) if infix ? (it1 := (tab(many(' ')) | "") & (it2 := tab(match("tonmp\\")))) then return it1 || it2 else fail end procedure write_note(note) write("") write(note) write("") end procedure stripped(in) iii := 1 out := "" while iii <= *in do { if in[iii] ~== " " then out ||:= in[iii] iii +:= 1 } return out end # for Negation procedure sub_ndot(linein, neg , dot_str, dots_out) write(&errout, "SUB_NDOT") write(&errout, "linein = ",linein) write(&errout, "symbol = ", neg) write(&errout, "dot_str = ", dot_str) write(&errout, "dots_out = ", dots_out) # immediately before quantifier while linein ? ( # (part0 := tab(many(' ')) | tab(match(""))) & part0 := tab(find(neg)) & write(&errout, "PART0 blank = ", part0) & part1 := tab(match(neg)) & write(&errout, "PART1 (NEG) = ", part1) & part2 := (tab(many(' ')) | tab(match(""))) & part2X := tab(many('(')) & write(dbg2, "part2X = ", part2X) & (szX := *part2X) & write(dbg2, "szX = ", szX) & (mchX := repl(")", szX)) & write(dbg2, "mchX = ", mchX) & (part3 := tab(find(mchX))) & write(dbg2, "part3 = ", part3) & tab(match(mchX)) & write(&errout, "part3 (negated) = ", part3) & part4 := tab(match("\\")) & write(&errout, "part4 \\ = ", part4) & (tab(many(' ')) | tab(match(""))) & part5 := tab(0) & write(&errout, "part5 = ", part5)) do { write(&errout, "PART5 = ", part5) max_exe -:= 1 if max_exe <= 0 then exit() if part6 := sub_ndot2(part5, dotttttt, (" " || repl("!", 6 + nextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_ndot2(part5, dottttt, (" " || repl("!", 5 + nextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_ndot2(part5, dotttt, (" " || repl("!", 4 + nextra) || " ")) then linein := "part0 || part2 || TEMP" || part3 || part4 || part6 else if part6 := sub_ndot2(part5, dottt, (" " || repl("!", 3 + nextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_ndot2(part5, dott, (" " || repl("!",2 + nextra) || " ")) then linein := part0 || part2 || "TEMP" || part3 ||part4 || part6 else if part6 := sub_ndot2(part5, dot, (" " || repl("!", 1 + nextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 else if part6 := sub_ndot2(part5, " ", (" " || repl("!", nextra) || " " )) then linein := part0 || part2 || "TEMP" || part3 || part4 || part6 write(&errout, "BOTTOM linein = ", linein) } write(&errout, "linein = ", lineout) return linein end procedure sub_ndot2(part, dot_str, dots_out) write(&errout, "SUB_NDOT2") write(&errout, "SUB_NDOT2 part = ", part) write(&errout, "SUB_NDOT2 dot_str = ", dot_str) write(&errout, "SUB_NDOT2 dots_out = ", dots_out) if dot_str ~== " " then { if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & (part1 := tab(match(dot_str))) & (part2 := tab(0)))) then { part := part0 || dots_out || part2 return part } else if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(any(delim_n2)) & part2 := tab(0))) then { part := part0 || part1 || part2 return part } } fail end # function to check if character is operator or not procedure is_1_Operator(x) case x of { "N": return default: fail } end procedure is_2_Operator(x) case x of { "A": return "K": return "C": return "E": return "=": return default: fail } end # Convert prefix to Infix expression procedure preToInfix(s) # length of expression length := *s stack := [] # reading from right to left s := reverse(s) i := 1 while i <= length do { if s[i] == " " then { i +:= 1 next } # for (int i = length - 1; i >= 0; i--) # { # check if symbol is unary operator if (is_1_Operator(s[i])) then { # pop one operand from stack op1 := stack[1] pop(stack) # concat the operands and operator temp := "(" || s[i] || op1 || ")" # Push string temp back to stack push(stack, temp) } # check if symbol is binarty operator else if (is_2_Operator(s[i])) then { # pop two operands from stack op1 := stack[1] pop(stack) op2 := stack[1] pop(stack) # concat the operands and operator temp := "(" || op1 || s[i] || op2 || ")" # Push string temp back to stack push(stack, temp) } # if symbol is an operand else { # push the operand to the stack # push(string(1, s[i])); push(stack, s[i]) } i +:= 1 } # Stack now contains the Infix expression return tran(stack[1]) end procedure tran(in) out := "" i := 1 l := *in while i <= l do { if in[i] == "C" then out ||:= " \\pmimp " else if in[i] == "A" then out ||:= " \\pmor " else if in[i] == "K" then out ||:= " \\land " else if in[i] == "E" then out ||:= " \\pmiff " else if in[i] == " = " then out ||:= " \\pmiddf " else if in[i] == "N" then out ||:= " \\pmnot " else out ||:= in[i] i +:= 1 } return out end # The Main work procedure analyze0(linein) # dots := scan1(linein) # first_dots ddd := find("^", linein) linein ? ((front1 := tab(ddd)) & (linework := tab(0))) # linein := repl("^", dots) || linework return linework end procedure analyze1(linein) lineout := "" # write(" ") # write("% Stripped = ", linein) # write(" ") dots := scan1(linein) linein := repl("^", dots) || linein if linein ? find("(") then { write(dbg2, "Analyze1 FOUND (") found_paren := 1 write(dbg2,"Analyze1 linein = ", linein) if linein ? find("(") then { while (linein ? ((partA1 ||:= tab(find("("))) & tab(match("(")) & (inner := tab(0)))) do { write(dbg2,"Analyze1 partA1 = ", partA1) write(dbg2,"Analyze1 inner = ", inner) len_in := *inner i := 1 inner2 := "" dot_cnt := 1 while (i <= len_in) & (dot_cnt > 0) do { charout := inner[i] # write(dbg, "charout = ", charout) if charout == "(" then dot_cnt +:= 1 if charout == ")" then dot_cnt -:= 1 if dot_cnt = 0 then { break } inner2 ||:= charout # write(dbg, "inner2 = ", inner2) if dot_cnt = 0 then { break } i +:= 1 # increment position in current line } partA2 := inner[i + 1 : 0] || partA2 write(dbg2,"Analyze1 partA2 = ", partA2) write(dbg2,"Analyze1 inner2 = ", inner2) if (inner2 ? find("(")) then { linein := analyze1(inner2) write(dbg2,"Analyze1 linein recur = ", linein) } else { linein := partA1 || "[" || inner2 || "]" || partA2 write(dbg2,"Analyze1 linein done = ", linein) partA1 := "" partA2 := "" } } } } lineout2 := linein write(dbg, "bot analyze1 lineout2 = ", lineout2) return lineout2 end procedure analyze2(linein) len_in := *linein i := 1 lineout := "" while (i <= len_in) do { lineout ||:= next_paren(linein[i]) i +:= 1 } write(dbg2, "Analyze2 LINEOUT = ",lineout) write(" ") # write("% Original = ", linein) write(" ") # linein := repl("^", first_dots) || lineout # at end of line output line with enough closing parens to balance write(dbg2, "FRONT BB = ", front1) # lineout := front1 || lineout lineout := reverse(lineout) lineout ? (part1 := tab(find("$")) & tab(match("$")) & part2 := tab(0)) lineout := part1 || part2 lineout := reverse(lineout) dots := scan2(lineout) write(dbg2, "dots = ", dots) write(dbg2, "OUT AA = ", lineout) lineout := front1 || lineout || repl(")", dots) || "$" write(dbg2, "OUT BB = ", lineout) return lineout end # see how many opening paren to start with procedure scan1(linein) tot_dots := 1 i := 1 while i <= *linein do { # if linein[i] == "." then tot_dots +:= 1 if linein[i] == "!" then tot_dots +:= 1 if linein[i] == "^" then tot_dots +:= 1 if linein[i] == "%" then tot_dots +:= 1 if linein[i] == "(" then tot_dots +:= 1 if linein[i] == "[" then tot_dots +:= 1 i +:= 1 } return (tot_dots) end # see how many closing paren to add procedure scan2(linein) tot_dots := 0 i := 1 while i <= *linein do { $ifdef OLD if linein[i] == "^" then tot_dots +:= 1 if linein[i] == "." then tot_dots -:= 1 if linein[i] == "!" then tot_dots +:= 1 if linein[i] == "%" then tot_dots -:= 1 if linein[i] == ":" then tot_dots +:= 1 if linein[i] == ";" then tot_dots -:= 1 if linein[i] == "[" then tot_dots +:= 1 if linein[i] == "]" then tot_dots -:= 1 $endif if linein[i] == "(" then tot_dots +:= 1 if linein[i] == ")" then tot_dots -:= 1 i +:= 1 } return (tot_dots) end procedure fix_paren_str(in) i := 1 out := "" len_in := *in while (i <= len_in) do { out ||:= fix_paren(in[i]) i +:= 1 } return out end procedure fix_paren_str2(in) i := 1 out := "" len_in := *in while (i <= len_in) do { out ||:= fix_paren2(in[i]) i +:= 1 } return out end $ifdef PAST # for group II procedure sub_ldot(linein, log_conn , dot_str, dots_out) write(&errout, " SUB_LDOT") write(&errout, " linein = ",linein) write(&errout, " symbol = ", log_conn) write(&errout, " dot_str = ", dot_str) write(&errout, " dots_out = ", dots_out) # immediately before connective linein := reverse(linein) write(dbg2, "LDOT linein = ",linein) while linein ? ( (if dot_str ~== " " then { ((tab(many(' '))| tab(match(""))) & part2 := tab(match(reverse(log_conn))) & part0 := tab(find(dot_str)) & part1 := tab(match(dot_str))) write(dbg2, "LDOT part2 = ", part2) write(dbg2, "LDOT part0 = ", part0) write(dbg2, "LDOT part1 = ", part1) } else { ((part2 := tab(match(log_conn))) & (part0 := tab(many(' ')) | tab(match(""))) & part1 := "") }) & write(&errout, "% part1 (dot_str) = ", part1) & write(&errout, "% part2 (dot_str) = ", part2) & bad := (tab(many(' ')) | tab(match(""))) & write(&errout,"% BAD = |", bad, "|") & # bad2 := tab(0) & # # write("% BAD2 = ", bad2) & # part2 := tab(match(log_conn)) & # write("% part2 (log_conn) = ", part2, "part2 = ", part2) & part5 := tab(0)) do { part5 := reverse(part5) max_exe -:= 1 if max_exe <= 0 then exit() write(&errout, "part5 = ", part5) # write("% part5 = ", part5)) do { if part6 := sub_ldot2(part5, dotttttt, (" " || repl("^", 6 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dottttt, (" " || repl("^", 5 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dotttt, (" " || repl("^", 4 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dottt, (" " || repl("^", 3 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dott, (" " || repl("^", 2 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, dot, (" " || repl("^", 1 + lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 else if part6 := sub_ldot2(part5, " ", (" " || repl("^", lextra) || " ")) then linein := part0 || dots_out || "TEMP" || part6 # linein := reverse(linein) write(&errout, "% BOTTOM linein = ", linein) } # write("% FAILED lineout = ", lineout) return reverse(linein) end procedure sub_ldot2(part, dot_str, dots_out) # part := reverse(part) write(&errout, "SUB_LDOT2") write(&errout, "SUB_LDOT2 part = ", part) write(&errout, "SUB_LDOT2 dot_str = ", dot_str) write(&errout, "SUB_LDOT2 dots_out = ", dots_out) if (dot_str ~== " ") then { if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(match(dot_str)) & part2 := tab(0))) then { part := part0 || dots_out || part2 # write("% SUB_LDOT2 return part = ", part) return part } } else if (part ? (part0 := (tab(many(' ')) | tab(match(""))) & part1 := tab(any(delim_l2)) & part2 := tab(0))) then { part := part0 || dots_out || part2 # write("% SUB_LDOT2 return part = ", part) return part } fail end $endif procedure fix_op_dot(linein) lineout := linein changed := 1 while (changed = 1) do { if linein ? ((not ((part1 := tab(find(qneg))) & (tab(many(" ")) | tab(match(""))) & (part2 := tab(find("("))) & tab(match("(")) & (tab(many(" ")) | tab(match(""))) & tab(match(qneg)) || (rest := tab(0)))) & ((part1 := tab(find(qneg))) & (tab(many(" ")) | tab(match(""))) & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) $ifdef BAD if (((linein ? ((part1 := tab(find(qneg))) & (tab(many(" ")) | tab(match(""))) & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) & (not ((part1 := tab(find(qneg))) & (tab(many(" ")) | tab(match(""))) & part2 := tab(find("("))) & tab(match("(")) & tab(match(qneg)) || (rest := tab(0)))) | (linein ? ((part1 := tab(find(qor))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(qimp))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(qiff))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(andddddd))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(anddddd))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(andddd))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(anddd))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(andd))) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))) | (linein ? ((part1 := tab(find(and)) & (many(" ") | "") & (part2 := tab(find("("))) & tab(match("(")) & (rest := tab(0)))))) $endif then { linein := part1 || part2 || dot || " [ " || rest changed := 1 lastline := linein write(dbg2, "DOT FIX if in = ", linein) write(dbg2, "DOT FIX if out = ", lineout) } else changed := 0 write(dbg2, "DOT FIX loop in = ", linein) write(dbg2, "DOT FIX loop out = ", lineout) } while linein ? (part1 := tab(find("[")) & tab(match("[")) & (part2 := tab(0))) do linein := part1 || " ( " || part2 write(dbg2, "DOT FIX ret in = ", linein) return linein end