[38] | 1 | %include { |
---|
| 2 | #include <iostream> |
---|
| 3 | #include <sstream> |
---|
| 4 | #include "lemonglobal.h" |
---|
| 5 | #include "conv_f8tof1.h" |
---|
| 6 | #include "conv_f8_utils.h" |
---|
| 7 | #define PARSER_DEBUG 0 |
---|
| 8 | } |
---|
| 9 | %token_type {Token} |
---|
| 10 | %default_type {Token} |
---|
| 11 | %type production_tail {ProductionTailToken} |
---|
| 12 | %type prod_piece {ProdPieceToken} |
---|
| 13 | |
---|
| 14 | %left COMMA. |
---|
| 15 | %left PLUS MINUS. |
---|
| 16 | %left DIV TIMES. |
---|
| 17 | |
---|
| 18 | program ::= counter start_params delim first_prod productions. { |
---|
| 19 | *syntaxOk = true; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | counter ::= double_val(A) NEWLINE. { |
---|
| 23 | if (!syntaxOnly) { |
---|
| 24 | { |
---|
| 25 | #if PARSER_DEBUG > 0 |
---|
| 26 | std::cout << "counter ::= double_val NEWLINE." << std::endl; |
---|
| 27 | #endif |
---|
| 28 | } |
---|
| 29 | lsys->iterations = (int) A.dblValue; |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | delim ::= DELIMETER NEWLINE. |
---|
| 34 | |
---|
| 35 | start_params ::= start_parameter start_params. |
---|
| 36 | start_params ::= . |
---|
| 37 | |
---|
| 38 | start_parameter ::= param_name(A) ASSIGN double_val(B) NEWLINE. { |
---|
| 39 | if (!syntaxOnly) { |
---|
| 40 | { |
---|
| 41 | #if PARSER_DEBUG > 0 |
---|
| 42 | std::cout << "start_parameter ::= param_name ASSIGN double_val NEWLINE." << std::endl; |
---|
| 43 | #endif |
---|
| 44 | } |
---|
| 45 | lsys->startParams[sstringToString(*(A.strValue))] = B.dblValue; |
---|
| 46 | #if PARSER_DEBUG > 0 |
---|
| 47 | //cout << "**** " << lsys->startParams["n0"] << endl; |
---|
| 48 | //cout << "**** " << lsys->startParams["n1"] << endl; |
---|
| 49 | #endif |
---|
| 50 | delete A.strValue; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
[45] | 54 | productions ::= production productions_others. |
---|
| 55 | productions_others ::= production productions_others. |
---|
| 56 | productions_others ::= . |
---|
[38] | 57 | |
---|
| 58 | first_prod ::= prod_name(A) NEWLINE. { |
---|
| 59 | if (!syntaxOnly) { |
---|
| 60 | { |
---|
| 61 | #if PARSER_DEBUG > 0 |
---|
| 62 | std::cout << "first_prod ::= prod_name NEWLINE." << std::endl; |
---|
| 63 | #endif |
---|
| 64 | } |
---|
| 65 | lsys->firstProductionName = sstringToString(*(A.strValue)); |
---|
| 66 | delete A.strValue; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | production ::= production_head(A) SEMICOLON production_tail(B) NEWLINE. { |
---|
| 71 | if (!syntaxOnly) { |
---|
| 72 | { |
---|
| 73 | #if PARSER_DEBUG > 0 |
---|
| 74 | std::cout << "production ::= production_head SEMICOLON production_tail NEWLINE." << std::endl; |
---|
| 75 | #endif |
---|
| 76 | } |
---|
| 77 | Production *p = lsys->productions[sstringToString(*(A.strValue))]; |
---|
| 78 | for (vector<SString>::iterator paramIter = A.vectorStr->begin(); paramIter != A.vectorStr->end(); paramIter++) { |
---|
| 79 | #if PARSER_DEBUG > 0 |
---|
| 80 | std::cout << "1.1 " << *paramIter << std::endl; |
---|
| 81 | std::cout << *(A.strValue) << " # " << (p == NULL) << " # " << true << std::endl; |
---|
| 82 | #endif |
---|
| 83 | p->parameters.addParameter(*paramIter); |
---|
| 84 | } |
---|
| 85 | p->subproductions = *(B.subproductions); |
---|
| 86 | delete A.strValue; |
---|
| 87 | delete A.vectorStr; |
---|
| 88 | delete B.subproductions; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | production_head(A) ::= prod_name(B) LPAREN prod_params(C) RPAREN. { |
---|
| 93 | if (!syntaxOnly) { |
---|
| 94 | { |
---|
| 95 | #if PARSER_DEBUG > 0 |
---|
| 96 | std::cout << "production_head ::= prod_name LPAREN prod_params RPAREN." << std::endl; |
---|
| 97 | #endif |
---|
| 98 | } |
---|
| 99 | #if PARSER_DEBUG > 0 |
---|
| 100 | std::cout << "---------" << *(B.strValue) << std::endl; |
---|
| 101 | #endif |
---|
| 102 | A.strValue = new SString(*(B.strValue)); |
---|
| 103 | A.vectorStr = new vector<SString>(*(C.vectorStr)); |
---|
| 104 | delete B.strValue; |
---|
| 105 | delete C.vectorStr; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | production_head(A) ::= prod_name(B) LPAREN RPAREN. { |
---|
| 109 | if (!syntaxOnly) { |
---|
| 110 | { |
---|
| 111 | #if PARSER_DEBUG > 0 |
---|
| 112 | std::cout << "production_head ::= prod_name LPAREN RPAREN." << std::endl; |
---|
| 113 | #endif |
---|
| 114 | } |
---|
| 115 | #if PARSER_DEBUG > 0 |
---|
| 116 | std::cout << "---------" << *(B.strValue) << std::endl; |
---|
| 117 | #endif |
---|
| 118 | A.strValue = new SString(*(B.strValue)); |
---|
| 119 | A.vectorStr = new vector<SString>(); |
---|
| 120 | delete B.strValue; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | prod_params(A) ::= param_name(B) COMMA prod_params(C). { |
---|
| 125 | if (!syntaxOnly) { |
---|
| 126 | { |
---|
| 127 | #if PARSER_DEBUG > 0 |
---|
| 128 | std::cout << "prod_params ::= param_name COMMA prod_params." << std::endl; |
---|
| 129 | #endif |
---|
| 130 | } |
---|
| 131 | A.vectorStr = new vector<SString>(); |
---|
| 132 | A.vectorStr->push_back(*(B.strValue)); |
---|
| 133 | for (vector<SString>::iterator iter = C.vectorStr->begin(); iter != C.vectorStr->end(); iter++) { |
---|
| 134 | A.vectorStr->push_back(*iter); |
---|
| 135 | } |
---|
| 136 | delete B.strValue; |
---|
| 137 | delete C.vectorStr; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | prod_params(A) ::= param_name(B). { |
---|
| 141 | if (!syntaxOnly) { |
---|
| 142 | { |
---|
| 143 | #if PARSER_DEBUG > 0 |
---|
| 144 | std::cout << "prod_params ::= param_name." << std::endl; |
---|
| 145 | #endif |
---|
| 146 | } |
---|
| 147 | A.vectorStr = new vector<SString>(); |
---|
| 148 | A.vectorStr->push_back(*(B.strValue)); |
---|
| 149 | delete B.strValue; |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | production_tail(A) ::= subproduction(B) SEMICOLON production_tail(C). { |
---|
| 154 | if (!syntaxOnly) { |
---|
| 155 | { |
---|
| 156 | #if PARSER_DEBUG > 0 |
---|
| 157 | std::cout << "production_tail ::= subproduction SEMICOLON production_tail." << std::endl; |
---|
| 158 | #endif |
---|
| 159 | } |
---|
| 160 | SubProduction sp; |
---|
| 161 | sp.conditions = *(B.vectorConditions); |
---|
| 162 | vector<ActionStrP> actions; |
---|
| 163 | actions.reserve(B.vectorActions->size()); |
---|
| 164 | for (int i = 0; i < B.vectorActions->size() && i < B.parameters->size(); i++) { |
---|
| 165 | ActionStrP ap; |
---|
| 166 | ap.action = (*(B.vectorActions)).at(i); |
---|
| 167 | ap.params = (*(B.parameters)).at(i); |
---|
| 168 | actions.push_back(ap); |
---|
| 169 | } |
---|
| 170 | sp.actions = actions; |
---|
| 171 | A.subproductions = new vector<SubProduction>(); |
---|
| 172 | A.subproductions->push_back(sp); |
---|
| 173 | for (vector<SubProduction>::iterator iter = C.subproductions->begin(); iter != C.subproductions->end(); iter++) { |
---|
| 174 | A.subproductions->push_back(*iter); |
---|
| 175 | } |
---|
| 176 | delete B.vectorConditions; |
---|
| 177 | delete B.vectorActions; |
---|
| 178 | delete B.parameters; |
---|
| 179 | delete C.subproductions; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | production_tail(A) ::= subproduction(B). { |
---|
| 183 | if (!syntaxOnly) { |
---|
| 184 | { |
---|
| 185 | #if PARSER_DEBUG > 0 |
---|
| 186 | std::cout << "production_tail ::= subproduction." << std::endl; |
---|
| 187 | #endif |
---|
| 188 | } |
---|
| 189 | SubProduction sp; |
---|
| 190 | sp.conditions = *(B.vectorConditions); |
---|
| 191 | vector<ActionStrP> actions; |
---|
| 192 | actions.reserve(B.vectorActions->size()); |
---|
| 193 | for (int i = 0; i < B.vectorActions->size() && i < B.parameters->size(); i++) { |
---|
| 194 | ActionStrP ap; |
---|
| 195 | ap.action = (*(B.vectorActions)).at(i); |
---|
| 196 | ap.params = (*(B.parameters)).at(i); |
---|
| 197 | actions.push_back(ap); |
---|
| 198 | } |
---|
| 199 | sp.actions = actions; |
---|
| 200 | A.subproductions = new vector<SubProduction>(); |
---|
| 201 | A.subproductions->push_back(sp); |
---|
| 202 | delete B.vectorConditions; |
---|
| 203 | delete B.vectorActions; |
---|
| 204 | delete B.parameters; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | subproduction(A) ::= conditions(B) PIPE real_prod(C). { |
---|
| 209 | if (!syntaxOnly) { |
---|
| 210 | { |
---|
| 211 | #if PARSER_DEBUG > 0 |
---|
| 212 | std::cout << "subproduction ::= conditions PIPE real_prod." << std::endl; |
---|
| 213 | #endif |
---|
| 214 | } |
---|
| 215 | A.vectorConditions = new vector<Condition>(*(B.vectorConditions)); |
---|
| 216 | A.vectorActions = new vector<Action*>(*(C.vectorActions)); |
---|
| 217 | A.parameters = new vector<vector<SString> >(*(C.parameters)); |
---|
| 218 | delete B.vectorConditions; |
---|
| 219 | delete C.vectorActions; |
---|
| 220 | delete C.parameters; |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | subproduction(A) ::= real_prod(C). { |
---|
| 224 | if (!syntaxOnly) { |
---|
| 225 | { |
---|
| 226 | #if PARSER_DEBUG > 0 |
---|
| 227 | std::cout << "subproduction ::= real_prod." << std::endl; |
---|
| 228 | #endif |
---|
| 229 | } |
---|
| 230 | A.vectorConditions = new vector<Condition>(); |
---|
| 231 | A.vectorActions = new vector<Action*>(*(C.vectorActions)); |
---|
| 232 | A.parameters = new vector<vector<SString> >(*(C.parameters)); |
---|
| 233 | delete C.vectorActions; |
---|
| 234 | delete C.parameters; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | conditions(A) ::= conditions(B) COMMA conditions(C). { |
---|
| 239 | if (!syntaxOnly) { |
---|
| 240 | { |
---|
| 241 | #if PARSER_DEBUG > 0 |
---|
| 242 | std::cout << "conditions ::= condition COMMA conditions." << std::endl; |
---|
| 243 | #endif |
---|
| 244 | } |
---|
| 245 | A.vectorConditions = new vector<Condition>(*(B.vectorConditions)); |
---|
| 246 | for (vector<Condition>::iterator iter = C.vectorConditions->begin(); |
---|
| 247 | iter != C.vectorConditions->end(); iter++) { |
---|
| 248 | A.vectorConditions->push_back(*iter); |
---|
| 249 | } |
---|
| 250 | delete B.vectorConditions; |
---|
| 251 | delete C.vectorConditions; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | conditions(A) ::= condition(B). { |
---|
| 255 | if (!syntaxOnly) { |
---|
| 256 | { |
---|
| 257 | #if PARSER_DEBUG > 0 |
---|
| 258 | std::cout << "conditions ::= condition." << std::endl; |
---|
| 259 | #endif |
---|
| 260 | } |
---|
| 261 | A.vectorConditions = new vector<Condition>(); |
---|
| 262 | A.vectorConditions->push_back(*(B.cond)); |
---|
| 263 | delete B.cond; |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | condition(A) ::= param_name(B) LESS double_val(C). { |
---|
| 268 | if (!syntaxOnly) { |
---|
| 269 | { |
---|
| 270 | #if PARSER_DEBUG > 0 |
---|
| 271 | std::cout << "condition ::= param_name LESS double_val." << std::endl; |
---|
| 272 | #endif |
---|
| 273 | } |
---|
| 274 | A.cond = new Condition(); |
---|
| 275 | A.cond->relation = r_less; |
---|
| 276 | A.cond->parameter = *(B.strValue); |
---|
| 277 | A.cond->value = C.dblValue; |
---|
| 278 | delete B.strValue; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | condition(A) ::= param_name(B) LESS_EQUAL double_val(C). { |
---|
| 282 | if (!syntaxOnly) { |
---|
| 283 | { |
---|
| 284 | #if PARSER_DEBUG > 0 |
---|
| 285 | std::cout << "condition ::= param_name LESS_EQUAL double_val." << std::endl; |
---|
| 286 | #endif |
---|
| 287 | } |
---|
| 288 | A.cond = new Condition(); |
---|
| 289 | A.cond->relation = r_lessEqual; |
---|
| 290 | A.cond->parameter = *(B.strValue); |
---|
| 291 | A.cond->value = C.dblValue; |
---|
| 292 | delete B.strValue; |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | condition(A) ::= param_name(B) NOT_EQUAL double_val(C). { |
---|
| 296 | if (!syntaxOnly) { |
---|
| 297 | { |
---|
| 298 | #if PARSER_DEBUG > 0 |
---|
| 299 | std::cout << "condition ::= param_name NOT_EQUAL double_val." << std::endl; |
---|
| 300 | #endif |
---|
| 301 | } |
---|
| 302 | A.cond = new Condition(); |
---|
| 303 | A.cond->relation = r_different; |
---|
| 304 | A.cond->parameter = *(B.strValue); |
---|
| 305 | A.cond->value = C.dblValue; |
---|
| 306 | delete B.strValue; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | condition(A) ::= param_name(B) EQUAL double_val(C). { |
---|
| 310 | if (!syntaxOnly) { |
---|
| 311 | { |
---|
| 312 | #if PARSER_DEBUG > 0 |
---|
| 313 | std::cout << "condition ::= param_name EQUAL double_val." << std::endl; |
---|
| 314 | #endif |
---|
| 315 | } |
---|
| 316 | A.cond = new Condition(); |
---|
| 317 | A.cond->relation = r_equal; |
---|
| 318 | A.cond->parameter = *(B.strValue); |
---|
| 319 | A.cond->value = C.dblValue; |
---|
| 320 | delete B.strValue; |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | condition(A) ::= param_name(B) GREATER_EQUAL double_val(C). { |
---|
| 324 | if (!syntaxOnly) { |
---|
| 325 | { |
---|
| 326 | #if PARSER_DEBUG > 0 |
---|
| 327 | std::cout << "condition ::= param_name GREATER_EQUAL double_val." << std::endl; |
---|
| 328 | #endif |
---|
| 329 | } |
---|
| 330 | A.cond = new Condition(); |
---|
| 331 | A.cond->relation = r_greaterEqual; |
---|
| 332 | A.cond->parameter = *(B.strValue); |
---|
| 333 | A.cond->value = C.dblValue; |
---|
| 334 | delete B.strValue; |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | condition(A) ::= param_name(B) GREATER double_val(C). { |
---|
| 338 | if (!syntaxOnly) { |
---|
| 339 | { |
---|
| 340 | #if PARSER_DEBUG > 0 |
---|
| 341 | std::cout << "condition ::= param_name GREATER double_val." << std::endl; |
---|
| 342 | #endif |
---|
| 343 | } |
---|
| 344 | A.cond = new Condition(); |
---|
| 345 | A.cond->relation = r_greater; |
---|
| 346 | A.cond->parameter = *(B.strValue); |
---|
| 347 | A.cond->value = C.dblValue; |
---|
| 348 | delete B.strValue; |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | real_prod(A) ::= . { |
---|
| 353 | if (!syntaxOnly) { |
---|
| 354 | { |
---|
| 355 | #if PARSER_DEBUG > 0 |
---|
| 356 | std::cout << "real_prod ::= ." << std::endl; |
---|
| 357 | #endif |
---|
| 358 | } |
---|
| 359 | A.vectorActions = new vector<Action*>(); |
---|
| 360 | A.parameters = new vector<vector<SString> >(); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | real_prod(A) ::= prod_piece(B) real_prod(C). { |
---|
| 364 | if (!syntaxOnly) { |
---|
| 365 | { |
---|
| 366 | #if PARSER_DEBUG > 0 |
---|
| 367 | std::cout << "real_prod ::= prod_piece real_prod." << std::endl; |
---|
| 368 | for (vector<Action*>::iterator actIter = B.actions->begin(); actIter != B.actions->end(); actIter++) { |
---|
| 369 | cout << "\t" << (*actIter)->name << endl; |
---|
| 370 | } |
---|
| 371 | #endif |
---|
| 372 | } |
---|
| 373 | //A = B.clone() && A.append(C) |
---|
| 374 | A.vectorActions = new vector<Action*>(*(B.actions)); |
---|
| 375 | A.parameters = new vector<vector<SString> >(*(B.parameters)); |
---|
| 376 | if (C.vectorActions != NULL && C.parameters != NULL) { |
---|
| 377 | for (vector<Action*>::iterator iter = C.vectorActions->begin(); iter != C.vectorActions->end(); iter++) { |
---|
| 378 | A.vectorActions->push_back(*iter); |
---|
| 379 | } |
---|
| 380 | for(vector<vector<SString> >::iterator iter = C.parameters->begin(); iter != C.parameters->end(); iter++) { |
---|
| 381 | A.parameters->push_back(*iter); |
---|
| 382 | } |
---|
| 383 | delete C.vectorActions; |
---|
| 384 | delete C.parameters; |
---|
| 385 | } else { |
---|
| 386 | #if PARSER_DEBUG > 0 |
---|
| 387 | cout << "\tNULL~~~~~~~~~~~~" << endl; |
---|
| 388 | #endif |
---|
| 389 | } |
---|
| 390 | delete B.actions; |
---|
| 391 | delete B.parameters; |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | real_prod(A) ::= FORLOOP_BEGIN real_prod(B) FORLOOP_END LPAREN single_val(C) RPAREN real_prod(D). { |
---|
| 395 | if (!syntaxOnly) { |
---|
| 396 | { |
---|
| 397 | #if PARSER_DEBUG > 0 |
---|
| 398 | std::cout << "real_prod ::= FORLOOP_BEGIN real_prod FORLOOP_END LPAREN single_val RPAREN." << std::endl; |
---|
| 399 | #endif |
---|
| 400 | } |
---|
| 401 | A.vectorActions = new vector<Action*>(); |
---|
| 402 | A.parameters = new vector<vector<SString> >(); |
---|
| 403 | int iterations = (int) parseExpression(*(C.strValue)); |
---|
| 404 | for (int i = 0; i < iterations; i++) { |
---|
| 405 | for (vector<Action*>::iterator iter = B.vectorActions->begin(); iter != B.vectorActions->end(); iter++) { |
---|
| 406 | A.vectorActions->push_back(*iter); |
---|
| 407 | } |
---|
| 408 | for (vector<vector<SString> >::iterator iter = B.parameters->begin(); iter != B.parameters->end(); iter++) { |
---|
| 409 | A.parameters->push_back(*iter); |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | for (vector<Action*>::iterator iter = D.vectorActions->begin(); iter != D.vectorActions->end(); iter++) { |
---|
| 413 | A.vectorActions->push_back(*iter); |
---|
| 414 | } |
---|
| 415 | for (vector<vector<SString> >::iterator iter = D.parameters->begin(); iter != D.parameters->end(); iter++) { |
---|
| 416 | A.parameters->push_back(*iter); |
---|
| 417 | } |
---|
| 418 | delete B.vectorActions; |
---|
| 419 | delete B.parameters; |
---|
| 420 | delete C.strValue; |
---|
| 421 | delete D.vectorActions; |
---|
| 422 | delete D.parameters; |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | prod_piece(A) ::= prod_name(B) LPAREN multiple_val(C) RPAREN. { |
---|
| 427 | if (!syntaxOnly) { |
---|
| 428 | { |
---|
| 429 | #if PARSER_DEBUG > 0 |
---|
| 430 | std::cout << "prod_piece ::= prod_name LPAREN multiple_val RPAREN." << std::endl; |
---|
| 431 | #endif |
---|
| 432 | } |
---|
| 433 | A.actions = new vector<Action*>(); |
---|
| 434 | A.parameters = new vector<vector<SString> >(); |
---|
| 435 | |
---|
| 436 | Production *p = lsys->productions.find(sstringToString(*(B.strValue)))->second; |
---|
| 437 | A.actions->push_back(p); |
---|
| 438 | A.parameters->push_back(*(C.vectorStr)); |
---|
| 439 | delete B.strValue; |
---|
| 440 | delete C.vectorStr; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | prod_piece(A) ::= prod_name(B) LPAREN RPAREN. { |
---|
| 444 | if (!syntaxOnly) { |
---|
| 445 | { |
---|
| 446 | #if PARSER_DEBUG > 0 |
---|
| 447 | std::cout << "prod_piece ::= prod_name LPAREN RPAREN." << std::endl; |
---|
| 448 | #endif |
---|
| 449 | } |
---|
| 450 | A.actions = new vector<Action*>(); |
---|
| 451 | vector<SString> param; |
---|
| 452 | A.parameters = new vector<vector<SString> >(); |
---|
| 453 | A.parameters->push_back(param); |
---|
| 454 | |
---|
| 455 | Production *p = lsys->productions.find(sstringToString(*(B.strValue)))->second; |
---|
| 456 | A.actions->push_back(p); |
---|
| 457 | delete B.strValue; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | prod_piece(A) ::= command(B). { |
---|
| 461 | if (!syntaxOnly) { |
---|
| 462 | { |
---|
| 463 | #if PARSER_DEBUG > 0 |
---|
| 464 | std::cout << "prod_piece ::= command." << std::endl; |
---|
| 465 | #endif |
---|
| 466 | } |
---|
| 467 | A.actions = new vector<Action*>(); |
---|
| 468 | A.parameters = new vector<vector<SString> >(); |
---|
| 469 | PrimitiveProduction *pp = lsys->getPrimitiveProduction(*(B.strValue)); |
---|
| 470 | A.actions->push_back(pp); |
---|
| 471 | vector<SString> param; |
---|
| 472 | A.parameters->push_back(param); |
---|
| 473 | delete B.strValue; |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | prod_piece(A) ::= param_name(B). { |
---|
| 477 | if (!syntaxOnly) { |
---|
| 478 | { |
---|
| 479 | #if PARSER_DEBUG > 0 |
---|
| 480 | std::cout << "prod_piece ::= paramName." << std::endl; |
---|
| 481 | #endif |
---|
| 482 | } |
---|
| 483 | A.actions = new vector<Action*>(); |
---|
| 484 | A.parameters = new vector<vector<SString> >(); |
---|
| 485 | ParamProduction *pp = lsys->getParamProduction(*(B.strValue)); |
---|
| 486 | A.actions->push_back(pp); |
---|
| 487 | vector<SString> param; |
---|
| 488 | param.push_back(*(B.strValue)); |
---|
| 489 | A.parameters->push_back(param); |
---|
| 490 | delete B.strValue; |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | prod_piece(A) ::= neuron(B). { |
---|
| 494 | if (!syntaxOnly) { |
---|
| 495 | { |
---|
| 496 | #if PARSER_DEBUG > 0 |
---|
| 497 | std::cout << "prod_piece ::= neuron." << std::endl; |
---|
| 498 | #endif |
---|
| 499 | } |
---|
| 500 | A.actions = new vector<Action*>(); |
---|
| 501 | A.parameters = new vector<vector<SString> >(); |
---|
| 502 | NeuronProduction *np = new NeuronProduction(*(B.strValue)); |
---|
| 503 | lsys->neuronProductions.push_back(np); |
---|
| 504 | A.actions->push_back(np); |
---|
| 505 | vector<SString> param; |
---|
| 506 | A.parameters->push_back(param); |
---|
| 507 | delete B.strValue; |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | multiple_val(A) ::= single_val(B). { |
---|
| 512 | if (!syntaxOnly) { |
---|
| 513 | { |
---|
| 514 | #if PARSER_DEBUG > 0 |
---|
| 515 | std::cout << "multiple_val ::= single_val." << std::endl; |
---|
| 516 | #endif |
---|
| 517 | } |
---|
| 518 | A.vectorStr = new vector<SString>(); |
---|
| 519 | A.vectorStr->push_back(SString(*(B.strValue))); |
---|
| 520 | delete B.strValue; |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | multiple_val(A) ::= multiple_val(B) COMMA multiple_val(C). { |
---|
| 524 | if (!syntaxOnly) { |
---|
| 525 | { |
---|
| 526 | #if PARSER_DEBUG > 0 |
---|
| 527 | std::cout << "multiple_val ::= multiple_val COMMA multiple_val." << std::endl; |
---|
| 528 | #endif |
---|
| 529 | } |
---|
| 530 | A.vectorStr = new vector<SString>(); |
---|
| 531 | for (vector<SString>::iterator iter = B.vectorStr->begin(); iter != B.vectorStr->end(); iter++) { |
---|
| 532 | A.vectorStr->push_back(*iter); |
---|
| 533 | } |
---|
| 534 | for (vector<SString>::iterator iter = C.vectorStr->begin(); iter != C.vectorStr->end(); iter++) { |
---|
| 535 | A.vectorStr->push_back(*iter); |
---|
| 536 | } |
---|
| 537 | delete B.vectorStr; |
---|
| 538 | delete C.vectorStr; |
---|
| 539 | } |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | single_val(A) ::= double_val(B). { |
---|
| 543 | if (!syntaxOnly) { |
---|
| 544 | { |
---|
| 545 | #if PARSER_DEBUG > 0 |
---|
| 546 | std::cout << "single_val ::= double_val." << std::endl; |
---|
| 547 | #endif |
---|
| 548 | } |
---|
| 549 | A.strValue = new SString(SString::valueOf(B.dblValue) + ";"); |
---|
| 550 | delete B.strValue; |
---|
| 551 | } |
---|
| 552 | } |
---|
| 553 | single_val(A) ::= param_name(B). { |
---|
| 554 | if (!syntaxOnly) { |
---|
| 555 | { |
---|
| 556 | #if PARSER_DEBUG > 0 |
---|
| 557 | std::cout << "single_val ::= param_name." << std::endl; |
---|
| 558 | #endif |
---|
| 559 | } |
---|
| 560 | A.strValue = new SString(*(B.strValue) + ";"); |
---|
| 561 | delete B.strValue; |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | single_val(A) ::= single_val(B) PLUS single_val(C). { |
---|
| 565 | if (!syntaxOnly) { |
---|
| 566 | { |
---|
| 567 | #if PARSER_DEBUG > 0 |
---|
| 568 | std::cout << "single_val ::= single_val PLUS single_val." << std::endl; |
---|
| 569 | #endif |
---|
| 570 | } |
---|
| 571 | A.strValue = new SString(*(B.strValue) + *(C.strValue) + "+;"); |
---|
| 572 | delete B.strValue; |
---|
| 573 | delete C.strValue; |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | single_val(A) ::= single_val(B) MINUS single_val(C). { |
---|
| 577 | if (!syntaxOnly) { |
---|
| 578 | { |
---|
| 579 | #if PARSER_DEBUG > 0 |
---|
| 580 | std::cout << "single_val ::= single_val MINUS single_val." << std::endl; |
---|
| 581 | #endif |
---|
| 582 | } |
---|
| 583 | A.strValue = new SString(*(B.strValue) + *(C.strValue) + "-;"); |
---|
| 584 | delete B.strValue; |
---|
| 585 | delete C.strValue; |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | single_val(A) ::= single_val(B) TIMES single_val(C). { |
---|
| 589 | if (!syntaxOnly) { |
---|
| 590 | { |
---|
| 591 | #if PARSER_DEBUG > 0 |
---|
| 592 | std::cout << "single_val ::= single_val TIMES single_val." << std::endl; |
---|
| 593 | #endif |
---|
| 594 | } |
---|
| 595 | A.strValue = new SString(*(B.strValue) + *(C.strValue) + "*;"); |
---|
| 596 | delete B.strValue; |
---|
| 597 | delete C.strValue; |
---|
| 598 | } |
---|
| 599 | } |
---|
| 600 | single_val(A) ::= single_val(B) DIV single_val(C). { |
---|
| 601 | if (!syntaxOnly) { |
---|
| 602 | { |
---|
| 603 | #if PARSER_DEBUG > 0 |
---|
| 604 | std::cout << "single_val ::= single_val DIV single_val." << std::endl; |
---|
| 605 | #endif |
---|
| 606 | } |
---|
| 607 | A.strValue = new SString(*(B.strValue) + *(C.strValue) + "/;"); |
---|
| 608 | delete B.strValue; |
---|
| 609 | delete C.strValue; |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | double_val(A) ::= DOUBLE_VAL(B). { |
---|
| 614 | if (!syntaxOnly) { |
---|
| 615 | { |
---|
| 616 | #if PARSER_DEBUG > 0 |
---|
| 617 | std::cout << "double_val ::= DOUBLE_VAL. -> " << (string(B.strArrValue)).c_str() << std::endl; |
---|
| 618 | #endif |
---|
| 619 | } |
---|
| 620 | A.dblValue = atof((string(B.strArrValue)).c_str()); |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | param_name(A) ::= PARAM_NAME(B). { |
---|
| 624 | if (!syntaxOnly) { |
---|
| 625 | { |
---|
| 626 | #if PARSER_DEBUG > 0 |
---|
| 627 | std::cout << "param_name ::= PARAM_NAME. -> " << (string(B.strArrValue)).c_str() << std::endl; |
---|
| 628 | #endif |
---|
| 629 | } |
---|
| 630 | A.strValue = new SString(string(B.strArrValue).c_str()); |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | prod_name(A) ::= PROD_NAME(B). { |
---|
| 634 | if (!syntaxOnly) { |
---|
| 635 | { |
---|
| 636 | #if PARSER_DEBUG > 0 |
---|
| 637 | std::cout << "prod_name ::= PROD_NAME." << std::endl; |
---|
| 638 | #endif |
---|
| 639 | } |
---|
| 640 | A.strValue = new SString(string(B.strArrValue).c_str()); |
---|
| 641 | } |
---|
| 642 | } |
---|
| 643 | command(A) ::= COMMAND(B). { |
---|
| 644 | if (!syntaxOnly) { |
---|
| 645 | { |
---|
| 646 | #if PARSER_DEBUG > 0 |
---|
| 647 | std::cout << "command ::= COMMAND." << std::endl; |
---|
| 648 | #endif |
---|
| 649 | } |
---|
| 650 | A.strValue = new SString(string(B.strArrValue).c_str()); |
---|
| 651 | } |
---|
| 652 | } |
---|
| 653 | neuron(A) ::= NEURON(B). { |
---|
| 654 | if (!syntaxOnly) { |
---|
| 655 | { |
---|
| 656 | #if PARSER_DEBUG > 0 |
---|
| 657 | std::cout << "neuron ::= NEURON." << std::endl; |
---|
| 658 | #endif |
---|
| 659 | } |
---|
| 660 | A.strValue = new SString(string(B.strArrValue).c_str()); |
---|
| 661 | } |
---|
| 662 | } |
---|