-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathparser.h
More file actions
46 lines (41 loc) · 738 Bytes
/
mathparser.h
File metadata and controls
46 lines (41 loc) · 738 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
39
40
41
42
43
44
45
46
#ifndef MATH_PARSER_H
#define MATH_PARSER_H
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
union MathParser;
typedef union MathParser{
int (*parse)(char expr[]);
} MathParser;
char operations(int expr){
switch (expr){
case (int) '+':
return (char) expr;
break;
case (int) '-':
return (char) expr;
break;
case (int) '*':
return (char) expr;
break;
case (int) '/':
return (char) expr;
break;
default:
return 'N';
}
}
int parse(char expr[]){
int len= (int) strlen(expr);
char operators[]="+-*/";
for(int i=0; i<len;i++){
//printf("## %d %c \n",expr[i],expr[i]);
printf("##### %c\n",operations(expr[i]));
}
return 9;
}
MathParser init_parser(){
MathParser mp={parse};
return mp;
}
#endif