#ifndef SYMBOL_TABLE
#define SYMBOL_TABLE 1
#include "token.h"
#include "tablist.h"

class SymbolTable {
    
    private :
    
        TabList **pvTable ;       // the table
        TabList *pvCurrentLevel ; // current level of table
        int     pvSize ;          // current size of table
        int     pvSizeMax ;       // current allocated space for table
    
    public :
    
        //constructor
        SymbolTable ()
        {
            pvSize = pvSizeMax = 0 ;
            pvTable = 0 ;
        }
        
        // destructor
        ~SymbolTable ()
        {
            
            // free each level
            while ( pvSize > 0 ) {
                delete pvCurrentLevel ;
                pvCurrentLevel-- ;
                pvSize-- ;
            }
            
            // free the table
            if ( pvTable ) {
                free(pvTable);
                pvTable = 0 ;
            }
        }
        
        // add a level to the table
        int     AddLevel () ;
        
        // remove a level to the table
        int     RemoveLevel () ;
        
        // insert a var at the current level
        void    AddVar (PTREE) ;
        
        // remove a var at the current level
        void    RemoveVar (PTREE) ;
        
        // get a var definition
        PTREE GetVar ( PTREE tree )
        {
            return GetVar(Value(tree));
        }
        
        PTREE operator[] ( PTREE tree )
        {
            return GetVar(tree);
        }
        
        // get a var definition by its name
        PTREE   GetVar (char *name) ;
        
        PTREE operator[] ( char *name )
        {
            return GetVar(name);
        }
        
        // GetList : get a list at a given level
        TabList *GetTabList ( int level )
        {
            if ( level < pvSize && level >= 0 ) 
                return pvTable [level];
            else 
                return (TabList *)0 ;
        }
};
#endif
