use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class StructuredPrologOutput method closeTerm.
public IPrologTermOutput closeTerm() {
PrologTerm[] elements = getArguments();
final String functor = currentFunctor;
popFromStack();
addArgument(new CompoundPrologTerm(functor, elements));
return this;
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class CliBParser method parseTemporalFormula.
private static void parseTemporalFormula(BufferedReader in, final TemporalLogicParser<?> parser) throws IOException {
String theFormula;
PrologTermStringOutput strOutput = new PrologTermStringOutput();
theFormula = in.readLine();
try {
final PrologTerm term = parser.generatePrologTerm(theFormula, null);
strOutput.openTerm("ltl").printTerm(term).closeTerm();
} catch (LtlParseException e) {
strOutput.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
}
strOutput.fullstop();
// A Friendly Reminder: strOutput includes a newline!
print(strOutput.toString());
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class PrologTermGenerator method toPrologTerm.
private static PrologTerm toPrologTerm(final PTerm node) {
PrologTerm term;
if (node instanceof ANumberTerm) {
String text = ((ANumberTerm) node).getNumber().getText();
term = new IntegerPrologTerm(new BigInteger(text));
} else if (node instanceof AAtomTerm) {
String text = ((AAtomTerm) node).getName().getText();
if ("[]".equals(text)) {
term = new ListPrologTerm(EMPTY_PROLOG_LIST);
} else {
text = removeQuotes(text);
term = new CompoundPrologTerm(text);
}
} else if (node instanceof ATerm) {
ATerm aterm = (ATerm) node;
int listSize = getListSize(node);
if (listSize >= 0) {
PrologTerm[] list = new PrologTerm[listSize];
fillListWithElements(list, aterm);
term = new ListPrologTerm(list);
} else {
String functor = removeQuotes(aterm.getFunctor().getText());
PrologTerm[] params = evalParameters((AParams) aterm.getParams());
term = new CompoundPrologTerm(functor, params);
}
} else if (node instanceof AVariableTerm) {
String text = removeQuotes(((AVariableTerm) node).getVariable().getText());
term = new VariablePrologTerm(text);
} else
throw new IllegalStateException("Unexpected subclass of PTerm: " + node.getClass().getCanonicalName());
return term;
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class FastReadTransformer method write.
public String write() {
Collection<PrologTerm> sentences = spo.getSentences();
if (sentences.isEmpty())
throw new IllegalArgumentException(EMPTY_MSG);
if (sentences.size() > 1)
throw new IllegalArgumentException(MULTI_MSG);
PrologTerm term = sentences.iterator().next();
fastwrite(term);
return sb.toString();
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class FastReadTransformer method write.
private void write(PrologTerm cp) {
if (cp.isAtom()) {
sb.append("A");
sb.append(cp.getFunctor());
sb.append(ZERO);
} else {
sb.append("S");
sb.append(cp.getFunctor());
sb.append(ZERO);
sb.append((char) cp.getArity());
for (int i = 1; i <= cp.getArity(); i++) {
PrologTerm argument = cp.getArgument(i);
fastwrite(argument);
}
}
}
Aggregations