NonGroundLiteral litHead = null;
LattVal constHead = null;
LiteralParser headParser = new LiteralParser();
LattValParser constParser = new LattValParser();
// Following is needed for proper error line output:
Token headToken = st.lookahead();
if(headParser.tryParse(st)) {
litHead = headParser.getResult();
if(litHead.isNaf())
throw new ParseException(headToken.getLocation(),"non-naf-literal","naf-literal: "+litHead.toString());
constraint = false;
} else if(constParser.tryParse(st)) {
constHead = constParser.getResult();
constraint = true;
} else {
throw new ParseException(st,"literal or lattice constant",st.lookahead().toString());
}
// Next: get the rule type token
Token ruleType = st.getNext();
if(!(ruleType.getType().equals(Token.Type.FUZZYRULE)
|| ruleType.getType().equals(Token.Type.REGRULE)
|| ruleType.getType().equals(Token.Type.CHOICERULE)))
throw new ParseException(st,"rule symbol (:-, :/, or :~)",ruleType.toString());
// Now parse the rule operator
Token bodyOpTok = st.getNext();
if(!bodyOpTok.getType().equals(Token.Type.SYMBOL))
throw new ParseException(bodyOpTok.getLocation(),"body operator",bodyOpTok.toString());
SymbolToken bodyOpSym = (SymbolToken)bodyOpTok;
if(!BODYOPERATORS.containsKey(bodyOpSym.getSymbol()))
throw new ParseException(st,unsupportedBodyOp(),bodyOpSym.getSymbol());