Symbol Table: Basic skeleton definitions and declarations

This commit is contained in:
Victor Fernandes 2017-03-24 18:12:08 -04:00
parent c3c41f5a36
commit 1efdeaf3e7
2 changed files with 224 additions and 0 deletions

177
stable.c Normal file
View File

@ -0,0 +1,177 @@
/* Filename: stable.c
* Compiler: msvc (Visual Studio 2015)
* Store and provide functions for the symbol table database
* CST8152, Assignment #3
* Professor: Svillen Ranev
* Author: Victor Fernandes, 040772243
* Version: 0.1
* Date: 24 March 2017
*/
#include "stable.h"
/* Forward function declarations */
static void st_setsize(void);
static void st_incoffset(void);
extern STD sym_table;
/* Create a symbol table
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters: int - size of the symbol table
* Return value: The symbol table descriptor
* Algorithm:
*/
STD st_create(int st_size){
STD new_stable;
if (st_size <= 0 || (new_stable.pstvr = (STVR*)malloc((size_t)st_size * sizeof(STVR)) == NULL))
new_stable.st_size = 0;
if ((new_stable.plsBD = b_create(st_size, 1, 'a')) == NULL){
free(new_stable.plsBD);
new_stable.st_size = 0;
}
new_stable.st_size = 0;
new_stable.st_offset = 0;
return new_stable;
}
/* Install a new entry in the symbol table
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
int st_install(STD sym_table, char *lexeme, char type, int line){
}
/* Look up the lexeme string in the symbol table's buffer
* Author: Victor Fernandes
* Version: 0.1
*/
int st_lookup(STD sym_table, char *lexeme){
}
/* Change the data type indicator of the variable entry located
in vid_offset.
* Author: Victor Fernandes
* Version: 0.1
*/
int st_change_type(STD sym_table, int vid_offset, char v_type) {
}
/* Change the i_value of the variable located by vid_offset to new Value
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
int st_change_value(STD sym_table, int vid_offset, Value value){
}
/* Get the type of the variable specified by vid_offset
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
char st_get_type(STD sym_table, int vid_offset){
}
/* Return the i_value of the variable specified by vid_offset
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value: Value i_value, incorrect parameters will have undefined behaviour
* Algorithm:
*/
Value st_get_value(STD sym_table, int vid_offset){
}
/* Free memory used by the symbol table
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
void st_destroy(STD sym_table){
}
/* Print the contents of the symbol table to standard output
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
int st_print(STD sym_table){
}
/* Internal function to set the table size to 0.
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
static void st_setsize(void){
}
/* Internal function to increment st_offset by 1.
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
static void st_incoffset(void){
}
/* Store the symbol table to a file named $stable.ste.
It overwrites any existing file named $stable.ste.
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
int st_store(STD sym_table){
}
/* Sorts the table by variable name in ascending/descenging order
* Author: Victor Fernandes, 040772243
* Version: 0.0.1
* Called functions:
* Parameters:
* Return value:
* Algorithm:
*/
int st_sort(STD sym_table, char s_order){
return 0; /* SYKE! */
}

47
stable.h Normal file
View File

@ -0,0 +1,47 @@
/* Filename: stable.h
* Compiler: msvc (Visual Studio 2015)
* Function declarations for the symbol table
* CST8152, Assignment #3
* Professor: Svillen Ranev
* Author: Victor Fernandes, 040772243
* Version: 0.1
* Date: 24 March 2017
*/
#ifndef STABLE_H_
#define STABLE_H_
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "buffer.h"
typedef union InitialValue {
int int_val; /* Integer variable initial value */
float fpl_val /* Floating-point variable initial value */
int str_offset /* String variable initial value (location offset) */
} Value;
typedef struct SymbolTableVidRecord {
unsigned short status_field /* Variable record status field */
char *plex; /* Pointer to lexeme (VID name) in CA (character array) */
int o_line /* Line of first occurence */
Value i_value; /* Variable initial value */
void *reserved; /* Reserved for future use, not needed right now */
} STVR;
typedef struct SymbolTableDescriptor {
STVR *pstvr; /* Pointer to array of STVR */
int st_size; /* Size in number of STVR elements */
int st_offset; /* Offset in number of STVR elements */
Buffer *plsBD; /* Pointer to the lexeme storage buffer descriptor */
} STD;
int st_install(STD, char*, char, int);
int st_lookup(STD, char*);
int st_change_type(STD, int, char);
int st_change_value(STD, int, Value);
char st_get_type(STD, int);
Value st_get_value(STD, int);
void st_destroy(STD);
int st_print(STD);
int st_store(STD);
int st_sort(STD, char);
#endif