how well written is my symbol table?

closed account (Dy7SLyTq)
so i started writing my compiler with the help of the purple dragon book (and some useful pdfs ive found online) and decided to start with the symbol table, because apparently all phases use it. so anyways, how well did i write it? im not providing the definitions of the methods, because its obvious what they do and im not asking how well theyre written.

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
//Symbol Table Class
class Token
{
     public:
          //representation of token
          enum TokenType
          {
               Function,                     //token is a function
               If, Elif, Else, Switch        //token is a branch
               Variable, Array,              //token is an object
               While, DoWhile, For, ForEach, //token is a loop
               DataStructure,                //token is a structure
               Comment                       //token is a comment
          };

          //if variable, representation of value
          enum ValueType
          {
               Boolean, //object is of type Boolean
               String,  //object is of type String
               Integer, //object is of type Integer
               Float,   //object is of type Floating Point Number
               Null,    //object is of type NULL (ie was not initialized)
               NAV      //Token is not an object, so is Not A Variable (NAV)
          };

          SymbolTable(string, TokenType, int, ValueType, string); //Declaration Constructor

          //Getters
          string GetName();         //Returns Identifier of Token
          TokenType GetTokenType(); //Returns representation of Token Type
          int GetLine();            //Returns Line Token is found on
          ValueType GetValueType(); //Returns Value Type, if object
          string GetValue();        //Returns Value, if object

          //Setters (returns -1 on failure, 0 on success)
          int SetName(string);         //Set Name of Token
          int SetTokenType(TokenType); //Set representation of Token
          int SetLine(int);            //Set Line of Token
          int SetValue(ValueType);     //Set Value Type, if object
          int SetValue(string);        //Set Value, if object

     private:
          string Identifier;  //Token Name
          TokenType Token;    //Token Type
          int Line;           //Line found on
          ValueType Value;    //Type of value, if object
          string ObjectValue; //Value, if object
};
1
2
3
4
//Symbol Table Class
class Token
...
          SymbolTable(string, TokenType, int, ValueType, string); //Declaration Constructor 


Is this a symbol table or a token class? It looks more like the latter. You say symbol table; the implementation says token.
closed account (Dy7SLyTq)
sorry I was confusing myself. Yes that a token class and my symbol table
Would be vector<Token> SymbolTable
my symbol table Would be vector<Token> SymbolTable
???
The symbol table stores information about the meaning of a name in a particular context, such as type, value (in the case of constants), etc.
A vector of tokens sounds more like a representation of a program once it has been lexically analyzed.
Topic archived. No new replies allowed.