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