Exemplo n.º 1
0
Arquivo: storage.c Projeto: att/uwin
void
init_storage ()
{

  /* Functions: we start with none and ask for more. */
  f_count = 0;
  more_functions ();
  f_names[0] = "(main)";

  /* Variables. */
  v_count = 0;
  more_variables ();
  
  /* Arrays. */
  a_count = 0;
  more_arrays ();

  /* Other things... */
  ex_stack = NULL;
  fn_stack = NULL;
  i_base = 10;
  o_base = 10;
  scale  = 0;
#ifdef READLINE
  n_history = -1;	/* no limit. */
#endif
  c_code = FALSE;
  init_numbers();
}
Exemplo n.º 2
0
int
lookup (char *name, int  namekind)
{
  id_rec *id;

  /* Warn about non-standard name. */
  if (strlen(name) != 1)
    ct_warn ("multiple letter name - %s", name);

  /* Look for the id. */
  id = find_id (name_tree, name);
  if (id == NULL)
    {
      /* We need to make a new item. */
      id = bc_malloc (sizeof (id_rec));
      id->id = strcopyof (name);
      id->a_name = 0;
      id->f_name = 0;
      id->v_name = 0;
      insert_id_rec (&name_tree, id);
    }

  /* Return the correct value. */
  switch (namekind)
    {
      
    case ARRAY:
      /* ARRAY variable numbers are returned as negative numbers. */
      if (id->a_name != 0)
	{
	  free (name);
	  return (-id->a_name);
	}
      id->a_name = next_array++;
      if (id->a_name < MAX_STORE)
	{
	  if (id->a_name >= a_count)
	    more_arrays ();
	  a_names[id->a_name] = name;
	  return (-id->a_name);
	}
      yyerror ("Too many array variables");
      bc_exit (1);
      /*NOTREACHED*/

    case FUNCT:
    case FUNCTDEF:
      if (id->f_name != 0)
	{
          free(name);
	  /* Check to see if we are redefining a math lib function. */ 
	  if (use_math && namekind == FUNCTDEF && id->f_name <= 6)
	    id->f_name = next_func++;
	  return (id->f_name);
	}
      id->f_name = next_func++;
      if (id->f_name < MAX_STORE)
	{
	  if (id->f_name >= f_count)
	    more_functions ();
          f_names[id->f_name] = name;
	  return (id->f_name);
	}
      yyerror ("Too many functions");
      bc_exit (1);
      /*NOTREACHED*/

    case SIMPLE:
      if (id->v_name != 0)
	{
	  free(name);
	  return (id->v_name);
	}
      id->v_name = next_var++;
      if (id->v_name <= MAX_STORE)
	{
	  if (id->v_name >= v_count)
	    more_variables ();
          v_names[id->v_name - 1] = name;
	  return (id->v_name);
	}
      yyerror ("Too many variables");
      bc_exit (1);
      /*NOTREACHED*/

    }

  yyerror ("End of util.c/lookup() reached.  Please report this bug.");
  bc_exit (1);
  /*NOTREACHED*/
}