Robert. It is not my intention to sound rude, but several
people have already told you in past replies that
"Std_lib_facilities.h" is not part of standard C++. If you
do not intend to read and understand the replies people are
providing then you have more serious problems than code
that will not compile.


--- Robert Ryan <[EMAIL PROTECTED]> wrote:

> you will have to explain that to me. what do you use if
> not "Std_lib_facilities.h" do you use
> <iostream.h>.......since I am new to this .......this is
> what was given with the code........
>   thanks
> 
> "Victor A. Wagner Jr." <[EMAIL PROTECTED]> wrote:
>           At 17:17 2007-02-19, Robert Ryan wrote:
>   I got it solved after a lot of confusion.   
>  
> #include "std_lib_facilities.h"
> you realize that this is a non-standard include file.....
> the rest of us don't have it
> 
> 
>   class Token {
> public:
>  char kind;   // what kind of token
>  double value;   // for numbers: a value 
>  Token(char ch) :kind(ch), value(0) { }
>  Token(char ch, double val) :kind(ch), value(val) { }
> };
> 
> class Token_stream {
>  bool full;   // is there a Token in the buffer
>  Token buffer; // here is where we keep a Token put back
> using unget()
> public:
>  Token get();   // get a Token (get() is defined
> elsewhere)
>  void unget(Token t); // put a Token back
>  Token_stream();   // make a Token_stream that reads from
> cin
> };
> 
> void Token_stream::unget(Token t) // unget takes one
> argument
>  {
>   buffer = t;  // copy t to buffer
>   full = true; // buffer is now full
>  }
> Token_stream::Token_stream()
>   :full(false), buffer(0) // no Token in buffer
>  {
>  }
> Token Token_stream::get()
> {
>  if (full) {  // check if we already have a Token ready
>   full=false;
>   return buffer;
>  }
>  char ch;
>  cin >> ch; // note that >> skips whitespace (space,
> newline, tab, etc.)
>  switch (ch) {
>  case '=': // print
>  case 'x': // quit/exit
>  case '%': 
>  case '(': case ')': case '+': case '-': case '*': case
> '/': 
>   return Token(ch);  // let each character represent
> itself
>  case '.':
>  case '0': case '1': case '2': case '3': case '4': case
> '5': case '6': case '7': case '8': case '9':
>  { cin.unget();  // put digit back into the input stream
>   double val;
>   cin >> val;   // read a floating-point number  
>   return Token('8',val); // let ‘8’ represent “a number”
>  }
>  default:
>   error("Bad token");
>    // XXX
>  } // add (
> }
> 
> Token_stream ts;  // provides get() and unget() 
> double expression();  // declaration so that primary()
> can call expression()
> double primary()
> {
>  Token t = ts.get();
>  switch (t.kind) { 
>  case '(': // handle ‘(‘ expression ‘)’
>   { double d = expression();
>    t = ts.get();
>    if (t.kind != ')')  error("'(' expected");
>    return d;
>   }
>  case '8':  // we use '8' to represent a number
>   return t.value; // return the number’s value
>  default:
>   error("primary expected");
>  }
> }
> double term()
> {
>  double left = primary();
>  Token t = ts.get();
>  switch (t.kind) {
>  case '*':
>    return left *term();
>  case '/':
>   { double d = term();
>    if (d == 0) error("divide by zero");
>    return left / d;
>   }
>  case '%':
>   { int i1 = int(left);
>    int i2 = int(term());
>    return i1%i2;
>   }
>  default:
>   ts.unget(t);
>   return left;
>  }
> }
> double expression()
> {
>  double left = term(); // read and evaluate a Term
>  Token t = ts.get();  // get the next token
>  switch (t.kind) {  // see which kind of token that is
>  case '+':
>   return left + expression(); // read and evaluate an
> Expression,
>          // then do an add
>  case '-':
>   return left - expression(); // read and evaluate an
> Expression,
>          // then do a subtraction
>  default:
>    ts.unget(t);
>   return left;  // return the value of the Term
>  }
> }
> 
> int main()
> try
> {
>  //while (cin) cout << expression() << '\n'; // version 0
>  cout <<"Welcome to our simple calculator\n";
>  cout << "Please enter-expression using floating-point
> expression\n";
>  cout << "type = to print and x to exit\n";
>  
>  double val=  0; // version 1
>  while (cin) {
>   Token t = ts.get();
>   if (t.kind == 'x') break;
>   if (t.kind == '=') 
>    cout << val << '\n';
>   else {
>    ts.unget(t);
>    val = expression();}
>  }
>  /*
>  double val = 0; // version 2
>  while (cin) {
>   cout << "> ";
>   Token t = ts.get();
>   while (t.kind == ';') t=ts.get(); // eat ';'
>   if (t.kind == 'q') {
>    keep_window_open();
>    return 0;
>   }
>   ts.unget(t);
>   cout << "= " << expression() << endl;
>  }
>  */
>  keep_window_open();
>  return 0;
> }
> catch (runtime_error& e) {
>  cerr << e.what() << endl;
>  keep_window_open("~~");
>  return 1;
> }
> catch (...) {
>  cerr << "exception \n";
>  keep_window_open("~~");
>  return 2;
> }
> 
> 
> "Victor A. Wagner Jr." <[EMAIL PROTECTED]> wrote:
>     
>    At 15:06 2007-02-19, Robert Ryan wrote:
>     
>    does anyone have an idea
>   
>    
>    
>    /* "be-bugged" calculator: many syntax and type
> errors, just three logic 
>   
>    errors (we hope).
>   
>    Our aim waw to be "medium devious"; that is, to
> provide errors that 
>   
>    are not impossible to find, easy to fix once found,
> but 
=== message truncated ===


_________________
Joseph A. Marrero
http://www.l33tprogrammer.com/


 
____________________________________________________________________________________
Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

Reply via email to