#include <stdio.h>
#include <math.h>	/* atof goes silently wrong without this! */
#include "calc_defs.h"
#include "stack.h"
#include "getop.h"

#define MAXOP	100

void main()
{
  int type;
  double op2;
  char s[MAXOP];

  while ((type = getop(s)) != EOF) {
    switch(type) {
      case NUMBER: push(atof(s)); break;
      case '+'   : push(pop()+pop()); break;
      case '*'   : push(pop()*pop()); break;
      case '-'   : op2 = pop(); push(pop()-op2); break;
      case '/'   : op2 = pop();
                   if (op2 != 0.0) {
                     push(pop()/op2);
                   } else {
                     printf("error: zero divisor\n");
                   }/*endif*/
                   break;
      case '\n'  : printf("\t%.30g\n", pop()); break;
      default    : printf("error: unknown command %s\n", s); break;
    }/*endswitch*/
  }/*endwhile*/
  exit(0);
}
