BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
symbolmap.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "symbolmap.h"
20
21#include "sym_table.h"
22
23#include <cstdlib>
24#include <iostream>
25
26using namespace GMAD;
27
29{
30 std::map<std::string,Symtab*>::iterator it = symtab_map.find(s);
31 if (it!=symtab_map.end())
32 {
33 std::cerr << "ERROR Variable " << s << " is already defined!" << std::endl;
34 exit(1);
35 }
36
37 Symtab* sp = new Symtab(s);
38 std::pair<std::map<std::string,Symtab*>::iterator,bool> ret = symtab_map.insert(std::make_pair(s,sp));
39 return (*(ret.first)).second;
40}
41
42Symtab * SymbolMap::symlook(std::string s)
43{
44 std::map<std::string,Symtab*>::iterator it = symtab_map.find(s);
45 return it == symtab_map.end() ? nullptr : (*it).second;
46}
47
49{
50 for (auto& kv : symtab_map)
51 {delete kv.second;}
52 symtab_map.clear();
53}
void clear()
Destructor that clears memory.
Definition: symbolmap.cc:48
std::map< std::string, Symtab * > symtab_map
Parser symbol map.
Definition: symbolmap.h:44
Symtab * symlook(std::string s)
Look up parser symbol.
Definition: symbolmap.cc:42
Symtab * symcreate(std::string s)
Create new parser symbol.
Definition: symbolmap.cc:28
Common header for the lexer and the parser to share Symbol table for numeric variables,...
Definition: sym_table.h:33
Parser namespace for GMAD language. Combination of Geant4 and MAD.