364 enum SyntaxTableEntry {
366 NumberVariableOrFunction = 1,
367 UnaryPlusOrMinus = 2,
370 static const int SyntaxTable[19][19] = {
372 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
373 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
374 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
375 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
376 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
377 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
378 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
379 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
380 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
381 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
382 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
383 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
384 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
385 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
386 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
387 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
388 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
389 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 },
390 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 }
392 enum ActionTableEntry {
393 UnbalancedParentheses = -1,
394 ExpressionCompleted = 0,
395 HigherPrecedenceOperator = 1,
396 SamePrecedenceOperator = 2,
397 CloseProcessedParenthesesOrExpression = 3,
398 LowerPrecedenceOperator = 4
400 static const int ActionTable[17][18] = {
402 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1 },
403 {-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 },
404 { 4, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
405 { 4, 1, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
406 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
407 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
408 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
409 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
410 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
411 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
412 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 },
413 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 },
414 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 },
415 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 },
416 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 },
417 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 },
418 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4 }
425 pchar pointer = begin;
426 int iWhat, iCur, iPrev = 0, iTop, EVAL_STATUS;
429 op.push(0); pos.push(pointer);
431 if (c ==
'\0') {
EVAL_EXIT( EVAL::WARNING_BLANK_STRING, begin ); }
436 c = (pointer > end) ?
'\0' : *pointer;
437 if (isspace(c))
continue;
439 case '\0': iCur =
ENDL;
break;
440 case '(': iCur =
LBRA;
break;
442 if (*(pointer+1) ==
'|') {
443 pointer++; iCur =
OR;
break;
445 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
448 if (*(pointer+1) ==
'&') {
449 pointer++; iCur =
AND;
break;
451 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
454 if (*(pointer+1) ==
'=') {
455 pointer++; iCur =
EQ;
break;
457 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
460 if (*(pointer+1) ==
'=') {
461 pointer++; iCur =
NE;
break;
463 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
466 if (*(pointer+1) ==
'=') { pointer++; iCur =
GE; }
else { iCur =
GT; }
469 if (*(pointer+1) ==
'=') { pointer++; iCur =
LE; }
else { iCur =
LT; }
471 case '+': iCur =
PLUS;
break;
472 case '-': iCur =
MINUS;
break;
474 if (*(pointer+1) ==
'*') { pointer++; iCur =
POW; }
else{ iCur =
MULT; }
476 case '/': iCur =
DIV;
break;
477 case '^': iCur =
POW;
break;
478 case ')': iCur =
RBRA;
break;
480 if (c ==
'.' || isalnum(c)) {
483 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
489 iWhat = SyntaxTable[iPrev][iCur];
493 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
495 EVAL_STATUS =
operand(pointer, end, value, pointer, dictionary);
496 if (EVAL_STATUS != EVAL::OK) {
EVAL_EXIT( EVAL_STATUS, pointer ); }
512 if (op.size() == 0) {
EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer ); }
514 switch (ActionTable[iTop][iCur]) {
516 if (op.size() > 1) pointer = pos.top();
517 EVAL_EXIT( EVAL::ERROR_UNPAIRED_PARENTHESIS, pointer );
519 if (val.size() == 1) {
523 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
526 op.push(iCur); pos.push(pointer);
529 EVAL_STATUS =
maker(iTop, val);
530 if (EVAL_STATUS != EVAL::OK) {
533 op.top() = iCur; pos.top() = pointer;
539 EVAL_STATUS =
maker(iTop, val);
540 if (EVAL_STATUS != EVAL::OK) {
G4double G4ParticleHPJENDLHEData::G4double result
static int operand(pchar begin, pchar end, double &result, pchar &endp, const dic_type &dictionary)
static int maker(int op, stack< double > &val)
const XML_Char int const XML_Char * value
#define EVAL_EXIT(STATUS, POSITION)
static const G4double pos