Esempio n. 1
0
long FileVarsParse(Scanner_p in, FileVars_p vars)
{
   char*     name;
   StrTree_p cell, test;
   long      res = 0;
   DStr_p    value = DStrAlloc();

   assert(!PStackEmpty(vars->names));
   assert(strcmp(PStackTopP(vars->names), DStrView(Source(in))) == 0);
   
   while(!TestInpTok(in, NoToken))
   {
      CheckInpTok(in, Identifier);
      name = DStrCopy(AktToken(in)->literal);
      cell = StrTreeFind(&(vars->vars), name);
      if(cell)
      {
	 FREE(cell->val1.p_val);
      }
      else
      {
	 cell = StrTreeCellAllocEmpty();
	 cell->key = name;
	 cell->val2.p_val = PStackTopP(vars->names);
	 test = StrTreeInsert(&(vars->vars), cell);
	 assert(test == NULL);
      }
      NextToken(in);
      AcceptInpTok(in, EqualSign);

      DStrReset(value);
      while(!TestInpTok(in, Semicolon))
      {
	 DStrAppendDStr(value, AktToken(in)->literal);
	 NextToken(in);
      }
      AcceptInpTok(in, Semicolon);
      cell->val1.p_val = DStrCopy(value);
      res++;
   }
   DStrFree(value);
   return res;
}
Esempio n. 2
0
static void pdtree_forward(PDTree_p tree, Subst_p subst)
{
   PDTNode_p handle = tree->tree_pos, next = NULL;
   FunCode   i = tree->tree_pos->trav_count, limit;
   Term_p    term = PStackTopP(tree->term_stack);
   
   limit = PDT_NODE_CLOSED(tree,handle);
   while(i<limit)
   {
      if(((i==0)||(i>handle->max_var))&&!TermIsVar(term))
      {
	 next = IntMapGetVal(handle->f_alternatives,term->f_code);
	 i++;
	 if(next)
	 {
	    PStackPushP(tree->term_proc, term);
	    TermLRTraverseNext(tree->term_stack);
	    next->trav_count = PDT_NODE_INIT_VAL(tree);
	    next->bound      = false;
	    assert(!next->variable);
	    tree->tree_pos = next;
#ifdef MEASURE_EXPENSIVE
	    tree->visited_count++;
#endif 
	    break;
	 }
      }
      else
      {
	 next = PDArrayElementP(handle->v_alternatives,i);
	 i++;
	 if(next)
	 {
	    assert(next->variable);
	    if((!next->variable->binding)&&(!TermCellQueryProp(term,TPPredPos)))
	    {
	       PStackDiscardTop(tree->term_stack);
	       SubstAddBinding(subst, next->variable, term);
	       next->trav_count   = PDT_NODE_INIT_VAL(tree);
	       next->bound        = true;
	       tree->tree_pos     = next;
	       tree->term_weight  -= (TermStandardWeight(term) -
                                      TermStandardWeight(next->variable));
#ifdef MEASURE_EXPENSIVE
	       tree->visited_count++;
#endif 
	       break;
	    }
	    else if(TBTermEqual(next->variable->binding,term))
	    {
	       PStackDiscardTop(tree->term_stack);
	       next->trav_count   = PDT_NODE_INIT_VAL(tree);
	       next->bound        = false;
	       tree->tree_pos     = next;
	       tree->term_weight  -= (TermStandardWeight(term) -
                                      TermStandardWeight(next->variable));
#ifdef MEASURE_EXPENSIVE
	       tree->visited_count++;
#endif 
	       break;		       
	    }
	 }
      }
   }
   handle->trav_count = i;
}