rasdaman complete source
symtab.hh
Go to the documentation of this file.
1 #ifndef _SYMTAB_HH_
2 #define _SYMTAB_HH_
3 
4 /*
5 * This file is part of rasdaman community.
6 *
7 * Rasdaman community is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Rasdaman community is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
21 rasdaman GmbH.
22 *
23 * For more information please see <http://www.rasdaman.org>
24 * or contact Peter Baumann via <baumann@rasdaman.com>.
25 */
26 /*************************************************************************
27  *
28  *
29  * PURPOSE:
30  * store symbols (identifiers) during the parse process
31  *
32  *
33  * COMMENTS:
34  * none
35  *
36  ***********************************************************************/
37 
38 #include <iostream>
39 #include <vector>
40 #include <map>
41 #include <string>
42 #include "raslib/rmdebug.hh"
43 
44 //@ManMemo: Module: {\bf qlparser}
45 
46 /*@Doc:
47 
48  This class represents a generic symbol table. The operations on
49  symbols in the symbol table are: putSymbol, getSymbol, lookupSymbol.
50  The operations on scopes are: initScope, exitScope, outScope, clearScope,
51  wipe.
52 
53 */
54 
55 template <class T>
57 {
58 public:
60  std::vector<std::string > keys;
62  std::vector<std::string >::iterator keyIterator;
63 
65  SymbolTable();
66 
68  ~SymbolTable();
69 
70  //@Man: Methods for symbol manipulation
72  bool putSymbol( const std::string& symbol, T value );
75  T getSymbol( const std::string& symbol );
77  bool lookupSymbol( const std::string& symbol );
79 
80  //@Man: Methods for scope manipulation
82  void initScope();
85  void exitScope();
87  void outScope();
89  void clearScope();
91  void wipe();
93 
94 private:
96  void storeSymbol( const std::string& symbol, T value ); // put only in the hash_map
97 
99  std::map<std::string , T> STVars;
100 
102  std::vector<std::map<std::string , T> > STScopes;
103 };
104 
105 #ifdef EARLY_TEMPLATE
106 #ifdef __EXECUTABLE__
107 #include "symtab.cc"
108 #endif
109 #endif
110 
111 #endif
SymbolTable()
default constructor creates an empty symbol table, calls initScope(), clears local symbols...
std::vector< std::string >::iterator keyIterator
This is an iterator for the vector storing the keys available in the map.
Definition: symtab.hh:62
void clearScope()
Init scope by clearing inner symbols.
Definition: symtab.hh:56
void initScope()
Enter new scope.
void exitScope()
Exit current scope.
std::vector< std::string > keys
This vector stores keys available in the map.
Definition: symtab.hh:60
bool putSymbol(const std::string &symbol, T value)
Puts value at position symbol in the table. Returns true if it succeeded, otherwise false...
T getSymbol(const std::string &symbol)
Get value at position symbol from the table. If symbol doesn't exist, it returns NULL.
void outScope()
Output current scope to RMInit::logOut.
bool lookupSymbol(const std::string &symbol)
Returns true if symbol is in table.
~SymbolTable()
default destructor, calls exitScope().
void wipe()
Clear all symbols in all scopes.