예제 #1
0
파일: cal24.cpp 프로젝트: timepp/monalisa
bool check_bone(const node* p, int rr_level)
{
	if (!p || p->t == nt_num) return true;

	// '_'是连字符,要求右孩子是数,左孩子是数或者也是个'_'
	if (p->op == L'_')
	{
		if (p->r_child->t == nt_op) return false;
		if (p->l_child->t == nt_op && p->l_child->op != L'_') return false;
	}

	if (rr_level >= 1)
	{
		// 交换率:规定两个分支的顺序
		if (commulative(p->op))
		{
			// 不可以在这里判断,在check_exp时对满足交换率的左右子树采用了求值的方法:大值在左
			// if (shape_less(p->l_child, p->r_child, false)) return false;
		}

		// 不能出现 A-B+C A/B*C,应该是A+C-B, A*C/B
		if (p->l_child->t == nt_op && get_pred(p->op) == get_pred(p->l_child->op))
		{
			if (p->op < p->l_child->op) return false;
		}

		// 结合率
		// 不能出现 A+(B+C), A+(B-C), A-(B+C), A-(B-C)这样的情况,乘除类似
		if (p->r_child->t == nt_op && associative(p->op) && get_pred(p->op) == get_pred(p->r_child->op)) return false;
	}

	if (!check_bone(p->l_child, rr_level)) return false;
	if (!check_bone(p->r_child, rr_level)) return false;
	return true;
}
예제 #2
0
파일: cal24.cpp 프로젝트: timepp/monalisa
std::wstring get_exp(const node* p)
{
	if (!p) return L"";
	if (p->t == nt_num)
	{
		std::wostringstream oss;
		oss << p->num;
		return get_trans(p, oss.str());
	}
	std::wstring lexp = get_exp(p->l_child);
	std::wstring rexp = get_exp(p->r_child);
	
	if (p->l_child->t == nt_op && get_pred(p->l_child->op) < get_pred(p->op))
	{
		lexp = std::wstring(L"(") + lexp + L")";
	}
	if (p->r_child->t == nt_op && !(get_pred(p->op) < get_pred(p->r_child->op)))
	{
		rexp = std::wstring(L"(") + rexp + L")";
	}
	
	std::wstring e;
	if (p->op == L'_') 
		e = lexp + rexp;
	else 
		e = lexp + L" " + p->op + L" " + rexp;
	return get_trans(p, e);
}
예제 #3
0
파일: Flow.hpp 프로젝트: fev2g/SGL
	void augment() // Add flow along the path proc.tPred
	{ 
		type_flow d = proc_ful.tPred.pred((*this).t)->capRto((*this).t);
		for (int v = get_pred((*this).t); v != (*this).s; v = get_pred(v)) // Find minimal capacity on the path search.tPred
		{
			if (proc_ful.tPred.pred(v)->capRto(v) < d) 
				d = proc_ful.tPred.pred(v)->capRto(v);
		}
		proc_ful.tPred.pred((*this).t)->addflowRto((*this).t, d); 
		for (int v = get_pred((*this).t); v != (*this).s; v = get_pred(v)) // Add this minimal capacity
			proc_ful.tPred.pred(v)->addflowRto(v, d); 
	}
예제 #4
0
파일: mm.c 프로젝트: msr23trini/malloclab
void check_succ_pred(void *bp)
{
  void *succ = get_succ(bp);
  void *pred = get_pred(succ);
  if (bp != pred)
    printf("Successor does not point to Predecessor! \n");
}
예제 #5
0
int dcpred_for_enc(M4V_DCPRED* p, int n, int level)
{
	int* dc_cur = p->dc_cur[n];
	int scale = get_scale(p, n);
	int pred = get_pred(dc_cur, p->stride[n], scale);

	set_dc_to_dc_cur(dc_cur, level, scale);
	return level - pred; 
}
예제 #6
0
파일: mm.c 프로젝트: msr23trini/malloclab
// Returns 0 if no errors were found, otherwise returns the error
int mm_checkheap(int verbose) {
  // char *bp = heap_listp;

  if (verbose)
    printf("Heap (%p):\n", heap_listp);

  if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp)))
    printf("Bad prologue header\n");
  checkblock(heap_listp);

  void* list;
  int count_free_in_list = 0;
  int count_free_in_heap = 0;
  for (int i =0; i < 9; i++)
    {
      for (list = (void*)(*(long*)GET_BUCKET(root,i)); list != NULL;
           list =  get_succ(list)  ) {
        if (verbose)
          printblock(list);
        checkblock(list);
        if ( get_succ(list) != NULL && get_pred(list) !=NULL)
          check_succ_pred(list);
        check_address(list);
        count_free_in_list++;
        check_in_correct_bucket(list, i);
      }
    }

  char *bp;

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
    if (verbose)
      {
        if (GET_ALLOC(HDRP(bp)) == 0)
          count_free_in_heap ++;
        printblock(bp);
        checkblock(bp);
        check_coalescing( (void*)bp);
      }
  }

  if (count_free_in_heap != count_free_in_list)
    printf ("Number of free block not consistent in heap and list list \n");

  if (verbose)
    printblock(bp);
    if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp))))
      {
        printf("Bad epilogue header\n");
        if (GET_SIZE(HDRP(bp)) != 0)
          printf ("size is not 0\n");
        if (!(GET_ALLOC(HDRP(bp))) )
           printf ("not allocated properly\n");
     }
    return 0;
}
예제 #7
0
파일: mm.c 프로젝트: msr23trini/malloclab
static void remove_block(void *bp, size_t size)
{
  //printf ("remove block\n");
  REQUIRES ( bp != NULL );
  REQUIRES ( (size_t)(bp) % 8 == 0);

  int offset = get_offset(size);
  void *pred = get_pred(bp);
  void *succ = get_succ(bp);

  if ( pred == NULL && succ != NULL)
    //block to be removed is the first block in the list
    {
      SET_SUCC(bp) = 0;
      SET_PRED(succ) = 0;
      SET_ROOT(GET_BUCKET(root, offset)) = (long)succ;

    }
  else if (pred != NULL && succ == NULL)
    //block to be removed is the last block in the list
    {
      SET_SUCC(pred) = 0;
      SET_PRED(bp) = 0;

    }

  else if (pred != NULL && succ != NULL)
    //block to be removed is located somewhere within the list.
    {
      SET_SUCC(pred) = (int)( (long)succ - BASE);
      SET_PRED(succ) = (int)((long)pred - BASE);
      SET_PRED(bp) = 0;
      SET_SUCC(bp) = 0;

    }

  else if ( pred == NULL && succ == NULL)
    {
      //printf("resetting root\n");
      SET_ROOT(GET_BUCKET(root, offset)) = 0;
    }
  print_list();
  return;
}
예제 #8
0
//---------------------------MatchList Methods-------------------------------
bool MatchList::search(const char *opc, const char *res, const char *lch,
                       const char *rch, Predicate *pr) {
  bool tmp = false;
  if ((res == _resultStr) || (res && _resultStr && !strcmp(res, _resultStr))) {
    if ((lch == _lchild) || (lch && _lchild && !strcmp(lch, _lchild))) {
      if ((rch == _rchild) || (rch && _rchild && !strcmp(rch, _rchild))) {
        char * predStr = get_pred();
        char * prStr = pr?pr->_pred:NULL;
        if (ADLParser::equivalent_expressions(prStr, predStr)) {
          return true;
        }
      }
    }
  }
  if (_next) {
    tmp = _next->search(opc, res, lch, rch, pr);
  }
  return tmp;
}