-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbet_driver.cpp
More file actions
93 lines (72 loc) · 2.17 KB
/
Copy pathbet_driver.cpp
File metadata and controls
93 lines (72 loc) · 2.17 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <list>
#include <iostream>
#include "opnum.h"
#include "token.h"
#include "bet.h"
using namespace std;
/* This function uses the interface from opnum.h.
* It extracts tokens from one line of input, and inserts
* them to a list. If there are some incorrect token,
* it reports the total number accordingly. */
int get_postfix(std::list<Token> & postfix, int * ret)
{
int num = 0;
int retval = 0;
do {
char * opnum = get_opnum(&retval);
if (retval) {
string str = opnum;
Token nt (str, retval);
if (retval >= SYM_INVAL) {
cout<< opnum << endl;
num ++;
} else if (retval < SYM_ENDLN) {
postfix.push_back(nt);
}
}
} while (retval > SYM_NULL && retval != SYM_ENDLN);
*ret = retval;
return num;
}
int main(int argc, char ** argv)
{
int ret = 0;
std::list<Token> postfix;
set_input(argc, argv);
do {
int num = get_postfix(postfix, &ret);
if (num) {
cout << num << " incorrect tokens found. "<<endl << postfix <<endl;
postfix.clear();
break;
}
if (!postfix.empty()) {
BET<Token> bet;
bool correct = bet.buildFromPostfix(postfix);
if (!correct) {
cout << "Incorrect construction from postfix ...\n" << endl;
} else if (!bet.empty()) {
cout << "Postfix expression: ";
bet.printPostfixExpression();
cout << "Infix expression: ";
bet.printInfixExpression();
cout << "Number of nodes: ";
cout << bet.size() << endl;
cout << "Number of leaf nodes: ";
cout << bet.leaf_nodes() << endl;
//test copy constructor
BET<Token> bet2(bet);
cout << "Testing copy constructor: ";
bet2.printInfixExpression();
//test assignment operator
BET<Token> bet3;
bet3 = bet;
cout << "Testing assignment operator: ";
bet3.printInfixExpression();
}
cout << "Terminating one line ... ...\n" << endl;
postfix.clear();
}
} while (ret > SYM_NULL);
return 0;
}