Esempio n. 1
0
/* TODO: obey static to declare a function to the file level */
symbol *define_function(char *name, YYLTYPE  loc, data_type_t  return_type, symbol* param_list) {
    
    symbol *s;
    MALLOC(s, symbol, 1);
    s->type = FUNCTION;
    s->loc  = loc;
    strcpy(s->name, name);

    //s->u.func.arity = size;
    s->u.func.return_type = return_type;
    s->u.func.defined = TRUE;
    s->u.func.plist = param_list;

    print_fn_signature(s);


    if ( check_duplicate(GLOBAL_LEVEL, s) ) {
        /* if a prototype exists, replace it by the definition */
        symbol *sym;
        if ( (sym = find_symbol(GLOBAL_LEVEL, s->name)) ) {
            delete_symbol(GLOBAL_LEVEL, sym);
        }
        add_symbol(GLOBAL_LEVEL, s);
        // add all params as vars to the current function symtable
        for ( sym = param_list; sym; sym = sym->u.param.next )
            if ( !declare_symbol(VARIABLE,  sym->name, sym->loc, FUNCTION_LEVEL, sym->u.param.data_type, sym->u.param.size) )
                return NULL;
        return s;
    } else {
        nberrs++;
        printf("errrrrr\n");
        return NULL;
    }
}
Esempio n. 2
0
int replace(int *i, int *j,int size, char* s1, int size_s1)
{
    int k, res = 0;
    char c;
    is_saved = 0;
    *j -= size;
    for (k = 0; k < size; k++)
    {
        delete_symbol(*i, *j);
    }
    for (k = 0; k < size_s1; k++)
    {
        c = s1[k];
        if (c == '\n')
        {
            insert_symbol(*i, *j, '\n');
            *j = 1;
            *i = *i + 1;
            res++;
        }
        else
        {
            insert_symbol(*i, *j, c);
            *j = *j + 1;
        }
    }
    return res;
    
}
Esempio n. 3
0
void list_store_new(char *widget)
{
        int n = 0;
        char *column, *columns, *tmp, *n_columns;
        symrec *sym;
       
        if (getsymval("iter") == NULL) {
                syminst(TYPE_ITER, "iter", "&iter");
                prtstr(2, "GtkTreeIter ", "iter;\n");
        }

        if ((sym = get_symbol_by_type(TYPE_COLUMN)) != NULL) {
                column = strdup(sym->value);
                delete_symbol(sym);
                columns = concat("", column);
                free(column);
                n++;
 
                while ((sym = get_symbol_by_type(TYPE_COLUMN)) != NULL) {
                      column = strdup(sym->value);
                      delete_symbol(sym);
                      tmp = concatv(3, columns, ", ", column);
                      free(column);
                      free(columns);
                      columns = tmp;
                      n++;
                }
        } else {
                columns = "";
        }

        n_columns = itoa(n);

        this = syminst(TYPE_LIST_STORE, widget, widget);

        putdef("GtkListStore *"
             , widget
             , "gtk_list_store_new"
             , 2
             , n_columns
             , columns);

        free(n_columns);
}
void update_and_append_scope(symtabEntry * scope, char * name, symtabEntryType type, int parameter_count) {
	int i;
	
	symtabEntry * existing = find_symbol(name, 0);
	
	if (existing != NULL) {
		if (parameter_count != existing->parameter) {
			puts("Parameter count not matched.\n");
		} else {
			for (i = 0; i < parameter_count; ++i) {
				symtabEntry * param1 = find_parameter_symbol(scope, i + 1, scope);
				symtabEntry * param2 = find_parameter_symbol(existing, i + 1, theSymboltable);
				
				if (param1 == NULL) {
					puts("Could not find the parameter in the current scope");
				} else if (param2 == NULL) {
					puts("Could not find the parameter in the existing symbol table");
				} else if (param1->type != param2->type) {
					puts("Parameters of prototype do not match actual function definition in `__test__`\n");
				}
			}
		}
		
		for (i = 0; i < existing->parameter; ++i) {
			delete_symbol(find_parameter_symbol(existing, i + 1, theSymboltable));
		}
		delete_symbol(find_symbol(name, 0));
	}
	
	scope->name      = strdup(name);
	
	if (strcmp(scope->name, "main") == 0) {
		scope->type       = PROG;
	} else if (type == NOP) {
		scope->type       = PROC;
	} else {
		scope->type       = FUNC;
		scope->internType = type;
	}
	
	scope->parameter = parameter_count;
	
	append_to_symbol_table(scope);
}
Esempio n. 5
0
void free_symbol_table(visibility_level_t vl) {
    symbol *s, *old_s;

    for( s = symbol_tables[vl]; s != NULL; ) {
        old_s = s;
        s = s->hh.next;
        delete_symbol(vl, old_s);
        free(old_s);
    }
}
Esempio n. 6
0
void delete_slice
(     MPL *mpl,
      SLICE *slice            /* destroyed */
)
{     SLICE *temp;
      while (slice != NULL)
      {  temp = slice;
         slice = temp->next;
         if (temp->sym != NULL) delete_symbol(mpl, temp->sym);
         dmp_free_atom(mpl->tuples, temp);
      }
      return;
}
Esempio n. 7
0
/*--------------------------------------------------------------
 Routine : draw_symbol_small
 Purpose :
---------------------------------------------------------------*/
void
draw_symbol_small(Canvas canvas, CanvasCoord symbol_centre, SYMBOL *symbol)
{
/*     SEGMENT        *seg_list; */
/*     ARC                *arc; */
/*     RECTANGLE        *rect; */
/*     POLYLINE        *poly; */
/*     LINE        *line; */
    SYMBOL *small_symbol;

    ASSERT( symbol != NULL );

    small_symbol = scale_symbol(symbol, 1.1);
    symbol_centre.y += (symbol->depth - small_symbol->depth)/2.0;
    draw_symbol(canvas, symbol_centre, small_symbol);
    delete_symbol(small_symbol);
}
Esempio n. 8
0
void tabular_format
(     MPL *mpl,
      PARAMETER *par,         /* not changed */
      SLICE *slice,           /* not changed */
      int tr
)
{     SLICE *list, *col, *temp;
      TUPLE *tuple;
      SYMBOL *row;
      insist(par != NULL);
      insist(par->dim == slice_dimen(mpl, slice));
      insist(slice_arity(mpl, slice) == 2);
      /* read the table heading that contains column symbols (the table
         may have no columns) */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* read column symbol and append it to the column list */
         if (!is_symbol(mpl))
            error(mpl, "number, symbol, or := missing where expected");
         list = expand_slice(mpl, list, read_symbol(mpl));
      }
      get_token(mpl /* := */);
      /* read zero or more rows that contain tabular data */
      while (is_symbol(mpl))
      {  /* read row symbol (if the table has no columns, these symbols
            are just ignored) */
         row = read_symbol(mpl);
         /* read values accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  int which = 0;
            /* if the token is single point, no value is provided */
            if (is_literal(mpl, "."))
            {  get_token(mpl /* . */);
               continue;
            }
            /* construct complete subscript list */
            tuple = create_tuple(mpl);
            for (temp = slice; temp != NULL; temp = temp->next)
            {  if (temp->sym == NULL)
               {  /* substitution is needed */
                  switch (++which)
                  {  case 1:
                        /* substitute in the first null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? col->sym : row));
                        break;
                     case 2:
                        /* substitute in the second null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? row : col->sym));
                        break;
                     default:
                        insist(which != which);
                  }
               }
               else
               {  /* copy symbol from the slice */
                  tuple = expand_tuple(mpl, tuple, copy_symbol(mpl,
                     temp->sym));
               }
            }
            insist(which == 2);
            /* read value and assign it to new parameter member */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, col);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, row));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, row));
            }
            read_value(mpl, par, tuple);
         }
         /* delete the row symbol */
         delete_symbol(mpl, row);
      }
      /* delete the column list */
      delete_slice(mpl, list);
      return;
}
Esempio n. 9
0
void matrix_format
(     MPL *mpl,
      SET *set,               /* not changed */
      MEMBER *memb,           /* modified */
      SLICE *slice,           /* not changed */
      int tr
)
{     SLICE *list, *col, *temp;
      TUPLE *tuple;
      SYMBOL *row;
      insist(set != NULL);
      insist(memb != NULL);
      insist(slice != NULL);
      insist(set->dimen == slice_dimen(mpl, slice));
      insist(memb->value.set->dim == set->dimen);
      insist(slice_arity(mpl, slice) == 2);
      /* read the matrix heading that contains column symbols (there
         may be no columns at all) */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* read column symbol and append it to the column list */
         if (!is_symbol(mpl))
            error(mpl, "number, symbol, or := missing where expected");
         list = expand_slice(mpl, list, read_symbol(mpl));
      }
      get_token(mpl /* := */);
      /* read zero or more rows that contain matrix data */
      while (is_symbol(mpl))
      {  /* read row symbol (if the matrix has no columns, row symbols
            are just ignored) */
         row = read_symbol(mpl);
         /* read the matrix row accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  int which = 0;
            /* check indicator */
            if (is_literal(mpl, "+"))
               ;
            else if (is_literal(mpl, "-"))
            {  get_token(mpl /* - */);
               continue;
            }
            else
            {  int lack = slice_dimen(mpl, col);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, row));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, row));
            }
            /* construct complete n-tuple */
            tuple = create_tuple(mpl);
            for (temp = slice; temp != NULL; temp = temp->next)
            {  if (temp->sym == NULL)
               {  /* substitution is needed */
                  switch (++which)
                  {  case 1:
                        /* substitute in the first null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? col->sym : row));
                        break;
                     case 2:
                        /* substitute in the second null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? row : col->sym));
                        break;
                     default:
                        insist(which != which);
                  }
               }
               else
               {  /* copy symbol from the slice */
                  tuple = expand_tuple(mpl, tuple, copy_symbol(mpl,
                     temp->sym));
               }
            }
            insist(which == 2);
            /* add constructed n-tuple to elemental set */
            check_then_add(mpl, memb->value.set, tuple);
            get_token(mpl /* + */);
         }
         /* delete the row symbol */
         delete_symbol(mpl, row);
      }
      /* delete the column list */
      delete_slice(mpl, list);
      return;
}
Esempio n. 10
0
void parameter_data(MPL *mpl)
{     PARAMETER *par;
      SYMBOL *altval = NULL;
      SLICE *slice;
      int tr = 0;
      insist(is_literal(mpl, "param"));
      get_token(mpl /* param */);
      /* read optional default value */
      if (is_literal(mpl, "default"))
      {  get_token(mpl /* default */);
         if (!is_symbol(mpl))
            error(mpl, "default value missing where expected");
         altval = read_symbol(mpl);
         /* if the default value follows the keyword 'param', the next
            token must be only the colon */
         if (mpl->token != T_COLON)
            error(mpl, "colon missing where expected");
      }
      /* being used after the keyword 'param' or the optional default
         value the colon begins data in the tabbing format */
      if (mpl->token == T_COLON)
      {  get_token(mpl /* : */);
         /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* read parameter data in the tabbing format */
         tabbing_format(mpl, altval);
         /* on reading data in the tabbing format the default value is
            always copied, so delete the original symbol */
         if (altval != NULL) delete_symbol(mpl, altval);
         /* the next token must be only semicolon */
         if (mpl->token != T_SEMICOLON)
            error(mpl, "symbol, number, or semicolon missing where expe"
               "cted");
         get_token(mpl /* ; */);
         goto done;
      }
      /* in other cases there must be symbolic name of parameter, which
         follows the keyword 'param' */
      if (!is_symbol(mpl))
         error(mpl, "parameter name missing where expected");
      /* select the parameter to saturate it with data */
      par = select_parameter(mpl, mpl->image);
      get_token(mpl /* <symbol> */);
      /* read optional default value */
      if (is_literal(mpl, "default"))
      {  get_token(mpl /* default */);
         if (!is_symbol(mpl))
            error(mpl, "default value missing where expected");
         altval = read_symbol(mpl);
         /* set default value for the parameter */
         set_default(mpl, par, altval);
      }
      /* create initial fake slice of all asterisks */
      slice = fake_slice(mpl, par->dim);
      /* read zero or more data assignments */
      for (;;)
      {  /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* process current assignment */
         if (mpl->token == T_ASSIGN)
         {  /* assignment ligature is non-significant element */
            get_token(mpl /* := */);
         }
         else if (mpl->token == T_LBRACKET)
         {  /* left bracket begins new slice; delete the current slice
               and read new one */
            delete_slice(mpl, slice);
            slice = read_slice(mpl, par->name, par->dim);
            /* each new slice resets the "transpose" indicator */
            tr = 0;
         }
         else if (is_symbol(mpl))
         {  /* number or symbol begins data in the plain format */
            plain_format(mpl, par, slice);
         }
         else if (mpl->token == T_COLON)
         {  /* colon begins data in the tabular format */
            if (par->dim == 0)
err1:          error(mpl, "%s not a subscripted parameter",
                  par->name);
            if (slice_arity(mpl, slice) != 2)
err2:          error(mpl, "slice currently used must specify 2 asterisk"
                  "s, not %d", slice_arity(mpl, slice));
            get_token(mpl /* : */);
            /* read parameter data in the tabular format */
            tabular_format(mpl, par, slice, tr);
         }
         else if (mpl->token == T_LEFT)
         {  /* left parenthesis begins the "transpose" indicator, which
               is followed by data in the tabular format */
            get_token(mpl /* ( */);
            if (!is_literal(mpl, "tr"))
err3:          error(mpl, "transpose indicator (tr) incomplete");
            if (par->dim == 0) goto err1;
            if (slice_arity(mpl, slice) != 2) goto err2;
            get_token(mpl /* tr */);
            if (mpl->token != T_RIGHT) goto err3;
            get_token(mpl /* ) */);
            /* in this case the colon is optional */
            if (mpl->token == T_COLON) get_token(mpl /* : */);
            /* set the "transpose" indicator */
            tr = 1;
            /* read parameter data in the tabular format */
            tabular_format(mpl, par, slice, tr);
         }
         else if (mpl->token == T_SEMICOLON)
         {  /* semicolon terminates the data block */
            get_token(mpl /* ; */);
            break;
         }
         else
            error(mpl, "syntax error in parameter data block");
      }
      /* delete the current slice */
      delete_slice(mpl, slice);
done: return;
}
Esempio n. 11
0
static void _free_symbol_leaf(leaf_t self)
{
  delete_symbol(self->leaf);
}
Esempio n. 12
0
void delete_one_pair_braces(int *i, int *j)
{
    int k, count_braces = 0;
    char c;
    struct MyString *tmpstring;
    struct MySymbol *tmpsymbol;
    tmpstring = my_strings_start;
    for (k = 0; k < *i-1; k++)
    {
        tmpstring = tmpstring->next_string;
    }
    tmpsymbol = tmpstring->first_symbol;
    for (k = 0; k < *j-1; k++)
    {
        tmpsymbol = tmpsymbol->next_symbol;
    }
    
    while (1)
    {
        if ((*i == N) && (*j > tmpstring->cur_size))
        {
            break;
        }
        if (*j > tmpstring->cur_size)
        {
            delete_symbol(*i,*j);
            tmpsymbol = get_symbol(*i, *j);
            tmpstring = my_strings_start;
            for (k = 0; k < *i-1; k++)
            {
                tmpstring = tmpstring->next_string;
            }
        }
        if (tmpsymbol == NULL)
        {
            while (tmpsymbol == NULL)
            {
                if ((*i == N) && (*j > tmpstring->cur_size))
                {
                    *j = *j -1;
                    return;
                }
                delete_symbol(*i,*j);
                tmpsymbol = get_symbol(*i, *j);
                tmpstring = my_strings_start;
                for (k = 0; k < *i-1; k++)
                {
                    tmpstring = tmpstring->next_string;
                }
            }
        }
        c = tmpsymbol->symbol;
        switch (c)
        {
            case '{':
                count_braces++;
                delete_symbol(*i, *j);
                tmpsymbol = get_symbol(*i, *j);
                break;
            case '}':
                count_braces--;
                delete_symbol(*i, *j);
                tmpsymbol = get_symbol(*i, *j);
                break;
            default:
                delete_symbol(*i, *j);
                tmpsymbol = get_symbol(*i, *j);
                break;
        }
        if (count_braces == 0)
        {
            break;
        }
    }
    *j = *j -1;
}