[go: up one dir, main page]

Menu

[r377]: / libpetey / symbol_table.h  Maximize  Restore  History

Download this file

52 lines (34 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef SYMBOL_TABLE_H_INCLUDED
#define SYMBOL_TABLE_H_INCLUDED
#include <stdio.h>
namespace libpetey {
template <class sym_t>
class symbol_table {
protected:
long n; //number of entries
long nunq; //number of unique symbols
long array_size; //size of arrays
sym_t *sym; //the symbols
long *sind; //indexes the variables in terms of the symbols
int update_flag;
//for thread-safe code, update must be atomic
void update();
public:
symbol_table();
~symbol_table();
long * collect_garbage(long &ndup);
//adds a new symbol to the table--returns its id
long add(sym_t name);
//returns a unique, pervasive (until the death of the object) ID:
long lookup(sym_t name);
//looks up symbol based on ID:
sym_t get(long id);
//looks up symbol based on lexical ordering:
sym_t let(long ind);
//looks up id based on lexical ordering:
long getid(long ind);
void print();
long entries(int uflag=0);
};
}
#endif