/*******************************************
* file: stack_cal.cpp
* author: ideawu
* date: 2006-11-17
*******************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum{
Token_Error = 0,
Token_Int = ''i'',
Token_Div = ''/'',
Token_Mul = ''*'',
Token_Sub = ''-'',
Token_Add = ''+'',
Token_Mod = ''%'',
Token_Lp = ''('',
Token_Rp = '')''
}TokenType;
class Token{
public:
int type;
double value;
Token(){
type = Token_Error;
value = 0;
}
};
class ArrayStack{
private:
char * name;
Token *tokens;
int size;
int capacity;
public:
ArrayStack(char* n){
name = n;
size = 0;
capacity = 256;
tokens = new Token[capacity];
}
~ArrayStack(){
delete tokens;
}
int getSize(){
return size;
}
bool isEmpty(){
return (size == 0);
}
bool isFull(){
return (size == capacity);
}
void push(Token token){
if(size < capacity){
tokens[size ++] = token;
}else{
}
}
Token* pop(){
if(size > 0){
size --;
return &tokens[size];
}else{
return NULL;
}
}
Token* peek(){
if(size > 0){
return &tokens[size-1];
}else{
return NULL;
}
}
void toString(){
if(size == 0){
&nb