42#include "parser.tab.hh"
49#define YY_NO_UNISTD_H 1
55extern int yyerror(
const char *);
59const int max_include_depth = 10;
60YY_BUFFER_STATE include_stack[max_include_depth];
61std::vector<std::string> include_filename_stack(max_include_depth);
62int include_linenum_stack[max_include_depth];
63int include_stack_ptr = 0;
66std::string yyfilename;
Parser namespace for GMAD language. Combination of Geant4 and MAD.
80(([0-9]+)|([0-9]*\.[0-9]*))((e|E)[+|-]?[0-9]+)? { yylval.dval=atof(yytext);
return NUMBER; }
91marker {
return MARKER; }
92drift {
return DRIFT; }
96rfcavity {
return RF; }
97sbend {
return SBEND; }
99hkicker {
return HKICKER; }
100vkicker {
return VKICKER; }
101kicker {
return KICKER; }
102tkicker {
return TKICKER; }
103quadrupole {
return QUADRUPOLE; }
104sextupole {
return SEXTUPOLE; }
105octupole {
return OCTUPOLE; }
106decapole {
return DECAPOLE; }
107multipole {
return MULTIPOLE; }
108thinmultipole {
return THINMULT; }
109solenoid {
return SOLENOID; }
113bmcol {
return BMCOL; }
114jcoltip {
return JCOLTIP; }
115gascap {
return GASCAP; }
116gasjet {
return GASJET; }
117muonspoiler {
return MUONSPOILER; }
118muspoiler {
return MUONSPOILER; }
119shield {
return SHIELD; }
120element {
return ELEMENT; }
121screen {
return SCREEN; }
122awakescreen {
return AWAKESCREEN; }
123awakespectrometer {
return AWAKESPECTROMETER; }
124transform3d {
return TRANSFORM3D ; }
125laser {
return LASERWIREOLD; }
126degrader {
return DEGRADER;}
128thinrmatrix {
return THINRMATRIX;}
129paralleltransporter {
return PARALLELTRANSPORTER;}
130rmatrix {
return RMATRIX;}
131crystalcol {
return CRYSTALCOL; }
132wirescanner {
return WIRESCANNER; }
133undulator {
return UNDULATOR; }
134usercomponent {
return USERCOMPONENT; }
136muoncooler {
return MUONCOOLER; }
138target {
return TARGET; }
139gaborlens {
return GABORLENS; }
140laserwire {
return LASERWIRE; }
141cavitymodel {
return CAVITYMODEL; }
142cutsregion {
return REGION; }
143newcolour {
return NEWCOLOUR; }
144coolingchannel {
return COOLINGCHANNEL; }
145crystal {
return CRYSTAL; }
146field {
return FIELD; }
147placement {
return PLACEMENT; }
148laserflux {
return LASER; }
149query {
return QUERY; }
150samplerplacement {
return SAMPLERPLACEMENT; }
151scorer {
return SCORER; }
152scorermesh {
return SCORERMESH; }
153tunnel {
return TUNNEL; }
154xsecbias {
return XSECBIAS; }
155xsecBias {
return XSECBIAS; }
156aperture {
return APERTURE; }
158modulator {
return MODULATOR;}
160matdef {
return MATERIAL; }
166period {
return PERIOD; }
167range {
return RANGE; }
171"else" {
return ELSE; }
172"begin" {
return BEGN; }
179option {
return OPTION; }
180beta0 {
return BEAM; }
181print {
return PRINT; }
182"return" {
return STOP; }
185sample {
return SAMPLE; }
186csample {
return CSAMPLE; }
194 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.
202 std::string errorstring =
"malformed string or unmatched quote";
203 yyerror(errorstring.c_str());
208[a-zA-Z#][A-Za-z0-9_#.]* {
209 std::string var(yytext);
216 case Symtab::symtabtype::FUNCTION:
218 case Symtab::symtabtype::ARRAY:
220 case Symtab::symtabtype::NUMBER:
222 case Symtab::symtabtype::STRING:
228 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.
234. {
return yytext[0]; }
240 std::string bdsimpath = (std::string)getEnv(
"BDSIMPATH");
241 std::string includefilename =
"";
242 std::string mainfilename = yyfilename;
243 std::string mainfilepath =
"";
244 if(bdsimpath.length()>0){
246 std::cout <<
"parser> using BDSIMPATH to build included filepaths" << std::endl;
248 includefilename = bdsimpath + (std::string)yytext;
251 std::string::size_type found = mainfilename.rfind(
"/");
252 if (found != std::string::npos) {
253 mainfilepath = mainfilename.substr(0,found+1);
256 if ((mainfilename.substr(0,1)) ==
"/"){
258 includefilename = mainfilepath + (std::string)yytext;
263 std::string cwd = (std::string)getcwd(cwdchars,
sizeof(cwdchars)) +
"/";
264 includefilename = cwd + mainfilepath + (std::string)yytext;
268 std::cout <<
"parser> reading file " << includefilename << std::endl;
269 if (includefilename == yyfilename)
271 std::string errorstring =
"\nError: recursively including the same file inside itself!\n\n Problem";
272 yyerror(errorstring.c_str());
274 if(include_stack_ptr >= max_include_depth - 1)
276 std::string errorstring =
"Error : Include depth exceeds " + std::to_string(max_include_depth);
277 yyerror(errorstring.c_str());
281 yyin = fopen(includefilename.c_str(),
"r");
286 include_linenum_stack[include_stack_ptr] = line_num;
288 include_filename_stack[include_stack_ptr] = yyfilename;
289 yyfilename = includefilename;
290 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
291 include_filename_stack[include_stack_ptr] = yyfilename;
292 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
297 std::string errorstring =
"Error : can't open " + includefilename;
298 yyerror(errorstring.c_str());
305 if (--include_stack_ptr < 0)
313 yy_delete_buffer(YY_CURRENT_BUFFER);
314 yy_switch_to_buffer(include_stack[include_stack_ptr]);
315 yyfilename = include_filename_stack[include_stack_ptr];
316 line_num = include_linenum_stack[include_stack_ptr];