Changeset 2305 in Sophya for trunk/SophyaPI/PIext/piacmd.cc


Ignore:
Timestamp:
Jan 8, 2003, 6:18:56 PM (23 years ago)
Author:
ansari
Message:

Correction bug ds PIACmd::SubstituteVar(), ajout commandes line2vec line2nt vec2var ... - Reza 08/01/2003

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/piacmd.cc

    r2298 r2305  
    417417cmdhgrp["All"] = 0;
    418418cmdgrpid = 1;
    419 cmdhgrp["Commands"] = 1;
     419cmdhgrp["PIACmd"] = 1;
    420420helpwin = new PIAHelpWind(app, this);
    421421helpwin->AddHelpGroup("All", 0);
    422 helpwin->AddHelpGroup("Commands", 1);
    423 
    424 string kw = "piacmd";
     422helpwin->AddHelpGroup("PIACmd", 1);
     423
     424string kw = "Interpreter";
    425425string usage;
    426426usage = ">>> (piacmd) Interpreter's keywords : \n";
     
    430430usage += "  > unset varname          # clear variable definition \n";
    431431usage += "  > rpneval varname RPNExpression # Reverse Polish Notation evaluation \n";
     432usage += "  > varname = 'string string ...' # To set a variable, $varname  \n";
     433usage += "  > varname = RPNExpression # RPN evaluation / result -> varname \n";
    432434usage += "  > echo string            # output string \n";
    433435usage += "  > echo2file filename string # Append the string to the specified file \n";
     
    453455usage += "  > helpwindow           # Displays help window \n";
    454456usage += "  > timingon  timingoff traceon  traceoff \n";
    455 string grp = "Commands";
     457string grp = "PIACmd";
     458RegisterHelp(kw, usage, grp);
     459
     460kw = "RPNEvaluator";
     461usage = " Reverse Polish Notation (HP calculator like) expression evaluation \n";
     462usage += "  >> Stack: \n";
     463usage += "     ... (4) (3) z=(2) y=(1) x=(0)=Stack.Top() \n";
     464usage += "  >> Examples:  \n";
     465usage += "  - sin(PI/6): pi 6 / sin \n";
     466usage += "  - 1*2*...*5: 1 2 3 4 5 product \n";
     467usage += "  - x = $x $y * \n";
     468usage += "  >>> Stack operations : \n";
     469usage += "      print x<>y pop push (duplicate x) \n";
     470usage += "  >>> Constants (Cst pushed to stack): \n";
     471usage += "      pi e \n";
     472usage += "  >>> Arithmetic operators (x,y) --> x@y \n";
     473usage += "      + - * / % ( (int)y % (int)x )\n";
     474usage += "  >>> F(X): x --> F(x) \n";
     475usage += "      chs sqrt sq log log10 exp  \n";
     476usage += "      fabs  floor ceil nint trunc  \n";
     477usage += "      cos sin tan acos asin atan deg2rad rad2deg \n";
     478usage += "  >>> F(X,Y): (x,y) --> F(x,y) \n";
     479usage += "      pow atan2 \n";
     480usage += "  >>> Stack sum/product/mean/sigma/sigma^2 \n";
     481usage += "      sum product mean sigma sigma2 sigmean (y->sigma x->mean) \n";
    456482RegisterHelp(kw, usage, grp);
    457483
     
    459485usage  = "> shell  command_string  # Execute  shell command\n";
    460486usage += "> cshell command_string  # Execute cshell command\n";
    461 usage += "---Exemples:\n";
     487usage += "---Examples:\n";
    462488usage += "  > shell ls\n";
    463489usage += "  > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n";
     
    858884
    859885rcs = SubstituteVars(s, s2);
    860 if (rcs) return(rcs);
    861 
     886if (rcs) {
     887  cerr << "PIACmd::Interpret()/syntax error in SubstituteVars() \n"
     888       << "line: " << s << endl;
     889  return(rcs);
     890}
    862891// >>>> Separating keyword and tokens
    863892vector<string> tokens;
     
    885914  int rct = EvaluateTest(tokens, s, restst);
    886915  if (rct) {
    887     cerr << "PIACmd::Interpret() if syntax Error ! " << endl;
     916    cerr << "PIACmd::Interpret() if syntax Error ! " << "line: " << s << endl;
    888917    return(1);
    889918  }
     
    900929  int rcev = EvalRPNExpr(tokens, s);
    901930  if (rcev) {
    902     cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << endl;
     931    cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << "line: " << s << endl;
    903932    return(1);
    904933  }
     
    913942  }
    914943  else {
    915     cerr << "PIACmd::Interpret() No script name in defscript" << endl;
     944    cerr << "PIACmd::Interpret() No script name in defscript" << "line: " << s << endl;
    916945    return(1);
    917946  }
     
    9931022string vn, vv;
    9941023while (p < l) {
     1024  iarr = -1;
    9951025  q = s.find('$',p);
    9961026  if (q > l) break;
     
    12811311      rpnstack.top() = y/x;
    12821312    }
     1313    else if (args[k] == "%") {
     1314      if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
     1315      rpnstack.top() = (int)y % (int)x;
     1316    }
    12831317    // Les constantes : e , pi
    12841318    else if (args[k] == "e") {
     
    13131347      rpnstack.top() = atan(x);
    13141348    }
     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    }
    13151361    else if (args[k] == "log") {
    13161362      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
     
    13291375      rpnstack.top() = fabs(x);
    13301376    }
    1331     else if (args[k] == "chs") {
     1377    else if (args[k] == "floor") {
    13321378      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);
    13341392    }
    13351393    else if (args[k] == "deg2rad") {
     
    13511409    }
    13521410    // 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") ||
    13541412             (args[k] == "sigma") || (args[k] == "sigma2") ) {
    13551413      double sx, sx2;
     
    13631421        }
    13641422        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)));
    13681427      }
    13691428    }
     
    13851444      if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
    13861445      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());
    13871453    }
    13881454    // On met un nombre sur le stack
Note: See TracChangeset for help on using the changeset viewer.