43#include "parser.tab.hh"
50#define YY_NO_UNISTD_H 1
56extern int yyerror(
const char *);
60const int max_include_depth = 10;
61YY_BUFFER_STATE include_stack[max_include_depth];
62std::vector<std::string> include_filename_stack(max_include_depth);
63int include_linenum_stack[max_include_depth];
64int include_stack_ptr = 0;
67std::string yyfilename;
Parser namespace for GMAD language. Combination of Geant4 and MAD.
81(([0-9]+)|([0-9]*\.[0-9]*))((e|E)[+|-]?[0-9]+)? { yylval.dval=atof(yytext);
return NUMBER; }
92marker {
return MARKER; }
93drift {
return DRIFT; }
97rfcavity {
return RF; }
98sbend {
return SBEND; }
100hkicker {
return HKICKER; }
101vkicker {
return VKICKER; }
102kicker {
return KICKER; }
103tkicker {
return TKICKER; }
104quadrupole {
return QUADRUPOLE; }
105sextupole {
return SEXTUPOLE; }
106octupole {
return OCTUPOLE; }
107decapole {
return DECAPOLE; }
108multipole {
return MULTIPOLE; }
109thinmultipole {
return THINMULT; }
110solenoid {
return SOLENOID; }
114bmcol {
return BMCOL; }
115jcoltip {
return JCOLTIP; }
116gascap {
return GASCAP; }
117gasjet {
return GASJET; }
118muonspoiler {
return MUONSPOILER; }
119muspoiler {
return MUONSPOILER; }
120shield {
return SHIELD; }
121element {
return ELEMENT; }
122screen {
return SCREEN; }
123awakescreen {
return AWAKESCREEN; }
124awakespectrometer {
return AWAKESPECTROMETER; }
125transform3d {
return TRANSFORM3D ; }
126laser {
return LASERWIREOLD; }
127degrader {
return DEGRADER;}
129thinrmatrix {
return THINRMATRIX;}
130paralleltransporter {
return PARALLELTRANSPORTER;}
131rmatrix {
return RMATRIX;}
132crystalcol {
return CRYSTALCOL; }
133wirescanner {
return WIRESCANNER; }
134undulator {
return UNDULATOR; }
135usercomponent {
return USERCOMPONENT; }
137muoncooler {
return MUONCOOLER; }
139target {
return TARGET; }
140gaborlens {
return GABORLENS; }
141laserwire {
return LASERWIRE; }
143cavitymodel {
return CAVITYMODEL; }
144cutsregion {
return REGION; }
145newcolour {
return NEWCOLOUR; }
146coolingchannel {
return COOLINGCHANNEL; }
147crystal {
return CRYSTAL; }
148field {
return FIELD; }
149placement {
return PLACEMENT; }
150laserflux {
return LASER; }
151query {
return QUERY; }
152samplerplacement {
return SAMPLERPLACEMENT; }
153scorer {
return SCORER; }
154scorermesh {
return SCORERMESH; }
155tunnel {
return TUNNEL; }
156xsecbias {
return XSECBIAS; }
157xsecBias {
return XSECBIAS; }
158aperture {
return APERTURE; }
160modulator {
return MODULATOR;}
162matdef {
return MATERIAL; }
168period {
return PERIOD; }
169range {
return RANGE; }
173"else" {
return ELSE; }
174"begin" {
return BEGN; }
181option {
return OPTION; }
182beta0 {
return BEAM; }
183print {
return PRINT; }
184"return" {
return STOP; }
187sample {
return SAMPLE; }
188csample {
return CSAMPLE; }
196 yylval.str =
new std::string(yytext+1,strlen(yytext)-2);
static Parser * Instance()
Access method.
void AddVariable(std::string *name)
Add variable memory to variable list for memory management.
204 std::string errorstring =
"malformed string or unmatched quote";
205 yyerror(errorstring.c_str());
210[a-zA-Z#][A-Za-z0-9_#.]* {
211 std::string var(yytext);
218 case Symtab::symtabtype::FUNCTION:
220 case Symtab::symtabtype::ARRAY:
222 case Symtab::symtabtype::NUMBER:
224 case Symtab::symtabtype::STRING:
230 std::string* name =
new std::string(var);
Symtab * symlook(const std::string &s)
look up parser symbol
Common header for the lexer and the parser to share Symbol table for numeric variables,...
symtabtype GetType() const
Get type.
236. {
return yytext[0]; }
242 std::string bdsimpath = (std::string)getEnv(
"BDSIMPATH");
243 std::string includefilename =
"";
244 std::string mainfilename = yyfilename;
245 std::string mainfilepath =
"";
246 if(bdsimpath.length()>0){
248 std::cout <<
"parser> using BDSIMPATH to build included filepaths" << std::endl;
250 includefilename = bdsimpath + (std::string)yytext;
253 std::string::size_type found = mainfilename.rfind(
"/");
254 if (found != std::string::npos) {
255 mainfilepath = mainfilename.substr(0,found+1);
258 if ((mainfilename.substr(0,1)) ==
"/"){
260 includefilename = mainfilepath + (std::string)yytext;
265 std::string cwd = (std::string)getcwd(cwdchars,
sizeof(cwdchars)) +
"/";
266 includefilename = cwd + mainfilepath + (std::string)yytext;
270 std::cout <<
"parser> reading file " << includefilename << std::endl;
271 if (includefilename == yyfilename)
273 std::string errorstring =
"\nError: recursively including the same file inside itself!\n\n Problem";
274 yyerror(errorstring.c_str());
276 if(include_stack_ptr >= max_include_depth - 1)
278 std::string errorstring =
"Error : Include depth exceeds " + std::to_string(max_include_depth);
279 yyerror(errorstring.c_str());
283 yyin = fopen(includefilename.c_str(),
"r");
288 include_linenum_stack[include_stack_ptr] = line_num;
290 include_filename_stack[include_stack_ptr] = yyfilename;
291 yyfilename = includefilename;
292 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
293 include_filename_stack[include_stack_ptr] = yyfilename;
294 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
299 std::string errorstring =
"Error : can't open " + includefilename;
300 yyerror(errorstring.c_str());
307 if (--include_stack_ptr < 0)
315 yy_delete_buffer(YY_CURRENT_BUFFER);
316 yy_switch_to_buffer(include_stack[include_stack_ptr]);
317 yyfilename = include_filename_stack[include_stack_ptr];
318 line_num = include_linenum_stack[include_stack_ptr];