use of de.prob.core.sablecc.node.ATerm 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;
}
Aggregations