Example #1
0
mkname(register char *s)
#endif
{
	struct Hashentry *hp;
	register Namep q;
	register int c, hash, i;
	register char *t;
	char *s0;
	char errbuf[64];

	hash = i = 0;
	s0 = s;
	while(c = *s++) {
		hash += c;
		if (c == '_')
			i = 2;
		}
	if (!i && in_vector(s0,c_keywords,n_keywords) >= 0)
		i = 2;
	hash %= maxhash;

/* Add the name to the closed hash table */

	hp = hashtab + hash;

	while(q = hp->varp)
		if( hash == hp->hashval && !strcmp(s0,q->fvarname) )
			return(q);
		else if(++hp >= lasthash)
			hp = hashtab;

	if(++nintnames >= maxhash-1)
		many("names", 'n', maxhash);	/* Fatal error */
	hp->varp = q = ALLOC(Nameblock);
	hp->hashval = hash;
	q->tag = TNAME;	/* TNAME means the tag type is NAME */
	c = s - s0;
	if (c > 7 && noextflag) {
		sprintf(errbuf, "\"%.35s%s\" over 6 characters long", s0,
			c > 36 ? "..." : "");
		errext(errbuf);
		}
	q->fvarname = strcpy(mem(c,0), s0);
	t = q->cvarname = mem(c + i + 1, 0);
	s = s0;
	/* add __ to the end of any name containing _ and to any C keyword */
	while(*t = *s++)
		t++;
	if (i) {
		do *t++ = '_';
			while(--i > 0);
		*t = 0;
		}
	return(q);
}
Example #2
0
File: main.c Project: Elytum/Lemins
static void		remove_used(t_map *map)
{
	size_t		i;
	void		*tmp;

	tmp = map->working_list;
	map->working_list = map->list;
	map->list = tmp;
	map->list->len = 0;
	i = 0;
	while (i < map->working_list->len)
	{
		tmp = get_vector(*(map->working_list), i);
		if (!in_vector(*(map->solution), tmp))
			add_vector(map->list, tmp);
		++i;
	}
}
Example #3
0
File: Lex.cpp Project: zzloojit/cpp
void Preprocess::direct_def(void)
{
  Token tok;

  except(tok::SPACE);

  int t = lex.next(tok, fbuffer);  

  
  if (t != tok::IDENT)
    {
      fatal_error("macro name define need identifier");
    }
  
  string n(tok.str);
  
  if (macros_map.find(n) != macros_map.end())
    std::cout << "redefined " + n << std::endl;
  
  macro_type& vec = macros_map[n];

  t = lex.next(tok, fbuffer);
    
  if (t == tok::LPAREN)
    {
      vec.kind = tok::macfunc_type;
      
      // 
      while ((t = lex.next(tok, fbuffer)) != tok::TEOF)
      {
        if (t == tok::SPACE)
          continue;
        else if ( t == tok::IDENT)
        {
          vec.params.push_back(tok);
          do{
            t = lex.next(tok, fbuffer);
          }while (t == tok::SPACE);
          
          if (t == tok::COMMA)
            continue;
          else if (t == tok::RPAREN)
            break;
          else
           {
             fatal_error(tok.str + " may not appear in macro parameter list");
           }
        }
      }
      
      
      
      bool seen_sharp = false;
      while ((t = lex.next(tok, fbuffer)) != tok::TEOF)
        {
          if (t == tok::NEWLINE)
            break;

          if (t == tok::SHARP)
            {
              vec.expand.push_back(tok);

              do {
                t = lex.next(tok, fbuffer);
              }while (t == tok::SPACE);
              
              if (!in_vector(vec.params, tok))
                fatal_error("# is not followed by a macro parameter");
            }
          
          if (t = tok::TWOSHARP)
            {
              while (!vec.expand.empty() && (vec.expand.back().kind == tok::SPACE))
                vec.expand.pop_back();
            }
          
          vec.expand.push_back(tok);
        }

      while (!vec.expand.empty() && (vec.expand.back().kind == tok::SPACE))
        vec.expand.pop_back();

      if (!vec.expand.empty() && ((vec.expand.front().kind == tok::TWOSHARP)
                                  ||(vec.expand.back().kind == tok::TWOSHARP)))
        fatal_error("'##' cannot appear at either end of a macro expansion");
      
      reduce_adjacent_twosharp(vec.expand);
    }
  else if (t == tok::SPACE)
    {
      vec.kind == tok::macobj_type;
      
      bool allspace = true;

      while ((t = lex.next(tok, fbuffer)) != tok::TEOF)
        {
          if (t == tok::NEWLINE)
            break;
 
          if (t != tok::SPACE)
            allspace = false;
          
          vec.expand.push_back(tok);
        }
      
      string one("1");
      if (allspace)
        vec.expand.push_back(Token(tok::NUMBER, one));
    }
  else if (t == tok::NEWLINE)
  {
    string one("1");
    vec.expand.push_back(Token(tok::NUMBER, one));
  }
  else
  {
    fatal_error("parse define error");
  }
}
Example #4
0
  /****************************************************************************
  * Метод Гомори
  */
  opt_table gomory (opt_table tab)
  {
    tab = simplex_max (tab, false, false);

    int i, j;
    // общее количество переменных
    size_t  n = tab.c.size ();
    // количество базисных переменных
    size_t  m = tab.bp.size ();

    for ( size_t k = 0; k < DEBUG_MAX_ITER_NUM; ++k )
    {
      print_line ();
      std::cout << "Gomory iteration #" << k << std::endl;
      print_line ();

      // условие выхода
      if ( vector_is_integer (tab.br) )
      { return tab; }

      // максимальная дробная часть
      number max_fract = 0;

      // номер строки с максимальной дробной частью
      int r = -1;

      // поиск переменной с максимальной дробной частью
      for ( i = 0; i < m; ++i )
      {
        number fract = tab.br[i].fract ();
        if ( fract >= max_fract )
        {
          max_fract = fract;
          r = i;
        }
      }

      // составляем новую таблицу, добавляя один столбец и одну строку
      ++n;
      ++m;
      opt_table ext_tab;

      // вектор коэффициентов всех переменных
      ext_tab.c = vector_nums (n);
      for ( j = 0; j < n - 1; ++j )
      {
        ext_tab.c[j] = tab.c[j];
      }
      ext_tab.c[n - 1] = 0;

      // матрица a
      ext_tab.a = matrix_nums (m, vector_nums (n));
      for ( i = 0; i < m - 1; ++i )
      {
        for ( j = 0; j < n - 1; ++j )
        {
          ext_tab.a[i][j] = tab.a[i][j];
        }
        ext_tab.a[i][n - 1] = 0;
      }
      for ( j = 0; j < n - 1; ++j )
      {
        if ( in_vector (j, tab.bp) )
        {
          ext_tab.a[m - 1][j] = 0;
        }
        else
        {
          ext_tab.a[m - 1][j] = tab.a[r][j].fract ();
        }
      }
      ext_tab.a[m - 1][n - 1] = -1;

      // вектор-решение
      ext_tab.bp = vector_ints (m);
      ext_tab.br = vector_nums (m);
      for ( i = 0; i < m - 1; ++i )
      {
        //ext_tab.cib[i] = tab.cib[i];
        ext_tab.bp[i] = tab.bp[i];
        ext_tab.br[i] = tab.br[i];
      }
      // ext_tab.cib[m - 1] = ?
      ext_tab.bp[m - 1] = -1; // ?
      ext_tab.br[m - 1] = tab.br[r].fract ();

      tab = simplex_max (ext_tab, true, true);
    }

    return tab;
  }