361 enum SyntaxTableEntry {
363 NumberVariableOrFunction = 1,
364 UnaryPlusOrMinus = 2,
367 static const int SyntaxTable[19][19] = {
369 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
370 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
371 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1 },
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 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 },
387 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 }
389 enum ActionTableEntry {
390 UnbalancedParentheses = -1,
391 ExpressionCompleted = 0,
392 HigherPrecedenceOperator = 1,
393 SamePrecedenceOperator = 2,
394 CloseProcessedParenthesesOrExpression = 3,
395 LowerPrecedenceOperator = 4
397 static const int ActionTable[17][18] = {
399 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1 },
400 {-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 },
401 { 4, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
402 { 4, 1, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
403 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
404 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
405 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
406 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 },
407 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 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, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 },
410 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 },
411 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 },
412 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 },
413 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 },
414 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 },
415 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4 }
422 pchar pointer = begin;
423 int iWhat, iCur, iPrev = 0, iTop, EVAL_STATUS;
426 op.push(0); pos.push(pointer);
428 if (c ==
'\0') {
EVAL_EXIT( EVAL::WARNING_BLANK_STRING, begin ); }
433 c = (pointer > end) ?
'\0' : *pointer;
434 if (isspace(c))
continue;
436 case '\0': iCur =
ENDL;
break;
437 case '(': iCur =
LBRA;
break;
439 if (*(pointer+1) ==
'|') {
440 pointer++; iCur =
OR;
break;
442 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
445 if (*(pointer+1) ==
'&') {
446 pointer++; iCur =
AND;
break;
448 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
451 if (*(pointer+1) ==
'=') {
452 pointer++; iCur =
EQ;
break;
454 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
457 if (*(pointer+1) ==
'=') {
458 pointer++; iCur =
NE;
break;
460 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
463 if (*(pointer+1) ==
'=') { pointer++; iCur =
GE; }
else { iCur =
GT; }
466 if (*(pointer+1) ==
'=') { pointer++; iCur =
LE; }
else { iCur =
LT; }
468 case '+': iCur =
PLUS;
break;
469 case '-': iCur =
MINUS;
break;
471 if (*(pointer+1) ==
'*') { pointer++; iCur =
POW; }
else{ iCur =
MULT; }
473 case '/': iCur =
DIV;
break;
474 case '^': iCur =
POW;
break;
475 case ')': iCur =
RBRA;
break;
477 if (c ==
'.' || isalnum(c)) {
480 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
486 iWhat = SyntaxTable[iPrev][iCur];
490 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
492 EVAL_STATUS =
operand(pointer, end, value, pointer, dictionary);
493 if (EVAL_STATUS != EVAL::OK) {
EVAL_EXIT( EVAL_STATUS, pointer ); }
509 if (op.size() == 0) {
EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer ); }
511 switch (ActionTable[iTop][iCur]) {
513 if (op.size() > 1) pointer = pos.top();
514 EVAL_EXIT( EVAL::ERROR_UNPAIRED_PARENTHESIS, pointer );
516 if (val.size() == 1) {
520 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
523 op.push(iCur); pos.push(pointer);
526 EVAL_STATUS =
maker(iTop, val);
527 if (EVAL_STATUS != EVAL::OK) {
530 op.top() = iCur; pos.top() = pointer;
536 EVAL_STATUS =
maker(iTop, val);
537 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