コード例 #1
0
ファイル: platy_tt.c プロジェクト: Flaniel44/Symbol-Table
/* The function display buffer contents 
 */
void display (Buffer *ptrBuffer){
  printf("\nPrinting input buffer parameters:\n\n");
  printf("The capacity of the buffer is:  %d\n",b_capacity(ptrBuffer));
  printf("The current size of the buffer is:  %d\n",b_size(ptrBuffer));
  printf("The reallocation flag is:   %d\n",b_rflag(ptrBuffer));
  printf("\nPrinting input buffer contents:\n\n");
  b_print(ptrBuffer);
}
コード例 #2
0
ファイル: stable.c プロジェクト: skyeturriff/Parser
/*******************************************************************************
* Purpose:			Add a new entry into the symbol table array of STVR at the 
*					next available element. 
* Author:			Skye Turriff
* History:			Version 1, 19 November 2015
* Called functions:	st_lookup(), b_setmark(), b_size(), b_addc(), b_rflag(),
*					st_incoffset()
* Parameters:		STD sym_table struct with valid st_size
*					char* lexeme pointer to VID name to be added to table
*					char type of VID
*					int line of first occurence of VID
* Return value:		int offset into STVR array where VID record is installed, 
*					-2 on bad parameters, or -1 if symbol table is full.
* Algorithm:		Check parameters, return -2 if bad. If lexeme already in
*					symbol table, return the offset. If symbol table is full,
*					return -1. Set plex for new STVR to point to the next space
*					available in CA. Add each character in the VID lexeme to 
*					this location and make a C-type string. Once the new lexeme
*					has been added, if at any time the location of the CA was 
*					moved, re-calculate plex for each STVR in the STVR array. 
*					Finally, initialize remaining members for new STVR, and
*					increment st_offset of global sym_table. Return offset of
*					new STVR in STVR array.
*******************************************************************************/
int st_install(STD sym_table, char* lexeme, char type, int line) {
	int offset;		/* Offset into array of STVR */
	char r_flag;	/* Memory reallocation flag for lexeme storage buffer */
	char* tplex;	/* Used to iterate through lexeme storage buffer */
	int i;			/* Loop counter for iteration through STVR array */

	/* Check for valid symbol table */
	if (sym_table.st_size == 0) 
		return ERR_FAIL2;	

	/* Check if lexeme already exists */
	if ((offset = st_lookup(sym_table, lexeme)) != ERR_FAIL1) 
		return offset;

	/* Ensure there is room for a new record */
	if (sym_table.st_offset >= sym_table.st_size) 
		return ERR_FAIL1;

	/* Set plex for new VID record */
	sym_table.pstvr[sym_table.st_offset].plex =
		b_setmark(sym_table.plsBD, b_size(sym_table.plsBD));

	/* Install new entry into STVR array, make C-type string */
	r_flag = 0;
	for (; *lexeme; lexeme++) {
		b_addc(sym_table.plsBD, *lexeme);
		if (b_rflag(sym_table.plsBD)) 
			r_flag = 1;
	}
	b_addc(sym_table.plsBD, '\0');
	if (b_rflag(sym_table.plsBD)) 
		r_flag = 1;

	/* If r_flag set, use tplex to interate through lexeme storage 
	until '\0'. Then set plex of the current STVR to tplex + 1 */
	if (r_flag) {
		sym_table.pstvr[0].plex = b_setmark(sym_table.plsBD, 0);
		tplex = sym_table.pstvr[0].plex;
		for (i = 1; i <= sym_table.st_offset; i++) {
			while (*tplex) { tplex++;  continue; }
			sym_table.pstvr[i].plex = ++tplex;
		}
	}

	/* Record source line number */
	sym_table.pstvr[sym_table.st_offset].o_line = line;

	/* Initialize status_field and i_value */
	sym_table.pstvr[sym_table.st_offset].status_field &= DEFAULTZ;
	sym_table.pstvr[sym_table.st_offset].status_field |= DEFAULT;
	if (type == 'I') { /* integer */
		sym_table.pstvr[sym_table.st_offset].status_field |= DT_INT;
		sym_table.pstvr[sym_table.st_offset].i_value.int_val = 0;
	}
	else if (type == 'F') {	/* float */
		sym_table.pstvr[sym_table.st_offset].status_field |= DT_FPL;
		sym_table.pstvr[sym_table.st_offset].i_value.fpl_val = 0.0F;
	}
	else { /* string */
		sym_table.pstvr[sym_table.st_offset].status_field |= DT_STR;
		sym_table.pstvr[sym_table.st_offset].status_field |= SET_FLG;
		sym_table.pstvr[sym_table.st_offset].i_value.str_offset = -1;
	}

	st_incoffset();	/* Increment offset into STVR array of global sym_table */

	return sym_table.st_offset;
}