#!/bin/awk -f # Goal for this script is to replace P_ACT by P_BUILD, P_TOKEN, and P_PRINT. BEGIN {inrule = ""; MAX_CH = 10; ntoks = 0;} /^%token/ {ntoks++; tokens[$NF] = ntoks; print; next;} /^[A-za-z][A-Za-z0-9_]*file *:/ {inrule = "TPTP_file"; } /^[A-za-z][A-Za-z0-9_]*input *:/ {inrule = "TPTP_input"; } /^ *[;]/ {inrule = ""; print; next;} inrule == "TPTP_file" {sub("{P_ACT.*}","{}"); print; next;} inrule == "TPTP_input" { if ($1 ~ "[A-za-z][A-Za-z0-9_]*input") i = 3; else i = 2; s = $i; if (s in tokens) { arg = "P_TOKEN(\"" s " \", $1)"; } else { arg = "$$"; } repl = "{P_PRINT(" arg ");}"; sub("{P_ACT.*}", repl); print; next;} /^[A-Za-z0-9_][A-Za-z0-9_]* *:/ { inrule = $1; n = NF - 3; repl = "{$$ = P_BUILD(\"" inrule "\""; for (i = 1; i <= n; i++) { j = i + 2; s = $j; if (s in tokens) { arg = "P_TOKEN(\"" s " \", $" i ")"; } else { arg = "$" i; } repl = repl ", " arg; } for (i = n+1; i <= MAX_CH; i++) { repl = repl ", 0"; } if (inrule ~ "f_formula") { repl = repl ");}"; } else { repl = repl ");}"; } sub("{P_ACT.*}",repl); print; next; } /^ *[|]/ { n = NF - 2; repl = "{$$ = P_BUILD(\"" inrule "\""; for (i = 1; i <= n; i++) { j = i + 1; s = $j; if (s in tokens) { arg = "P_TOKEN(\"" s " \", $" i ")"; } else { arg = "$" i; } repl = repl ", " arg; } for (i = n+1; i <= MAX_CH; i++) { repl = repl ", 0"; } if (inrule ~ "f_formula") { repl = repl ");}"; } else { repl = repl ");}"; } sub("{P_ACT.*}",repl); print; next; } {print;next;}