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; }
95rfcavity {
return RF; }
96sbend {
return SBEND; }
98hkicker {
return HKICKER; }
99vkicker {
return VKICKER; }
100kicker {
return KICKER; }
101tkicker {
return TKICKER; }
102quadrupole {
return QUADRUPOLE; }
103sextupole {
return SEXTUPOLE; }
104octupole {
return OCTUPOLE; }
105decapole {
return DECAPOLE; }
106multipole {
return MULTIPOLE; }
107thinmultipole {
return THINMULT; }
108solenoid {
return SOLENOID; }
112muonspoiler {
return MUONSPOILER; }
113muspoiler {
return MUONSPOILER; }
114shield {
return SHIELD; }
115element {
return ELEMENT; }
116screen {
return SCREEN; }
117awakescreen {
return AWAKESCREEN; }
118awakespectrometer {
return AWAKESPECTROMETER; }
119transform3d {
return TRANSFORM3D ; }
120laser {
return LASER; }
121degrader {
return DEGRADER;}
123thinrmatrix {
return THINRMATRIX;}
124paralleltransporter {
return PARALLELTRANSPORTER;}
125rmatrix {
return RMATRIX;}
126crystalcol {
return CRYSTALCOL; }
127wirescanner {
return WIRESCANNER; }
128undulator {
return UNDULATOR; }
129usercomponent {
return USERCOMPONENT; }
132target {
return TARGET; }
134cavitymodel {
return CAVITYMODEL; }
135cutsregion {
return REGION; }
136newcolour {
return NEWCOLOUR; }
137crystal {
return CRYSTAL; }
138field {
return FIELD; }
139placement {
return PLACEMENT; }
140query {
return QUERY; }
141samplerplacement {
return SAMPLERPLACEMENT; }
142scorer {
return SCORER; }
143scorermesh {
return SCORERMESH; }
144tunnel {
return TUNNEL; }
145xsecbias {
return XSECBIAS; }
146xsecBias {
return XSECBIAS; }
147aperture {
return APERTURE; }
150matdef {
return MATERIAL; }
156period {
return PERIOD; }
157range {
return RANGE; }
161"else" {
return ELSE; }
162"begin" {
return BEGN; }
169option {
return OPTION; }
170beta0 {
return BEAM; }
171print {
return PRINT; }
172"return" {
return STOP; }
175sample {
return SAMPLE; }
176csample {
return CSAMPLE; }
184 yylval.str =
new std::string(yytext+1,strlen(yytext)-2);
186 Parser::Instance()->AddVariable(yylval.str);
192 std::string errorstring =
"malformed string or unmatched quote";
193 yyerror(errorstring.c_str());
198[a-zA-Z#][A-Za-z0-9_#.]* {
199 std::string var(yytext);
202 Symtab *sp = Parser::Instance()->symlook(var);
206 case Symtab::symtabtype::FUNCTION:
208 case Symtab::symtabtype::ARRAY:
210 case Symtab::symtabtype::NUMBER:
212 case Symtab::symtabtype::STRING:
218 std::string* name =
new std::string(var);
220 Parser::Instance()->AddVariable(name);
Common header for the lexer and the parser to share Symbol table for numeric variables,...
symtabtype GetType() const
Get type.
224. {
return yytext[0]; }
230 std::string bdsimpath = (std::string)getEnv(
"BDSIMPATH");
231 std::string includefilename =
"";
232 std::string mainfilename = yyfilename;
233 std::string mainfilepath =
"";
234 if(bdsimpath.length()>0){
236 std::cout <<
"parser> using BDSIMPATH to build included filepaths" << std::endl;
238 includefilename = bdsimpath + (std::string)yytext;
241 std::string::size_type found = mainfilename.rfind(
"/");
242 if (found != std::string::npos) {
243 mainfilepath = mainfilename.substr(0,found+1);
246 if ((mainfilename.substr(0,1)) ==
"/"){
248 includefilename = mainfilepath + (std::string)yytext;
253 std::string cwd = (std::string)getcwd(cwdchars,
sizeof(cwdchars)) +
"/";
254 includefilename = cwd + mainfilepath + (std::string)yytext;
258 std::cout <<
"parser> reading file " << includefilename << std::endl;
259 if(include_stack_ptr >= max_include_depth - 1)
261 std::string errorstring =
"Error : Include depth exceeds " + std::to_string(max_include_depth);
262 yyerror(errorstring.c_str());
266 yyin = fopen(includefilename.c_str(),
"r");
271 include_linenum_stack[include_stack_ptr] = line_num;
273 include_filename_stack[include_stack_ptr] = yyfilename;
274 yyfilename = includefilename;
275 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
276 include_filename_stack[include_stack_ptr] = yyfilename;
277 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
282 std::string errorstring =
"Error : can't open " + includefilename;
283 yyerror(errorstring.c_str());
290 if (--include_stack_ptr < 0)
298 yy_delete_buffer(YY_CURRENT_BUFFER);
299 yy_switch_to_buffer(include_stack[include_stack_ptr]);
300 yyfilename = include_filename_stack[include_stack_ptr];
301 line_num = include_linenum_stack[include_stack_ptr];