示例#1
0
void identifyposlits(int i,Sfma *f) {
  Sfmalist *fs;
  int j;

  switch(f->t) {
  case Spatom:
    if(!staticp(f->a[0])) return;
    for(j=0;j<f->a[1];j++) {
      if(f->a[j+2] == -1-i) {
	trueposlits[litcnt++] = f->a;
	printatom(f->a);
	return;
      }
    }
    return;
  case Sconj:
    fs = f->juncts;
    while(fs != NULL) {
      identifyposlits(i,fs->hd);
      fs = fs->tl;
    }
    return;

  default: return;
  }
}
示例#2
0
static K printq(K x)
{
    K result;
    
    if (xt < 0) result = printatom(x);
    else if ((xt >= 0) && (xt < 20)) result = printlist(x);
    else if (xt == 98) result = printtable(x);
    else if (xt == 99) result = printdict(x);
    else result = krr((S)"notimplemented");
    
    printf("\n");
    return result;
}
示例#3
0
void findrelevantbindings(int i,Sfma *f) {
  int cnt,j;
  int value;
  atom *as;

  litcnt = 0;
  cnt = 0;

  /* Identify literals that have to be matched. */

  printf("Positive literals with parameter %i are:",i);

  identifyposlits(i,f);
  assert(litcnt > 0);

  printf("\n");

  /* Match first lit with the initial state to obtain a binding, and
     verify that others match with this binding. */

  printf("Relevant bindings for parameter %i are...\n",i);

  as = Sinit;

  while(*as != NULL) {
    printf("Trying match with "); printatom(*as); printf(":");
    if(match(trueposlits[0],*as,i,&value)) { /* There is a match. */
      for(j=0;j<cnt;j++) {
	if(relevantbindings[j] == value) goto hadalready;
      }
      relevantbindings[cnt++] = value;
      printf(" %s OK",symbol(relevantbindings[cnt-1]));
    }

    hadalready:
    printf("\n");

    as = as + 1;
  }

  printf("\n");

  relevantbindings[cnt] = -1; /* The list is terminated with -1. */
}
示例#4
0
int legalstaticbindingA(int i,int *a) {
  int j;
  atom *as;

  /* Go through the atoms in the initial state description, and check. */
  as = Sinit;
  if(staticp(a[0]) == 0) return 1;
  while(*as != NULL) {  /* Go through all initial state atoms. */

#ifdef DEBUG
    printf("Matching ");
    printSfma(f);
    printf(" against ");
    printatom(*as);
    printf(" with");
    for(j=0;j<=i;j++) {
      printf(" #%i:%s",j,symbol(binding[j]));
    }
    printf("\n");
#endif

    if((*as)[0] == a[0]) { /* Same predicate. Binding OK? */
      for(j=2;j<a[1]+2;j++) { /* Go through parameters. */
	/* Is it unassigned or a match. */
	if(assignedvar(a[j],i) && ((*as)[j] != binding[-1-a[j]])) {
	  goto nextinitatom; /* Did not match. */
	}
      }
#ifdef DEBUG
      printf("MATCH!\n");
#endif
      return 1;
    }
  nextinitatom:
    as = as  + 1;
  }
#ifdef DEBUG
  printf("NO MATCH!\n");
#endif
  return 0;
}