-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.hpp
44 lines (38 loc) · 1.07 KB
/
eval.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <string>
#include <vector>
#include <iostream>
struct ParseException : public std::exception {
const char * what () const throw () {
return "Parsing exception";
}
};
//---------------------------------[Class and Struct declarations]----------------------------------
struct Token{
Token(std::string t, std::string v):type(t), value(v){}
Token():type("null"), value(""){}
std::string type;
std::string value;
};
class TokenStack{
public:
TokenStack();
TokenStack(const TokenStack&);
TokenStack& operator=(const TokenStack&);
friend std::ostream& operator<< (std::ostream&, const TokenStack&);
~TokenStack();
void push(Token);
Token pop();
Token peek();
size_t size();
bool is_empty();
bool not_empty();
private:
size_t capacity = 1024;
Token* data;
size_t numTokens;
int top;
};
std::vector<Token> tokenize(const std::string&);
TokenStack infix_to_postfix(std::vector<Token> list);
double evaluate(std::string);