-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
35 lines (30 loc) · 868 Bytes
/
main.c
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
#include<string.h>
#include<stdio.h>
#include"modules/parser.h"
#include"modules/lexer.h"
#include"modules/intopost.h"
#include"modules/interpretor.h"
#define INVALID_RESULT 1.22323425442431
int main(){
while(1){
string input;
take_input(input);
if(strcmp(input, "exit") == 0){
break;
}
Tokens* tokens = returnTokens(input);
if(!tokens){
continue;
}
if(!isValidExpression(input))
printf("The expression is mathematically wrong\n");
Tokens* postfix = infixToPostfix(tokens);
char* postfixExpression = returnPostfixExpression(postfix);
double result = evaluatePostfix(postfixExpression);
if(result == INVALID_RESULT){
continue;
}
printf("%.2f\n", result);
}
return 0;
}