示例#1
0
void symbol_FPrintOtter(FILE* File, SYMBOL Symbol)
/**************************************************************
  INPUT:   A file and a symbol.
  RETURNS: None.
  SUMMARY: Prints a symbol in Otter format to stdout. 
***************************************************************/
{ 
#ifdef CHECK
  if (!symbol_IsSymbol(Symbol)) {
    misc_StartErrorReport();
    misc_ErrorReport("\n In symbol_FPrintOtter: Illegal input.\n");
    misc_FinishErrorReport();
  }
#endif

  if (symbol_IsVariable(Symbol)) {
    SYMBOL NormSymbol;

    NormSymbol = symbol_NormVar(Symbol);

    if (symbol_IsStandardVariable(Symbol)) {
      if (Symbol <= 6)
	/* u, v, w, x, y, z */
	sprintf(symbol_VARSTRING,"%c", 116 + NormSymbol);
      else
	/* x1, x2, x3, ... */
	sprintf(symbol_VARSTRING,"x%d", NormSymbol - 6);
    }
    else if (symbol_IsIndexVariable(Symbol))
      /* I1, I2, I3, ... */
      sprintf(symbol_VARSTRING,"I%d", NormSymbol);

    fputs(symbol_VARSTRING, File);
  }
  else 
    if (symbol_SignatureExists()) {
      if (symbol_IsConstant(Symbol))
	fprintf(File, "c%s", symbol_Name(Symbol));
      else
	if (symbol_IsFunction(Symbol))
	  fprintf(File, "f%s", symbol_Name(Symbol));
	else
	  if (symbol_IsPredicate(Symbol))
	    fprintf(File, "P%s", symbol_Name(Symbol));
	  else
	    fputs(symbol_Name(Symbol), File);
    }
    else
      fprintf(File, "%d", Symbol);
}
示例#2
0
void symbol_FPrint(FILE* File, SYMBOL Symbol)
/**************************************************************
  INPUT:   A file and a symbol.
  RETURNS: None.
  SUMMARY: Prints a symbol to the file. 
***************************************************************/
{ 
#ifdef CHECK
  if (!symbol_IsSymbol(Symbol)) {
    misc_StartErrorReport();
    misc_ErrorReport("\n In symbol_FPrint: Illegal input.\n");
    misc_FinishErrorReport();
  }
#endif

  if (symbol_Equal(symbol_Null(),Symbol))
    fputs("NULL", File);
  else if (symbol_IsVariable(Symbol)) {
    SYMBOL NormSymbol;

    NormSymbol = symbol_NormVar(Symbol);

    if (symbol_IsStandardVariable(Symbol)) {
      if (Symbol <= 6)
	/* U, V, W, X, Y, Z */
	sprintf(symbol_VARSTRING,"%c", 'U' + NormSymbol - 1);
      else
	/* X1, X2, X3, ... */
	sprintf(symbol_VARSTRING,"X%d", NormSymbol - 6);
    }
    else if (symbol_IsIndexVariable(Symbol))
      /* I1, I2, I3, ... */
      sprintf(symbol_VARSTRING,"I%d", NormSymbol);

    fputs(symbol_VARSTRING, File);
  }
  else if (symbol_SignatureExists())
    fputs(symbol_Name(Symbol), File);
  else
    fprintf(File, "%d", Symbol);
}
示例#3
0
static BOOL kbo_ContGreaterCompareStruc(CONTEXT Context1, TERM Term1,
                                        CONTEXT Context2, TERM Term2)
