BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
sym_table.h
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#ifndef SYM_TABLE_H
19#define SYM_TABLE_H
20
21#include <list>
22#include <string>
23
24namespace GMAD
25{
26 class Array;
27
32 class Symtab {
33 public:
35 friend class Array;
36
37 enum class symtabtype {
38 NUMBER=0,
39 STRING=1,
40 ARRAY=2,
41 FUNCTION=3
42 };
44 typedef double (*function)(double);
45
46 public:
48 explicit Symtab(std::string s);
50 void Set(Array*);
52 void Set(std::string);
54 void Set(double,bool reserved=false);
56 void Set(function);
57
59 std::string GetName()const;
61 symtabtype GetType()const;
63 bool IsReserved()const;
65 std::list<double> GetArray()const;
67 std::string GetString()const;
69 double GetNumber()const;
71 function GetFunction()const;
72
74 void Print();
75
76 private:
78 std::string name;
82 symtabtype type;
85 double value;
86 std::string str;
87 std::list<double> array;
89
90 };
91}
92
93#endif
Representation of arrays used in tokens.
Definition array.h:39
Common header for the lexer and the parser to share Symbol table for numeric variables,...
Definition sym_table.h:32
std::list< double > array
data
Definition sym_table.h:87
std::list< double > GetArray() const
Get methods that check on type.
Definition sym_table.cc:99
symtabtype GetType() const
Get type.
Definition sym_table.cc:69
function funcptr
data
Definition sym_table.h:84
double value
data
Definition sym_table.h:85
function GetFunction() const
Set to function pointer.
Definition sym_table.cc:109
double GetNumber() const
Set to double.
Definition sym_table.cc:79
double(* function)(double)
typedef for function pointer
Definition sym_table.h:44
void Print()
Print method.
Definition sym_table.cc:119
symtabtype type
Enum type.
Definition sym_table.h:82
bool is_reserved
Flag is parser symbol is a reserved name.
Definition sym_table.h:80
std::string name
Name of parser symbol.
Definition sym_table.h:78
void Set(Array *)
Set to Array value.
Definition sym_table.cc:36
std::string str
data
Definition sym_table.h:86
bool IsReserved() const
Check if symbol is a reserved name.
Definition sym_table.cc:74
std::string GetName() const
Get name.
Definition sym_table.cc:64
std::string GetString() const
Set to string.
Definition sym_table.cc:89
Parser namespace for GMAD language. Combination of Geant4 and MAD.