-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.cpp
63 lines (52 loc) · 1.19 KB
/
main.cpp
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
#include "FormulaParser.h"
#include <string>
#include <iostream>
using std::cout;
using std::endl;
using std::string;
using ExcelFormula::Token;
using ExcelFormula::FormulaParser;
void printIndent(int i)
{
for(int j = 0; j < i; ++j)
{
cout << "|";
}
}
void printParser(FormulaParser& parser)
{
vector<Token*> tokens = parser.getTokens();
cout << "Formula:" << parser.getFormula() << endl;
cout << "Tokens:" << endl;
int indent = 0;
for(vector<Token*>::iterator it = tokens.begin();
it != tokens.end();
++it)
{
if((*it)->getSubtype() == Token::Start)
{
++indent;
}
printIndent(indent);
cout << (*it)->getPrintableString() << endl;
if((*it)->getSubtype() == Token::Stop)
{
--indent;
}
}
cout << endl;
}
int main(int argc, char* argv[])
{
const char szFormula1[] = "=1+3+5";
FormulaParser parser1(szFormula1);
parser1.parserToToken1();
parser1.parserToToken2();
printParser(parser1);
const char szFormula2[] = "=IF(R13C3>DATE(2002,1,6),0,IF(ISERROR(R[41]C[2]),0,IF(R13C3>=R[41]C[2],0, IF(AND(R[23]C[11]>=55,R[24]C[11]>=20),R53C3,0))))";
FormulaParser parser2(szFormula2);
parser2.parserToToken1();
parser2.parserToToken2();
printParser(parser2);
return 0;
}