/**************************************************************
  INPUT:   Two contexts and two terms where the kbo-variable condition
           for <Term1> and <Term2> is satisfied as well as the
	   weight difference between the terms is zero.
  RETURNS: TRUE if Term1 is greater than Term2.
	   The Terms are interpreted with respect to the contexts.
  CAUTION: The precedence from the order module is used to determine
           the precedence of symbols!
***************************************************************/
{
    LIST   Scan1,Scan2;
    SYMBOL Top1,Top2;

    Term1      = cont_Deref(&Context1,Term1);
    Term2      = cont_Deref(&Context2,Term2);
    Top1       = term_TopSymbol(Term1);
    Top2       = term_TopSymbol(Term2);

    if (symbol_IsStandardVariable(Top1)) {
        if (symbol_IsStandardVariable(Top2))
            return FALSE;
        else
            return FALSE;
    }
    else if (symbol_IsStandardVariable(Top2) ||
             symbol_PrecedenceGreater(ord_PRECEDENCE, Top1, Top2))
        return TRUE;
    else if (Top1 == Top2) {
        int    RecWeightDiff;
        BOOL   T1VarCond, T2VarCond;
        TERM   RecTerm1,RecTerm2;
        Scan1 = term_ArgumentList(Term1);
        Scan2 = term_ArgumentList(Term2);
        if (symbol_HasProperty(Top1,ORDRIGHT)) {
            int i;
            for (i = symbol_Arity(Top1);
                    i > 0 && cont_TermEqual(Context1,list_NthElement(Scan1,i),
                                            Context2,list_NthElement(Scan2,i));
                    i--);
            if (i > 0) {
                RecTerm1 = cont_Deref(&Context1,list_NthElement(Scan1,i));
                RecTerm2 = cont_Deref(&Context2,list_NthElement(Scan2,i));
            }
            else
                return FALSE;
        }
        else {
            while (!list_Empty(Scan1) && cont_TermEqual(Context1,list_Car(Scan1),Context2,list_Car(Scan2))) {
                Scan1 = list_Cdr(Scan1);
                Scan2 = list_Cdr(Scan2);
            }
            if (list_Empty(Scan1)) /* Implies that list_Empty(Scan2)  */
                return FALSE;
            else {
                RecTerm1 = cont_Deref(&Context1,list_Car(Scan1));
                RecTerm2 = cont_Deref(&Context2,list_Car(Scan2));
            }
        }
        RecWeightDiff =  kbo_ContCompVarCondAndWeight(Context1,RecTerm1,&T1VarCond,
                         Context2,RecTerm2,&T2VarCond);

        if (T1VarCond) {
            if (RecWeightDiff > 0)
                return TRUE;
            else if (RecWeightDiff == 0)
                return kbo_ContGreaterCompareStruc(Context1, RecTerm1, Context2, RecTerm2);
        }
    }

    return FALSE;
}
示例#4
0
static ord_RESULT kbo_CompareStruc(TERM Term1, TERM Term2, int WeightDiff)
/**************************************************************
  INPUT:   Two terms where the kbo-variable condition for <Term1> and
           <Term2> is satisfied and <WeightDiff> is the kbo weight difference
	   between <Term1> and <Term2>
  RETURNS: ord_UNCOMPARABLE, if Term1 and Term2 are uncomparable
	   ord_EQUAL,        if Term1 and Term2 are equal
	   ord_GREATER_THAN, if Term1 is greater than Term2
  CAUTION: The precedence from the order module is used to determine
           the precedence of symbols!
***************************************************************/
{
    LIST   Scan1,Scan2;
    SYMBOL Top1,Top2;

    Top1       = term_TopSymbol(Term1);
    Top2       = term_TopSymbol(Term2);

    if (WeightDiff > 0)
        return ord_GREATER_THAN;
    else if (WeightDiff == 0) {
        if (symbol_IsStandardVariable(Top1)) {
            if (symbol_IsStandardVariable(Top2))
                return ord_EQUAL;
            else
                return ord_UNCOMPARABLE;
        }
        else if (symbol_IsStandardVariable(Top2) ||
                 symbol_PrecedenceGreater(ord_PRECEDENCE, Top1, Top2))
            return ord_GREATER_THAN;
        else if (Top1 == Top2) {
            int    RecWeightDiff;
            BOOL   T1VarCond, T2VarCond;
            TERM   RecTerm1,RecTerm2;
            Scan1 = term_ArgumentList(Term1);
            Scan2 = term_ArgumentList(Term2);
            if (symbol_HasProperty(Top1,ORDRIGHT)) {
                int i;
                for (i = symbol_Arity(Top1);
                        i > 0 && term_Equal(list_NthElement(Scan1,i),list_NthElement(Scan2,i));
                        i--);
                if (i > 0) {
                    RecTerm1 = (TERM)list_NthElement(Scan1,i);
                    RecTerm2 = (TERM)list_NthElement(Scan2,i);
                }
                else
                    return ord_EQUAL;
            }
            else {
                while (!list_Empty(Scan1) && term_Equal(list_Car(Scan1),list_Car(Scan2))) {
                    Scan1 = list_Cdr(Scan1);
                    Scan2 = list_Cdr(Scan2);
                }
                if (list_Empty(Scan1)) /* Implies that list_Empty(Scan2)  */
                    return ord_EQUAL;
                else {
                    RecTerm1 = (TERM)list_Car(Scan1);
                    RecTerm2 = (TERM)list_Car(Scan2);
                }
            }
            RecWeightDiff =  kbo_CompVarCondAndWeight(RecTerm1,&T1VarCond,RecTerm2,&T2VarCond);
            if (RecWeightDiff >= 0 && T1VarCond)
                return kbo_CompareStruc(RecTerm1, RecTerm2, RecWeightDiff);
            else
                return ord_UNCOMPARABLE;
        }
        else
            return ord_UNCOMPARABLE;
    }
    else
        return ord_UNCOMPARABLE;

    return ord_UNCOMPARABLE;
}