-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (32 loc) · 975 Bytes
/
main.cpp
File metadata and controls
38 lines (32 loc) · 975 Bytes
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
#include <iostream>
#include <string>
#include <validation.h>
#include <basic.h>
/* codeblocks
#include "validation.h"
#include "basic.h"
*/
int defaultCharPosition=0;
double parse(const std::string& expression, int &charPosition=defaultCharPosition){
std::string nestedExpression;
for (; charPosition<expression.size(); charPosition++){
if(expression[charPosition] == '('){
charPosition++;
nestedExpression += std::to_string(parse(expression, charPosition));
}
else if(expression[charPosition] == ')') return basicParse(nestedExpression);
else nestedExpression += expression[charPosition];
}
charPosition=0;
return basicParse(nestedExpression);
}
int main() {
std::string expression;
std::cout << "Wpisz dzialanie\n";
while (std::getline(std::cin, expression)){
if(validate(expression)){
std::cout << parse(expression) << "\n";
}
}
return 0;
}