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) 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#ifndef SYM_TABLE_H
20#define SYM_TABLE_H
21
22#include <list>
23#include <string>
24
25namespace GMAD
26{
27 class Array;
28
33 class Symtab {
34 public:
36 friend class Array;
37
38 enum class symtabtype {
39 NUMBER=0,
40 STRING=1,
41 ARRAY=2,
42 FUNCTION=3
43 };
45 typedef double (*function)(double);
46
47 public:
49 explicit Symtab(std::string s);
51 void Set(Array*);
53 void Set(std::string);
55 void Set(double,bool reserved=false);
57 void Set(function);
58
60 std::string GetName()const;
62 symtabtype GetType()const;
64 bool IsReserved()const;
66 std::list<double> GetArray()const;
68 std::string GetString()const;
70 double GetNumber()const;
72 function GetFunction()const;
73
75 void Print();
76
77 private:
79 std::string name;
83 symtabtype type;
86 double value;
87 std::string str;
88 std::list<double> array;
90
91 };
92}
93
94#endif
Representation of arrays used in tokens.
Definition: array.h:40
Common header for the lexer and the parser to share Symbol table for numeric variables,...
Definition: sym_table.h:33
std::list< double > array
data
Definition: sym_table.h:88
std::list< double > GetArray() const
Get methods that check on type.
Definition: sym_table.cc:100
symtabtype GetType() const
Get type.
Definition: sym_table.cc:70
function funcptr
data
Definition: sym_table.h:85
double value
data
Definition: sym_table.h:86
function GetFunction() const
Set to function pointer.
Definition: sym_table.cc:110
double GetNumber() const
Set to double.
Definition: sym_table.cc:80
double(* function)(double)
typedef for function pointer
Definition: sym_table.h:45
void Print()
Print method.
Definition: sym_table.cc:120
symtabtype type
Enum type.
Definition: sym_table.h:83
bool is_reserved
Flag is parser symbol is a reserved name.
Definition: sym_table.h:81
std::string name
Name of parser symbol.
Definition: sym_table.h:79
void Set(Array *)
Set to Array value.
Definition: sym_table.cc:37
std::string str
data
Definition: sym_table.h:87
bool IsReserved() const
Check if symbol is a reserved name.
Definition: sym_table.cc:75
std::string GetName() const
Get name.
Definition: sym_table.cc:65
std::string GetString() const
Set to string.
Definition: sym_table.cc:90
Parser namespace for GMAD language. Combination of Geant4 and MAD.