// compileSimpleClause can be used in order to implement assert(...) operations public Program compileSimpleClause(String programCode) { Vector programList = stringToList(programCode); CompilerStructure struc = new CompilerStructure(); if ((clause(programList, struc)) && (programList.size() == 0)) { CompilerStructure program = new CompilerStructure(); program.type = program.PROGRAM; program.head = struc; updateNames(program); return structureToCode(program); } else return null; } // end of PrologCompiler.compileSimpleClause(String)
public Program compile(String programCode) { long ms = System.currentTimeMillis(); owner.debug("Program Code:", 2); owner.debug(programCode, 2); Vector programList = stringToList(programCode); owner.debug("Program List:", 2); owner.debug("String to List: " + (System.currentTimeMillis() - ms) + " ms.", -1); owner.debug(programList.toString(), 2); CompilerStructure struc = new CompilerStructure(); ms = System.currentTimeMillis(); if ((program(programList, struc)) && (programList.size() == 0)) { owner.debug("List to Structure: " + (System.currentTimeMillis() - ms) + " ms.", -1); updateNames(struc); owner.debug(struc.toString(), 2); ms = System.currentTimeMillis(); Program p = structureToCode(struc); owner.debug("Structure to Code: " + (System.currentTimeMillis() - ms) + " ms.", -1); return p; } else { if (errorString.length() > 0) owner.writeLn(errorString); return null; } } // end of PrologCompiler.compile(String)
private void updateNames(CompilerStructure struc) { Vector procedureCount = new Vector(); CompilerStructure s, proc; if ((struc.type == struc.PROGRAM) && (struc.head != null)) { s = struc; do { proc = s.head.head.head; int cnt = getProcedureCount(proc.value, procedureCount); setProcedureCount(proc.value, ++cnt, procedureCount); proc.value = proc.value + '~' + cnt; s = s.tail; } while (s != null); } if ((struc.type == struc.PROGRAM) && (struc.head != null)) { s = struc; do { proc = s.head.head.head; String pv = proc.value; if (pv.indexOf('~') > 0) pv = pv.substring(0, pv.indexOf('~')); proc.value += "/" + getProcedureCount(pv, procedureCount); s = s.tail; } while (s != null); } } // end of PrologCompiler.updateNames(CompilerStructure)