String funname;
start = reader.getPosition();
switch (reader.getLastChar()) {
case -1:
throw new ParseError("premature EOF encountered.");
case '#':
return parseAbbrev(reader);
case '[':
c = reader.readSkippingWS();
if (c == -1) {
throw new ParseError("premature EOF encountered.");
}
if (c == ']') {
c = reader.readSkippingWS();
result = empty;
} else {
result = parseATerms(reader);
if (reader.getLastChar() != ']') {
throw new ParseError("expected ']' but got '" + (char) reader.getLastChar() + "'");
}
c = reader.readSkippingWS();
}
break;
case '<':
c = reader.readSkippingWS();
ATerm ph = parseFromReader(reader);
if (reader.getLastChar() != '>') {
throw new ParseError("expected '>' but got '" + (char) reader.getLastChar() + "'");
}
c = reader.readSkippingWS();
result = makePlaceholder(ph);
break;
case '"':
funname = parseString(reader);
c = reader.readSkippingWS();
if (reader.getLastChar() == '(') {
c = reader.readSkippingWS();
if (c == -1) {
throw new ParseError("premature EOF encountered.");
}
if (reader.getLastChar() == ')') {
result = makeAppl(makeAFun(funname, 0, true));
} else {
ATerm[] list = parseATermsArray(reader);
if (reader.getLastChar() != ')') {
throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
}
result = makeAppl(makeAFun(funname, list.length, true), list);
}
c = reader.readSkippingWS();
} else {
result = makeAppl(makeAFun(funname, 0, true));
}
break;
case '(':
c = reader.readSkippingWS();
if (c == -1) {
throw new ParseError("premature EOF encountered.");
}
if (reader.getLastChar() == ')') {
result = makeAppl(makeAFun("", 0, false));
} else {
ATerm[] list = parseATermsArray(reader);
if (reader.getLastChar() != ')') {
throw new ParseError("expected ')' but got '" + (char)reader.getLastChar() + "'");
}
result = makeAppl(makeAFun("", list.length, false), list);
}
c = reader.readSkippingWS();
break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
result = parseNumber(reader);
c = reader.skipWS();
break;
default:
c = reader.getLastChar();
if (Character.isLetter(c)) {
funname = parseId(reader);
c = reader.skipWS();
if (reader.getLastChar() == '(') {
c = reader.readSkippingWS();
if (c == -1) {
throw new ParseError("premature EOF encountered.");
}
if (reader.getLastChar() == ')') {
result = makeAppl(makeAFun(funname, 0, false));
} else {
ATerm[] list = parseATermsArray(reader);
if (reader.getLastChar() != ')') {
throw new ParseError("expected ')' but got '" + (char) reader.getLastChar() + "'");
}
result = makeAppl(makeAFun(funname, list.length, false), list);
}
c = reader.readSkippingWS();
} else {
result = makeAppl(makeAFun(funname, 0, false));
}
} else {
throw new ParseError("illegal character: '" + (char) reader.getLastChar() + "'");
}
}
if (reader.getLastChar() == '{') {
ATermList annos;
if (reader.readSkippingWS() == '}') {
reader.readSkippingWS();
annos = empty;
} else {
annos = parseATerms(reader);
if (reader.getLastChar() != '}') {
throw new ParseError("'}' expected '" + (char) reader.getLastChar() + "'");
}
reader.readSkippingWS();
}
result = result.setAnnotations(annos);
}