Changeset 2305 in Sophya for trunk/SophyaPI/PIext/piacmd.cc
- Timestamp:
- Jan 8, 2003, 6:18:56 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r2298 r2305 417 417 cmdhgrp["All"] = 0; 418 418 cmdgrpid = 1; 419 cmdhgrp[" Commands"] = 1;419 cmdhgrp["PIACmd"] = 1; 420 420 helpwin = new PIAHelpWind(app, this); 421 421 helpwin->AddHelpGroup("All", 0); 422 helpwin->AddHelpGroup(" Commands", 1);423 424 string kw = " piacmd";422 helpwin->AddHelpGroup("PIACmd", 1); 423 424 string kw = "Interpreter"; 425 425 string usage; 426 426 usage = ">>> (piacmd) Interpreter's keywords : \n"; … … 430 430 usage += " > unset varname # clear variable definition \n"; 431 431 usage += " > rpneval varname RPNExpression # Reverse Polish Notation evaluation \n"; 432 usage += " > varname = 'string string ...' # To set a variable, $varname \n"; 433 usage += " > varname = RPNExpression # RPN evaluation / result -> varname \n"; 432 434 usage += " > echo string # output string \n"; 433 435 usage += " > echo2file filename string # Append the string to the specified file \n"; … … 453 455 usage += " > helpwindow # Displays help window \n"; 454 456 usage += " > timingon timingoff traceon traceoff \n"; 455 string grp = "Commands"; 457 string grp = "PIACmd"; 458 RegisterHelp(kw, usage, grp); 459 460 kw = "RPNEvaluator"; 461 usage = " Reverse Polish Notation (HP calculator like) expression evaluation \n"; 462 usage += " >> Stack: \n"; 463 usage += " ... (4) (3) z=(2) y=(1) x=(0)=Stack.Top() \n"; 464 usage += " >> Examples: \n"; 465 usage += " - sin(PI/6): pi 6 / sin \n"; 466 usage += " - 1*2*...*5: 1 2 3 4 5 product \n"; 467 usage += " - x = $x $y * \n"; 468 usage += " >>> Stack operations : \n"; 469 usage += " print x<>y pop push (duplicate x) \n"; 470 usage += " >>> Constants (Cst pushed to stack): \n"; 471 usage += " pi e \n"; 472 usage += " >>> Arithmetic operators (x,y) --> x@y \n"; 473 usage += " + - * / % ( (int)y % (int)x )\n"; 474 usage += " >>> F(X): x --> F(x) \n"; 475 usage += " chs sqrt sq log log10 exp \n"; 476 usage += " fabs floor ceil nint trunc \n"; 477 usage += " cos sin tan acos asin atan deg2rad rad2deg \n"; 478 usage += " >>> F(X,Y): (x,y) --> F(x,y) \n"; 479 usage += " pow atan2 \n"; 480 usage += " >>> Stack sum/product/mean/sigma/sigma^2 \n"; 481 usage += " sum product mean sigma sigma2 sigmean (y->sigma x->mean) \n"; 456 482 RegisterHelp(kw, usage, grp); 457 483 … … 459 485 usage = "> shell command_string # Execute shell command\n"; 460 486 usage += "> cshell command_string # Execute cshell command\n"; 461 usage += "---Ex emples:\n";487 usage += "---Examples:\n"; 462 488 usage += " > shell ls\n"; 463 489 usage += " > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n"; … … 858 884 859 885 rcs = SubstituteVars(s, s2); 860 if (rcs) return(rcs); 861 886 if (rcs) { 887 cerr << "PIACmd::Interpret()/syntax error in SubstituteVars() \n" 888 << "line: " << s << endl; 889 return(rcs); 890 } 862 891 // >>>> Separating keyword and tokens 863 892 vector<string> tokens; … … 885 914 int rct = EvaluateTest(tokens, s, restst); 886 915 if (rct) { 887 cerr << "PIACmd::Interpret() if syntax Error ! " << endl;916 cerr << "PIACmd::Interpret() if syntax Error ! " << "line: " << s << endl; 888 917 return(1); 889 918 } … … 900 929 int rcev = EvalRPNExpr(tokens, s); 901 930 if (rcev) { 902 cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << endl;931 cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << "line: " << s << endl; 903 932 return(1); 904 933 } … … 913 942 } 914 943 else { 915 cerr << "PIACmd::Interpret() No script name in defscript" << endl;944 cerr << "PIACmd::Interpret() No script name in defscript" << "line: " << s << endl; 916 945 return(1); 917 946 } … … 993 1022 string vn, vv; 994 1023 while (p < l) { 1024 iarr = -1; 995 1025 q = s.find('$',p); 996 1026 if (q > l) break; … … 1281 1311 rpnstack.top() = y/x; 1282 1312 } 1313 else if (args[k] == "%") { 1314 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1); 1315 rpnstack.top() = (int)y % (int)x; 1316 } 1283 1317 // Les constantes : e , pi 1284 1318 else if (args[k] == "e") { … … 1313 1347 rpnstack.top() = atan(x); 1314 1348 } 1349 else if (args[k] == "chs") { 1350 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1351 rpnstack.top() = -x; 1352 } 1353 else if (args[k] == "sqrt") { 1354 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1355 rpnstack.top() = sqrt(x); 1356 } 1357 else if (args[k] == "sq") { // x^2 1358 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1359 rpnstack.top() = x*x; 1360 } 1315 1361 else if (args[k] == "log") { 1316 1362 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); … … 1329 1375 rpnstack.top() = fabs(x); 1330 1376 } 1331 else if (args[k] == " chs") {1377 else if (args[k] == "floor") { 1332 1378 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1333 rpnstack.top() = -x; 1379 rpnstack.top() = floor(x); 1380 } 1381 else if (args[k] == "ceil") { 1382 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1383 rpnstack.top() = ceil(x); 1384 } 1385 else if (args[k] == "nint") { 1386 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1387 rpnstack.top() = nint(x); 1388 } 1389 else if (args[k] == "trunc") { 1390 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1); 1391 rpnstack.top() = trunc(x); 1334 1392 } 1335 1393 else if (args[k] == "deg2rad") { … … 1351 1409 } 1352 1410 // Fonction a N arguments - Somme, produit, etc ... 1353 else if ((args[k] == "sum") || (args[k] == "mean") || 1411 else if ((args[k] == "sum") || (args[k] == "mean") || (args[k] == "sigmean") || 1354 1412 (args[k] == "sigma") || (args[k] == "sigma2") ) { 1355 1413 double sx, sx2; … … 1363 1421 } 1364 1422 double fnn = nn; 1365 if (args[k] == "mean") rpnstack.push(sx/fnn); 1366 else if (args[k] == "sigma2") rpnstack.push(sx2/fnn-(x*x/(fnn*fnn))); 1367 else rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn)))); 1423 if ((args[k] == "sigma") || (args[k] == "sigmean")) 1424 rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn)))); 1425 else if ((args[k] == "mean") || (args[k] == "sigmean")) rpnstack.push(sx/fnn); 1426 else rpnstack.push(sx2/fnn-(x*x/(fnn*fnn))); 1368 1427 } 1369 1428 } … … 1385 1444 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1); 1386 1445 rpnstack.top() = x; rpnstack.push(y); 1446 } 1447 else if (args[k] == "pop") { 1448 rpnstack.pop(); 1449 } 1450 else if (args[k] == "push") { 1451 if (rpnstack.empty()) rpnstack.push(0.); 1452 else rpnstack.push(rpnstack.top()); 1387 1453 } 1388 1454 // On met un nombre sur le stack
Note:
See TracChangeset
for help on using the changeset viewer.