Im building a symbol table and im having a hard time writing get_symbol, which has the arguments of (symbol_table symtab, char sym). I have to write code for 2 functions get_symbol and set_symbol, I'm having some trouble understanding what a symbol table is and how to write out these two functions. it says that get_symbol() has two arguments: the symbol table, and the symbol name whose value should be retrieved. If the symbol name is one of A,B,C the corresponding value from the symbol table should be returned. if it is not one of those names, then 0 should be returned. If any one could help that would be great thanks for your time.
symbol_table.c Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "globals.h"
#include "symbol_table.h"
typedef struct symbol_table_s {
int a,b,c;
}*symbol_table_rep;
status init_symbol_table (symbol_table *p_symtab)
{
symbol_table_rep st = malloc(sizeof(struct symbol_table_s));
if (st == NULL)
return ERROR;
st->a = st->b = st->c = 0;
*p_symtab = (symbol_table) st;
return OK;
}
void destroy_symbol_table (symbol_table *p_symtab)
{
free(*p_symtab);
*p_symtab = NULL;
}
void set_symbol(symbol_table *p_symtab, char sym, int value)
{
/* WRITE CODE FOR THIS */
}
int get_symbol (symbol_table symtab, char sym)
{
/* WRITE CODE FOR THIS FUNCTION */
symbol_table_rep symtab;
if (A,B,C)
{
return symbol_table;
}else{
return 0;
}
}
symbol_table.h Code:
#ifndef _SYMBOL_TABLE_H
#define _SYMBOL_TABLE_H
#include "globals.h"
ABSTRACT_TYPE(symbol_table);
status init_symbol_table (symbol_table *p_symtab);
void destroy_symbol_table(symbol_table *p_symtab);
void set_symbol (symbol_table *p_symtab, char sym, int value);
int get_symbol (symbol_table symtab, char sym);
#endif